forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathW3DStaticText.cpp
More file actions
264 lines (212 loc) · 8.35 KB
/
W3DStaticText.cpp
File metadata and controls
264 lines (212 loc) · 8.35 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
/*
** 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: W3DStaticText.cpp ////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Westwood Studios Pacific.
//
// Confidential Information
// Copyright (C) 2001 - All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Project: RTS3
//
// File name: W3DStaticText.cpp
//
// Created: Colin Day, June 2001
//
// Desc: W3D implementation of the static text GUI control
//
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
#include <stdlib.h>
// USER INCLUDES //////////////////////////////////////////////////////////////
#include "Common/GlobalData.h"
#include "GameClient/GameWindowGlobal.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GadgetStaticText.h"
#include "W3DDevice/GameClient/W3DGameWindow.h"
#include "W3DDevice/GameClient/W3DGadget.h"
#include "W3DDevice/GameClient/W3DDisplay.h"
// DEFINES ////////////////////////////////////////////////////////////////////
// PRIVATE TYPES //////////////////////////////////////////////////////////////
// PRIVATE DATA ///////////////////////////////////////////////////////////////
//enum { DRAW_BUF_LEN = 2048 };
//static WideChar drawBuf[ DRAW_BUF_LEN ];
// PUBLIC DATA ////////////////////////////////////////////////////////////////
// PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// drawStaticTextText =========================================================
/** Draw the text for a static text window */
//=============================================================================
static void drawStaticTextText( GameWindow *window, WinInstanceData *instData,
Color textColor, Color textDropColor )
{
TextData *tData = (TextData *)window->winGetUserData();
Int textWidth, textHeight, wordWrap;
DisplayString *text = tData->text;
ICoord2D origin, size, textPos;
IRegion2D clipRegion;
// sanity
if( text == nullptr || text->getTextLength() == 0 )
return;
// get window position and size
window->winGetScreenPosition( &origin.x, &origin.y );
window->winGetSize( &size.x, &size.y );
// Set the text Wrap width
wordWrap = size.x - 10;
//if(wordWrap == 89)
// wordWrap = 95;
text->setWordWrap(wordWrap);
if( BitIsSet(window->winGetStatus(), WIN_STATUS_WRAP_CENTERED) )
text->setWordWrapCentered(TRUE);
else
text->setWordWrapCentered(FALSE);
if( BitIsSet( window->winGetStatus(), WIN_STATUS_HOTKEY_TEXT ) && TheGlobalData)
text->setUseHotkey(TRUE, TheGlobalData->m_hotKeyTextColor);
else
text->setUseHotkey(FALSE, 0);
// how much space will this text take up
text->getSize( &textWidth, &textHeight );
//Init the clip region
clipRegion.lo.x = origin.x ;
clipRegion.lo.y = origin.y ;
clipRegion.hi.x = origin.x + size.x ;
clipRegion.hi.y = origin.y + size.y;
// horizontal centering?
if( tData->centered )
{
textPos.x = origin.x + (size.x / 2) - (textWidth / 2);
}
else
{
textPos.x = origin.x + tData->leftMargin;
}
// vertical centering?
if ( tData->centeredVertically )
{
textPos.y = origin.y + (size.y / 2) - (textHeight / 2);
}
else
{
textPos.y = origin.y + tData->topMargin;
}
// draw the text
text->setClipRegion(&clipRegion);
text->draw( textPos.x, textPos.y, textColor, textDropColor );
}
///////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// W3DGadgetStaticTextDraw ====================================================
/** Draw colored text field using standard graphics */
//=============================================================================
void W3DGadgetStaticTextDraw( GameWindow *window, WinInstanceData *instData )
{
TextData *tData = (TextData *)window->winGetUserData();
Color backColor, backBorder, textColor, textOutlineColor;
ICoord2D size, origin, start, end;
// get window position and size
window->winGetScreenPosition( &origin.x, &origin.y );
window->winGetSize( &size.x, &size.y );
// get the colors we will use
if( BitIsSet( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
{
backColor = GadgetStaticTextGetDisabledColor( window );
backBorder = GadgetStaticTextGetDisabledBorderColor( window );
textColor = window->winGetDisabledTextColor();
textOutlineColor = window->winGetDisabledTextBorderColor();
}
else
{
backColor = GadgetStaticTextGetEnabledColor( window );
backBorder = GadgetStaticTextGetEnabledBorderColor( window );
textColor = window->winGetEnabledTextColor();
textOutlineColor = window->winGetEnabledTextBorderColor();
}
// draw the back border
if( backBorder != WIN_COLOR_UNDEFINED )
{
start.x = origin.x;
start.y = origin.y;
end.x = start.x + size.x;
end.y = start.y + size.y;
TheWindowManager->winOpenRect( backBorder, WIN_DRAW_LINE_WIDTH,
start.x, start.y, end.x, end.y );
}
// draw the back fill area
if( backColor != WIN_COLOR_UNDEFINED )
{
start.x = origin.x + 1;
start.y = origin.y + 1;
end.x = start.x + size.x - 2;
end.y = start.y + size.y - 2;
TheWindowManager->winFillRect( backColor, WIN_DRAW_LINE_WIDTH,
start.x, start.y, end.x, end.y );
}
// draw the text
if( tData->text && (textColor != WIN_COLOR_UNDEFINED) )
drawStaticTextText( window, instData, textColor, textOutlineColor );
}
// W3DGadgetStaticTextImageDraw ===============================================
/** Draw colored text field with user supplied images */
//=============================================================================
void W3DGadgetStaticTextImageDraw( GameWindow *window, WinInstanceData *instData )
{
TextData *tData = (TextData *)window->winGetUserData();
Color textColor, textOutlineColor;
ICoord2D size, origin, start, end;
const Image *image;
// get window position and size
window->winGetScreenPosition( &origin.x, &origin.y );
window->winGetSize( &size.x, &size.y );
// get the colors we will use
if( BitIsSet( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
{
image = GadgetStaticTextGetDisabledImage( window );
textColor = window->winGetDisabledTextColor();
textOutlineColor = window->winGetDisabledTextBorderColor();
}
else
{
image = GadgetStaticTextGetEnabledImage( window );
textColor = window->winGetEnabledTextColor();
textOutlineColor = window->winGetEnabledTextBorderColor();
}
// draw the back image
if( image )
{
start.x = origin.x + instData->m_imageOffset.x;
start.y = origin.y + instData->m_imageOffset.y;
end.x = start.x + size.x;
end.y = start.y + size.y;
TheWindowManager->winDrawImage( image, start.x, start.y, end.x, end.y );
}
// draw the text
if( tData->text && (textColor != WIN_COLOR_UNDEFINED) )
drawStaticTextText( window, instData, textColor, textOutlineColor );
}