All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WindowsInputProcessor.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "WindowsInput.h"
6 #include "MousePanGesture.h"
7 #include "MouseRotateGesture.h"
8 #include "MouseZoomGesture.h"
9 #include "MouseTiltGesture.h"
10 #include "MouseTouchGesture.h"
11 #include "MouseTapGesture.h"
12 #include "TouchScreenPanGesture.h"
13 #include "TouchScreenPinchGesture.h"
14 #include "TouchScreenRotateGesture.h"
15 #include "TouchScreenTiltGesture.h"
16 #include "TouchScreenTouchGesture.h"
17 #include "TouchScreenTapGesture.h"
18 #include "WindowsNativeState.h"
19 #include "MouseInputEvent.h"
20 #include "TouchScreenInputEvent.h"
21 #include "IWindowsInputHandler.h"
22 #include "IUserIdleService.h"
23 
24 namespace Eegeo
25 {
26  namespace Windows
27  {
28  namespace Input
29  {
31  {
33  : PanStartThresholdPixels(0.f)
34  , ZoomSensitivity(0.f)
35  , MaxZoomPerSecond(0.f)
36  {}
37 
38  float PanStartThresholdPixels;
39  float ZoomSensitivity;
40  float MaxZoomPerSecond;
41  };
42 
44  {
45  private:
46  MousePanGesture m_mousePan;
47  MouseZoomGesture m_mouseZoom;
48  MouseRotateGesture m_mouseRotate;
49  MouseTiltGesture m_mouseTilt;
50  MouseTouchGesture m_mouseTouch;
51  MouseTapGesture m_mouseTap;
52 
53  TouchScreenPanGesture m_touchScreenPan;
54  TouchScreenPinchGesture m_touchScreenPinch;
55  TouchScreenRotateGesture m_touchScreenRotate;
56  TouchScreenTiltGesture m_touchScreenTilt;
57  TouchScreenTouchGesture m_touchScreenTouch;
58  TouchScreenTapGesture m_touchScreenTap;
59  bool m_isTouchInputEnabled;
60 
61  std::vector<TouchScreenInputEvent> m_touchScreenEvents;
62  void PushTouchEvent(const TouchScreenInputEvent& touchEvent);
63  void PopTouchEvent(const TouchScreenInputEvent& touchEvent);
64  void UpdateTouchEvents(const TouchScreenInputEvent& touchEvent);
65 
66  EGLNativeWindowType m_hwnd;
67 
68  IWindowsInputHandler* m_pHandler;
69 
70  long long m_lastTouchTimeMs;
71 
72  public:
73  WindowsInputProcessor(IWindowsInputHandler* pHandler, EGLNativeWindowType hwnd, const float screenWidth, const float screenHeight, const WindowsInputProcessorConfig& config, const bool isTouchInputEnabled, const int maxDeviceTouchCount);
74  void HandleMouseInput(const MouseInputEvent& event, float screenWidth, float screenHeight);
75  void HandleMousePreviewInput(const MouseInputEvent& mouseEvent);
76  void HandleMouseInput(const KeyboardInputEvent& keyEvent);
77  void HandleTouchScreenInput(const TouchScreenInputEvent& event, float screenWidth, float screenHeight);
78  void Update(float deltaSeconds);
79 
80  bool IsMouseInsideWindow();
81  void SetAllInputEventsToPointerUp(int x, int y);
82  void SetTouchInputEventToPointerUp(int touchId);
83  void PopAllTouchEvents();
84 
85  long long GetUserIdleTimeMs() const;
86 
87  inline static WindowsInputProcessorConfig DefaultConfig();
88 
89  static MouseInputEvent MakeMouseInputEvent(MouseInputAction mouseInputAction, WPARAM wparam, LPARAM lparam, int wheelDelta);
90 
91  void SaveInputTime();
92  };
93 
94  inline WindowsInputProcessorConfig WindowsInputProcessor::DefaultConfig()
95  {
97  config.PanStartThresholdPixels = 4.f;
98  // ZoomSensitivity is unitless scaling value
99  // WM_MOUSEWHEEL message values are first divided by WHEEL_DELTA (120)
100  // Then multiplied by ZoomSensitivity to convert to same units as used by pinch-zoom on touch devices
101  // (which is distance pinched in normalized screen coordinates).
102  config.ZoomSensitivity = 0.012f;
103  config.MaxZoomPerSecond = 5.0f;
104  return config;
105  }
106  }
107  }
108 }