Open CASCADE Technology  7.7.0
Public Member Functions | Static Public Member Functions | Protected Attributes
Wasm_Window Class Reference

This class defines WebAssembly window (HTML5 canvas) intended for creation of OpenGL (WebGL) context. More...

#include <Wasm_Window.hxx>

Inheritance diagram for Wasm_Window:
Inheritance graph
[legend]

Public Member Functions

 Wasm_Window (const TCollection_AsciiString &theCanvasId, const bool theToScaleBacking=true)
 Wraps existing HTML5 canvas into window. More...
 
virtual ~Wasm_Window ()
 Destroys the window. More...
 
virtual Standard_Boolean IsMapped () const override
 Return true if window is not hidden. More...
 
virtual void Map () const override
 Change window mapped flag to TRUE. More...
 
virtual void Unmap () const override
 Change window mapped flag to FALSE. More...
 
virtual Aspect_TypeOfResize DoResize () override
 Resize window. In case of ToScaleBacking flag, this method will resize the backing store of canvas basing on DevicePixelRatio() scale factor and CSS canvas size. More...
 
virtual Standard_Boolean DoMapping () const override
 Apply the mapping change to the window. More...
 
virtual Standard_Real Ratio () const override
 Returns window ratio equal to the physical width/height dimensions. More...
 
virtual void Position (Standard_Integer &theX1, Standard_Integer &theY1, Standard_Integer &theX2, Standard_Integer &theY2) const override
 Returns The Window POSITION in PIXEL. More...
 
virtual void Size (Standard_Integer &theWidth, Standard_Integer &theHeight) const override
 Return the window size in pixels. More...
 
void SetSizeLogical (const Graphic3d_Vec2d &theSize)
 Set new window size in logical (density-independent units). Backing store will be resized basing on DevicePixelRatio(). More...
 
void SetSizeBacking (const Graphic3d_Vec2i &theSize)
 Set new window size in pixels. Logical size of the element will be resized basing on DevicePixelRatio(). More...
 
const TCollection_AsciiStringCanvasId () const
 Returns canvas id. More...
 
virtual Aspect_Drawable NativeHandle () const override
 Current EGL implementation in Emscripten accepts only 0 for native window id. More...
 
virtual Aspect_Drawable NativeParentHandle () const override
 Always returns 0 for this class. More...
 
virtual Aspect_FBConfig NativeFBConfig () const override
 Always returns 0 for this class. More...
 
virtual Standard_Real DevicePixelRatio () const override
 Return device pixel ratio (logical to backing store scale factor). More...
 
void SetDevicePixelRatio (Standard_Real theDevicePixelRatio)
 Sets device pixel ratio for a window with IsVirtual() flag. More...
 
virtual void InvalidateContent (const Handle< Aspect_DisplayConnection > &theDisp) override
 Invalidate entire window content through generation of Expose event. More...
 
virtual bool ProcessMessage (Aspect_WindowInputListener &theListener, int theEventType, const void *theEvent)
 Process a single window message. More...
 
virtual bool ProcessMouseEvent (Aspect_WindowInputListener &theListener, int theEventType, const EmscriptenMouseEvent *theEvent)
 Process a mouse input message. More...
 
virtual bool ProcessWheelEvent (Aspect_WindowInputListener &theListener, int theEventType, const EmscriptenWheelEvent *theEvent)
 Process a (mouse) wheel input message. More...
 
virtual bool ProcessTouchEvent (Aspect_WindowInputListener &theListener, int theEventType, const EmscriptenTouchEvent *theEvent)
 Process a mouse input message. More...
 
virtual bool ProcessKeyEvent (Aspect_WindowInputListener &theListener, int theEventType, const EmscriptenKeyboardEvent *theEvent)
 Process a keyboard input message. More...
 
virtual bool ProcessUiEvent (Aspect_WindowInputListener &theListener, int theEventType, const EmscriptenUiEvent *theEvent)
 Process a UI input message (like window resize). More...
 
virtual bool ProcessFocusEvent (Aspect_WindowInputListener &theListener, int theEventType, const EmscriptenFocusEvent *theEvent)
 Process a focus input change message. More...
 
