Skip to content

Commit d8a7da7

Browse files
DevGeniusCodexezon
authored andcommitted
unify(gadget): Merge Gadget and related code from Zero Hour (#2672)
1 parent 0a65107 commit d8a7da7

5 files changed

Lines changed: 61 additions & 21 deletions

File tree

Generals/Code/GameEngine/Include/GameClient/Gadget.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ typedef struct _EntryData
276276

277277
DisplayString *text; ///< the entry text
278278
DisplayString *sText; ///< for displaying 'secret' text
279-
DisplayString *constructText; ///< for foriegn text construction
280-
Bool secretText; ///< If TRUE text appears as astericks
279+
DisplayString *constructText; ///< for foreign text construction
280+
Bool secretText; ///< If TRUE text appears as asterisks
281281
Bool numericalOnly; ///< If TRUE only numbers are allowed as input
282282
Bool alphaNumericalOnly; ///< If TRUE only numbers and letters are allowed as input
283283
Bool aSCIIOnly; ///< If TRUE ascii allowed as input
@@ -296,7 +296,7 @@ typedef struct _EntryData
296296

297297
GameWindow *constructList; // Listbox for construct list.
298298
UnsignedShort charPos; // Position of current character
299-
UnsignedShort conCharPos; // Position of current contruct character
299+
UnsignedShort conCharPos; // Position of current construct character
300300

301301
} EntryData;
302302

@@ -306,7 +306,10 @@ typedef struct _TextData
306306
{
307307

308308
DisplayString *text; ///< the text data
309-
Bool centered;
309+
Bool centered; ///< horizontal
310+
Bool centeredVertically; ///< vertical
311+
Int leftMargin; ///< left justification margin width
312+
Int topMargin; ///< top justification margin width
310313

311314
} TextData;
312315

@@ -427,7 +430,7 @@ typedef struct _PushButtonData
427430
Color colorBorder; ///< The color for the border around the button
428431
void *userData; ///< random additional data we can set
429432
const Image *overlayImage; ///< An overlay image (like a veterancy symbol)
430-
AsciiString altSound; ///< use an alternitive sound if one is set
433+
AsciiString altSound; ///< use an alternative sound if one is set
431434
} PushButtonData;
432435

433436
// TabControlData ------------------------------------------------------------

Generals/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666

6767
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
6868

69+
static Bool buttonTriggersOnMouseDown(GameWindow *window)
70+
{
71+
// Buttons with the on down status set trigger on mouse down. jba. [8/6/2003]
72+
Bool onDown = BitIsSet( window->winGetStatus(), WIN_STATUS_ON_MOUSE_DOWN);
73+
74+
// Checkboxes always trigger on mouse down. jba [8/6/2003]
75+
if (BitIsSet( window->winGetStatus(), WIN_STATUS_CHECK_LIKE )) {
76+
onDown = true;
77+
}
78+
return onDown;
79+
}
80+
6981
// GadgetPushButtonInput ======================================================
7082
/** Handle input for push button */
7183
//=============================================================================
@@ -171,8 +183,6 @@ WindowMsgHandledType GadgetPushButtonInput( GameWindow *window,
171183
else
172184
BitSet( instData->m_state, WIN_STATE_SELECTED );
173185

174-
TheWindowManager->winSendSystemMsg( instData->getOwner(), GBM_SELECTED,
175-
(WindowMsgData)window, mData1 );
176186

177187
}
178188
else
@@ -183,6 +193,11 @@ WindowMsgHandledType GadgetPushButtonInput( GameWindow *window,
183193

184194
}
185195

196+
if (buttonTriggersOnMouseDown(window)) {
197+
TheWindowManager->winSendSystemMsg( instData->getOwner(), GBM_SELECTED,
198+
(WindowMsgData)window, mData1 );
199+
}
200+
186201
break;
187202
}
188203

@@ -198,8 +213,11 @@ WindowMsgHandledType GadgetPushButtonInput( GameWindow *window,
198213
BitIsSet( window->winGetStatus(), WIN_STATUS_CHECK_LIKE ) == FALSE )
199214
{
200215

201-
TheWindowManager->winSendSystemMsg( instData->getOwner(), GBM_SELECTED,
202-
(WindowMsgData)window, mData1 );
216+
if (!buttonTriggersOnMouseDown(window)) {
217+
// If it didn't trigger on mouse down, trigger on the mouse up. jba [8/6/2003]
218+
TheWindowManager->winSendSystemMsg( instData->getOwner(), GBM_SELECTED,
219+
(WindowMsgData)window, mData1 );
220+
}
203221

204222
BitClear( instData->m_state, WIN_STATE_SELECTED );
205223

Generals/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,13 @@ static Bool parseStaticTextData( const char *token, WinInstanceData *instData,
11341134
c = strtok( nullptr, seps ); // value
11351135
scanBool( c, textData->centered );
11361136

1137+
// @todo: add these to GUIEdit options and output
1138+
// These are initialized here because any TextData constructor would never get called.
1139+
// The behavior with these defaults is the same as it was before these members were added.
1140+
textData->centeredVertically = TRUE;
1141+
textData->leftMargin = 7;
1142+
textData->topMargin = 7;
1143+
11371144
return TRUE;
11381145

11391146
}

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,17 @@ static void drawButtonText( GameWindow *window, WinInstanceData *instData )
121121
text->getSize( &width, &height );
122122

123123
// where to draw
124-
textPos.x = origin.x + (size.x / 2) - (width / 2);
125-
textPos.y = origin.y + (size.y / 2) - (height / 2);
124+
if( BitIsSet( window->winGetStatus(), WIN_STATUS_SHORTCUT_BUTTON ) )
125+
{
126+
// Oh god... this is a total hack for shortcut buttons to handle rendering text top left corner...
127+
textPos.x = origin.x + 2;
128+
textPos.y = origin.y + 0;
129+
}
130+
else
131+
{
132+
textPos.x = origin.x + (size.x / 2) - (width / 2);
133+
textPos.y = origin.y + (size.y / 2) - (height / 2);
134+
}
126135

127136
// draw it
128137
text->draw( textPos.x, textPos.y, textColor, dropColor );

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DStaticText.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,29 @@ static void drawStaticTextText( GameWindow *window, WinInstanceData *instData,
114114
clipRegion.hi.x = origin.x + size.x ;
115115
clipRegion.hi.y = origin.y + size.y;
116116

117+
// horizontal centering?
117118
if( tData->centered )
118119
{
119-
120120
textPos.x = origin.x + (size.x / 2) - (textWidth / 2);
121-
textPos.y = origin.y + (size.y / 2) - (textHeight / 2);
122-
text->setClipRegion(&clipRegion);
123-
text->draw( textPos.x, textPos.y, textColor, textDropColor );
124-
125121
}
126122
else
127123
{
124+
textPos.x = origin.x + tData->leftMargin;
125+
}
128126

129-
// draw the text
130-
textPos.x = origin.x + 7;
127+
// vertical centering?
128+
if ( tData->centeredVertically )
129+
{
131130
textPos.y = origin.y + (size.y / 2) - (textHeight / 2);
132-
text->setClipRegion(&clipRegion);
133-
text->draw( textPos.x, textPos.y, textColor, textDropColor );
134-
131+
}
132+
else
133+
{
134+
textPos.y = origin.y + tData->topMargin;
135135
}
136136

137+
// draw the text
138+
text->setClipRegion(&clipRegion);
139+
text->draw( textPos.x, textPos.y, textColor, textDropColor );
137140

138141
}
139142

0 commit comments

Comments
 (0)