Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Rishel <nicholas_rishel>2020-03-27 19:21:43 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-04-08 13:25:40 +0300
commit3d8c57f4daec7c07eca78c0290131d8c02629889 (patch)
tree82861e997b6b3bf3a10b1fb7c8cd0adc1c3444b5
parent4e4bf241c8a08d4f083e36eed9fe3938ef4301f2 (diff)
Cleanup: minor refactoring of pointer event handling
Ref D6675
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.cpp100
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.h22
-rw-r--r--intern/ghost/intern/GHOST_WindowWin32.cpp22
-rw-r--r--intern/ghost/intern/GHOST_WindowWin32.h24
4 files changed, 86 insertions, 82 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 12226be10ab..ad53afd9555 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -920,6 +920,14 @@ GHOST_EventButton *GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type,
GHOST_TButtonMask mask)
{
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
+
+ if (type == GHOST_kEventButtonDown) {
+ window->updateMouseCapture(MousePressed);
+ }
+ else if (type == GHOST_kEventButtonUp) {
+ window->updateMouseCapture(MouseReleased);
+ }
+
if (window->useTabletAPI(GHOST_kTabletNative)) {
window->setTabletData(NULL);
}
@@ -927,63 +935,63 @@ GHOST_EventButton *GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type,
system->getMilliSeconds(), type, window, mask, window->getTabletData());
}
-GHOST_Event *GHOST_SystemWin32::processPointerEvent(GHOST_TEventType type,
- GHOST_WindowWin32 *window,
- WPARAM wParam,
- LPARAM lParam,
- bool &eventHandled)
+void GHOST_SystemWin32::processPointerEvents(
+ UINT type, GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam, bool &eventHandled)
{
GHOST_PointerInfoWin32 pointerInfo;
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
if (!window->useTabletAPI(GHOST_kTabletNative)) {
- return NULL;
+ return;
}
if (window->getPointerInfo(&pointerInfo, wParam, lParam) != GHOST_kSuccess) {
- return NULL;
+ return;
}
if (!pointerInfo.isPrimary) {
eventHandled = true;
- return NULL; // For multi-touch displays we ignore these events
+ return; // For multi-touch displays we ignore these events
}
system->setCursorPosition(pointerInfo.pixelLocation.x, pointerInfo.pixelLocation.y);
switch (type) {
- case GHOST_kEventButtonDown:
+ case WM_POINTERDOWN:
/* Update window tablet data to be included in event. */
window->setTabletData(&pointerInfo.tabletData);
- eventHandled = true;
- return new GHOST_EventButton(system->getMilliSeconds(),
- GHOST_kEventButtonDown,
- window,
- pointerInfo.buttonMask,
- pointerInfo.tabletData);
- case GHOST_kEventButtonUp:
- eventHandled = true;
- return new GHOST_EventButton(system->getMilliSeconds(),
- GHOST_kEventButtonUp,
- window,
- pointerInfo.buttonMask,
- window->getTabletData());
- case GHOST_kEventCursorMove:
+ system->pushEvent(new GHOST_EventButton(system->getMilliSeconds(),
+ GHOST_kEventButtonDown,
+ window,
+ pointerInfo.buttonMask,
+ pointerInfo.tabletData));
+ window->updateMouseCapture(MousePressed);
+ break;
+ case WM_POINTERUPDATE:
/* Update window tablet data to be included in event. */
- eventHandled = true;
- return new GHOST_EventCursor(system->getMilliSeconds(),
- GHOST_kEventCursorMove,
- window,
- pointerInfo.pixelLocation.x,
- pointerInfo.pixelLocation.y,
- pointerInfo.tabletData);
+ system->pushEvent(GHOST_EventCursor(system->getMilliSeconds(),
+ GHOST_kEventCursorMove,
+ window,
+ pointerInfo.pixelLocation.x,
+ pointerInfo.pixelLocation.y,
+ pointerInfo.tabletData));
+ break;
+ case WM_POINTERUP:
+ system->pushEvent(new GHOST_EventButton(system->getMilliSeconds(),
+ GHOST_kEventButtonUp,
+ window,
+ pointerInfo.buttonMask,
+ window->getTabletData()));
+ window->updateMouseCapture(MouseReleased);
+ break;
default:
- return NULL;
+ break;
}
+
+ eventHandled = true;
}
-GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_TEventType type,
- GHOST_WindowWin32 *window)
+GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_WindowWin32 *window)
{
GHOST_TInt32 x_screen, y_screen;
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
@@ -1417,39 +1425,23 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
// Pointer events, processed
////////////////////////////////////////////////////////////////////////
case WM_POINTERDOWN:
- event = processPointerEvent(
- GHOST_kEventButtonDown, window, wParam, lParam, eventHandled);
- if (event && eventHandled) {
- window->registerMouseClickEvent(0);
- }
- break;
- case WM_POINTERUP:
- event = processPointerEvent(GHOST_kEventButtonUp, window, wParam, lParam, eventHandled);
- if (event && eventHandled) {
- window->registerMouseClickEvent(1);
- }
- break;
case WM_POINTERUPDATE:
- event = processPointerEvent(
- GHOST_kEventCursorMove, window, wParam, lParam, eventHandled);
+ case WM_POINTERUP:
+ processPointerEvents(msg, window, wParam, lParam, eventHandled);
break;
////////////////////////////////////////////////////////////////////////
// Mouse events, processed
////////////////////////////////////////////////////////////////////////
case WM_LBUTTONDOWN:
- window->registerMouseClickEvent(0);
event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskLeft);
break;
case WM_MBUTTONDOWN:
- window->registerMouseClickEvent(0);
event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskMiddle);
break;
case WM_RBUTTONDOWN:
- window->registerMouseClickEvent(0);
event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskRight);
break;
case WM_XBUTTONDOWN:
- window->registerMouseClickEvent(0);
if ((short)HIWORD(wParam) == XBUTTON1) {
event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskButton4);
}
@@ -1458,19 +1450,15 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
}
break;
case WM_LBUTTONUP:
- window->registerMouseClickEvent(1);
event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskLeft);
break;
case WM_MBUTTONUP:
- window->registerMouseClickEvent(1);
event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskMiddle);
break;
case WM_RBUTTONUP:
- window->registerMouseClickEvent(1);
event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskRight);
break;
case WM_XBUTTONUP:
- window->registerMouseClickEvent(1);
if ((short)HIWORD(wParam) == XBUTTON1) {
event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskButton4);
}
@@ -1479,7 +1467,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
}
break;
case WM_MOUSEMOVE:
- event = processCursorEvent(GHOST_kEventCursorMove, window);
+ event = processCursorEvent(window);
break;
case WM_MOUSEWHEEL: {
/* The WM_MOUSEWHEEL message is sent to the focus window
diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h
index 14ee1f38ecd..c6d810d2a38 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.h
+++ b/intern/ghost/intern/GHOST_SystemWin32.h
@@ -310,27 +310,29 @@ class GHOST_SystemWin32 : public GHOST_System {
GHOST_TButtonMask mask);
/**
- * Creates pointer event.
- * \param type The type of event to create.
+ * Creates tablet events from Wintab events.
+ * \param type The type of pointer event
+ * \param window The window receiving the event (the active window).
+ */
+ static GHOST_TSuccess processWintabEvents(GHOST_TEventType type, GHOST_WindowWin32 *window);
+
+ /**
+ * Creates tablet events from pointer events.
+ * \param type The type of pointer event
* \param window The window receiving the event (the active window).
* \param wParam The wParam from the wndproc
* \param lParam The lParam from the wndproc
* \param eventhandled true if the method handled the event
- * \return The event created.
*/
- static GHOST_Event *processPointerEvent(GHOST_TEventType type,
- GHOST_WindowWin32 *window,
- WPARAM wParam,
- LPARAM lParam,
- bool &eventhandled);
+ static void processPointerEvents(
+ UINT type, GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam, bool &eventhandled);
/**
* Creates cursor event.
- * \param type The type of event to create.
* \param window The window receiving the event (the active window).
* \return The event created.
*/
- static GHOST_EventCursor *processCursorEvent(GHOST_TEventType type, GHOST_WindowWin32 *window);
+ static GHOST_EventCursor *processCursorEvent(GHOST_WindowWin32 *window);
/**
* Handles a mouse wheel event.
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index f1a4110995e..9d957da61cd 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -785,21 +785,20 @@ bool GHOST_WindowWin32::isDialog() const
return (parent != 0) && (style & WS_POPUPWINDOW);
}
-void GHOST_WindowWin32::registerMouseClickEvent(int press)
+void GHOST_WindowWin32::updateMouseCapture(GHOST_MouseCaptureEventWin32 event)
{
-
- switch (press) {
- case 0:
+ switch (event) {
+ case MousePressed:
m_nPressedButtons++;
break;
- case 1:
+ case MouseReleased:
if (m_nPressedButtons)
m_nPressedButtons--;
break;
- case 2:
+ case OperatorGrab:
m_hasGrabMouse = true;
break;
- case 3:
+ case OperatorUngrab:
m_hasGrabMouse = false;
break;
}
@@ -814,6 +813,11 @@ void GHOST_WindowWin32::registerMouseClickEvent(int press)
}
}
+bool GHOST_WindowWin32::getMousePressed() const
+{
+ return m_nPressedButtons;
+}
+
HCURSOR GHOST_WindowWin32::getStandardCursor(GHOST_TStandardCursor shape) const
{
// Convert GHOST cursor to Windows OEM cursor
@@ -977,7 +981,7 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCursorGrab(GHOST_TGrabCursorMode mode
if (mode == GHOST_kGrabHide)
setWindowCursorVisibility(false);
}
- registerMouseClickEvent(2);
+ updateMouseCapture(OperatorGrab);
}
else {
if (m_cursorGrab == GHOST_kGrabHide) {
@@ -997,7 +1001,7 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCursorGrab(GHOST_TGrabCursorMode mode
* can be incorrect on exit. */
setCursorGrabAccum(0, 0);
m_cursorGrabBounds.m_l = m_cursorGrabBounds.m_r = -1; /* disable */
- registerMouseClickEvent(3);
+ updateMouseCapture(OperatorUngrab);
}
return GHOST_kSuccess;
diff --git a/intern/ghost/intern/GHOST_WindowWin32.h b/intern/ghost/intern/GHOST_WindowWin32.h
index ac1ec0ee852..fad8813c5d0 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.h
+++ b/intern/ghost/intern/GHOST_WindowWin32.h
@@ -206,6 +206,13 @@ struct GHOST_PointerInfoWin32 {
GHOST_TabletData tabletData;
};
+typedef enum {
+ MousePressed,
+ MouseReleased,
+ OperatorGrab,
+ OperatorUngrab
+} GHOST_MouseCaptureEventWin32;
+
/**
* GHOST window on M$ Windows OSs.
*/
@@ -364,17 +371,14 @@ class GHOST_WindowWin32 : public GHOST_Window {
GHOST_TSuccess endProgressBar();
/**
- * Register a mouse click event (should be called
+ * Register a mouse capture state (should be called
* for any real button press, controls mouse
* capturing).
*
- * \param press
- * 0 - mouse pressed
- * 1 - mouse released
- * 2 - operator grab
- * 3 - operator ungrab
+ * \param event Whether mouse was pressed and released, or an operator grabbed or ungrabbed the
+ * mouse
*/
- void registerMouseClickEvent(int press);
+ void updateMouseCapture(GHOST_MouseCaptureEventWin32 event);
/**
* Inform the window that it has lost mouse capture,
@@ -419,6 +423,12 @@ class GHOST_WindowWin32 : public GHOST_Window {
GHOST_TUns16 getDPIHint() override;
+ /**
+ * Get whether there are currently any mouse buttons pressed
+ * \return True if there are any currently pressed mouse buttons
+ */
+ bool getMousePressed() const;
+
GHOST_TSuccess getPointerInfo(GHOST_PointerInfoWin32 *pointerInfo, WPARAM wParam, LPARAM lParam);
/** if the window currently resizing */