forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGadgetTabControl.cpp
More file actions
366 lines (314 loc) · 12.2 KB
/
GadgetTabControl.cpp
File metadata and controls
366 lines (314 loc) · 12.2 KB
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
** Command & Conquer Generals Zero Hour(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/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: RadioButton.cpp //////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Westwood Studios Pacific.
//
// Confidential Information
// Copyright (C) 2001 - All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Project: RTS3
//
// File name: \projects\RTS\code\gameengine\Source\GameClient\GUI\Gadget\GadgetTabControl.cpp
//
// Created: Graham Smallwood, November 2001
//
// Desc: Tab Set GUI control
//
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
// USER INCLUDES //////////////////////////////////////////////////////////////
#include "Common/Language.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/Gadget.h"
#include "GameClient/GadgetTabControl.h"
// DEFINES ////////////////////////////////////////////////////////////////////
// PRIVATE TYPES //////////////////////////////////////////////////////////////
// PRIVATE DATA ///////////////////////////////////////////////////////////////
// PUBLIC DATA ////////////////////////////////////////////////////////////////
// PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
// GadgetTabControlInput =====================================================
/** Handle input for TabControl */
//=============================================================================
WindowMsgHandledType GadgetTabControlInput( GameWindow *tabControl, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
// WinInstanceData *instData = tabControl->winGetInstanceData();
TabControlData *tabData = (TabControlData *)tabControl->winGetUserData();
Int tabX, tabY;
tabControl->winGetScreenPosition( &tabX, &tabY );
Int mouseX = LOLONGTOSHORT(mData1) - tabX;//mData1 is packedMouseCoords in screen space
Int mouseY = HILONGTOSHORT(mData1) - tabY;
Int tabsLeft = tabData->tabsLeftLimit;
Int tabsRight = tabData->tabsRightLimit;
Int tabsBottom = tabData->tabsBottomLimit;
Int tabsTop = tabData->tabsTopLimit;
switch( msg )
{
case GWM_LEFT_DOWN:
{
if( (mouseX < tabsLeft)
|| (mouseX > tabsRight)
|| (mouseY < tabsTop)
|| (mouseY > tabsBottom)
)
{//I eat input on myself that isn't a tab (a button click would mean I don't see the input ever.)
return MSG_HANDLED;
}
Int distanceIn;
Int tabSize;
if( (tabData->tabEdge == TP_RIGHT_SIDE) || (tabData->tabEdge == TP_LEFT_SIDE) )
{//scan down to find which button
distanceIn = mouseY - tabsTop;
tabSize = tabData->tabHeight;
}
else
{//scan right to find which button
distanceIn = mouseX - tabsLeft;
tabSize = tabData->tabWidth;
}
Int tabPressed = distanceIn / tabSize;
if( ! tabData->subPaneDisabled[tabPressed] && (tabPressed != tabData->activeTab) )
GadgetTabControlShowSubPane( tabControl, tabPressed );
}
default:
{
return MSG_IGNORED;
}
}
return MSG_HANDLED;
}
// GadgetTabControlSystem ====================================================
/** Handle system messages for TabControl */
//=============================================================================
WindowMsgHandledType GadgetTabControlSystem( GameWindow *tabControl, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
switch( msg )
{
// ------------------------------------------------------------------------
case GWM_CREATE:
break;
// ------------------------------------------------------------------------
case GWM_DESTROY:
{
// free tab control user data
delete (TabControlData *)tabControl->winGetUserData();
tabControl->winSetUserData( nullptr );
break;
}
case GGM_RESIZED:
{//On resize, we need to upkeep the pane sizes and tabs since they are bound to us
GadgetTabControlResizeSubPanes( tabControl );
GadgetTabControlComputeTabRegion( tabControl );
break;
}
case GBM_SELECTED:
{//Pass buttons messages up
GameWindow *parent = tabControl->winGetParent();
if( parent )
return TheWindowManager->winSendSystemMsg( parent, msg, mData1, mData2 );
break;
}
default:
return MSG_IGNORED;
}
return MSG_HANDLED;
}
void GadgetTabControlComputeTabRegion( GameWindow *tabControl )///< Recalc the tab positions based on userData
{
Int winWidth, winHeight;
tabControl->winGetSize( &winWidth, &winHeight );
TabControlData *tabData = (TabControlData *)tabControl->winGetUserData();
Int horzOffset = 0, vertOffset = 0;
if( (tabData->tabEdge == TP_TOP_SIDE) || (tabData->tabEdge == TP_BOTTOM_SIDE) )
{
if( tabData->tabOrientation == TP_CENTER )
{
horzOffset = winWidth - ( 2 * tabData->paneBorder ) - ( tabData->tabCount * tabData->tabWidth );
horzOffset /= 2;
}
else if( tabData->tabOrientation == TP_BOTTOMRIGHT )
{
horzOffset = winWidth - ( 2 * tabData->paneBorder ) - ( tabData->tabCount * tabData->tabWidth );
}
else if( tabData->tabOrientation == TP_TOPLEFT )
{
horzOffset = 0;
}
}
else
{
if( tabData->tabOrientation == TP_CENTER )
{
vertOffset = winHeight - ( 2 * tabData->paneBorder ) - ( tabData->tabCount * tabData->tabHeight );
vertOffset /= 2;
}
else if( tabData->tabOrientation == TP_BOTTOMRIGHT )
{
vertOffset = winHeight - ( 2 * tabData->paneBorder ) - ( tabData->tabCount * tabData->tabHeight );
}
else if( tabData->tabOrientation == TP_TOPLEFT )
{
vertOffset = 0;
}
}
if( tabData->tabEdge == TP_TOP_SIDE )
{
tabData->tabsTopLimit = tabData->paneBorder;
tabData->tabsBottomLimit = tabData->paneBorder + tabData->tabHeight;
tabData->tabsLeftLimit = tabData->paneBorder + horzOffset;
tabData->tabsRightLimit = tabData->paneBorder + horzOffset + ( tabData->tabWidth * tabData->tabCount );
}
else if( tabData->tabEdge == TP_BOTTOM_SIDE )
{
tabData->tabsTopLimit = winHeight - tabData->paneBorder - tabData->tabHeight;
tabData->tabsBottomLimit = winHeight - tabData->paneBorder;
tabData->tabsLeftLimit = tabData->paneBorder + horzOffset;
tabData->tabsRightLimit = tabData->paneBorder + horzOffset + ( tabData->tabWidth * tabData->tabCount );
}
else if( tabData->tabEdge == TP_RIGHT_SIDE )
{
tabData->tabsLeftLimit = winWidth - tabData->paneBorder - tabData->tabWidth;
tabData->tabsRightLimit = winWidth - tabData->paneBorder;
tabData->tabsTopLimit = tabData->paneBorder + vertOffset;
tabData->tabsBottomLimit = tabData->paneBorder + vertOffset + ( tabData->tabHeight * tabData->tabCount );
}
else if( tabData->tabEdge == TP_LEFT_SIDE )
{
tabData->tabsLeftLimit = tabData->paneBorder;
tabData->tabsRightLimit = tabData->paneBorder + tabData->tabWidth;
tabData->tabsTopLimit = tabData->paneBorder + vertOffset;
tabData->tabsBottomLimit = tabData->paneBorder + vertOffset + ( tabData->tabHeight * tabData->tabCount );
}
}
void GadgetTabControlComputeSubPaneSize( GameWindow *tabControl, Int *width, Int *height, Int *x, Int *y )
{
Int winWidth, winHeight;
tabControl->winGetSize( &winWidth, &winHeight );
TabControlData *tabData = (TabControlData *)tabControl->winGetUserData();
if( (tabData->tabEdge == TP_TOP_SIDE) || (tabData->tabEdge == TP_BOTTOM_SIDE) )
*height = winHeight - (2 * tabData->paneBorder) - tabData->tabHeight;
else
*height = winHeight - (2 * tabData->paneBorder);
if( (tabData->tabEdge == TP_LEFT_SIDE) || (tabData->tabEdge == TP_RIGHT_SIDE) )
*width = winWidth - (2 * tabData->paneBorder) - tabData->tabWidth;
else
*width = winWidth - (2 * tabData->paneBorder);
if( tabData->tabEdge == TP_LEFT_SIDE )
*x = tabData->paneBorder + tabData->tabWidth;
else
*x = tabData->paneBorder;
if( tabData->tabEdge == TP_TOP_SIDE )
*y = tabData->paneBorder + tabData->tabHeight;
else
*y = tabData->paneBorder;
}
void GadgetTabControlShowSubPane( GameWindow *tabControl, Int whichPane)
{
TabControlData *tabData = (TabControlData *)tabControl->winGetUserData();
for( Int paneIndex = 0; paneIndex < NUM_TAB_PANES; paneIndex++ )
{
if( tabData->subPanes[paneIndex] != nullptr )
tabData->subPanes[paneIndex]->winHide( true );
}
if( tabData->subPanes[whichPane] )
tabData->activeTab = whichPane;
else
tabData->activeTab = 0;
tabData->activeTab = min( tabData->activeTab, tabData->tabCount - 1 );
tabData->subPanes[tabData->activeTab]->winHide( false );
}
void GadgetTabControlCreateSubPanes( GameWindow *tabControl )///< Create User Windows attached to userData as Panes
{//These two funcs are called after all the Editor set data is updated
TabControlData *tabData = (TabControlData *)tabControl->winGetUserData();
Int width, height, x, y;
GadgetTabControlComputeSubPaneSize(tabControl, &width, &height, &x, &y);
for( Int paneIndex = 0; paneIndex < NUM_TAB_PANES; paneIndex++ )
{
if( tabData->subPanes[paneIndex] == nullptr )//This one is blank
{
tabData->subPanes[paneIndex] = TheWindowManager->winCreate( tabControl,
WIN_STATUS_NONE, x, y,
width, height,
PassSelectedButtonsToParentSystem,
nullptr);
WinInstanceData *instData = tabData->subPanes[paneIndex]->winGetInstanceData();
BitSet( instData->m_style, GWS_TAB_PANE );
char buffer[20];
sprintf( buffer, "Pane %d", paneIndex );
instData->m_decoratedNameString = buffer;
//set enabled status to that of Parent
tabData->subPanes[paneIndex]->winEnable( BitIsSet(tabControl->winGetStatus(), WIN_STATUS_ENABLED) );
}
else//this one exists, tabCount will control keeping extra panes perma-hidden
{
tabData->subPanes[paneIndex]->winSetSize( width, height );
tabData->subPanes[paneIndex]->winSetPosition( x, y );
}
}
GadgetTabControlShowSubPane( tabControl, tabData->activeTab );
}
void GadgetTabControlResizeSubPanes( GameWindow *tabControl )
{
TabControlData *tabData = (TabControlData *)tabControl->winGetUserData();
Int width, height, x, y;
GadgetTabControlComputeSubPaneSize(tabControl, &width, &height, &x, &y);
for( Int paneIndex = 0; paneIndex < NUM_TAB_PANES; paneIndex++ )
{
if( tabData->subPanes[paneIndex] )
{
tabData->subPanes[paneIndex]->winSetSize( width, height );
tabData->subPanes[paneIndex]->winSetPosition( x, y );
}
}
}
///<In game creation finished, hook up Children to SubPane array
void GadgetTabControlFixupSubPaneList( GameWindow *tabControl )
{
Int childIndex =0;
TabControlData *tabData = (TabControlData *)tabControl->winGetUserData();
GameWindow *child = tabControl->winGetChild();
if( child )
{//need to write down children, and they are reversed from our array
while( child->winGetNext() != nullptr )
{
child = child->winGetNext();
}
while( child )
{
tabData->subPanes[childIndex] = child;
childIndex++;
child = child->winGetPrev();
}
}
}