- Public Member Functions inherited from Aspect_Window
Standard_Boolean IsVirtual () const
 Returns True if the window <me> is virtual. More...
 
void SetVirtual (const Standard_Boolean theVirtual)
 Setup the virtual state. More...
 
Graphic3d_Vec2i TopLeft () const
 Returns window top-left corner. More...
 
Graphic3d_Vec2i Dimensions () const
 Returns window dimensions. More...
 
const Handle< Aspect_DisplayConnection > & DisplayConnection () const
 Returns connection to Display or NULL. More...
 
Aspect_Background Background () const
 Returns the window background. More...
 
Aspect_FillMethod BackgroundFillMethod () const
 Returns the current image background fill mode. More...
 
Aspect_GradientBackground GradientBackground () const
 Returns the window gradient background. More...
 
void SetBackground (const Aspect_Background &theBack)
 Modifies the window background. More...
 
void SetBackground (const Quantity_Color &theColor)
 Modifies the window background. More...
 
void SetBackground (const Aspect_GradientBackground &theBackground)
 Modifies the window gradient background. More...
 
void SetBackground (const Quantity_Color &theFirstColor, const Quantity_Color &theSecondColor, const Aspect_GradientFillMethod theFillMethod)
 Modifies the window gradient background. More...
 
virtual void SetTitle (const TCollection_AsciiString &theTitle)
 Sets window title. More...
 
virtual Graphic3d_Vec2d ConvertPointToBacking (const Graphic3d_Vec2d &thePnt) const
 Convert point from logical units into backing store units. More...
 
virtual Graphic3d_Vec2d ConvertPointFromBacking (const Graphic3d_Vec2d &thePnt) const
 Convert point from backing store units to logical units. More...
 
void DumpJson (Standard_OStream &theOStream, Standard_Integer theDepth=-1) const
 Dumps the content of me into the stream. More...
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object. More...
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 
void IncrementRefCounter () const
 Increments the reference counter of this object. More...
 
Standard_Integer DecrementRefCounter () const
 Decrements the reference counter of this object; returns the decremented value. More...
 

Static Public Member Functions

static Aspect_VKeyMouse MouseButtonsFromNative (unsigned short theButtons)
 Convert Emscripten mouse buttons into Aspect_VKeyMouse. More...
 
static Aspect_VKey VirtualKeyFromNative (Standard_Integer theKey)
 Convert DOM virtual key into Aspect_VKey. More...
 
- Static Public Member Functions inherited from Standard_Transient
static const char * get_type_name ()
 Returns a type descriptor about this object. More...
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class. More...
 

Protected Attributes

TCollection_AsciiString myCanvasId
 
Graphic3d_Vec2i mySize
 
Standard_Real myDevicePixelRatio
 
Standard_Boolean myToScaleBacking
 
Standard_Boolean myIsMapped
 
- Protected Attributes inherited from Aspect_Window
Handle< Aspect_DisplayConnectionmyDisplay
 Display connection. More...
 
Aspect_Background MyBackground
 
Aspect_GradientBackground MyGradientBackground
 
Aspect_FillMethod MyBackgroundFillMethod
 
Standard_Boolean MyIsVirtual
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. More...
 
- Protected Member Functions inherited from Aspect_Window
 Aspect_Window ()
 Initializes the data of a Window. More...
 

Detailed Description

This class defines WebAssembly window (HTML5 canvas) intended for creation of OpenGL (WebGL) context.

Note that canvas may define an independent dimensions for backing store (WebGL buffer to render) and for CSS (logical units to present buffer onto screen). These dimensions differ when browser is dragged into a high pixel density screen (HiDPI), or when user scales page in the browser (in both cases window.devicePixelRatio JavaScript property becomes not equal to 1.0).

By default, Wasm_Window::DoResize() will scale backing store of a canvas basing on DevicePixelRatio() scale factor to ensure canvas content being rendered with the native resolution and not stretched by browser. This, however, might have side effects:

Constructor & Destructor Documentation

