1 #ifndef __LDINPUTHANDLER_H__ 2 #define __LDINPUTHANDLER_H__ 3 #include <TCFoundation/TCAlertSender.h> 4 5 class LDrawModelViewer; 6 class TCAlert; 7 class TCVector; 8 9 class LDInputHandler : public TCAlertSender 10 { 11 public: 12 enum ModifierKey 13 { 14 MKShift = 0x0001, 15 MKControl = 0x0002, 16 MKAppleControl = 0x0004, 17 }; 18 enum MouseButton 19 { 20 MBUnknown, 21 MBLeft, 22 MBFirst = MBLeft, // This intentionally skips MBUnknown 23 MBRight, 24 MBMiddle, 25 MBLast = MBMiddle 26 }; 27 enum ViewMode 28 { 29 VMExamine, 30 VMFlyThrough, 31 VMWalk, 32 }; 33 // Note: the special key values happen to match Windows, but that's only 34 // because it made it easy to be sure there were no repeats. Even the 35 // Windows code that relies on these should not assume that they will 36 // match. 37 enum KeyCode 38 { 39 KCUnknown, 40 KCReturn = 13, 41 KCShift = 16, 42 KCControl, 43 KCAlt, 44 KCSpace = ' ', 45 KCPageUp, 46 KCPageDown, 47 KCEnd, 48 KCHome, 49 KCEscape = 27, 50 KCLeft = 38, 51 KCUp, 52 KCRight, 53 KCDown, 54 KCInsert = 45, 55 KCDelete, 56 KCA = 'A', 57 KCB, 58 KCC, 59 KCD, 60 KCE, 61 KCF, 62 KCG, 63 KCH, 64 KCI, 65 KCJ, 66 KCK, 67 KCL, 68 KCM, 69 KCN, 70 KCO, 71 KCP, 72 KCQ, 73 KCR, 74 KCS, 75 KCT, 76 KCU, 77 KCV, 78 KCW, 79 KCX, 80 KCY, 81 KCZ, 82 }; 83 84 LDInputHandler(LDrawModelViewer *modelViewer); 85 86 void setViewMode(ViewMode value); getViewMode(void)87 ViewMode getViewMode(void) const { return m_viewMode; } 88 bool mouseDown(TCULong modifierKeys, MouseButton button, int x, int y); 89 bool mouseUp(TCULong modifierKeys, MouseButton button, int x, int y); 90 bool mouseMove(TCULong modifierKeys, int x, int y); 91 bool mouseWheel(TCULong modifierKeys, TCFloat amount); 92 bool mouseCaptureChanged(void); 93 bool keyDown(TCULong modifierKeys, KeyCode keyCode); 94 bool keyUp(TCULong modifierKeys, KeyCode keyCode); 95 void setMouseUpPending(bool value); 96 void cancelMouseDrag(void); 97 virtual TCObject *getAlertSender(void); 98 void stopRotation(void); 99 captureAlertClass(void)100 static const char *captureAlertClass(void) { return "LDCaptureMouse"; } releaseAlertClass(void)101 static const char *releaseAlertClass(void) { return "LDReleaseMouse"; } peekMouseUpAlertClass(void)102 static const char *peekMouseUpAlertClass(void) { return "LDPeekMouseUp"; } 103 protected: 104 typedef enum 105 { 106 MMNone, 107 MMNormal, 108 MMZoom, 109 MMPan, 110 MMLight, 111 } MouseMode; 112 113 ~LDInputHandler(void); 114 void dealloc(void); 115 bool leftDown(TCULong modifierKeys, int xPos, int yPos); 116 void updateSpinRateXY(int xPos, int yPos); 117 void updateXY(TCULong modifierKeys, int xPos, int yPos); 118 void updateHeadXY(TCULong modifierKeys, int xPos, int yPos); 119 void updatePanXY(int xPos, int yPos); 120 void updateLightXY(int xPos, int yPos); 121 void updateZoomY(int yPos); 122 void frameDone(TCAlert *alert); 123 void updateCameraMotion(TCVector &cameraMotion, TCFloat motionAmount, 124 TCFloat strafeAmount); 125 void updateCameraRotation(TCFloat rotationAmount, TCFloat rollAmount); 126 void updateRotation(TCFloat rotationSpeed); 127 void recordRotationStop(void); 128 void clearRotationStop(void); 129 bool checkSpin(void); 130 //double getTimeRef(void); 131 132 LDrawModelViewer *m_modelViewer; 133 ViewMode m_viewMode; 134 MouseMode m_mouseMode; 135 bool m_buttonsDown[3]; 136 bool m_appleRightClick; 137 int m_numButtons; 138 int m_clickX; 139 int m_clickY; 140 int m_lastX; 141 int m_lastY; 142 int m_lastFrameX; 143 int m_lastFrameY; 144 TCFloat m_rotationSpeed; 145 bool m_mouseUpPending; 146 bool m_mouseUpHandled; 147 //double m_lastMoveTime; 148 149 float m_lastXRotate; 150 float m_lastYRotate; 151 #ifdef WIN32 152 DWORD m_stopTicks; 153 bool m_haveStopTicks; 154 #endif // WIN32 155 #ifdef COCOA 156 void *m_stopTime; 157 #endif // COCOA 158 static TCFloat sm_keyRotationSpeed; 159 }; 160 161 #endif // __LDINPUTHANDLER_H__ 162