doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEWindowWrapper.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 "../../sys/win32/rc/guied_resource.h"
33 #include "../../renderer/tr_local.h"
34 #include "../../ui/EditWindow.h"
35 #include "../../ui/ListWindow.h"
36 #include "../../ui/BindWindow.h"
37 #include "../../ui/RenderWindow.h"
38 #include "../../ui/ChoiceWindow.h"
39 
40 #include "GEApp.h"
41 
43  assert(window);
44 
45  mWindow = window;
46  mFlippedHorz = false;
47  mFlippedVert = false;
48  mHidden = false;
49  mDeleted = false;
50  mSelected = false;
51  mType = type;
52  mExpanded = false;
53  mOldVisible = false;
54  mMoveable = true;
55 
56  if ( dynamic_cast< idEditWindow*>(window) ) {
57  mType = WT_EDIT;
58  } else if ( dynamic_cast< idListWindow*>(window) ) {
59  mType = WT_LIST;
60  } else if ( dynamic_cast< idBindWindow*>(window) ) {
61  mType = WT_BIND;
62  } else if ( dynamic_cast< idRenderWindow*>(window) ) {
63  mType = WT_RENDER;
64  } else if ( dynamic_cast< idChoiceWindow*>(window) ) {
65  mType = WT_CHOICE;
66  } else {
67  mType = WT_NORMAL;
68  }
69 
70  // Attach the wrapper to the window by adding a defined variable
71  // with the wrappers pointer stuffed into an integer
72  idWinInt *var = new idWinInt();
73  int x = (int)this;
74  *var = x;
75  var->SetEval(false);
76  var->SetName("guied_wrapper");
77  mWindow->AddDefinedVar(var);
78 
79  SetStateKey("name", mWindow->GetName(), false);
80 }
81 
82 /*
83 ================
84 rvGEWindowWrapper::GetWrapper
85 
86 Static method that returns the window wrapper for the given window class
87 ================
88 */
90  idWinInt *var;
91  var = dynamic_cast< idWinInt*>(window->GetWinVarByName("guied_wrapper"));
92  return var ? ((rvGEWindowWrapper *) (int) (*var)) : NULL;
93 }
94 
95 /*
96 ================
97 rvGEWindowWrapper::UpdateRect
98 
99 Updates the gui editor's representation of the window rectangle from the
100 windows rectangle
101 ================
102 */
104  idVec4 rect;
105  idWinRectangle *winrect;
106 
107  winrect = dynamic_cast< idWinRectangle*>(mWindow->GetWinVarByName("rect"));
108  assert(winrect);
109  rect = winrect->ToVec4();
110 
111  mFlippedHorz = false;
112  mFlippedVert = false;
113 
114  if ( rect[2] < 0 ) {
115  mFlippedHorz = true;
116  rect[2] *= -1;
117  }
118 
119  if ( rect[3] < 0 ) {
120  mFlippedVert = true;
121  rect[3] *= -1;
122  }
123 
124  mClientRect = rect;
125 
126  CalcScreenRect();
127 
128  const char *rstr = mState.GetString("rect", "0,0,0,0");
129  mMoveable = !IsExpression(rstr);
130 }
131 
132 /*
133 ================
134 rvGEWindowWrapper::CalcScreenRect
135 
136 Calculates the screen rectangle from the client rectangle by running through
137 the parent windows and adding their offsets
138 ================
139 */
141  idWindow *parent;
142 
144 
145  if ( NULL != (parent = mWindow->GetParent()) ) {
146  rvGEWindowWrapper *wrapper = GetWrapper(parent);
147  assert(wrapper);
148 
149  mScreenRect[0] += wrapper->GetScreenRect()[0];
150  mScreenRect[1] += wrapper->GetScreenRect()[1];
151  }
152 
153  // Since our screen rectangle has changed we need to tell all our our children to update
154  // their screen rectangles as well.
155  int i;
156  int count;
157  rvGEWindowWrapper *pwrapper;
158 
160 
161  for ( count = pwrapper->GetChildCount(), i = 0; i < count; i ++ ) {
162  rvGEWindowWrapper *wrapper;
163 
164  wrapper = rvGEWindowWrapper::GetWrapper(pwrapper->GetChild(i));
165 
166  // Usually we assert if there is no wrapper but since this method is called
167  // when the wrappers are being attached to the windows there may be no wrappers
168  // for any of the children.
169  if ( !wrapper ) {
170  continue;
171  }
172 
173  wrapper->CalcScreenRect();
174  }
175 }
176 
177 /*
178 ================
179 rvGEWindowWrapper::SetRect
180 
181 Sets the wrapper's rectangle and the attached windows rectangle as well
182 ================
183 */
185  const char *s;
186 
187  mClientRect = rect;
188  CalcScreenRect();
189 
190  s = va("%d,%d,%d,%d", (int) (rect.x + 0.5f), (int) (rect.y + 0.5f), (int) ((rect.w + 0.5f) * (mFlippedHorz ? -1 : 1)), (int) ((rect.h + 0.5f) * (mFlippedVert ? -1 : 1)));
191 
192  mState.Set("rect", s);
193 
195 }
196 
197 /*
198 ================
199 rvGEWindowWrapper::SetHidden
200 
201 Sets the wrappers hidden state
202 ================
203 */
205  mHidden = h;
206 
208 }
209 
210 /*
211 ================
212 rvGEWindowWrapper::SetDeleted
213 
214 Sets the deleted state of the wrapper which in turns sets whether or
215 not the window is visible
216 ================
217 */
219  mDeleted = del;
220 
222 }
223 
224 /*
225 ================
226 rvGEWindowWrapper::SetState
227 
228 Sets the window state from the given dictionary
229 ================
230 */
231 void rvGEWindowWrapper::SetState( const idDict &dict ) {
232  mState.Clear();
233  mState.Copy(dict);
234 
235  // Push the window state to the window itself
237 
238  // Update the internal rectangle since it may have changed in the state
239  UpdateRect();
240 }
241 
242 /*
243 ================
244 rvGEWindowWrapper::SetStateKey
245 
246 Sets the given state key and updates the
247 ================
248 */
249 void rvGEWindowWrapper::SetStateKey( const char *key,const char *value,bool update ) {
250  mState.Set(key, value);
251 
252  if ( update ) {
254 
255  // Make sure the rectangle gets updated if its changing
256  if ( !idStr::Icmp(key, "rect") ) {
257  UpdateRect();
258  }
259  }
260 }
261 
262 /*
263 ================
264 rvGEWindowWrapper::DeleteStateKey
265 
266 Sets the given state key and updates the
267 ================
268 */
269 void rvGEWindowWrapper::DeleteStateKey( const char *key ) {
270  if ( !idStr::Icmp(key, "rect") || !idStr::Icmp(key, "name") ) {
271  return;
272  }
273 
274  mState.Delete(key);
275 }
276 
277 /*
278 ================
279 rvGEWindowWrapper::UpdateWindowState
280 
281 Updates the windows real state with wrappers internal state. Visibility is
282 handled specially
283 ================
284 */
286  idStr realVisible;
287  bool tempVisible;
288  // int i;
289 
290  realVisible = mState.GetString("visible", "1");
291  tempVisible = atoi(realVisible) ? true : false;
292  if ( tempVisible != mOldVisible ) {
293  mHidden = !tempVisible;
294  mOldVisible = tempVisible;
295  }
296 
297  tempVisible = !mDeleted && !mHidden;
298 
299  // Temporarily change the visible state so we can hide/unhide the window
300  mState.Set("visible", tempVisible ? "1" : "0");
301 
303 
304  // Put the visible state back to the real value
305  mState.Set("visible", realVisible);
306 }
307 
308 /*
309 ================
310 rvGEWindowWrapper::WindowFromPoint
311 
312 Returns the topmost window under the given point
313 ================
314 */
315 idWindow * rvGEWindowWrapper::WindowFromPoint( float x,float y,bool visibleOnly ) {
316  int count;
317  int i;
318  rvGEWindowWrapper *pwrapper;
319 
320  // If the window isnt visible then skip it
321  if ( visibleOnly && (mHidden || mDeleted) ) {
322  return NULL;
323  }
324 
325  // Now check our children next
326  pwrapper = GetWrapper(mWindow);
327  count = pwrapper->GetChildCount();
328 
329  for ( i = count - 1; i >= 0; i -- ) {
330  rvGEWindowWrapper *wrapper;
331  idWindow *child;
332 
333  child = pwrapper->GetChild(i);
334  assert(child);
335 
336  wrapper = rvGEWindowWrapper::GetWrapper(child);
337  if ( !wrapper ) {
338  continue;
339  }
340 
341  if ( child = wrapper->WindowFromPoint(x, y) ) {
342  return child;
343  }
344  }
345 
346  // We have to check this last because a child could be out outside of the parents
347  // rectangle and we still want it selectable.
348  if ( !mScreenRect.Contains(x, y) ) {
349  return NULL;
350  }
351 
352  return mWindow;
353 }
354 
355 /*
356 ================
357 rvGEWindowWrapper::StringToWindowType
358 
359 Converts the given string to a window type
360 ================
361 */
363  if ( !idStr::Icmp(string, "windowDef") ) {
364  return WT_NORMAL;
365  } else if ( !idStr::Icmp(string, "editDef") ) {
366  return WT_EDIT;
367  } else if ( !idStr::Icmp(string, "choiceDef") ) {
368  return WT_CHOICE;
369  } else if ( !idStr::Icmp(string, "sliderDef") ) {
370  return WT_SLIDER;
371  } else if ( !idStr::Icmp(string, "bindDef") ) {
372  return WT_BIND;
373  } else if ( !idStr::Icmp(string, "listDef") ) {
374  return WT_LIST;
375  } else if ( !idStr::Icmp(string, "renderDef") ) {
376  return WT_RENDER;
377  } else if ( !idStr::Icmp(string, "htmlDef") ) {
378  return WT_HTML;
379  }
380 
381  return WT_UNKNOWN;
382 }
383 
384 /*
385 ================
386 rvGEWindowWrapper::WindowTypeToString
387 
388 Converts the given window type to a string
389 ================
390 */
392  static const char *typeNames[] = {
393  "Unknown", "windowDef", "editDef", "htmlDef", "choiceDef", "sliderDef", "bindDef", "listDef", "renderDef"
394  };
395 
396  return typeNames[(int) type];
397 }
398 
399 /*
400 ================
401 rvGEWindowWrapper::GetChildCount
402 
403 Returns the number of children the window being wrapped has
404 ================
405 */
407  if ( !CanHaveChildren() ) {
408  return 0;
409  }
410 
411  return mWindow->GetChildCount();
412 }
413 
414 /*
415 ================
416 rvGEWindowWrapper::EnumChildren
417 
418 Enumerates over the child windows while properly ignoring any that
419 are not wrapped.
420 ================
421 */
423  int count;
424  int i;
425 
426  if ( !CanHaveChildren() ) {
427  return false;
428  }
429 
430  for ( count = GetChildCount(), i = 0; i < count; i ++ ) {
431  if ( !proc(rvGEWindowWrapper::GetWrapper(GetChild(i)), data) ) {
432  return false;
433  }
434  }
435 
436  return true;
437 }
438 
439 /*
440 ================
441 rvGEWindowWrapper::CanHaveChildren
442 
443 Returns true if the window is allowed to have child windows
444 ================
445 */
447  if ( mType == WT_HTML || mType == WT_LIST ) {
448  return false;
449  }
450 
451  return true;
452 }
453 
454 /*
455 ================
456 rvGEWindowWrapper::GetDepth
457 
458 Returns the depth of the wrapped window
459 ================
460 */
462  idWindow *parent;
463  int depth;
464 
465  for ( depth = 0, parent = mWindow->GetParent(); parent; parent = parent->GetParent(), depth++ )
466  ;
467 
468  return depth;
469 }
470 
471 /*
472 ================
473 rvGEWindowWrapper::Expand
474 
475 Expand the window in the navigator and all of its parents too
476 ================
477 */
479  bool result;
480 
481  if ( mWindow->GetParent() ) {
483  } else {
484  result = false;
485  }
486 
487  if ( mExpanded || !CanHaveChildren() || !GetChildCount() ) {
488  return result;
489  }
490 
491  mExpanded = true;
492 
493  return true;
494 }
495 
496 /*
497 ================
498 rvGEWindowWrapper::Collapse
499 
500 Returns the depth of the wrapped window
501 ================
502 */
504  bool result;
505 
506  if ( mWindow->GetParent() ) {
508  } else {
509  result = false;
510  }
511 
512  if ( !mExpanded ) {
513  return result;
514  }
515 
516  mExpanded = false;
517 
518  return true;
519 }
520 
521 /*
522 ================
523 rvGEWindowWrapper::Finish
524 
525 After a the windwo wrapper is attached to a window and the window is parsed
526 the finish method is called to finish up any last details
527 ================
528 */
530  mOldVisible = ((bool) * dynamic_cast< idWinBool*>(mWindow->GetWinVarByName("visible")));
531  mHidden = mOldVisible ? false : true;
532  UpdateRect();
533 }
534 
535 /*
536 ================
537 rvGEWindowWrapper::Finish
538 
539 After a the windwo wrapper is attached to a window and the window is parsed
540 the finish method is called to finish up any last details
541 ================
542 */
543 bool rvGEWindowWrapper::VerfiyStateKey( const char *name,const char *value,idStr *result ) {
544  idStr old;
545  bool failed;
547 
548  // Save the current value
549  old = mState.GetString(name);
550  failed = false;
551 
552  // Try to parse in the value
553  try {
554  if ( !mWindow->ParseInternalVar(name, &src) ) {
555  // Kill the old register since the parse reg entry will add a new one
556  if ( !mWindow->ParseRegEntry(name, &src) ) {
557  failed = true;
558  }
559  }
560  } catch ( idException &) {
561  failed = true;
562  }
563 
564  // Restore the old value
566  if ( !mWindow->ParseInternalVar(name, &src2) ) {
567  if ( !mWindow->ParseRegEntry(name, &src2) ) {
568  }
569  }
570 
571  // Check to see if the old value matches the new value
572  idStr before;
573  idStr after;
574 
575  before = value;
576  before.StripTrailingWhitespace();
577  src.GetStringFromMarker(after);
578  after.StripTrailingWhitespace();
579 
580  if ( result ) {
581  *result = after;
582  }
583 
584  if ( failed || before.Cmp(after) ) {
585  return false;
586  }
587 
588  return true;
589 }
590 
bool(* PFNENUMCHILDRENPROC)(rvGEWindowWrapper *wrapper, void *data)
void UpdateWindowState(void)
GLsizei const GLfloat * value
Definition: glext.h:3614
assert(prefInfo.fullscreenBtn)
int Cmp(const char *text) const
Definition: Str.h:652
void Delete(const char *key)
Definition: Dict.cpp:496
bool UpdateFromDictionary(idDict &dict)
Definition: Window.cpp:4194
void AddDefinedVar(idWinVar *var)
Definition: Window.h:451
idWindow * WindowFromPoint(float x, float y, bool visibleOnly=true)
const char * GetName()
Definition: Window.h:247
int Length(void) const
Definition: Str.h:702
virtual bool ParseInternalVar(const char *name, idParser *src)
Definition: Window.cpp:1915
void StripTrailingWhitespace(void)
Definition: Str.cpp:648
GLenum GLint GLint y
Definition: glext.h:2849
case const int
Definition: Callbacks.cpp:52
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glext.h:2878
idVec4 & ToVec4()
Definition: Winvar.h:432
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
static const char * WindowTypeToString(EWindowType type)
static EWindowType StringToWindowType(const char *string)
GLdouble s
Definition: glext.h:2935
GLuint src
Definition: glext.h:5390
void Set(const char *key, const char *value)
Definition: Dict.cpp:275
void SetDeleted(bool del)
GLenum GLint x
Definition: glext.h:2849
int i
Definition: process.py:33
Boolean result
void Copy(const idDict &other)
Definition: Dict.cpp:70
int Icmp(const char *text) const
Definition: Str.h:667
bool CanHaveChildren(void)
void SetHidden(bool v)
idWindow * GetChild(int index)
bool IsExpression(const char *s)
Definition: guied.cpp:146
GLuint GLuint GLsizei count
Definition: glext.h:2845
void GetStringFromMarker(idStr &out, bool clean=false)
Definition: Parser.cpp:2929
const char * GetString(const char *key, const char *defaultString="") const
Definition: Dict.h:240
Definition: Vector.h:808
float y
Definition: Rectangle.h:37
Definition: Dict.h:65
#define NULL
Definition: Lib.h:88
void Clear(void)
Definition: Dict.cpp:201
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
idRectangle mClientRect
idRectangle & GetScreenRect(void)
bool VerfiyStateKey(const char *name, const char *value, idStr *result=NULL)
void SetName(const char *_name)
Definition: Winvar.h:53
rvGEWindowWrapper(idWindow *window, EWindowType type)
float x
Definition: Rectangle.h:36
bool ParseRegEntry(const char *name, idParser *src)
Definition: Window.cpp:2052
prefInfo window
static rvGEWindowWrapper * GetWrapper(idWindow *window)
bool Contains(float xt, float yt)
Definition: Rectangle.h:48
const GLcharARB * name
Definition: glext.h:3629
Definition: Str.h:116
int GetChildCount(void)
Definition: Window.cpp:4024
float w
Definition: Rectangle.h:38
idRectangle mScreenRect
float h
Definition: Rectangle.h:39
unsigned char bool
Definition: setup.h:74
void DeleteStateKey(const char *key)
void SetStateKey(const char *key, const char *value, bool update=true)
char * va(const char *fmt,...)
Definition: Str.cpp:1568
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
Definition: Window.cpp:1776
void SetEval(bool b)
Definition: Winvar.h:82
bool EnumChildren(PFNENUMCHILDRENPROC proc, void *data)
void SetState(const idDict &dict)
void SetRect(idRectangle &rect)
idWindow * GetParent()
Definition: Window.h:224