mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +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:
@@ -355,6 +355,16 @@ void WNT_Window::SetPos (const Standard_Integer theX, const Standard_Integer th
|
||||
aYBottom = theY1;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetTitle
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void WNT_Window::SetTitle (const TCollection_AsciiString& theTitle)
|
||||
{
|
||||
const TCollection_ExtendedString aTitleW (theTitle);
|
||||
SetWindowTextW ((HWND )myHWindow, aTitleW.ToWideString());
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : InvalidateContent
|
||||
// purpose :
|
||||
@@ -367,4 +377,270 @@ void WNT_Window::InvalidateContent (const Handle(Aspect_DisplayConnection)& )
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : VirtualKeyFromNative
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_VKey WNT_Window::VirtualKeyFromNative (Standard_Integer theKey)
|
||||
{
|
||||
if (theKey >= Standard_Integer('0')
|
||||
&& theKey <= Standard_Integer('9'))
|
||||
{
|
||||
return Aspect_VKey((theKey - Standard_Integer('0')) + Aspect_VKey_0);
|
||||
}
|
||||
if (theKey >= Standard_Integer('A')
|
||||
&& theKey <= Standard_Integer('Z'))
|
||||
{
|
||||
// main latin alphabet keys
|
||||
return Aspect_VKey((theKey - Standard_Integer('A')) + Aspect_VKey_A);
|
||||
}
|
||||
if (theKey >= VK_F1
|
||||
&& theKey <= VK_F24)
|
||||
{
|
||||
// special keys
|
||||
if (theKey <= VK_F12)
|
||||
{
|
||||
return Aspect_VKey((theKey - VK_F1) + Aspect_VKey_F1);
|
||||
}
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
}
|
||||
if (theKey >= VK_NUMPAD0
|
||||
&& theKey <= VK_NUMPAD9)
|
||||
{
|
||||
// numpad keys
|
||||
return Aspect_VKey((theKey - VK_NUMPAD0) + Aspect_VKey_Numpad0);
|
||||
}
|
||||
|
||||
switch (theKey)
|
||||
{
|
||||
case VK_LBUTTON:
|
||||
case VK_RBUTTON:
|
||||
case VK_CANCEL:
|
||||
case VK_MBUTTON:
|
||||
case VK_XBUTTON1:
|
||||
case VK_XBUTTON2:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_BACK:
|
||||
return Aspect_VKey_Backspace;
|
||||
case VK_TAB:
|
||||
return Aspect_VKey_Tab;
|
||||
case VK_CLEAR:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_RETURN:
|
||||
return Aspect_VKey_Enter;
|
||||
case VK_SHIFT:
|
||||
return Aspect_VKey_Shift;
|
||||
case VK_CONTROL:
|
||||
return Aspect_VKey_Control;
|
||||
case VK_MENU:
|
||||
return Aspect_VKey_Alt; //Aspect_VKey_Menu;
|
||||
case VK_PAUSE:
|
||||
case VK_CAPITAL:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_ESCAPE:
|
||||
return Aspect_VKey_Escape;
|
||||
case VK_CONVERT:
|
||||
case VK_NONCONVERT:
|
||||
case VK_ACCEPT:
|
||||
case VK_MODECHANGE:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_SPACE:
|
||||
return Aspect_VKey_Space;
|
||||
case VK_PRIOR:
|
||||
return Aspect_VKey_PageUp;
|
||||
case VK_NEXT:
|
||||
return Aspect_VKey_PageDown;
|
||||
case VK_END:
|
||||
return Aspect_VKey_End;
|
||||
case VK_HOME:
|
||||
return Aspect_VKey_Home;
|
||||
case VK_LEFT:
|
||||
return Aspect_VKey_Left;
|
||||
case VK_UP:
|
||||
return Aspect_VKey_Up;
|
||||
case VK_DOWN:
|
||||
return Aspect_VKey_Down;
|
||||
case VK_RIGHT:
|
||||
return Aspect_VKey_Right;
|
||||
case VK_SELECT:
|
||||
case VK_PRINT:
|
||||
case VK_EXECUTE:
|
||||
case VK_SNAPSHOT:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_INSERT:
|
||||
return Aspect_VKey_UNKNOWN; // Aspect_VKey_Insert
|
||||
case VK_DELETE:
|
||||
return Aspect_VKey_Delete;
|
||||
case VK_HELP:
|
||||
case VK_LWIN:
|
||||
case VK_RWIN:
|
||||
case VK_APPS:
|
||||
case VK_SLEEP:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_MULTIPLY:
|
||||
return Aspect_VKey_NumpadMultiply;
|
||||
case VK_ADD:
|
||||
return Aspect_VKey_NumpadAdd;
|
||||
case VK_SEPARATOR:
|
||||
case VK_DECIMAL:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_SUBTRACT:
|
||||
return Aspect_VKey_NumpadSubtract;
|
||||
case VK_DIVIDE:
|
||||
return Aspect_VKey_NumpadDivide;
|
||||
case VK_NUMLOCK:
|
||||
return Aspect_VKey_Numlock;
|
||||
case VK_SCROLL:
|
||||
return Aspect_VKey_Scroll;
|
||||
case VK_LSHIFT:
|
||||
case VK_RSHIFT:
|
||||
case VK_LCONTROL:
|
||||
case VK_RCONTROL:
|
||||
case VK_LMENU:
|
||||
case VK_RMENU:
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
case VK_BROWSER_BACK:
|
||||
return Aspect_VKey_BrowserBack;
|
||||
case VK_BROWSER_FORWARD:
|
||||
return Aspect_VKey_BrowserForward;
|
||||
case VK_BROWSER_REFRESH:
|
||||
return Aspect_VKey_BrowserRefresh;
|
||||
case VK_BROWSER_STOP:
|
||||
return Aspect_VKey_BrowserStop;
|
||||
case VK_BROWSER_SEARCH:
|
||||
return Aspect_VKey_BrowserSearch;
|
||||
case VK_BROWSER_FAVORITES:
|
||||
return Aspect_VKey_BrowserFavorites;
|
||||
case VK_BROWSER_HOME:
|
||||
return Aspect_VKey_BrowserHome;
|
||||
case VK_VOLUME_MUTE:
|
||||
return Aspect_VKey_VolumeMute;
|
||||
case VK_VOLUME_DOWN:
|
||||
return Aspect_VKey_VolumeDown;
|
||||
case VK_VOLUME_UP:
|
||||
return Aspect_VKey_VolumeUp;
|
||||
case VK_MEDIA_NEXT_TRACK:
|
||||
return Aspect_VKey_MediaNextTrack;
|
||||
case VK_MEDIA_PREV_TRACK:
|
||||
return Aspect_VKey_MediaPreviousTrack;
|
||||
case VK_MEDIA_STOP:
|
||||
return Aspect_VKey_MediaStop;
|
||||
case VK_MEDIA_PLAY_PAUSE:
|
||||
return Aspect_VKey_MediaPlayPause;
|
||||
case VK_OEM_1:
|
||||
return Aspect_VKey_Semicolon;
|
||||
case VK_OEM_PLUS:
|
||||
return Aspect_VKey_Plus;
|
||||
case VK_OEM_COMMA:
|
||||
return Aspect_VKey_Comma;
|
||||
case VK_OEM_MINUS:
|
||||
return Aspect_VKey_Minus;
|
||||
case VK_OEM_PERIOD:
|
||||
return Aspect_VKey_Period;
|
||||
case VK_OEM_2:
|
||||
return Aspect_VKey_Slash;
|
||||
case VK_OEM_3:
|
||||
return Aspect_VKey_Tilde;
|
||||
case VK_OEM_4:
|
||||
return Aspect_VKey_BracketLeft;
|
||||
case VK_OEM_5:
|
||||
return Aspect_VKey_Backslash;
|
||||
case VK_OEM_6:
|
||||
return Aspect_VKey_BracketRight;
|
||||
case VK_OEM_7:
|
||||
return Aspect_VKey_Apostrophe;
|
||||
}
|
||||
return Aspect_VKey_UNKNOWN;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : MouseKeyFlagsFromEvent
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_VKeyFlags WNT_Window::MouseKeyFlagsFromEvent (WPARAM theKeys)
|
||||
{
|
||||
Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
|
||||
if ((theKeys & MK_CONTROL) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_CTRL;
|
||||
}
|
||||
if ((theKeys & MK_SHIFT) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_SHIFT;
|
||||
}
|
||||
if (GetKeyState (VK_MENU) < 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_ALT;
|
||||
}
|
||||
return aFlags;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : MouseKeyFlagsAsync
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_VKeyFlags WNT_Window::MouseKeyFlagsAsync()
|
||||
{
|
||||
Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
|
||||
if ((GetAsyncKeyState (VK_CONTROL) & 0x8000) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_CTRL;
|
||||
}
|
||||
if ((GetAsyncKeyState (VK_SHIFT) & 0x8000) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_SHIFT;
|
||||
}
|
||||
if ((GetAsyncKeyState (VK_MENU) & 0x8000) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_ALT;
|
||||
}
|
||||
return aFlags;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : MouseButtonsFromEvent
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_VKeyMouse WNT_Window::MouseButtonsFromEvent (WPARAM theKeys)
|
||||
{
|
||||
Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
|
||||
if ((theKeys & MK_LBUTTON) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_LeftButton;
|
||||
}
|
||||
if ((theKeys & MK_MBUTTON) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_MiddleButton;
|
||||
}
|
||||
if ((theKeys & MK_RBUTTON) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_RightButton;
|
||||
}
|
||||
return aButtons;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : MouseButtonsAsync
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_VKeyMouse WNT_Window::MouseButtonsAsync()
|
||||
{
|
||||
Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
|
||||
const bool isSwapped = GetSystemMetrics (SM_SWAPBUTTON) != 0;
|
||||
|
||||
if ((GetAsyncKeyState (!isSwapped ? VK_LBUTTON : VK_RBUTTON) & 0x8000) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_LeftButton;
|
||||
}
|
||||
if ((GetAsyncKeyState (VK_MBUTTON) & 0x8000) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_MiddleButton;
|
||||
}
|
||||
if ((GetAsyncKeyState (!isSwapped ? VK_RBUTTON : VK_LBUTTON) & 0x8000) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_RightButton;
|
||||
}
|
||||
return aButtons;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
Reference in New Issue
Block a user