Blender V4.3
GHOST_TrackpadWin32.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#pragma once
11
12#ifndef WIN32
13# error WIN32 only!
14#endif // WIN32
15
16#include "GHOST_Types.h"
17
18#include <directmanipulation.h>
19#include <wrl.h>
20
21#define PINCH_SCALE_FACTOR 125.0f
22
27
29
31 : public Microsoft::WRL::RuntimeClass<
32 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
33 Microsoft::WRL::Implements<
34 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
35 Microsoft::WRL::FtmBase,
36 IDirectManipulationViewportEventHandler>> {
37 public:
39
40 /*
41 * Resets viewport and tracked touchpad state.
42 */
43 void resetViewport(IDirectManipulationViewport *viewport);
44
45 /* DirectManipulation callbacks. */
46 HRESULT STDMETHODCALLTYPE OnViewportStatusChanged(IDirectManipulationViewport *viewport,
47 DIRECTMANIPULATION_STATUS current,
48 DIRECTMANIPULATION_STATUS previous) override;
49
50 HRESULT STDMETHODCALLTYPE OnViewportUpdated(IDirectManipulationViewport *viewport) override;
51
52 HRESULT STDMETHODCALLTYPE OnContentUpdated(IDirectManipulationViewport *viewport,
53 IDirectManipulationContent *content) override;
54
55 private:
56 enum { GESTURE_NONE, GESTURE_PAN, GESTURE_PINCH } gesture_state;
57
58 int32_t last_x, last_y, last_scale;
59 GHOST_TTrackpadInfo accumulated_values;
60 uint16_t dpi;
61 DIRECTMANIPULATION_STATUS dm_status;
62
64};
65
67 public:
68 /*
69 * Creates a GHOST_DirectManipulationHelper for the provided window.
70 * \param hWnd: The window receiving DirectManipulation events.
71 * \param dpi: The current DPI.
72 * \return Pointer to the new GHOST_DirectManipulationHelper if created, nullptr if there was an
73 * error.
74 */
75 static GHOST_DirectManipulationHelper *create(HWND hWnd, uint16_t dpi);
76
78
79 /*
80 * Drives the DirectManipulation context.
81 * DirectManipulation's intended use is to tie user input into DirectComposition's compositor
82 * scaling and translating. We are not using DirectComposition and therefore must drive
83 * DirectManipulation manually.
84 */
85 void update();
86
87 /*
88 * Sets pointer in contact with the DirectManipulation context.
89 * \param pointerId: ID of the pointer in contact.
90 */
91 void onPointerHitTest(UINT32 pointerId);
92
93 /*
94 * Updates DPI information for touchpad scaling.
95 * \param dpi: The new DPI.
96 */
97 void setDPI(uint16_t dpi);
98
99 /*
100 * Retrieves trackpad input.
101 * \return The accumulated trackpad translation and scale since last call.
102 */
104
105 private:
107 HWND hWnd,
108 Microsoft::WRL::ComPtr<IDirectManipulationManager> directManipulationManager,
109 Microsoft::WRL::ComPtr<IDirectManipulationUpdateManager> directManipulationUpdateManager,
110 Microsoft::WRL::ComPtr<IDirectManipulationViewport> directManipulationViewport,
111 Microsoft::WRL::ComPtr<GHOST_DirectManipulationViewportEventHandler>
112 directManipulationEventHandler,
113 DWORD directManipulationViewportHandlerCookie,
114 bool isScrollDirectionInverted);
115
116 /*
117 * Retrieves the scroll direction from the registry.
118 * \return True if scroll direction is inverted.
119 */
120 static bool getScrollDirectionFromReg();
121
122 /*
123 * Registers listener for registry scroll direction entry changes.
124 */
125 void registerScrollDirectionChangeListener();
126
127 HWND m_hWnd;
128
129 HKEY m_scrollDirectionRegKey;
130 HANDLE m_scrollDirectionChangeEvent;
131
132 Microsoft::WRL::ComPtr<IDirectManipulationManager> m_directManipulationManager;
133 Microsoft::WRL::ComPtr<IDirectManipulationUpdateManager> m_directManipulationUpdateManager;
134 Microsoft::WRL::ComPtr<IDirectManipulationViewport> m_directManipulationViewport;
135 Microsoft::WRL::ComPtr<GHOST_DirectManipulationViewportEventHandler>
136 m_directManipulationEventHandler;
137 DWORD m_directManipulationViewportHandlerCookie;
138
139 bool m_isScrollDirectionInverted;
140};
void onPointerHitTest(UINT32 pointerId)
static GHOST_DirectManipulationHelper * create(HWND hWnd, uint16_t dpi)
void resetViewport(IDirectManipulationViewport *viewport)
HRESULT STDMETHODCALLTYPE OnContentUpdated(IDirectManipulationViewport *viewport, IDirectManipulationContent *content) override
HRESULT STDMETHODCALLTYPE OnViewportUpdated(IDirectManipulationViewport *viewport) override
HRESULT STDMETHODCALLTYPE OnViewportStatusChanged(IDirectManipulationViewport *viewport, DIRECTMANIPULATION_STATUS current, DIRECTMANIPULATION_STATUS previous) override
unsigned short uint16_t
Definition stdint.h:79
signed int int32_t
Definition stdint.h:77