Mouse.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Mouse.h //////////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: Mouse.h
  36. //
  37. // Created: Michael S. Booth, January 1995
  38. // Colin Day, June 2001
  39. //
  40. // Desc: Basic mouse structure layout
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. #pragma once
  45. #ifndef __MOUSE_H_
  46. #define __MOUSE_H_
  47. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  48. // USER INCLUDES //////////////////////////////////////////////////////////////
  49. #include "Lib/BaseType.h"
  50. #include "Common/SubsystemInterface.h"
  51. #include "Common/AsciiString.h"
  52. #include "Common/UnicodeString.h"
  53. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  54. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  55. enum MouseButtonState
  56. {
  57. MBS_Up = 0,
  58. MBS_Down,
  59. MBS_DoubleClick,
  60. };
  61. #define MOUSE_MOVE_RELATIVE 0
  62. #define MOUSE_MOVE_ABSOLUTE 1
  63. // In frames
  64. #define CLICK_SENSITIVITY 15
  65. // In pixels
  66. #define CLICK_DISTANCE_DELTA 10
  67. #define CLICK_DISTANCE_DELTA_SQUARED (CLICK_DISTANCE_DELTA*CLICK_DISTANCE_DELTA)
  68. //
  69. #define MOUSE_WHEEL_DELTA 120
  70. #define MOUSE_NONE 0x00
  71. #define MOUSE_OK 0x01
  72. #define MOUSE_FAILED 0x80
  73. #define MOUSE_LOST 0xFF
  74. #define MOUSE_EVENT_NONE 0x00
  75. class DisplayString;
  76. #define MAX_2D_CURSOR_ANIM_FRAMES 21
  77. #define MAX_2D_CURSOR_DIRECTIONS 8
  78. // MouseIO --------------------------------------------------------------------
  79. /** @todo this mouse structure needs to be revisited to allow for devices
  80. with more than 3 buttons */
  81. //-----------------------------------------------------------------------------
  82. struct MouseIO
  83. {
  84. ICoord2D pos; ///< mouse pointer position
  85. UnsignedInt time; ///< The time that this message was posted.
  86. Int wheelPos; /**< mouse wheel position, 0 is no event, + is up/away from
  87. user while - is down/toward user */
  88. ICoord2D deltaPos; ///< overall change in mouse pointer this frame
  89. MouseButtonState leftState; // button state: Up, Down, DoubleClick (Which is also down)
  90. Int leftEvent; // Most important event this frame
  91. Int leftFrame; // last frame button state changed
  92. MouseButtonState rightState;
  93. Int rightEvent;
  94. Int rightFrame;
  95. MouseButtonState middleState;
  96. Int middleEvent;
  97. Int middleFrame;
  98. };
  99. class CursorInfo
  100. {
  101. public:
  102. CursorInfo();
  103. AsciiString cursorName;
  104. AsciiString cursorText;
  105. RGBAColorInt cursorTextColor;
  106. RGBAColorInt cursorTextDropColor;
  107. AsciiString textureName;
  108. AsciiString imageName;
  109. AsciiString W3DModelName;
  110. AsciiString W3DAnimName;
  111. Real W3DScale;
  112. Bool loop;
  113. ICoord2D hotSpotPosition;
  114. Int numFrames;
  115. Real fps; //frames per ms.
  116. Int numDirections; //number of directions for cursors like scrolling/panning.
  117. };
  118. // Mouse ----------------------------------------------------------------------
  119. /** Class interface for working with a mouse pointing device */
  120. //-----------------------------------------------------------------------------
  121. class Mouse : public SubsystemInterface
  122. {
  123. public: // enumerations and types
  124. // ----------------------------------------------------------------------------------------------
  125. /** If you update this enum make sure you update CursorININames[] */
  126. // ----------------------------------------------------------------------------------------------
  127. enum MouseCursor
  128. {
  129. // ***** dont forget to update CursorININames[] *****
  130. // ***** dont forget to update CursorININames[] *****
  131. // ***** dont forget to update CursorININames[] *****
  132. INVALID_MOUSE_CURSOR = -1,
  133. NONE = 0,
  134. FIRST_CURSOR,
  135. NORMAL = FIRST_CURSOR,
  136. ARROW,
  137. SCROLL,
  138. CROSS,
  139. MOVETO,
  140. ATTACKMOVETO,
  141. ATTACK_OBJECT,
  142. FORCE_ATTACK_OBJECT,
  143. FORCE_ATTACK_GROUND,
  144. BUILD_PLACEMENT,
  145. INVALID_BUILD_PLACEMENT,
  146. GENERIC_INVALID,
  147. SELECTING,
  148. // ***** dont forget to update CursorININames[] *****
  149. ENTER_FRIENDLY,
  150. ENTER_AGGRESSIVELY,
  151. SET_RALLY_POINT,
  152. GET_REPAIRED,
  153. GET_HEALED,
  154. DO_REPAIR,
  155. RESUME_CONSTRUCTION,
  156. CAPTUREBUILDING,
  157. // ***** dont forget to update CursorININames[] *****
  158. SNIPE_VEHICLE,
  159. LASER_GUIDED_MISSILES,
  160. TANKHUNTER_TNT_ATTACK,
  161. STAB_ATTACK,
  162. PLACE_REMOTE_CHARGE,
  163. // ***** dont forget to update CursorININames[] *****
  164. PLACE_TIMED_CHARGE,
  165. DEFECTOR,
  166. #ifdef ALLOW_DEMORALIZE
  167. DEMORALIZE,
  168. #endif
  169. DOCK,
  170. // ***** dont forget to update CursorININames[] *****
  171. #ifdef ALLOW_SURRENDER
  172. PICK_UP_PRISONER,
  173. RETURN_TO_PRISON,
  174. #endif
  175. FIRE_FLAME,
  176. #ifdef ALLOW_SURRENDER
  177. FIRE_TRANQ_DARTS,
  178. FIRE_STUN_BULLETS,
  179. #endif
  180. FIRE_BOMB,
  181. PLACE_BEACON,
  182. // ***** dont forget to update CursorININames[] *****
  183. DISGUISE_AS_VEHICLE,
  184. WAYPOINT,
  185. OUTRANGE,
  186. STAB_ATTACK_INVALID,
  187. PLACE_CHARGE_INVALID,
  188. HACK,
  189. PARTICLE_UPLINK_CANNON,
  190. // ***** dont forget to update CursorININames[] *****
  191. NUM_MOUSE_CURSORS // keep this last
  192. };
  193. enum RedrawMode
  194. {
  195. RM_WINDOWS=0, //default Windows cursor - very fast.
  196. RM_W3D, //W3D model tied to frame rate.
  197. RM_POLYGON, //alpha blended polygon tied to frame rate.
  198. RM_DX8, //hardware cursor independent of frame rate.
  199. RM_MAX // keep this last.
  200. };
  201. static const char *RedrawModeName[RM_MAX];
  202. CursorInfo m_cursorInfo[NUM_MOUSE_CURSORS];
  203. public:
  204. Mouse( void );
  205. virtual ~Mouse( void );
  206. // you may need to extend these for your device
  207. virtual void parseIni(void); ///< parse ini settings associated with mouse (do this before init()).
  208. virtual void init( void ); ///< init mouse, extend this functionality, do not replace
  209. virtual void reset( void ); ///< Reset the system
  210. virtual void update( void ); ///< update the state of the mouse position and buttons
  211. virtual void initCursorResources(void)=0; ///< needed so Win32 cursors can load resources before D3D device created.
  212. virtual void createStreamMessages( void ); /**< given state of device, create
  213. messages and put them on the
  214. stream for the raw state. */
  215. virtual void draw( void ); ///< draw the mouse
  216. virtual void setPosition( Int x, Int y ); ///< set the mouse position
  217. virtual void setCursor( MouseCursor cursor ) = 0; ///< set mouse cursor
  218. virtual void capture( void ) = 0; ///< capture the mouse
  219. virtual void releaseCapture( void ) = 0; ///< release mouse capture
  220. // access methods for the mouse data
  221. const MouseIO *getMouseStatus( void ) { return &m_currMouse; } ///< get current mouse status
  222. Int getCursorTooltipDelay() { return m_tooltipDelay; }
  223. void setCursorTooltipDelay(Int delay) { m_tooltipDelay = delay; }
  224. void setCursorTooltip( UnicodeString tooltip, Int tooltipDelay = -1, const RGBColor *color = NULL, Real width = 1.0f ); ///< set tooltip string at cursor
  225. void setMouseText( UnicodeString text, const RGBAColorInt *color, const RGBAColorInt *dropColor ); ///< set the cursor text, *NOT* the tooltip text
  226. virtual void setMouseLimits( void ); ///< update the limit extents the mouse can move in
  227. MouseCursor getMouseCursor(void) { return m_currentCursor; } ///< get the current mouse cursor image type
  228. virtual void setRedrawMode(RedrawMode mode) {m_currentRedrawMode=mode;} ///<set cursor drawing method.
  229. virtual RedrawMode getRedrawMode(void) { return m_currentRedrawMode; } //get cursor drawing method
  230. virtual void setVisibility(Bool visible) { m_visible = visible; } // set visibility for load screens, etc
  231. inline Bool getVisibility(void) { return m_visible; } // get visibility state
  232. void drawTooltip( void ); ///< draw the tooltip text
  233. void drawCursorText( void ); ///< draw the mouse cursor text
  234. Int getCursorIndex( const AsciiString& name );
  235. void resetTooltipDelay( void );
  236. void mouseNotifyResolutionChange(void);
  237. Bool isClick(const ICoord2D *anchor, const ICoord2D *dest, UnsignedInt previousMouseClick, UnsignedInt currentMouseClick);
  238. AsciiString m_tooltipFontName; ///< tooltip font
  239. Int m_tooltipFontSize; ///< tooltip font
  240. Bool m_tooltipFontIsBold; ///< tooltip font
  241. Bool m_tooltipAnimateBackground; ///< animate the background with the text
  242. Int m_tooltipFillTime; ///< milliseconds to animate tooltip
  243. Int m_tooltipDelayTime; ///< milliseconds to wait before showing tooltip
  244. Real m_tooltipWidth; ///< default tooltip width in screen width %
  245. Real m_lastTooltipWidth;
  246. RGBAColorInt m_tooltipColorText;
  247. RGBAColorInt m_tooltipColorHighlight;
  248. RGBAColorInt m_tooltipColorShadow;
  249. RGBAColorInt m_tooltipColorBackground;
  250. RGBAColorInt m_tooltipColorBorder;
  251. RedrawMode m_currentRedrawMode; ///< mouse cursor drawing method
  252. Bool m_useTooltipAltTextColor; ///< draw tooltip text with house colors?
  253. Bool m_useTooltipAltBackColor; ///< draw tooltip backgrounds with house colors?
  254. Bool m_adjustTooltipAltColor; ///< adjust house colors (darker/brighter) for tooltips?
  255. Bool m_orthoCamera; ///< use an ortho camera for 3D cursors?
  256. Real m_orthoZoom; ///< uniform zoom to apply to 3D cursors when using ortho cameras
  257. UnsignedInt m_dragTolerance;
  258. UnsignedInt m_dragTolerance3D;
  259. UnsignedInt m_dragToleranceMS;
  260. protected:
  261. /// you must implement getting a buffered mouse event from you device here
  262. virtual UnsignedByte getMouseEvent( MouseIO *result, Bool flush ) = 0;
  263. //-----------------------------------------------------------------------------------------------
  264. // internal methods
  265. void updateMouseData( ); ///< update the mouse with the current device data
  266. void processMouseEvent( Int eventToProcess ); ///< combine mouse events into final data
  267. void checkForDrag( void ); ///< check for mouse drag
  268. void moveMouse( Int x, Int y, Int relOrAbs ); ///< move mouse by delta or absolute
  269. //---------------------------------------------------------------------------
  270. // internal mouse data members
  271. UnsignedByte m_numButtons; ///< number of buttons on this mouse
  272. UnsignedByte m_numAxes; ///< number of axes this mouse has
  273. Bool m_forceFeedback; ///< set to TRUE if mouse supprots force feedback
  274. UnicodeString m_tooltipString; ///< tooltip text
  275. DisplayString *m_tooltipDisplayString; ///< tooltipDisplayString
  276. Bool m_displayTooltip; /**< when the mouse has been still long enough this will be
  277. set to TRUE indicating it's Ok to fire off a tooltip */
  278. Bool m_isTooltipEmpty;
  279. enum { NUM_MOUSE_EVENTS = 256 };
  280. MouseIO m_mouseEvents[ NUM_MOUSE_EVENTS ]; ///< for event list
  281. MouseIO m_currMouse; ///< for current mouse data
  282. MouseIO m_prevMouse; ///< for previous mouse data
  283. Int m_minX; ///< mouse is locked to this region
  284. Int m_maxX; ///< mouse is locked to this region
  285. Int m_minY; ///< mouse is locked to this region
  286. Int m_maxY; ///< mouse is locked to this region
  287. UnsignedInt m_inputFrame; ///< frame input was gathered on
  288. UnsignedInt m_deadInputFrame; ///< Frame which last input occured
  289. Bool m_inputMovesAbsolute; /**< if TRUE, when processing mouse position
  290. chanages the movement will be done treating
  291. the coords as ABSOLUTE positions and NOT
  292. relative coordinate changes */
  293. Bool m_visible; // visibility status
  294. MouseCursor m_currentCursor; ///< current mouse cursor
  295. DisplayString *m_cursorTextDisplayString; ///< text to display on the cursor (if specified)
  296. RGBAColorInt m_cursorTextColor; ///< color of the cursor text
  297. RGBAColorInt m_cursorTextDropColor; ///< color of the cursor text drop shadow
  298. Int m_tooltipDelay; ///< millisecond delay for tooltips
  299. Int m_highlightPos;
  300. UnsignedInt m_highlightUpdateStart;
  301. UnsignedInt m_stillTime;
  302. RGBAColorInt m_tooltipTextColor;
  303. RGBAColorInt m_tooltipBackColor;
  304. Int m_eventsThisFrame;
  305. }; // end class Mouse
  306. // INLINING ///////////////////////////////////////////////////////////////////
  307. // EXTERNALS //////////////////////////////////////////////////////////////////
  308. extern Mouse *TheMouse; ///< extern mouse singleton definition
  309. #endif // _MOUSE_H_