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

GHOST_TrackpadWin32.h « intern « ghost « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e28f7569652f6650f895c64f2bd346931ff7a5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup GHOST
 * Declaration of GHOST DirectManipulation classes.
 */

#pragma once

#ifndef WIN32
#  error WIN32 only!
#endif  // WIN32

#include "GHOST_Types.h"

#include <directmanipulation.h>
#include <wrl.h>

#define PINCH_SCALE_FACTOR 125.0f

typedef struct {
  int32_t x, y, scale;
  bool isScrollDirectionInverted;
} GHOST_TTrackpadInfo;

class GHOST_DirectManipulationHelper;

class GHOST_DirectManipulationViewportEventHandler
    : public Microsoft::WRL::RuntimeClass<
          Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
          Microsoft::WRL::Implements<
              Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
              Microsoft::WRL::FtmBase,
              IDirectManipulationViewportEventHandler>> {
 public:
  GHOST_DirectManipulationViewportEventHandler(uint16_t dpi);

  /*
   * Resets viewport and tracked touchpad state.
   */
  void resetViewport(IDirectManipulationViewport *viewport);

  /* DirectManipulation callbacks. */
  HRESULT STDMETHODCALLTYPE OnViewportStatusChanged(IDirectManipulationViewport *viewport,
                                                    DIRECTMANIPULATION_STATUS current,
                                                    DIRECTMANIPULATION_STATUS previous) override;

  HRESULT STDMETHODCALLTYPE OnViewportUpdated(IDirectManipulationViewport *viewport) override;

  HRESULT STDMETHODCALLTYPE OnContentUpdated(IDirectManipulationViewport *viewport,
                                             IDirectManipulationContent *content) override;

 private:
  enum { GESTURE_NONE, GESTURE_PAN, GESTURE_PINCH } gesture_state;

  int32_t last_x, last_y, last_scale;
  GHOST_TTrackpadInfo accumulated_values;
  uint16_t dpi;
  DIRECTMANIPULATION_STATUS dm_status;

  friend class GHOST_DirectManipulationHelper;
};

class GHOST_DirectManipulationHelper {
 public:
  /*
   * Creates a GHOST_DirectManipulationHelper for the provided window.
   * \param hWnd: The window receiving DirectManipulation events.
   * \param dpi: The current DPI.
   * \return Pointer to the new GHOST_DirectManipulationHelper if created, nullptr if there was an
   * error.
   */
  static GHOST_DirectManipulationHelper *create(HWND hWnd, uint16_t dpi);

  ~GHOST_DirectManipulationHelper();

  /*
   * Drives the DirectManipulation context.
   * DirectManipulation's intended use is to tie user input into DirectComposition's compositor
   * scaling and translating. We are not using DirectComposition and therefore must drive
   * DirectManipulation manually.
   */
  void update();

  /*
   * Sets pointer in contact with the DirectManipulation context.
   * \param pointerId: ID of the pointer in contact.
   */
  void onPointerHitTest(UINT32 pointerId);

  /*
   * Updates DPI information for touchpad scaling.
   * \param dpi: The new DPI.
   */
  void setDPI(uint16_t dpi);

  /*
   * Retrieves trackpad input.
   * \return The accumulated trackpad translation and scale since last call.
   */
  GHOST_TTrackpadInfo getTrackpadInfo();

 private:
  GHOST_DirectManipulationHelper(
      HWND hWnd,
      Microsoft::WRL::ComPtr<IDirectManipulationManager> directManipulationManager,
      Microsoft::WRL::ComPtr<IDirectManipulationUpdateManager> directManipulationUpdateManager,
      Microsoft::WRL::ComPtr<IDirectManipulationViewport> directManipulationViewport,
      Microsoft::WRL::ComPtr<GHOST_DirectManipulationViewportEventHandler>
          directManipulationEventHandler,
      DWORD directManipulationViewportHandlerCookie,
      bool isScrollDirectionInverted);

  /*
   * Retrieves the scroll direction from the registry.
   * \return True if scroll direction is inverted.
   */
  static bool getScrollDirectionFromReg();

  /*
   * Registers listener for registry scroll direction entry changes.
   */
  void registerScrollDirectionChangeListener();

  HWND m_hWnd;

  HKEY m_scrollDirectionRegKey;
  HANDLE m_scrollDirectionChangeEvent;

  Microsoft::WRL::ComPtr<IDirectManipulationManager> m_directManipulationManager;
  Microsoft::WRL::ComPtr<IDirectManipulationUpdateManager> m_directManipulationUpdateManager;
  Microsoft::WRL::ComPtr<IDirectManipulationViewport> m_directManipulationViewport;
  Microsoft::WRL::ComPtr<GHOST_DirectManipulationViewportEventHandler>
      m_directManipulationEventHandler;
  DWORD m_directManipulationViewportHandlerCookie;

  bool m_isScrollDirectionInverted;
};