forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGadgetStaticText.cpp
More file actions
226 lines (181 loc) · 6.77 KB
/
GadgetStaticText.cpp
File metadata and controls
226 lines (181 loc) · 6.77 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
/*
** 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: StaticText.cpp ///////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Westwood Studios Pacific.
//
// Confidential Information
// Copyright (C) 2001 - All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Project: RTS3
//
// File name: StaticText.cpp
//
// Created: Colin Day, June 2001
//
// Desc: Static text 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/DisplayStringManager.h"
#include "GameClient/GameWindow.h"
#include "GameClient/Gadget.h"
#include "GameClient/GameWindowManager.h"
// DEFINES ////////////////////////////////////////////////////////////////////
// PRIVATE TYPES //////////////////////////////////////////////////////////////
// PRIVATE DATA ///////////////////////////////////////////////////////////////
// PUBLIC DATA ////////////////////////////////////////////////////////////////
// PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// GadgetStaticTextInput ======================================================
/** Handle input for text field */
//=============================================================================
WindowMsgHandledType GadgetStaticTextInput( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
switch( msg )
{
// ------------------------------------------------------------------------
case GWM_CHAR:
switch (mData1)
{
case KEY_DOWN:
case KEY_RIGHT:
case KEY_TAB:
// Just in case some fool sets static text as a tab stop
if( BitIsSet( mData2, KEY_STATE_DOWN ) )
window->winNextTab();
break;
case KEY_UP:
case KEY_LEFT:
if( BitIsSet( mData2, KEY_STATE_DOWN ) )
window->winPrevTab();
break;
default:
return MSG_IGNORED;
}
break;
default:
return MSG_IGNORED;
}
return MSG_HANDLED;
}
// GadgetStaticTextSystem =====================================================
/** Handle system messages for text field */
//=============================================================================
WindowMsgHandledType GadgetStaticTextSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
// WinInstanceData *instData = window->winGetInstanceData();
switch( msg )
{
// ------------------------------------------------------------------------
case GGM_GET_LABEL:
{
TextData *tData = (TextData *)window->winGetUserData();
if (tData && tData->text)
*(UnicodeString*)mData2 = tData->text->getText();
break;
}
// ------------------------------------------------------------------------
case GGM_SET_LABEL:
{
if( mData1 )
{
TextData *tData = (TextData *)window->winGetUserData();
if (tData && tData->text)
tData->text->setText( *(UnicodeString*)mData1 );
}
break;
}
// ------------------------------------------------------------------------
case GWM_CREATE:
break;
// ------------------------------------------------------------------------
case GWM_DESTROY:
{
TextData *data = (TextData *)window->winGetUserData();
// free the display string
TheDisplayStringManager->freeDisplayString( data->text );
// free text data
delete (TextData *)window->winGetUserData();
window->winSetUserData( nullptr );
break;
}
default:
return MSG_IGNORED;
}
return MSG_HANDLED;
}
// GadgetStaticTextSetText ====================================================
/** Set the text for a static text control */
//=============================================================================
void GadgetStaticTextSetText( GameWindow *window, UnicodeString text )
{
if(!window)
return;
TheWindowManager->winSendSystemMsg( window, GGM_SET_LABEL, (WindowMsgData)&text, 0 );
}
UnicodeString GadgetStaticTextGetText( GameWindow *window )
{
if(!window)
return UnicodeString::TheEmptyString;
TextData *tData = (TextData *)window->winGetUserData();
if(!tData)
return UnicodeString::TheEmptyString;
return tData->text->getText();
}
// GadgetStaticTextSetFont ====================================================
/** Set the font for a text control, we need to set the window
* text font, the tooltip font, and the static text display strings for
* the text data itself */
//=============================================================================
void GadgetStaticTextSetFont( GameWindow *g, GameFont *font )
{
TextData *textData = (TextData *)g->winGetUserData();
DisplayString *dString;
// set the font for the display strings all windows have
dString = g->winGetInstanceData()->getTextDisplayString();
if( dString )
dString->setFont( font );
dString = g->winGetInstanceData()->getTooltipDisplayString();
if( dString )
dString->setFont( font );
// static text specific
if( textData )
{
dString = textData->text;
if( dString )
dString->setFont( font );
}
}