◆ Wasm_Window()

Wasm_Window::Wasm_Window ( const TCollection_AsciiString theCanvasId,
const bool  theToScaleBacking = true 
)

Wraps existing HTML5 canvas into window.

Parameters
[in]theCanvasIdtarget HTML element id defined in a querySelector() syntax
[in]theToScaleBackingwhen TRUE, window will automatically scale backing store of canvas basing on DevicePixelRatio() scale factor within DoResize()

◆ ~Wasm_Window()

virtual Wasm_Window::~Wasm_Window ( )
virtual

Destroys the window.

Member Function Documentation

◆ CanvasId()

const TCollection_AsciiString& Wasm_Window::CanvasId ( ) const
inline

Returns canvas id.

◆ DevicePixelRatio()

virtual Standard_Real Wasm_Window::DevicePixelRatio ( ) const
inlineoverridevirtual

Return device pixel ratio (logical to backing store scale factor).

Reimplemented from Aspect_Window.

◆ DoMapping()

virtual Standard_Boolean Wasm_Window::DoMapping ( ) const
inlineoverridevirtual

Apply the mapping change to the window.

Implements Aspect_Window.

◆ DoResize()

virtual Aspect_TypeOfResize Wasm_Window::DoResize ( )
overridevirtual

Resize window. In case of ToScaleBacking flag, this method will resize the backing store of canvas basing on DevicePixelRatio() scale factor and CSS canvas size.

Implements Aspect_Window.

◆ InvalidateContent()

virtual void Wasm_Window::InvalidateContent ( const Handle< Aspect_DisplayConnection > &  theDisp)
overridevirtual

Invalidate entire window content through generation of Expose event.

Reimplemented from Aspect_Window.

◆ IsMapped()

virtual Standard_Boolean Wasm_Window::IsMapped ( ) const
inlineoverridevirtual

Return true if window is not hidden.

Implements Aspect_Window.

◆ Map()

virtual void Wasm_Window::Map ( ) const
inlineoverridevirtual

Change window mapped flag to TRUE.

Implements Aspect_Window.

◆ MouseButtonsFromNative()

static Aspect_VKeyMouse Wasm_Window::MouseButtonsFromNative ( unsigned short  theButtons)
static

Convert Emscripten mouse buttons into Aspect_VKeyMouse.

◆ NativeFBConfig()

virtual Aspect_FBConfig Wasm_Window::NativeFBConfig ( ) const
inlineoverridevirtual

Always returns 0 for this class.

Implements Aspect_Window.

◆ NativeHandle()

virtual Aspect_Drawable Wasm_Window::NativeHandle ( ) const
inlineoverridevirtual

Current EGL implementation in Emscripten accepts only 0 for native window id.

Implements Aspect_Window.

◆ NativeParentHandle()

virtual Aspect_Drawable Wasm_Window::NativeParentHandle ( ) const
inlineoverridevirtual

Always returns 0 for this class.

Implements Aspect_Window.

◆ Position()

virtual void Wasm_Window::Position ( Standard_Integer theX1,
Standard_Integer theY1,
Standard_Integer theX2,
Standard_Integer theY2 
) const
overridevirtual

Returns The Window POSITION in PIXEL.

Implements Aspect_Window.

◆ ProcessFocusEvent()

virtual bool Wasm_Window::ProcessFocusEvent ( Aspect_WindowInputListener theListener,
int  theEventType,
const EmscriptenFocusEvent *  theEvent 
)
virtual

Process a focus input change message.

Parameters
[in,out]theListenerlistener to redirect message
[in]theEventTypemessage type to process
[in]theEventmessage to process
Returns
TRUE if message has been processed

◆ ProcessKeyEvent()

virtual bool Wasm_Window::ProcessKeyEvent ( Aspect_WindowInputListener theListener,
int  theEventType,
const EmscriptenKeyboardEvent *  theEvent 
)
virtual

Process a keyboard input message.

Parameters
[in,out]theListenerlistener to redirect message
[in]theEventTypemessage type to process
[in]theEventmessage to process
Returns
TRUE if message has been processed

