mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0032433: Visualization, TKService - introduce Wasm_Window implementing Aspect_Window interface using Emscripten SDK
Introduced Wasm_Window implementing Aspect_Window interface. Aspect_WindowInputListener has been extended by touch input callbacks (moved from AIS_ViewController), which now implements redirection of single taps to UpdateMouseClick(). AIS_ViewController::FetchNavigationKeys() now requests more frames even if Delta is zero, but navigation keys are pressed - indicated by a new flag AIS_WalkDelta::IsDefined(). Fixed missing implementation of Xw_Window::DisplayConnection() getter. The property has been moved to the base class Aspect_Window. Removed unused Aspect_Convert.hxx. DRAWEXE targeting Wasm: - added exposing of FS interface so that it is possible uploading/downloading files to/from emulated file system on JavaScript level; - added printer redirecting messages to Module.printMessage callback accepting message gravity; - Run_Appli() now skips std::cin when Module.noExitRuntime is set.
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Aspect_Convert_HeaderFile
|
||||
#define _Aspect_Convert_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Real.hxx>
|
||||
|
||||
//! Auxiliary functions for DCU <-> Pixels conversions.
|
||||
namespace Aspect_Convert
|
||||
{
|
||||
|
||||
inline Standard_Integer Round (Standard_Real theValue)
|
||||
{
|
||||
return Standard_Integer(theValue + (theValue >= 0 ? 0.5 : -0.5 ));
|
||||
}
|
||||
|
||||
inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
|
||||
const Standard_Real theQCenterX, const Standard_Real theQCenterY,
|
||||
const Standard_Real theQSizeX, const Standard_Real theQSizeY,
|
||||
Standard_Integer& thePxLeft, Standard_Integer& thePxTop,
|
||||
Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
|
||||
{
|
||||
Standard_Real theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
|
||||
thePxSizeX = Round (theQSizeX * theParentSizeMin);
|
||||
thePxSizeY = Round (theQSizeY * theParentSizeMin);
|
||||
Standard_Integer thePxCenterX = Round(theQCenterX * Standard_Real (theParentPxSizeX));
|
||||
Standard_Integer thePxCenterY = Round((1.0 - theQCenterY) * Standard_Real (theParentPxSizeY));
|
||||
thePxLeft = thePxCenterX - thePxSizeX / 2;
|
||||
thePxTop = thePxCenterY - thePxSizeY / 2;
|
||||
}
|
||||
|
||||
inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
|
||||
const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
|
||||
const Standard_Integer thePxSizeX, const Standard_Integer thePxSizeY,
|
||||
Standard_Real& theQCenterX, Standard_Real& theQCenterY,
|
||||
Standard_Real& theQSizeX, Standard_Real& theQSizeY)
|
||||
{
|
||||
Standard_Real theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
|
||||
theQSizeX = Standard_Real(thePxSizeX) / theParentSizeMin;
|
||||
theQSizeY = Standard_Real(thePxSizeY) / theParentSizeMin;
|
||||
Standard_Integer thePxCenterX = thePxLeft + thePxSizeX / 2;
|
||||
Standard_Integer thePxCenterY = thePxTop + thePxSizeY / 2;
|
||||
theQCenterX = Standard_Real (thePxCenterX) / Standard_Real (theParentPxSizeX);
|
||||
theQCenterY = 1.0 - Standard_Real (thePxCenterY) / Standard_Real (theParentPxSizeY);
|
||||
}
|
||||
|
||||
inline void FitIn (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
|
||||
Standard_Integer& thePxLeft, Standard_Integer& thePxTop,
|
||||
Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
|
||||
{
|
||||
if (thePxLeft < 0)
|
||||
{
|
||||
//thePxSizeX -= 2 * thePxLeft;
|
||||
thePxLeft = 0;
|
||||
}
|
||||
if ((thePxLeft + thePxSizeX) > theParentPxSizeX)
|
||||
{
|
||||
thePxSizeX = theParentPxSizeX - thePxLeft;
|
||||
}
|
||||
|
||||
if (thePxTop < 0)
|
||||
{
|
||||
//thePxSizeY -= 2 * thePxTop;
|
||||
thePxTop = 0;
|
||||
}
|
||||
if ((thePxTop + thePxSizeY) > theParentPxSizeY)
|
||||
{
|
||||
thePxSizeY = theParentPxSizeY - thePxTop;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Aspect_Convert
|
||||
|
||||
#endif /* _Aspect_Convert_HeaderFile */
|
@@ -24,6 +24,7 @@
|
||||
#include <Aspect_GradientFillMethod.hxx>
|
||||
#include <Aspect_TypeOfResize.hxx>
|
||||
#include <Aspect_Drawable.hxx>
|
||||
#include <Graphic3d_Vec2.hxx>
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
@@ -36,7 +37,7 @@ DEFINE_STANDARD_HANDLE(Aspect_Window, Standard_Transient)
|
||||
//! Defines a window.
|
||||
class Aspect_Window : public Standard_Transient
|
||||
{
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Aspect_Window, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Modifies the window background.
|
||||
@@ -102,6 +103,9 @@ public:
|
||||
//! Returns native Window FB config (GLXFBConfig on Xlib)
|
||||
Standard_EXPORT virtual Aspect_FBConfig NativeFBConfig() const = 0;
|
||||
|
||||
//! Returns connection to Display or NULL.
|
||||
const Handle(Aspect_DisplayConnection)& DisplayConnection() const { return myDisplay; }
|
||||
|
||||
//! Sets window title.
|
||||
virtual void SetTitle (const TCollection_AsciiString& theTitle) { (void )theTitle; }
|
||||
|
||||
@@ -114,12 +118,29 @@ public:
|
||||
//! on platforms implementing thread-unsafe connections to display.
|
||||
//! NULL can be passed instead otherwise.
|
||||
virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp) { (void )theDisp; }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//! Return device pixel ratio (logical to backing store scale factor).
|
||||
virtual Standard_Real DevicePixelRatio() const { return 1.0; }
|
||||
|
||||
//! Convert point from logical units into backing store units.
|
||||
virtual Graphic3d_Vec2d ConvertPointToBacking (const Graphic3d_Vec2d& thePnt) const
|
||||
{
|
||||
return thePnt * DevicePixelRatio();
|
||||
}
|
||||
|
||||
//! Convert point from backing store units to logical units.
|
||||
virtual Graphic3d_Vec2d ConvertPointFromBacking (const Graphic3d_Vec2d& thePnt) const
|
||||
{
|
||||
return thePnt / DevicePixelRatio();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! Dumps the content of me into the stream
|
||||
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Aspect_Window,Standard_Transient)
|
||||
|
||||
protected:
|
||||
|
||||
//! Initializes the data of a Window.
|
||||
@@ -127,6 +148,7 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Aspect_DisplayConnection) myDisplay; //!< Display connection
|
||||
Aspect_Background MyBackground;
|
||||
Aspect_GradientBackground MyGradientBackground;
|
||||
Aspect_FillMethod MyBackgroundFillMethod;
|
||||
|
@@ -75,6 +75,70 @@ void Aspect_WindowInputListener::KeyFromAxis (Aspect_VKey theNegative,
|
||||
myKeys.KeyFromAxis (theNegative, thePositive, theTime, thePressure);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AddTouchPoint
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Aspect_WindowInputListener::AddTouchPoint (Standard_Size theId,
|
||||
const Graphic3d_Vec2d& thePnt,
|
||||
Standard_Boolean theClearBefore)
|
||||
{
|
||||
if (theClearBefore)
|
||||
{
|
||||
RemoveTouchPoint ((Standard_Size )-1);
|
||||
}
|
||||
|
||||
myTouchPoints.Add (theId, Aspect_Touch (thePnt, false));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : RemoveTouchPoint
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Aspect_WindowInputListener::RemoveTouchPoint (Standard_Size theId,
|
||||
Standard_Boolean theClearSelectPnts)
|
||||
{
|
||||
(void )theClearSelectPnts;
|
||||
if (theId == (Standard_Size )-1)
|
||||
{
|
||||
myTouchPoints.Clear (false);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Standard_Integer anOldExtent = myTouchPoints.Extent();
|
||||
myTouchPoints.RemoveKey (theId);
|
||||
if (myTouchPoints.Extent() == anOldExtent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (myTouchPoints.Extent() == 1)
|
||||
{
|
||||
// avoid incorrect transition from pinch to one finger
|
||||
Aspect_Touch& aFirstTouch = myTouchPoints.ChangeFromIndex (1);
|
||||
aFirstTouch.To = aFirstTouch.From;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : UpdateTouchPoint
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Aspect_WindowInputListener::UpdateTouchPoint (Standard_Size theId,
|
||||
const Graphic3d_Vec2d& thePnt)
|
||||
{
|
||||
if (Aspect_Touch* aTouch = myTouchPoints.ChangeSeek (theId))
|
||||
{
|
||||
aTouch->To = thePnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddTouchPoint (theId, thePnt);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : update3dMouseTranslation
|
||||
// purpose :
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#define _Aspect_WindowInputListener_HeaderFile
|
||||
|
||||
#include <Aspect_VKeySet.hxx>
|
||||
#include <Aspect_TouchMap.hxx>
|
||||
#include <Graphic3d_Vec.hxx>
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
@@ -159,6 +160,39 @@ public: //! @name mouse input
|
||||
//! Return last mouse position.
|
||||
const Graphic3d_Vec2i& LastMousePosition() const { return myMousePositionLast; }
|
||||
|
||||
public: //! @name multi-touch input
|
||||
|
||||
//! Return TRUE if touches map is not empty.
|
||||
bool HasTouchPoints() const { return !myTouchPoints.IsEmpty(); }
|
||||
|
||||
//! Return map of active touches.
|
||||
const Aspect_TouchMap& TouchPoints() const { return myTouchPoints; }
|
||||
|
||||
//! Add touch point with the given ID.
|
||||
//! This method is expected to be called from UI thread.
|
||||
//! @param theId touch unique identifier
|
||||
//! @param thePnt touch coordinates
|
||||
//! @param theClearBefore if TRUE previously registered touches will be removed
|
||||
Standard_EXPORT virtual void AddTouchPoint (Standard_Size theId,
|
||||
const Graphic3d_Vec2d& thePnt,
|
||||
Standard_Boolean theClearBefore = false);
|
||||
|
||||
//! Remove touch point with the given ID.
|
||||
//! This method is expected to be called from UI thread.
|
||||
//! @param theId touch unique identifier
|
||||
//! @param theClearSelectPnts if TRUE will initiate clearing of selection points
|
||||
//! @return TRUE if point has been removed
|
||||
Standard_EXPORT virtual bool RemoveTouchPoint (Standard_Size theId,
|
||||
Standard_Boolean theClearSelectPnts = false);
|
||||
|
||||
//! Update touch point with the given ID.
|
||||
//! If point with specified ID was not registered before, it will be added.
|
||||
//! This method is expected to be called from UI thread.
|
||||
//! @param theId touch unique identifier
|
||||
//! @param thePnt touch coordinates
|
||||
Standard_EXPORT virtual void UpdateTouchPoint (Standard_Size theId,
|
||||
const Graphic3d_Vec2d& thePnt);
|
||||
|
||||
public: //! @name 3d mouse input
|
||||
|
||||
//! Return acceleration ratio for translation event; 2.0 by default.
|
||||
@@ -222,6 +256,10 @@ protected: //! @name mouse input variables
|
||||
Aspect_VKeyMouse myMousePressed; //!< active mouse buttons
|
||||
Aspect_VKeyFlags myMouseModifiers; //!< active key modifiers passed with last mouse event
|
||||
|
||||
protected:
|
||||
|
||||
Aspect_TouchMap myTouchPoints; //!< map of active touches
|
||||
|
||||
protected: //! @name 3d mouse input variables
|
||||
|
||||
bool my3dMouseButtonState[32];//!< cached button state
|
||||
|
@@ -6,7 +6,6 @@ Aspect_Background.hxx
|
||||
Aspect_CircularGrid.cxx
|
||||
Aspect_CircularGrid.hxx
|
||||
Aspect_ColorSpace.hxx
|
||||
Aspect_Convert.hxx
|
||||
Aspect_Display.hxx
|
||||
Aspect_DisplayConnection.cxx
|
||||
Aspect_DisplayConnection.hxx
|
||||
|
Reference in New Issue
Block a user