This repository was archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathDIAL8.CPP
317 lines (273 loc) · 12.8 KB
/
DIAL8.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
** Command & Conquer(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $Header: F:\projects\c&c\vcs\code\dial8.cpv 2.18 16 Oct 1995 16:51:32 JOE_BOSTIC $ */
/***************************************************************************
** 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 **
***************************************************************************
* *
* Project Name : Command & Conquer *
* *
* File Name : DIAL8.CPP *
* *
* Programmer : Bill Randolph *
* *
* Start Date : February 6, 1995 *
* *
* Last Update : February 6, 1995 [BR] *
* *
*-------------------------------------------------------------------------*
* Functions: *
* Dial8Class::Action -- action routine for Dial8Class *
* Dial8Class::Dial8Class -- constructor for the facing dial *
* Dial8Class::Draw_Me -- render routine for Dial8Class *
* Dial8Class::Get_Direction -- retrieves direction (0-255) of dial *
* Dial8Class::Set_Direction -- sets current direction (0-255) of dial *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
/***************************************************************************
* Dial8Class::Dial8Class -- constructor for the facing dial *
* *
* INPUT: *
* id button ID *
* x,y,w,h dimensions in window-relative pixels *
* dir numerical initial facing value (0-255); this is the *
* value returned by WWLIB Desired_Facing8() *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 11/16/1994 BR : Created. *
*=========================================================================*/
Dial8Class::Dial8Class(int id, int x, int y, int w, int h, DirType dir) :
ControlClass(id, x, y, w, h, LEFTPRESS | LEFTHELD | LEFTRELEASE, true)
{
/*
** Center coordinates.
*/
FaceX = X + (Width / 2);
FaceY = Y + (Height / 2);
/*
** Init directions.
*/
Direction = dir; // 0 - 255
Facing = Dir_Facing(Direction); // 0 - 7
OldFacing = Facing; // 0 - 7
/*
** Compute the drawing dimensions: a 45-degree angle intersects a unity-
** radius circle at (.707,.707). Make the decorations 8/10 of the radius,
** and the line extend to 6/10 of the radius. Use Width/2 for x-radius,
** Height/2 for y-radius.
*/
FacePoint[0][0] = FaceX;
FacePoint[0][1] = FaceY - (h * 8 / 2) / 10;
FacePoint[1][0] = FaceX + (w * 7 * 8 / 2) / 100;
FacePoint[1][1] = FaceY - (h * 7 * 8 / 2) / 100;
FacePoint[2][0] = FaceX + (w * 8 / 2) / 10;
FacePoint[2][1] = FaceY;
FacePoint[3][0] = FaceX + (w * 7 * 8 / 2) / 100;
FacePoint[3][1] = FaceY + (h * 7 * 8 / 2) / 100;
FacePoint[4][0] = FaceX;
FacePoint[4][1] = FaceY + (h * 8 / 2) / 10;
FacePoint[5][0] = FaceX - (w * 7 * 8 / 2) / 100;
FacePoint[5][1] = FaceY + (h * 7 * 8 / 2) / 100;
FacePoint[6][0] = FaceX - (w * 8 / 2) / 10;
FacePoint[6][1] = FaceY;
FacePoint[7][0] = FaceX - (w * 7 * 8 / 2) / 100;
FacePoint[7][1] = FaceY - (h * 7 * 8 / 2) / 100;
FaceLine[0][0] = FaceX;
FaceLine[0][1] = FaceY - (h * 6 / 2) / 10;
FaceLine[1][0] = FaceX + (w * 7 * 6 / 2) / 100;
FaceLine[1][1] = FaceY - (h * 7 * 6 / 2) / 100;
FaceLine[2][0] = FaceX + (w * 6 / 2) / 10;
FaceLine[2][1] = FaceY;
FaceLine[3][0] = FaceX + (w * 7 * 6 / 2) / 100;
FaceLine[3][1] = FaceY + (h * 7 * 6 / 2) / 100;
FaceLine[4][0] = FaceX;
FaceLine[4][1] = FaceY + (h * 6 / 2) / 10;
FaceLine[5][0] = FaceX - (w * 7 * 6 / 2) / 100;
FaceLine[5][1] = FaceY + (h * 7 * 6 / 2) / 100;
FaceLine[6][0] = FaceX - (w * 6 / 2) / 10;
FaceLine[6][1] = FaceY;
FaceLine[7][0] = FaceX - (w * 7 * 6 / 2) / 100;
FaceLine[7][1] = FaceY - (h * 7 * 6 / 2) / 100;
}
/***************************************************************************
* Dial8Class::Action -- activation function for Dial8Class *
* *
* INPUT: *
* flags the reason we're being called *
* key the KN_number that was pressed *
* *
* OUTPUT: *
* true = event was processed, false = event not processed *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 02/06/1995 BR : Created. *
*=========================================================================*/
int Dial8Class::Action(unsigned flags, KeyNumType &key)
{
static int is_sel = 0;
/*
** We might end up clearing the event bits. Make sure that the sticky
** process is properly updated anyway.
*/
Sticky_Process(flags);
if (flags & LEFTPRESS) {
is_sel = 1;
}
/*
** If left mouse is clicked or held, and the dial has changed its direction,
** invoke the parent Action routine:
** GadgetClass::Action handles Sticky processing, & sets IsToRepaint if any
** flag bits are set.
** ControlClass::Action handles Peer_To_Peer notification, and substitues
** 'key' with the button ID if any flags are set, or 0 if no flags are set
*/
if (flags & LEFTPRESS || ((flags & LEFTHELD) && is_sel)) {
/*
** Get new dial position (0-255)
*/
Direction = (DirType)Desired_Facing8(FaceX, FaceY, Get_Mouse_X(), Get_Mouse_Y());
/*
** Convert to Facing value (0-7).
*/
Facing = Dir_Facing(Direction);
/*
** If it's moved, redraw.
*/
if (Facing!=OldFacing) {
OldFacing = Facing;
ControlClass::Action(flags,key);
return(true);
} else {
/*
** Dial hasn't moved; kill the event & return
*/
key = KN_NONE;
ControlClass::Action(0,key);
return(true);
}
} else {
/*
** Otherwise, no events have occurred; kill the event if it's a LEFTRELEASE,
** and return
*/
if (flags & LEFTRELEASE) {
key = KN_NONE;
is_sel = 0;
}
return(ControlClass::Action(0,key));
}
}
/***************************************************************************
* Dial8Class::Draw_Me -- custom render routine for Dial8Class *
* *
* INPUT: *
* forced true = draw regardless of the current redraw flag state*
* *
* OUTPUT: *
* true = gadget was redrawn, false = wasn't *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 02/06/1995 BR : Created. *
*=========================================================================*/
int Dial8Class::Draw_Me(int forced)
{
/*
** Redraw if parent indicates a redraw is needed
*/
if (ControlClass::Draw_Me(forced)) {
/*
** Hide the mouse.
*/
if (LogicPage == &SeenBuff) {
Hide_Mouse();
}
/*
** Draw background & decorations.
*/
Draw_Box(X, Y, Width, Height, BOXSTYLE_GREEN_DOWN, true);
for (int i=0; i<8; i++) {
Draw_Box(FacePoint[i][0] - 1, FacePoint[i][1] -1, 3, 3, BOXSTYLE_GREEN_RAISED, false);
}
/*
** Draw the hand & its shadow.
*/
LogicPage->Draw_Line(FaceX+1, FaceY+1, FaceLine[Facing][0]+1, FaceLine[Facing][1]+1,CC_GREEN_SHADOW);
LogicPage->Draw_Line(FaceX, FaceY, FaceLine[Facing][0], FaceLine[Facing][1],CC_LIGHT_GREEN);
/*
** Restore the mouse.
*/
if (LogicPage == &SeenBuff) {
Show_Mouse();
}
return(true);
}
return(false);
}
/***************************************************************************
* Dial8Class::Get_Direction -- retrieves direction (0-255) of dial *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* DirType dial is pointing to *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 11/17/1994 BR : Created. *
*=========================================================================*/
DirType Dial8Class::Get_Direction(void) const
{
return(Direction);
}
/***************************************************************************
* Dial8Class::Set_Direction -- sets current direction (0-255) of dial *
* *
* INPUT: *
* DirType to set dial to *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 11/17/1994 BR : Created. *
*=========================================================================*/
void Dial8Class::Set_Direction(DirType dir)
{
Direction = dir;
Facing = Dir_Facing(Direction);
OldFacing = Facing;
Flag_To_Redraw();
}