mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0030507: Visualization - introduce AIS_ViewController
ViewerTest_EventManager now inherits AIS_ViewController. Platform-dependent user input handling within ViewerTest has been revised to process events in common way through AIS_ViewController. The mouse navigation has been changed, so that left mouse clicked without modifers now rotates View. The rubber-band selection can be activated via Alt+LeftMouseButton. Selection is now done on mouse unclick and keyboard short-cuts take effect on unclick. Aspect_Window::SetTitle() - added new method configuring Window title. Introduced new types Aspect_Touch, Aspect_VKey, Aspect_ScrollDelta for processing window events in platform-independent way.
This commit is contained in:
59
src/Aspect/Aspect_ScrollDelta.hxx
Normal file
59
src/Aspect/Aspect_ScrollDelta.hxx
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2019 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_ScrollDelta_HeaderFile
|
||||
#define _Aspect_ScrollDelta_HeaderFile
|
||||
|
||||
#include <Aspect_VKeyFlags.hxx>
|
||||
#include <NCollection_Vec2.hxx>
|
||||
#include <Standard_Real.hxx>
|
||||
|
||||
//! Parameters for mouse scroll action.
|
||||
struct Aspect_ScrollDelta
|
||||
{
|
||||
|
||||
NCollection_Vec2<int> Point; //!< scale position
|
||||
Standard_Real Delta; //!< delta in pixels
|
||||
Aspect_VKeyFlags Flags; //!< key flags
|
||||
|
||||
//! Return true if action has point defined.
|
||||
bool HasPoint() const
|
||||
{
|
||||
return Point.x() >= 0
|
||||
&& Point.y() >= 0;
|
||||
}
|
||||
|
||||
//! Reset at point.
|
||||
void ResetPoint()
|
||||
{
|
||||
Point.SetValues (-1, -1);
|
||||
}
|
||||
|
||||
//! Empty constructor.
|
||||
Aspect_ScrollDelta()
|
||||
: Point (-1, -1), Delta (0.0), Flags (Aspect_VKeyFlags_NONE) {}
|
||||
|
||||
//! Constructor.
|
||||
Aspect_ScrollDelta (const NCollection_Vec2<int>& thePnt,
|
||||
Standard_Real theValue,
|
||||
Aspect_VKeyFlags theFlags = Aspect_VKeyFlags_NONE)
|
||||
: Point (thePnt), Delta (theValue), Flags (theFlags) {}
|
||||
|
||||
//! Constructor with undefined point.
|
||||
Aspect_ScrollDelta (Standard_Real theValue,
|
||||
Aspect_VKeyFlags theFlags = Aspect_VKeyFlags_NONE)
|
||||
: Point (-1, -1), Delta (theValue), Flags (theFlags) {}
|
||||
|
||||
};
|
||||
|
||||
#endif // _Aspect_ScrollDelta_HeaderFile
|
49
src/Aspect/Aspect_Touch.hxx
Normal file
49
src/Aspect/Aspect_Touch.hxx
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2016-2019 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_Touch_HeaderFile
|
||||
#define _Aspect_Touch_HeaderFile
|
||||
|
||||
#include <NCollection_Vec2.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard_Real.hxx>
|
||||
|
||||
//! Structure holding touch position - original and current location.
|
||||
class Aspect_Touch
|
||||
{
|
||||
public:
|
||||
|
||||
NCollection_Vec2<Standard_Real> From; //!< original touch position
|
||||
NCollection_Vec2<Standard_Real> To; //!< current touch position
|
||||
Standard_Boolean IsPreciseDevice; //!< precise device input (e.g. mouse cursor, NOT emulated from touch screen)
|
||||
|
||||
//! Return values delta.
|
||||
NCollection_Vec2<Standard_Real> Delta() const { return To - From; }
|
||||
|
||||
//! Empty constructor
|
||||
Aspect_Touch()
|
||||
: From (0.0, 0.0), To (0.0, 0.0), IsPreciseDevice (false) {}
|
||||
|
||||
//! Constructor with initialization.
|
||||
Aspect_Touch (const NCollection_Vec2<Standard_Real>& thePnt,
|
||||
Standard_Boolean theIsPreciseDevice)
|
||||
: From (thePnt), To (thePnt), IsPreciseDevice (theIsPreciseDevice) {}
|
||||
|
||||
//! Constructor with initialization.
|
||||
Aspect_Touch (Standard_Real theX, Standard_Real theY,
|
||||
Standard_Boolean theIsPreciseDevice)
|
||||
: From (theX, theY), To (theX, theY), IsPreciseDevice (theIsPreciseDevice) {}
|
||||
|
||||
};
|
||||
|
||||
#endif // _Aspect_Touch_HeaderFile
|
23
src/Aspect/Aspect_TouchMap.hxx
Normal file
23
src/Aspect/Aspect_TouchMap.hxx
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2016-2019 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_TouchMap_HeaderFile
|
||||
#define _Aspect_TouchMap_HeaderFile
|
||||
|
||||
#include <Aspect_Touch.hxx>
|
||||
|
||||
#include <NCollection_IndexedDataMap.hxx>
|
||||
|
||||
typedef NCollection_IndexedDataMap<Standard_Size, Aspect_Touch> Aspect_TouchMap;
|
||||
|
||||
#endif // _Aspect_TouchMap_HeaderFile
|
199
src/Aspect/Aspect_VKey.hxx
Normal file
199
src/Aspect/Aspect_VKey.hxx
Normal file
@@ -0,0 +1,199 @@
|
||||
// Copyright (c) 2016-2019 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_VKey_HeaderFile
|
||||
#define _Aspect_VKey_HeaderFile
|
||||
|
||||
#include <Aspect_VKeyFlags.hxx>
|
||||
|
||||
//! Define virtual key as integer number to allow extensions.
|
||||
typedef unsigned int Aspect_VKey;
|
||||
|
||||
//! Enumeration defining virtual keys irrelevant to current keyboard layout for simplified hot-keys management logic.
|
||||
enum Aspect_VKeyBasic
|
||||
{
|
||||
Aspect_VKey_UNKNOWN = 0,
|
||||
|
||||
// main latin alphabet keys
|
||||
Aspect_VKey_A = 1,
|
||||
Aspect_VKey_B,
|
||||
Aspect_VKey_C,
|
||||
Aspect_VKey_D,
|
||||
Aspect_VKey_E,
|
||||
Aspect_VKey_F,
|
||||
Aspect_VKey_G,
|
||||
Aspect_VKey_H,
|
||||
Aspect_VKey_I,
|
||||
Aspect_VKey_J,
|
||||
Aspect_VKey_K,
|
||||
Aspect_VKey_L,
|
||||
Aspect_VKey_M,
|
||||
Aspect_VKey_N,
|
||||
Aspect_VKey_O,
|
||||
Aspect_VKey_P,
|
||||
Aspect_VKey_Q,
|
||||
Aspect_VKey_R,
|
||||
Aspect_VKey_S,
|
||||
Aspect_VKey_T,
|
||||
Aspect_VKey_U,
|
||||
Aspect_VKey_V,
|
||||
Aspect_VKey_W,
|
||||
Aspect_VKey_X,
|
||||
Aspect_VKey_Y,
|
||||
Aspect_VKey_Z,
|
||||
|
||||
Aspect_VKey_0,
|
||||
Aspect_VKey_1,
|
||||
Aspect_VKey_2,
|
||||
Aspect_VKey_3,
|
||||
Aspect_VKey_4,
|
||||
Aspect_VKey_5,
|
||||
Aspect_VKey_6,
|
||||
Aspect_VKey_7,
|
||||
Aspect_VKey_8,
|
||||
Aspect_VKey_9,
|
||||
|
||||
Aspect_VKey_F1,
|
||||
Aspect_VKey_F2,
|
||||
Aspect_VKey_F3,
|
||||
Aspect_VKey_F4,
|
||||
Aspect_VKey_F5,
|
||||
Aspect_VKey_F6,
|
||||
Aspect_VKey_F7,
|
||||
Aspect_VKey_F8,
|
||||
Aspect_VKey_F9,
|
||||
Aspect_VKey_F10,
|
||||
Aspect_VKey_F11,
|
||||
Aspect_VKey_F12,
|
||||
|
||||
// standard keys
|
||||
Aspect_VKey_Up,
|
||||
Aspect_VKey_Down,
|
||||
Aspect_VKey_Left,
|
||||
Aspect_VKey_Right,
|
||||
Aspect_VKey_Plus, //!< '+'
|
||||
Aspect_VKey_Minus, //!< '-'
|
||||
Aspect_VKey_Equal, //!< '=+'
|
||||
Aspect_VKey_PageUp,
|
||||
Aspect_VKey_PageDown,
|
||||
Aspect_VKey_Home,
|
||||
Aspect_VKey_End,
|
||||
Aspect_VKey_Escape,
|
||||
Aspect_VKey_Back,
|
||||
Aspect_VKey_Enter,
|
||||
Aspect_VKey_Backspace,
|
||||
Aspect_VKey_Space,
|
||||
Aspect_VKey_Delete,
|
||||
Aspect_VKey_Tilde,
|
||||
Aspect_VKey_Tab,
|
||||
Aspect_VKey_Comma, //!< ','
|
||||
Aspect_VKey_Period, //!< '.'
|
||||
Aspect_VKey_Semicolon, //!< ';:'
|
||||
Aspect_VKey_Slash, //!< '/?'
|
||||
Aspect_VKey_BracketLeft, //!< '[{'
|
||||
Aspect_VKey_Backslash, //!< '\|'
|
||||
Aspect_VKey_BracketRight, //!< ']}'
|
||||
Aspect_VKey_Apostrophe, //!< ''"'
|
||||
Aspect_VKey_Numlock, //!< Num Lock key
|
||||
Aspect_VKey_Scroll, //!< Scroll Lock key
|
||||
|
||||
// numpad keys
|
||||
Aspect_VKey_Numpad0,
|
||||
Aspect_VKey_Numpad1,
|
||||
Aspect_VKey_Numpad2,
|
||||
Aspect_VKey_Numpad3,
|
||||
Aspect_VKey_Numpad4,
|
||||
Aspect_VKey_Numpad5,
|
||||
Aspect_VKey_Numpad6,
|
||||
Aspect_VKey_Numpad7,
|
||||
Aspect_VKey_Numpad8,
|
||||
Aspect_VKey_Numpad9,
|
||||
Aspect_VKey_NumpadMultiply, //!< numpad '*'
|
||||
Aspect_VKey_NumpadAdd, //!< numpad '+'
|
||||
Aspect_VKey_NumpadSubtract, //!< numpad '-'
|
||||
Aspect_VKey_NumpadDivide, //!< numpad '/'
|
||||
|
||||
// Multimedia keys
|
||||
Aspect_VKey_MediaNextTrack,
|
||||
Aspect_VKey_MediaPreviousTrack,
|
||||
Aspect_VKey_MediaStop,
|
||||
Aspect_VKey_MediaPlayPause,
|
||||
Aspect_VKey_VolumeMute,
|
||||
Aspect_VKey_VolumeDown,
|
||||
Aspect_VKey_VolumeUp,
|
||||
Aspect_VKey_BrowserBack,
|
||||
Aspect_VKey_BrowserForward,
|
||||
Aspect_VKey_BrowserRefresh,
|
||||
Aspect_VKey_BrowserStop,
|
||||
Aspect_VKey_BrowserSearch,
|
||||
Aspect_VKey_BrowserFavorites,
|
||||
Aspect_VKey_BrowserHome,
|
||||
|
||||
// modifier keys, @sa Aspect_VKey_ModifiersLower and Aspect_VKey_ModifiersUpper below
|
||||
Aspect_VKey_Shift,
|
||||
Aspect_VKey_Control,
|
||||
Aspect_VKey_Alt,
|
||||
Aspect_VKey_Menu,
|
||||
Aspect_VKey_Meta,
|
||||
|
||||
// virtual navigation keys, @sa Aspect_VKey_NavigationKeysLower and Aspect_VKey_NavigationKeysUpper below
|
||||
Aspect_VKey_NavInteract, //!< interact
|
||||
Aspect_VKey_NavForward, //!< go forward
|
||||
Aspect_VKey_NavBackward, //!< go backward
|
||||
Aspect_VKey_NavSlideLeft, //!< sidewalk, left
|
||||
Aspect_VKey_NavSlideRight, //!< sidewalk, right
|
||||
Aspect_VKey_NavSlideUp, //!< lift up
|
||||
Aspect_VKey_NavSlideDown, //!< fall down
|
||||
Aspect_VKey_NavRollCCW, //!< bank left (roll counter-clockwise)
|
||||
Aspect_VKey_NavRollCW, //!< bank right (roll clockwise)
|
||||
Aspect_VKey_NavLookLeft, //!< look left (yaw counter-clockwise)
|
||||
Aspect_VKey_NavLookRight, //!< look right (yaw clockwise)
|
||||
Aspect_VKey_NavLookUp, //!< look up (pitch clockwise)
|
||||
Aspect_VKey_NavLookDown, //!< look down (pitch counter-clockwise)
|
||||
Aspect_VKey_NavCrouch, //!< crouch walking
|
||||
Aspect_VKey_NavJump, //!< jump
|
||||
Aspect_VKey_NavThrustForward, //!< increase continuous velocity in forward direction
|
||||
Aspect_VKey_NavThrustBackward, //!< increase continuous velocity in reversed direction
|
||||
Aspect_VKey_NavThrustStop, //!< reset continuous velocity
|
||||
Aspect_VKey_NavSpeedIncrease, //!< increase navigation speed
|
||||
Aspect_VKey_NavSpeedDecrease, //!< decrease navigation speed
|
||||
};
|
||||
|
||||
//! Auxiliary ranges.
|
||||
enum
|
||||
{
|
||||
Aspect_VKey_Lower = 0,
|
||||
Aspect_VKey_ModifiersLower = Aspect_VKey_Shift,
|
||||
Aspect_VKey_ModifiersUpper = Aspect_VKey_Meta,
|
||||
Aspect_VKey_NavigationKeysLower = Aspect_VKey_NavInteract,
|
||||
Aspect_VKey_NavigationKeysUpper = Aspect_VKey_NavSpeedDecrease,
|
||||
Aspect_VKey_Upper = Aspect_VKey_NavSpeedDecrease,
|
||||
Aspect_VKey_NB = Aspect_VKey_Upper - Aspect_VKey_Lower + 1,
|
||||
Aspect_VKey_MAX = 255
|
||||
};
|
||||
|
||||
//! Return modifier flags for specified modifier key.
|
||||
inline Aspect_VKeyFlags Aspect_VKey2Modifier (Aspect_VKey theKey)
|
||||
{
|
||||
switch (theKey)
|
||||
{
|
||||
case Aspect_VKey_Shift: return Aspect_VKeyFlags_SHIFT;
|
||||
case Aspect_VKey_Control: return Aspect_VKeyFlags_CTRL;
|
||||
case Aspect_VKey_Alt: return Aspect_VKeyFlags_ALT;
|
||||
case Aspect_VKey_Menu: return Aspect_VKeyFlags_MENU;
|
||||
case Aspect_VKey_Meta: return Aspect_VKeyFlags_META;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _Aspect_VKey_HeaderFile
|
49
src/Aspect/Aspect_VKeyFlags.hxx
Normal file
49
src/Aspect/Aspect_VKeyFlags.hxx
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2016-2019 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_VKeyFlags_HeaderFile
|
||||
#define _Aspect_VKeyFlags_HeaderFile
|
||||
|
||||
//! Key modifier, for combining with general key from Aspect_VKey.
|
||||
typedef unsigned int Aspect_VKeyFlags;
|
||||
|
||||
//! Key modifier, for combining with general key from Aspect_VKey.
|
||||
enum
|
||||
{
|
||||
Aspect_VKeyFlags_NONE = 0,
|
||||
// reserve first 8 bits to combine value with Aspect_VKey
|
||||
Aspect_VKeyFlags_SHIFT = 1 << 8, //!< Aspect_VKey_Shift
|
||||
Aspect_VKeyFlags_CTRL = 1 << 9, //!< Aspect_VKey_Control
|
||||
Aspect_VKeyFlags_ALT = 1 << 10, //!< Aspect_VKey_Alt
|
||||
Aspect_VKeyFlags_MENU = 1 << 11, //!< Aspect_VKey_Menu
|
||||
Aspect_VKeyFlags_META = 1 << 12, //!< Aspect_VKey_Meta
|
||||
|
||||
Aspect_VKeyFlags_ALL = Aspect_VKeyFlags_SHIFT | Aspect_VKeyFlags_CTRL | Aspect_VKeyFlags_ALT | Aspect_VKeyFlags_MENU | Aspect_VKeyFlags_META
|
||||
};
|
||||
|
||||
//! Mouse buttons, for combining with Aspect_VKey and Aspect_VKeyFlags.
|
||||
typedef unsigned int Aspect_VKeyMouse;
|
||||
|
||||
//! Mouse button bitmask
|
||||
enum
|
||||
{
|
||||
Aspect_VKeyMouse_NONE = 0, //!< no buttons
|
||||
|
||||
Aspect_VKeyMouse_LeftButton = 1 << 13, //!< mouse left button
|
||||
Aspect_VKeyMouse_MiddleButton = 1 << 14, //!< mouse middle button (scroll)
|
||||
Aspect_VKeyMouse_RightButton = 1 << 15, //!< mouse right button
|
||||
|
||||
Aspect_VKeyMouse_MainButtons = Aspect_VKeyMouse_LeftButton | Aspect_VKeyMouse_MiddleButton | Aspect_VKeyMouse_RightButton
|
||||
};
|
||||
|
||||
#endif // _Aspect_VKeyFlags_HeaderFile
|
150
src/Aspect/Aspect_VKeySet.cxx
Normal file
150
src/Aspect/Aspect_VKeySet.cxx
Normal file
@@ -0,0 +1,150 @@
|
||||
// Copyright (c) 2016-2019 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.
|
||||
|
||||
#include "Aspect_VKeySet.hxx"
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Aspect_VKeySet, Standard_Transient)
|
||||
|
||||
// ================================================================
|
||||
// Function : As1pect_VKeySet
|
||||
// Purpose :
|
||||
// ================================================================
|
||||
Aspect_VKeySet::Aspect_VKeySet()
|
||||
: myKeys (0, Aspect_VKey_MAX),
|
||||
myModifiers (Aspect_VKeyFlags_NONE)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Function : Reset
|
||||
// Purpose :
|
||||
// ================================================================
|
||||
void Aspect_VKeySet::Reset()
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
myModifiers = 0;
|
||||
for (NCollection_Array1<KeyState>::Iterator aKeyIter (myKeys); aKeyIter.More(); aKeyIter.Next())
|
||||
{
|
||||
aKeyIter.ChangeValue().Reset();
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Function : KeyDown
|
||||
// Purpose :
|
||||
// ================================================================
|
||||
void Aspect_VKeySet::KeyDown (Aspect_VKey theKey,
|
||||
double theTime,
|
||||
double thePressure)
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
if (myKeys[theKey].Status != KeyStatus_Pressed)
|
||||
{
|
||||
myKeys[theKey].Status = KeyStatus_Pressed;
|
||||
myKeys[theKey].TimeDown = theTime;
|
||||
}
|
||||
myKeys[theKey].Pressure = thePressure;
|
||||
|
||||
const unsigned int aModif = Aspect_VKey2Modifier (theKey);
|
||||
myModifiers = myModifiers | aModif;
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Function : KeyUp
|
||||
// Purpose :
|
||||
// ================================================================
|
||||
void Aspect_VKeySet::KeyUp (Aspect_VKey theKey,
|
||||
double theTime)
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
if (myKeys[theKey].Status == KeyStatus_Pressed)
|
||||
{
|
||||
myKeys[theKey].Status = KeyStatus_Released;
|
||||
myKeys[theKey].TimeUp = theTime;
|
||||
}
|
||||
|
||||
const unsigned int aModif = Aspect_VKey2Modifier (theKey);
|
||||
if (aModif != 0)
|
||||
{
|
||||
myModifiers = myModifiers & ~aModif;
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Function : KeyFromAxis
|
||||
// Purpose :
|
||||
// ================================================================
|
||||
void Aspect_VKeySet::KeyFromAxis (Aspect_VKey theNegative,
|
||||
Aspect_VKey thePositive,
|
||||
double theTime,
|
||||
double thePressure)
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
if (thePressure != 0)
|
||||
{
|
||||
const Aspect_VKey aKeyDown = thePressure > 0 ? thePositive : theNegative;
|
||||
const Aspect_VKey aKeyUp = thePressure < 0 ? thePositive : theNegative;
|
||||
|
||||
KeyDown (aKeyDown, theTime, Abs (thePressure));
|
||||
if (myKeys[aKeyUp].Status == KeyStatus_Pressed)
|
||||
{
|
||||
KeyUp (aKeyUp, theTime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (myKeys[theNegative].Status == KeyStatus_Pressed)
|
||||
{
|
||||
KeyUp (theNegative, theTime);
|
||||
}
|
||||
if (myKeys[thePositive].Status == KeyStatus_Pressed)
|
||||
{
|
||||
KeyUp (thePositive, theTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Function : HoldDuration
|
||||
// Purpose :
|
||||
// ================================================================
|
||||
bool Aspect_VKeySet::HoldDuration (Aspect_VKey theKey,
|
||||
double theTime,
|
||||
double& theDuration,
|
||||
double& thePressure)
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
switch (myKeys[theKey].Status)
|
||||
{
|
||||
case KeyStatus_Free:
|
||||
{
|
||||
theDuration = 0.0;
|
||||
return false;
|
||||
}
|
||||
case KeyStatus_Released:
|
||||
{
|
||||
myKeys[theKey].Status = KeyStatus_Free;
|
||||
theDuration = myKeys[theKey].TimeUp - myKeys[theKey].TimeDown;
|
||||
thePressure = myKeys[theKey].Pressure;
|
||||
return true;
|
||||
}
|
||||
case KeyStatus_Pressed:
|
||||
{
|
||||
theDuration = theTime - myKeys[theKey].TimeDown;
|
||||
thePressure = myKeys[theKey].Pressure;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
152
src/Aspect/Aspect_VKeySet.hxx
Normal file
152
src/Aspect/Aspect_VKeySet.hxx
Normal file
@@ -0,0 +1,152 @@
|
||||
// Copyright (c) 2016-2019 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_VKeySet_HeaderFile
|
||||
#define _Aspect_VKeySet_HeaderFile
|
||||
|
||||
#include <Aspect_VKey.hxx>
|
||||
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <OSD_Timer.hxx>
|
||||
#include <Standard_Mutex.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
|
||||
//! Structure defining key state.
|
||||
class Aspect_VKeySet : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Aspect_VKeySet, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Main constructor.
|
||||
Standard_EXPORT Aspect_VKeySet();
|
||||
|
||||
//! Return active modifiers.
|
||||
Aspect_VKeyFlags Modifiers() const
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
return myModifiers;
|
||||
}
|
||||
|
||||
//! Return timestamp of press event.
|
||||
double DownTime (Aspect_VKey theKey) const
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
return myKeys[theKey].TimeDown;
|
||||
}
|
||||
|
||||
//! Return timestamp of release event.
|
||||
double TimeUp (Aspect_VKey theKey) const
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
return myKeys[theKey].TimeUp;
|
||||
}
|
||||
|
||||
//! Return TRUE if key is in Free state.
|
||||
bool IsFreeKey (Aspect_VKey theKey) const
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
return myKeys[theKey].Status == KeyStatus_Free;
|
||||
}
|
||||
|
||||
//! Return TRUE if key is in Pressed state.
|
||||
bool IsKeyDown (Aspect_VKey theKey) const
|
||||
{
|
||||
Standard_Mutex::Sentry aLock (myLock);
|
||||
return myKeys[theKey].Status == KeyStatus_Pressed;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! Reset the key state into unpressed state.
|
||||
Standard_EXPORT void Reset();
|
||||
|
||||
//! Press key.
|
||||
//! @param theKey key pressed
|
||||
//! @param theTime event timestamp
|
||||
Standard_EXPORT void KeyDown (Aspect_VKey theKey,
|
||||
double theTime,
|
||||
double thePressure = 1.0);
|
||||
|
||||
//! Release key.
|
||||
//! @param theKey key pressed
|
||||
//! @param theTime event timestamp
|
||||
Standard_EXPORT void KeyUp (Aspect_VKey theKey,
|
||||
double theTime);
|
||||
|
||||
//! Simulate key up/down events from axis value.
|
||||
Standard_EXPORT void KeyFromAxis (Aspect_VKey theNegative,
|
||||
Aspect_VKey thePositive,
|
||||
double theTime,
|
||||
double thePressure);
|
||||
|
||||
//! Return duration of the button in pressed state.
|
||||
//! @param theKey key to check
|
||||
//! @param theTime current time (for computing duration from key down time)
|
||||
//! @param theDuration key press duration
|
||||
//! @return TRUE if key was in pressed state
|
||||
bool HoldDuration (Aspect_VKey theKey,
|
||||
double theTime,
|
||||
double& theDuration)
|
||||
{
|
||||
double aPressure = -1.0;
|
||||
return HoldDuration (theKey, theTime, theDuration, aPressure);
|
||||
}
|
||||
|
||||
//! Return duration of the button in pressed state.
|
||||
//! @param theKey key to check
|
||||
//! @param theTime current time (for computing duration from key down time)
|
||||
//! @param theDuration key press duration
|
||||
//! @param thePressure key pressure
|
||||
//! @return TRUE if key was in pressed state
|
||||
Standard_EXPORT bool HoldDuration (Aspect_VKey theKey,
|
||||
double theTime,
|
||||
double& theDuration,
|
||||
double& thePressure);
|
||||
|
||||
private:
|
||||
|
||||
//! Key state.
|
||||
enum KeyStatus
|
||||
{
|
||||
KeyStatus_Free, //!< free status
|
||||
KeyStatus_Pressed, //!< key is in pressed state
|
||||
KeyStatus_Released, //!< key has been just released (transient state before KeyStatus_Free)
|
||||
};
|
||||
|
||||
//! Structure defining key state.
|
||||
struct KeyState
|
||||
{
|
||||
KeyState() : TimeDown (0.0), TimeUp (0.0), Pressure (1.0), Status (KeyStatus_Free) {}
|
||||
void Reset()
|
||||
{
|
||||
Status = KeyStatus_Free;
|
||||
TimeDown = 0.0;
|
||||
TimeUp = 0.0;
|
||||
Pressure = 1.0;
|
||||
}
|
||||
|
||||
double TimeDown; //!< time of key press event
|
||||
double TimeUp; //!< time of key release event
|
||||
double Pressure; //!< key pressure
|
||||
KeyStatus Status; //!< key status
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
NCollection_Array1<KeyState> myKeys; //!< keys state
|
||||
mutable Standard_Mutex myLock; //!< mutex for thread-safe updates
|
||||
Aspect_VKeyFlags myModifiers; //!< active modifiers
|
||||
|
||||
};
|
||||
|
||||
#endif // _Aspect_VKeySet_HeaderFile
|
@@ -16,28 +16,21 @@
|
||||
#ifndef _Aspect_Window_HeaderFile
|
||||
#define _Aspect_Window_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <Aspect_Background.hxx>
|
||||
#include <Aspect_GradientBackground.hxx>
|
||||
#include <Aspect_FBConfig.hxx>
|
||||
#include <Aspect_FillMethod.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Quantity_Color.hxx>
|
||||
#include <Aspect_GradientFillMethod.hxx>
|
||||
#include <Aspect_TypeOfResize.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <Aspect_Drawable.hxx>
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
class Aspect_DisplayConnection;
|
||||
class Aspect_WindowDefinitionError;
|
||||
class Aspect_WindowError;
|
||||
class Aspect_Background;
|
||||
class Aspect_GradientBackground;
|
||||
|
||||
class Aspect_Window;
|
||||
DEFINE_STANDARD_HANDLE(Aspect_Window, Standard_Transient)
|
||||
|
||||
//! Defines a window.
|
||||
@@ -109,6 +102,9 @@ public:
|
||||
//! Returns native Window FB config (GLXFBConfig on Xlib)
|
||||
Standard_EXPORT virtual Aspect_FBConfig NativeFBConfig() const = 0;
|
||||
|
||||
//! Sets window title.
|
||||
virtual void SetTitle (const TCollection_AsciiString& theTitle) { (void )theTitle; }
|
||||
|
||||
//! Invalidate entire window content.
|
||||
//!
|
||||
//! Implementation is expected to allow calling this method from non-GUI thread,
|
||||
|
@@ -34,6 +34,9 @@ Aspect_RectangularGrid.cxx
|
||||
Aspect_RectangularGrid.hxx
|
||||
Aspect_RenderingContext.hxx
|
||||
Aspect_SequenceOfColor.hxx
|
||||
Aspect_ScrollDelta.hxx
|
||||
Aspect_Touch.hxx
|
||||
Aspect_TouchMap.hxx
|
||||
Aspect_TypeOfColorScaleData.hxx
|
||||
Aspect_TypeOfColorScaleOrientation.hxx
|
||||
Aspect_TypeOfColorScalePosition.hxx
|
||||
@@ -47,6 +50,10 @@ Aspect_TypeOfResize.hxx
|
||||
Aspect_TypeOfStyleText.hxx
|
||||
Aspect_TypeOfTriedronPosition.hxx
|
||||
Aspect_Units.hxx
|
||||
Aspect_VKey.hxx
|
||||
Aspect_VKeyFlags.hxx
|
||||
Aspect_VKeySet.cxx
|
||||
Aspect_VKeySet.hxx
|
||||
Aspect_WidthOfLine.hxx
|
||||
Aspect_Window.cxx
|
||||
Aspect_Window.hxx
|
||||
|
Reference in New Issue
Block a user