doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleWindow.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "DeviceContext.h"
33 #include "Window.h"
34 #include "UserInterfaceLocal.h"
35 #include "SimpleWindow.h"
36 
37 
39  gui = win->GetGui();
40  dc = win->dc;
41  drawRect = win->drawRect;
42  clientRect = win->clientRect;
43  textRect = win->textRect;
44  origin = win->origin;
45  fontNum = win->fontNum;
46  name = win->name;
47  matScalex = win->matScalex;
48  matScaley = win->matScaley;
49  borderSize = win->borderSize;
50  textAlign = win->textAlign;
51  textAlignx = win->textAlignx;
52  textAligny = win->textAligny;
53  background = win->background;
54  flags = win->flags;
55  textShadow = win->textShadow;
56 
57  visible = win->visible;
58  text = win->text;
59  rect = win->rect;
60  backColor = win->backColor;
61  matColor = win->matColor;
62  foreColor = win->foreColor;
63  borderColor = win->borderColor;
64  textScale = win->textScale;
65  rotate = win->rotate;
66  shear = win->shear;
68  if (backGroundName.Length()) {
71  background->SetImageClassifications( 1 ); // just for resource tracking
72  }
74 
75 //
76 // added parent
77  mParent = win->GetParent();
78 //
79 
80  hideCursor = win->hideCursor;
81 
82  idWindow *parent = win->GetParent();
83  if (parent) {
84  if (text.NeedsUpdate()) {
85  parent->AddUpdateVar(&text);
86  }
87  if (visible.NeedsUpdate()) {
88  parent->AddUpdateVar(&visible);
89  }
90  if (rect.NeedsUpdate()) {
91  parent->AddUpdateVar(&rect);
92  }
93  if (backColor.NeedsUpdate()) {
94  parent->AddUpdateVar(&backColor);
95  }
96  if (matColor.NeedsUpdate()) {
97  parent->AddUpdateVar(&matColor);
98  }
99  if (foreColor.NeedsUpdate()) {
100  parent->AddUpdateVar(&foreColor);
101  }
102  if (borderColor.NeedsUpdate()) {
103  parent->AddUpdateVar(&borderColor);
104  }
105  if (textScale.NeedsUpdate()) {
106  parent->AddUpdateVar(&textScale);
107  }
108  if (rotate.NeedsUpdate()) {
109  parent->AddUpdateVar(&rotate);
110  }
111  if (shear.NeedsUpdate()) {
112  parent->AddUpdateVar(&shear);
113  }
114  if (backGroundName.NeedsUpdate()) {
115  parent->AddUpdateVar(&backGroundName);
116  }
117  }
118 }
119 
121 
122 }
123 
124 void idSimpleWindow::StateChanged( bool redraw ) {
125  if ( redraw && background && background->CinematicLength() ) {
127  }
128 }
129 
130 void idSimpleWindow::SetupTransforms(float x, float y) {
131  static idMat3 trans;
132  static idVec3 org;
133 
134  trans.Identity();
135  org.Set( origin.x + x, origin.y + y, 0 );
136  if ( rotate ) {
137  static idRotation rot;
138  static idVec3 vec( 0, 0, 1 );
139  rot.Set( org, vec, rotate );
140  trans = rot.ToMat3();
141  }
142 
143  static idMat3 smat;
144  smat.Identity();
145  if (shear.x() || shear.y()) {
146  smat[0][1] = shear.x();
147  smat[1][0] = shear.y();
148  trans *= smat;
149  }
150 
151  if ( !trans.IsIdentity() ) {
152  dc->SetTransformInfo( org, trans );
153  }
154 }
155 
157  if (backColor.w() > 0) {
158  dc->DrawFilledRect(drawRect.x, drawRect.y, drawRect.w, drawRect.h, backColor);
159  }
160 
161  if (background) {
162  if (matColor.w() > 0) {
163  float scalex, scaley;
164  if ( flags & WIN_NATURALMAT ) {
165  scalex = drawRect.w / background->GetImageWidth();
166  scaley = drawRect.h / background->GetImageHeight();
167  } else {
168  scalex = matScalex;
169  scaley = matScaley;
170  }
171  dc->DrawMaterial(drawRect.x, drawRect.y, drawRect.w, drawRect.h, background, matColor, scalex, scaley);
172  }
173  }
174 }
175 
177  if (flags & WIN_BORDER) {
178  if (borderSize) {
179  dc->DrawRect(drawRect.x, drawRect.y, drawRect.w, drawRect.h, borderSize, borderColor);
180  }
181  }
182 }
183 
184 void idSimpleWindow::CalcClientRect(float xofs, float yofs) {
185 
186  drawRect = rect;
187 
188  if ( flags & WIN_INVERTRECT ) {
189  drawRect.x = rect.x() - rect.w();
190  drawRect.y = rect.y() - rect.h();
191  }
192 
193  drawRect.x += xofs;
194  drawRect.y += yofs;
195 
197  if (rect.h() > 0.0 && rect.w() > 0.0) {
198 
199  if (flags & WIN_BORDER && borderSize != 0.0) {
204  }
205 
207  textRect.x += 2.0;
208  textRect.w -= 2.0;
209  textRect.y += 2.0;
210  textRect.h -= 2.0;
211  textRect.x += textAlignx;
212  textRect.y += textAligny;
213 
214  }
215  origin.Set( rect.x() + ( rect.w() / 2 ), rect.y() + ( rect.h() / 2 ) );
216 
217 }
218 
219 
220 void idSimpleWindow::Redraw(float x, float y) {
221 
222  if (!visible) {
223  return;
224  }
225 
226  CalcClientRect(0, 0);
227  dc->SetFont(fontNum);
228  drawRect.Offset(x, y);
229  clientRect.Offset(x, y);
230  textRect.Offset(x, y);
231  SetupTransforms(x, y);
232  if ( flags & WIN_NOCLIP ) {
233  dc->EnableClipping( false );
234  }
237  if ( textShadow ) {
238  idStr shadowText = text;
239  idRectangle shadowRect = textRect;
240 
241  shadowText.RemoveColors();
242  shadowRect.x += textShadow;
243  shadowRect.y += textShadow;
244 
245  dc->DrawText( shadowText, textScale, textAlign, colorBlack, shadowRect, !( flags & WIN_NOWRAP ), -1 );
246  }
249  if ( flags & WIN_NOCLIP ) {
250  dc->EnableClipping( true );
251  }
252  drawRect.Offset(-x, -y);
253  clientRect.Offset(-x, -y);
254  textRect.Offset(-x, -y);
255 }
256 
258  int ret = -1;
259 
260  if ( wv == &rect ) {
261  ret = (int)&( ( idSimpleWindow * ) 0 )->rect;
262  }
263 
264  if ( wv == &backColor ) {
265  ret = (int)&( ( idSimpleWindow * ) 0 )->backColor;
266  }
267 
268  if ( wv == &matColor ) {
269  ret = (int)&( ( idSimpleWindow * ) 0 )->matColor;
270  }
271 
272  if ( wv == &foreColor ) {
273  ret = (int)&( ( idSimpleWindow * ) 0 )->foreColor;
274  }
275 
276  if ( wv == &borderColor ) {
277  ret = (int)&( ( idSimpleWindow * ) 0 )->borderColor;
278  }
279 
280  if ( wv == &textScale ) {
281  ret = (int)&( ( idSimpleWindow * ) 0 )->textScale;
282  }
283 
284  if ( wv == &rotate ) {
285  ret = (int)&( ( idSimpleWindow * ) 0 )->rotate;
286  }
287 
288  if ( ret != -1 ) {
289  owner->simp = this;
290  }
291  return ret;
292 }
293 
295  idWinVar *retVar = NULL;
296  if (idStr::Icmp(_name, "background") == 0) {
297  retVar = &backGroundName;
298  }
299  if (idStr::Icmp(_name, "visible") == 0) {
300  retVar = &visible;
301  }
302  if (idStr::Icmp(_name, "rect") == 0) {
303  retVar = &rect;
304  }
305  if (idStr::Icmp(_name, "backColor") == 0) {
306  retVar = &backColor;
307  }
308  if (idStr::Icmp(_name, "matColor") == 0) {
309  retVar = &matColor;
310  }
311  if (idStr::Icmp(_name, "foreColor") == 0) {
312  retVar = &foreColor;
313  }
314  if (idStr::Icmp(_name, "borderColor") == 0) {
315  retVar = &borderColor;
316  }
317  if (idStr::Icmp(_name, "textScale") == 0) {
318  retVar = &textScale;
319  }
320  if (idStr::Icmp(_name, "rotate") == 0) {
321  retVar = &rotate;
322  }
323  if (idStr::Icmp(_name, "shear") == 0) {
324  retVar = &shear;
325  }
326  if (idStr::Icmp(_name, "text") == 0) {
327  retVar = &text;
328  }
329  return retVar;
330 }
331 
332 /*
333 ========================
334 idSimpleWindow::WriteToSaveGame
335 ========================
336 */
338 
339  savefile->Write( &flags, sizeof( flags ) );
340  savefile->Write( &drawRect, sizeof( drawRect ) );
341  savefile->Write( &clientRect, sizeof( clientRect ) );
342  savefile->Write( &textRect, sizeof( textRect ) );
343  savefile->Write( &origin, sizeof( origin ) );
344  savefile->Write( &fontNum, sizeof( fontNum ) );
345  savefile->Write( &matScalex, sizeof( matScalex ) );
346  savefile->Write( &matScaley, sizeof( matScaley ) );
347  savefile->Write( &borderSize, sizeof( borderSize ) );
348  savefile->Write( &textAlign, sizeof( textAlign ) );
349  savefile->Write( &textAlignx, sizeof( textAlignx ) );
350  savefile->Write( &textAligny, sizeof( textAligny ) );
351  savefile->Write( &textShadow, sizeof( textShadow ) );
352 
353  text.WriteToSaveGame( savefile );
354  visible.WriteToSaveGame( savefile );
355  rect.WriteToSaveGame( savefile );
356  backColor.WriteToSaveGame( savefile );
357  matColor.WriteToSaveGame( savefile );
358  foreColor.WriteToSaveGame( savefile );
359  borderColor.WriteToSaveGame( savefile );
360  textScale.WriteToSaveGame( savefile );
361  rotate.WriteToSaveGame( savefile );
362  shear.WriteToSaveGame( savefile );
363  backGroundName.WriteToSaveGame( savefile );
364 
365  int stringLen;
366 
367  if ( background ) {
368  stringLen = strlen( background->GetName() );
369  savefile->Write( &stringLen, sizeof( stringLen ) );
370  savefile->Write( background->GetName(), stringLen );
371  } else {
372  stringLen = 0;
373  savefile->Write( &stringLen, sizeof( stringLen ) );
374  }
375 
376 }
377 
378 /*
379 ========================
380 idSimpleWindow::ReadFromSaveGame
381 ========================
382 */
384 
385  savefile->Read( &flags, sizeof( flags ) );
386  savefile->Read( &drawRect, sizeof( drawRect ) );
387  savefile->Read( &clientRect, sizeof( clientRect ) );
388  savefile->Read( &textRect, sizeof( textRect ) );
389  savefile->Read( &origin, sizeof( origin ) );
390  savefile->Read( &fontNum, sizeof( fontNum ) );
391  savefile->Read( &matScalex, sizeof( matScalex ) );
392  savefile->Read( &matScaley, sizeof( matScaley ) );
393  savefile->Read( &borderSize, sizeof( borderSize ) );
394  savefile->Read( &textAlign, sizeof( textAlign ) );
395  savefile->Read( &textAlignx, sizeof( textAlignx ) );
396  savefile->Read( &textAligny, sizeof( textAligny ) );
397  savefile->Read( &textShadow, sizeof( textShadow ) );
398 
399  text.ReadFromSaveGame( savefile );
400  visible.ReadFromSaveGame( savefile );
401  rect.ReadFromSaveGame( savefile );
402  backColor.ReadFromSaveGame( savefile );
403  matColor.ReadFromSaveGame( savefile );
404  foreColor.ReadFromSaveGame( savefile );
405  borderColor.ReadFromSaveGame( savefile );
406  textScale.ReadFromSaveGame( savefile );
407  rotate.ReadFromSaveGame( savefile );
408  shear.ReadFromSaveGame( savefile );
409  backGroundName.ReadFromSaveGame( savefile );
410 
411  int stringLen;
412 
413  savefile->Read( &stringLen, sizeof( stringLen ) );
414  if ( stringLen > 0 ) {
415  idStr backName;
416 
417  backName.Fill( ' ', stringLen );
418  savefile->Read( &(backName)[0], stringLen );
419 
420  background = declManager->FindMaterial( backName );
422  } else {
423  background = NULL;
424  }
425 
426 }
427 
428 
429 /*
430 ===============================
431 */
432 
434  size_t sz = sizeof(*this);
435  sz += name.Size();
436  sz += text.Size();
437  sz += backGroundName.Size();
438  return sz;
439 }
idRectangle clientRect
Definition: SimpleWindow.h:70
void SetTransformInfo(const idVec3 &origin, const idMat3 &mat)
idUserInterfaceLocal * gui
Definition: SimpleWindow.h:66
idWinFloat textScale
Definition: Window.h:405
idWinVec2 shear
Definition: SimpleWindow.h:91
idMat3 mat3_identity(idVec3(1, 0, 0), idVec3(0, 1, 0), idVec3(0, 0, 1))
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:228
virtual void ReadFromSaveGame(idFile *savefile)
const int WIN_NOWRAP
Definition: Window.h:54
signed char textShadow
Definition: Window.h:391
float y
Definition: Vector.h:55
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:538
void Offset(float x, float y)
Definition: Rectangle.h:44
unsigned int flags
Definition: Window.h:371
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:467
void UpdateCinematic(int time) const
Definition: Material.cpp:2548
idWinBool hideCursor
Definition: SimpleWindow.h:98
void Set(const float x, const float y, const float z)
Definition: Vector.h:409
GLenum GLint GLint y
Definition: glext.h:2849
idWinVec4 matColor
Definition: Window.h:401
virtual void WriteToSaveGame(idFile *savefile)
case const int
Definition: Callbacks.cpp:52
signed char textAlign
Definition: Window.h:394
float y() const
Definition: Winvar.h:505
float w() const
Definition: Winvar.h:420
const char * GetName(void) const
Definition: DeclManager.h:140
Definition: Vector.h:316
idWinFloat rotate
Definition: Window.h:406
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:622
int GetImageHeight(void) const
Definition: Material.cpp:2526
idDeviceContext * dc
Definition: SimpleWindow.h:67
idDeviceContext * dc
Definition: Window.h:425
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
idWinVec4 borderColor
Definition: SimpleWindow.h:88
float y() const
Definition: Winvar.h:417
void Identity(void)
Definition: Matrix.h:591
const idMaterial * background
Definition: Window.h:414
idWinRectangle rect
Definition: SimpleWindow.h:84
GLenum GLint x
Definition: glext.h:2849
void SetFont(int num)
int Icmp(const char *text) const
Definition: Str.h:667
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:137
idWinVec4 foreColor
Definition: SimpleWindow.h:87
float borderSize
Definition: Window.h:384
Definition: File.h:50
idRectangle drawRect
Definition: SimpleWindow.h:69
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:355
idRectangle clientRect
Definition: Window.h:374
virtual size_t Size()
Definition: Winvar.h:222
idWinFloat rotate
Definition: SimpleWindow.h:90
void Redraw(float x, float y)
void SetupTransforms(float x, float y)
void AddUpdateVar(idWinVar *var)
Definition: Window.cpp:575
idWinBool visible
Definition: Window.h:397
idRectangle drawRect
Definition: Window.h:373
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:626
float matScalex
Definition: Window.h:382
float x() const
Definition: Winvar.h:502
idSimpleWindow(idWindow *win)
int DrawText(const char *text, float textScale, int textAlign, idVec4 color, idRectangle rectDraw, bool wrap, int cursor=-1, bool calcOnly=false, idList< int > *breaks=NULL, int limit=0)
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:810
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
idWinVec4 matColor
Definition: SimpleWindow.h:86
float y
Definition: Rectangle.h:37
idWinVec4 backColor
Definition: SimpleWindow.h:85
void DrawFilledRect(float x, float y, float width, float height, const idVec4 &color)
idWindow * mParent
Definition: SimpleWindow.h:96
#define NULL
Definition: Lib.h:88
void StateChanged(bool redraw)
bool IsIdentity(const float epsilon=MATRIX_EPSILON) const
Definition: Matrix.h:595
float w() const
Definition: Winvar.h:588
unsigned char fontNum
Definition: Window.h:392
const int WIN_NATURALMAT
Definition: Window.h:57
idWinVec4 foreColor
Definition: Window.h:402
virtual int Read(void *buffer, int len)
Definition: File.cpp:179
idWinBool visible
Definition: SimpleWindow.h:83
void SetMaterialPtr(const idMaterial **m)
Definition: Winvar.h:806
float x
Definition: Vector.h:54
float matScaley
Definition: Window.h:383
void EnableClipping(bool b)
Definition: DeviceContext.h:90
float x() const
Definition: Winvar.h:414
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:141
idStr & RemoveColors(void)
Definition: Str.h:849
idWinBackground backGroundName
Definition: SimpleWindow.h:92
int CinematicLength(void) const
Definition: Material.cpp:2536
idWinVar * GetWinVarByName(const char *_name)
idWinStr text
Definition: Window.h:407
void Set(const idVec3 &rotationOrigin, const idVec3 &rotationVec, const float rotationAngle)
Definition: Rotation.h:108
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:819
idWinRectangle rect
Definition: Window.h:399
float x
Definition: Rectangle.h:36
idDeclManager * declManager
virtual size_t Size()
Definition: Winvar.h:801
idVec2 shear
Definition: Window.h:389
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:237
idWinVec4 borderColor
Definition: Window.h:404
int GetWinVarOffset(idWinVar *wv, drawWin_t *owner)
float textAlignx
Definition: Window.h:385
idWinBool hideCursor
Definition: Window.h:448
Definition: Matrix.h:333
int Length()
Definition: Winvar.h:763
float textAligny
Definition: Window.h:386
idWinVec4 backColor
Definition: Window.h:400
idUserInterfaceLocal * GetGui()
Definition: Window.h:225
const idMat3 & ToMat3(void) const
Definition: Rotation.cpp:60
void DrawBorderAndCaption(const idRectangle &drawRect)
const int WIN_INVERTRECT
Definition: Window.h:56
const GLcharARB * name
Definition: glext.h:3629
virtual int Write(const void *buffer, int len)
Definition: File.cpp:189
Definition: Str.h:116
idWinFloat textScale
Definition: SimpleWindow.h:89
void Fill(const char ch, int newlen)
Definition: Str.h:867
int GetImageWidth(void) const
Definition: Material.cpp:2516
float w
Definition: Rectangle.h:38
Window win
Definition: glimp.cpp:46
void DrawBackground(const idRectangle &drawRect)
void SetSort(float s) const
Definition: Material.h:513
idStr name
Definition: Window.h:387
float h
Definition: Rectangle.h:39
void SetImageClassifications(int tag) const
Definition: Material.cpp:2644
idWinStr text
Definition: SimpleWindow.h:82
void Set(const float x, const float y)
Definition: Vector.h:114
virtual ~idSimpleWindow()
const int WIN_BORDER
Definition: Window.h:41
idSimpleWindow * simp
Definition: SimpleWindow.h:38
const int WIN_NOCLIP
Definition: Window.h:55
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:534
idWinBackground backGroundName
Definition: Window.h:408
void DrawMaterial(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex=1.0, float scaley=1.0)
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:359
idVec4 colorBlack
Definition: Lib.cpp:115
void CalcClientRect(float xofs, float yofs)
const idMaterial * background
Definition: SimpleWindow.h:94
idRectangle textRect
Definition: SimpleWindow.h:71
idWindow * GetParent()
Definition: Window.h:224
void DrawRect(float x, float y, float width, float height, float size, const idVec4 &color)
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:463
idRectangle textRect
Definition: Window.h:413
float h() const
Definition: Winvar.h:423
bool NeedsUpdate()
Definition: Winvar.h:69
idVec2 origin
Definition: Window.h:375