◆ ProcessMessage()

virtual bool Wasm_Window::ProcessMessage ( Aspect_WindowInputListener theListener,
int  theEventType,
const void *  theEvent 
)
virtual

Process a single window message.

Parameters
[in,out]theListenerlistener to redirect message
[in]theEventTypemessage type to process
[in]theEventmessage to process
Returns
TRUE if message has been processed

◆ ProcessMouseEvent()

virtual bool Wasm_Window::ProcessMouseEvent ( Aspect_WindowInputListener theListener,
int  theEventType,
const EmscriptenMouseEvent *  theEvent 
)
virtual

Process a mouse input message.

Parameters
[in,out]theListenerlistener to redirect message
[in]theEventTypemessage type to process
[in]theEventmessage to process
Returns
TRUE if message has been processed

◆ ProcessTouchEvent()

virtual bool Wasm_Window::ProcessTouchEvent ( Aspect_WindowInputListener theListener,
int  theEventType,
const EmscriptenTouchEvent *  theEvent 
)
virtual

Process a mouse input message.

Parameters
[in,out]theListenerlistener to redirect message
[in]theEventTypemessage type to process
[in]theEventmessage to process
Returns
TRUE if message has been processed

◆ ProcessUiEvent()

virtual bool Wasm_Window::ProcessUiEvent ( Aspect_WindowInputListener theListener,
int  theEventType,
const EmscriptenUiEvent *  theEvent 
)
virtual

Process a UI input message (like window resize).

Parameters
[in,out]theListenerlistener to redirect message
[in]theEventTypemessage type to process
[in]theEventmessage to process
Returns
TRUE if message has been processed

◆ ProcessWheelEvent()

virtual bool Wasm_Window::ProcessWheelEvent ( Aspect_WindowInputListener theListener,
int  theEventType,
const EmscriptenWheelEvent *  theEvent 
)
virtual

Process a (mouse) wheel input message.

Parameters
[in,out]theListenerlistener to redirect message
[in]theEventTypemessage type to process
[in]theEventmessage to process
Returns
TRUE if message has been processed

◆ Ratio()

virtual Standard_Real Wasm_Window::Ratio ( ) const
overridevirtual

Returns window ratio equal to the physical width/height dimensions.

Implements Aspect_Window.

◆ SetDevicePixelRatio()

void Wasm_Window::SetDevicePixelRatio ( Standard_Real  theDevicePixelRatio)
inline

Sets device pixel ratio for a window with IsVirtual() flag.

◆ SetSizeBacking()

void Wasm_Window::SetSizeBacking ( const Graphic3d_Vec2i theSize)

Set new window size in pixels. Logical size of the element will be resized basing on DevicePixelRatio().

◆ SetSizeLogical()

void Wasm_Window::SetSizeLogical ( const Graphic3d_Vec2d theSize)

Set new window size in logical (density-independent units). Backing store will be resized basing on DevicePixelRatio().

◆ Size()

virtual void Wasm_Window::Size ( Standard_Integer theWidth,
Standard_Integer theHeight 
) const
overridevirtual

Return the window size in pixels.

Implements Aspect_Window.

◆ Unmap()

virtual void Wasm_Window::Unmap ( ) const
inlineoverridevirtual

Change window mapped flag to FALSE.

Implements Aspect_Window.

◆ VirtualKeyFromNative()

static Aspect_VKey Wasm_Window::VirtualKeyFromNative ( Standard_Integer  theKey)
static

Convert DOM virtual key into Aspect_VKey.

Field Documentation

◆ myCanvasId

TCollection_AsciiString Wasm_Window::myCanvasId
protected

◆ myDevicePixelRatio

Standard_Real Wasm_Window::myDevicePixelRatio
protected

◆ myIsMapped

Standard_Boolean Wasm_Window::myIsMapped
mutableprotected

◆ mySize

Graphic3d_Vec2i Wasm_Window::mySize
protected

◆ myToScaleBacking

Standard_Boolean Wasm_Window::myToScaleBacking
protected

The documentation for this class was generated from the following file: