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