wwmouse.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. ** Command & Conquer Renegade(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Code/Library/wwmouse.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 8/11/97 10:11a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef WW_MOUSE_H
  36. #define WW_MOUSE_H
  37. #include "win.h"
  38. #include "xmouse.h"
  39. class BSurface;
  40. /*
  41. ** Handles the mouse as it relates to the C&C game engine. It is expected that only
  42. ** one object of this type will be created during the lifetime of the game.
  43. */
  44. class WWMouseClass : public Mouse {
  45. public:
  46. /*
  47. ** Private constructor.
  48. */
  49. WWMouseClass(Surface * surfaceptr, HWND window);
  50. virtual ~WWMouseClass(void);
  51. /*
  52. ** Maintenance callback routine.
  53. */
  54. void Process_Mouse(void);
  55. /*
  56. ** Sets the game-drawn mouse imagery.
  57. */
  58. virtual void Set_Cursor(int xhotspot, int yhotspot, ShapeSet const * cursor, int shape);
  59. /*
  60. ** Controls visibility of the game-drawn mouse.
  61. */
  62. virtual void Hide_Mouse(void);
  63. virtual void Show_Mouse(void);
  64. /*
  65. ** Takes control of and releases control of the mouse with
  66. ** respect to the operating system. The mouse must be released
  67. ** during operations with the operating system. When the mouse is
  68. ** relased, it may move outside of the confining rectangle and its
  69. ** shape is controlled by the operating sytem.
  70. */
  71. virtual void Release_Mouse(void);
  72. virtual void Capture_Mouse(void);
  73. virtual bool Is_Captured(void) const {return(IsCaptured);}
  74. /*
  75. ** Hide the mouse if it falls within this game screen region.
  76. */
  77. virtual void Conditional_Hide_Mouse(Rect region);
  78. virtual void Conditional_Show_Mouse(void);
  79. /*
  80. ** Query about the mouse visiblity state and location.
  81. */
  82. virtual int Get_Mouse_State(void) const;
  83. virtual int Get_Mouse_X(void) const {return(MouseX);}
  84. virtual int Get_Mouse_Y(void) const {return(MouseY);}
  85. /*
  86. ** Set the mouse location.
  87. */
  88. virtual void Set_Mouse_XY( int xpos, int ypos );
  89. /*
  90. ** The following two routines can be used to render the mouse onto an alternate
  91. ** surface.
  92. */
  93. virtual void Draw_Mouse(Surface * scr, bool issidebarsurface = false);
  94. virtual void Erase_Mouse(Surface * scr, bool issidebarsurface = false);
  95. //virtual void Draw_Mouse(Surface * scr);
  96. //virtual void Erase_Mouse(Surface * scr);
  97. /*
  98. ** Converts O/S screen coordinates into game coordinates.
  99. */
  100. virtual void Convert_Coordinate(int & x, int & y) const;
  101. /*
  102. ** Recalculate the confining rectangle from the window.
  103. */
  104. void Calc_Confining_Rect(void);
  105. private:
  106. /*
  107. ** Used to prevent conflict between the processing callback and
  108. ** the normal mouse processing routines. The only potential conflict
  109. ** would be with the maintenance callback routine. Since this callback
  110. ** and the mouse class maintain a strict master/slave relationship, a
  111. ** simple critial section flag is all that is needed.
  112. */
  113. long Blocked;
  114. /*
  115. ** Mouse hide/show state. If zero or greater, the mouse is visible. Otherwise
  116. ** it is invisible.
  117. */
  118. long MouseState;
  119. /*
  120. ** If the mouse is being managed by this class (for the game), then this flag
  121. ** will be true. When the mouse has been released to be managed by the operating
  122. ** system, this flag will be false. However, this class will still track the mouse
  123. ** position.
  124. */
  125. bool IsCaptured;
  126. /*
  127. ** This is the last recorded mouse position that it was drawn to.
  128. */
  129. int MouseX;
  130. int MouseY;
  131. /*
  132. ** Points to the main display surface that the mouse will be drawn
  133. ** to as it moves.
  134. */
  135. Surface * SurfacePtr;
  136. /*
  137. ** This is the window handle that is used to bind and bias the mouse
  138. ** position and drawing procedures.
  139. */
  140. HWND Window;
  141. /*
  142. ** This specifies the rectangle that the game oriented mouse will be
  143. ** confined to on the visible surface. If the mouse is manually drawn
  144. ** on another surface, then this rectangle cooresponds to the hidden
  145. ** surface area where the mouse is to be drawn.
  146. */
  147. Rect ConfiningRect;
  148. /*
  149. ** This specifies the mouse shape data. It records the shape set
  150. ** data as well as the particular image contained within.
  151. */
  152. ShapeSet const * MouseShape;
  153. int ShapeNumber;
  154. /*
  155. ** Specifies the hot spot where the image click maps to. This is an
  156. ** offset from the upper left corner of the shape image.
  157. */
  158. int MouseXHot;
  159. int MouseYHot;
  160. /*
  161. ** Holds the background image behind the mouse to be used for
  162. ** restoring the surface pixels.
  163. */
  164. BSurface * Background;
  165. Rect SavedRegion;
  166. /*
  167. ** This is the alternate mouse background buffer to be used when the
  168. ** mouse is manually drawn to an alternate surface by the Draw_Mouse()
  169. ** function.
  170. */
  171. BSurface * Alternate;
  172. Rect AltRegion;
  173. /*
  174. ** This is another alternate buffer for drawing the mouse pointer across a second, adjoining
  175. ** offscreen buffer.
  176. */
  177. BSurface * SidebarAlternate;
  178. Rect SidebarAltRegion;
  179. /*
  180. ** Conditional hide mouse bounding rectangle and mouse state
  181. ** flag.
  182. */
  183. Rect ConditionalRect;
  184. int ConditionalState;
  185. /*
  186. ** Maintenance timer handle.
  187. */
  188. MMRESULT TimerHandle;
  189. // Determines if there is valid mouse shape data available.
  190. bool Is_Data_Valid(void) const;
  191. bool Validate_Copy_Buffer(void);
  192. void Save_Background(void);
  193. void Restore_Background(void);
  194. Rect Matching_Rect(void) const;
  195. void Raw_Draw_Mouse(Surface * surface, int xoffset, int yoffset);
  196. void Get_Bounded_Position(int & x, int & y) const;
  197. void Update_Mouse_Position(int x, int y);
  198. void Low_Show_Mouse(void);
  199. void Low_Hide_Mouse(void);
  200. void Block_Mouse(void) {InterlockedIncrement(&Blocked);/*Blocked++;*/}
  201. void Unblock_Mouse(void) {InterlockedDecrement(&Blocked);/*Blocked--;*/}
  202. bool Is_Blocked(void) const {return(Blocked != 0);}
  203. bool Is_Hidden(void) const {return(MouseState < 0);}
  204. };
  205. #endif