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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
|
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code 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.
Doom 3 Source Code 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
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.
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.
===========================================================================
*/
#include "tools/edit_gui_common.h"
#include "../../sys/win32/rc/guied_resource.h"
#include "../../renderer/tr_local.h"
#include "../../ui/EditWindow.h"
#include "../../ui/ListWindow.h"
#include "../../ui/BindWindow.h"
#include "../../ui/RenderWindow.h"
#include "../../ui/ChoiceWindow.h"
#include "GEApp.h"
rvGEWindowWrapper::rvGEWindowWrapper( idWindow *window,EWindowType type ) {
assert(window);
mWindow = window;
mFlippedHorz = false;
mFlippedVert = false;
mHidden = false;
mDeleted = false;
mSelected = false;
mType = type;
mExpanded = false;
mOldVisible = false;
mMoveable = true;
if ( dynamic_cast< idEditWindow*>(window) ) {
mType = WT_EDIT;
} else if ( dynamic_cast< idListWindow*>(window) ) {
mType = WT_LIST;
} else if ( dynamic_cast< idBindWindow*>(window) ) {
mType = WT_BIND;
} else if ( dynamic_cast< idRenderWindow*>(window) ) {
mType = WT_RENDER;
} else if ( dynamic_cast< idChoiceWindow*>(window) ) {
mType = WT_CHOICE;
} else {
mType = WT_NORMAL;
}
// Attach the wrapper to the window by adding a defined variable
// with the wrappers pointer stuffed into an integer
idWinInt *var = new idWinInt();
int x = (int)this;
*var = x;
var->SetEval(false);
var->SetName("guied_wrapper");
mWindow->AddDefinedVar(var);
SetStateKey("name", mWindow->GetName(), false);
}
/*
================
rvGEWindowWrapper::GetWrapper
Static method that returns the window wrapper for the given window class
================
*/
rvGEWindowWrapper * rvGEWindowWrapper::GetWrapper( idWindow *window ) {
idWinInt *var;
var = dynamic_cast< idWinInt*>(window->GetWinVarByName("guied_wrapper"));
return var ? ((rvGEWindowWrapper *) (int) (*var)) : NULL;
}
/*
================
rvGEWindowWrapper::UpdateRect
Updates the gui editor's representation of the window rectangle from the
windows rectangle
================
*/
void rvGEWindowWrapper::UpdateRect( void ) {
idVec4 rect;
idWinRectangle *winrect;
winrect = dynamic_cast< idWinRectangle*>(mWindow->GetWinVarByName("rect"));
assert(winrect);
rect = winrect->ToVec4();
mFlippedHorz = false;
mFlippedVert = false;
if ( rect[2] < 0 ) {
mFlippedHorz = true;
rect[2] *= -1;
}
if ( rect[3] < 0 ) {
mFlippedVert = true;
rect[3] *= -1;
}
mClientRect = rect;
CalcScreenRect();
const char *rstr = mState.GetString("rect", "0,0,0,0");
mMoveable = !IsExpression(rstr);
}
/*
================
rvGEWindowWrapper::CalcScreenRect
Calculates the screen rectangle from the client rectangle by running through
the parent windows and adding their offsets
================
*/
void rvGEWindowWrapper::CalcScreenRect( void ) {
idWindow *parent;
mScreenRect = mClientRect;
if ( NULL != (parent = mWindow->GetParent()) ) {
rvGEWindowWrapper *wrapper = GetWrapper(parent);
assert(wrapper);
mScreenRect[0] += wrapper->GetScreenRect()[0];
mScreenRect[1] += wrapper->GetScreenRect()[1];
}
// Since our screen rectangle has changed we need to tell all our our children to update
// their screen rectangles as well.
int i;
int count;
rvGEWindowWrapper *pwrapper;
pwrapper = rvGEWindowWrapper::GetWrapper(mWindow);
for ( count = pwrapper->GetChildCount(), i = 0; i < count; i ++ ) {
rvGEWindowWrapper *wrapper;
wrapper = rvGEWindowWrapper::GetWrapper(pwrapper->GetChild(i));
// Usually we assert if there is no wrapper but since this method is called
// when the wrappers are being attached to the windows there may be no wrappers
// for any of the children.
if ( !wrapper ) {
continue;
}
wrapper->CalcScreenRect();
}
}
/*
================
rvGEWindowWrapper::SetRect
Sets the wrapper's rectangle and the attached windows rectangle as well
================
*/
void rvGEWindowWrapper::SetRect( idRectangle &rect ) {
const char *s;
mClientRect = rect;
CalcScreenRect();
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)));
mState.Set("rect", s);
UpdateWindowState();
}
/*
================
rvGEWindowWrapper::SetHidden
Sets the wrappers hidden state
================
*/
void rvGEWindowWrapper::SetHidden( bool h ) {
mHidden = h;
UpdateWindowState();
}
/*
================
rvGEWindowWrapper::SetDeleted
Sets the deleted state of the wrapper which in turns sets whether or
not the window is visible
================
*/
void rvGEWindowWrapper::SetDeleted( bool del ) {
mDeleted = del;
UpdateWindowState();
}
/*
================
rvGEWindowWrapper::SetState
Sets the window state from the given dictionary
================
*/
void rvGEWindowWrapper::SetState( const idDict &dict ) {
mState.Clear();
mState.Copy(dict);
// Push the window state to the window itself
UpdateWindowState();
// Update the internal rectangle since it may have changed in the state
UpdateRect();
}
/*
================
rvGEWindowWrapper::SetStateKey
Sets the given state key and updates the
================
*/
void rvGEWindowWrapper::SetStateKey( const char *key,const char *value,bool update ) {
mState.Set(key, value);
if ( update ) {
UpdateWindowState();
// Make sure the rectangle gets updated if its changing
if ( !idStr::Icmp(key, "rect") ) {
UpdateRect();
}
}
}
/*
================
rvGEWindowWrapper::DeleteStateKey
Sets the given state key and updates the
================
*/
void rvGEWindowWrapper::DeleteStateKey( const char *key ) {
if ( !idStr::Icmp(key, "rect") || !idStr::Icmp(key, "name") ) {
return;
}
mState.Delete(key);
}
/*
================
rvGEWindowWrapper::UpdateWindowState
Updates the windows real state with wrappers internal state. Visibility is
handled specially
================
*/
void rvGEWindowWrapper::UpdateWindowState( void ) {
idStr realVisible;
bool tempVisible;
// int i;
realVisible = mState.GetString("visible", "1");
tempVisible = atoi(realVisible) ? true : false;
if ( tempVisible != mOldVisible ) {
mHidden = !tempVisible;
mOldVisible = tempVisible;
}
tempVisible = !mDeleted && !mHidden;
// Temporarily change the visible state so we can hide/unhide the window
mState.Set("visible", tempVisible ? "1" : "0");
mWindow->UpdateFromDictionary(mState);
// Put the visible state back to the real value
mState.Set("visible", realVisible);
}
/*
================
rvGEWindowWrapper::WindowFromPoint
Returns the topmost window under the given point
================
*/
idWindow * rvGEWindowWrapper::WindowFromPoint( float x,float y,bool visibleOnly ) {
int count;
int i;
rvGEWindowWrapper *pwrapper;
// If the window isnt visible then skip it
if ( visibleOnly && (mHidden || mDeleted) ) {
return NULL;
}
// Now check our children next
pwrapper = GetWrapper(mWindow);
count = pwrapper->GetChildCount();
for ( i = count - 1; i >= 0; i -- ) {
rvGEWindowWrapper *wrapper;
idWindow *child;
child = pwrapper->GetChild(i);
assert(child);
wrapper = rvGEWindowWrapper::GetWrapper(child);
if ( !wrapper ) {
continue;
}
if ( child = wrapper->WindowFromPoint(x, y) ) {
return child;
}
}
// We have to check this last because a child could be out outside of the parents
// rectangle and we still want it selectable.
if ( !mScreenRect.Contains(x, y) ) {
return NULL;
}
return mWindow;
}
/*
================
rvGEWindowWrapper::StringToWindowType
Converts the given string to a window type
================
*/
rvGEWindowWrapper::EWindowType rvGEWindowWrapper::StringToWindowType( const char *string ) {
if ( !idStr::Icmp(string, "windowDef") ) {
return WT_NORMAL;
} else if ( !idStr::Icmp(string, "editDef") ) {
return WT_EDIT;
} else if ( !idStr::Icmp(string, "choiceDef") ) {
return WT_CHOICE;
} else if ( !idStr::Icmp(string, "sliderDef") ) {
return WT_SLIDER;
} else if ( !idStr::Icmp(string, "bindDef") ) {
return WT_BIND;
} else if ( !idStr::Icmp(string, "listDef") ) {
return WT_LIST;
} else if ( !idStr::Icmp(string, "renderDef") ) {
return WT_RENDER;
} else if ( !idStr::Icmp(string, "htmlDef") ) {
return WT_HTML;
}
return WT_UNKNOWN;
}
/*
================
rvGEWindowWrapper::WindowTypeToString
Converts the given window type to a string
================
*/
const char * rvGEWindowWrapper::WindowTypeToString( EWindowType type ) {
static const char *typeNames[] = {
"Unknown", "windowDef", "editDef", "htmlDef", "choiceDef", "sliderDef", "bindDef", "listDef", "renderDef"
};
return typeNames[(int) type];
}
/*
================
rvGEWindowWrapper::GetChildCount
Returns the number of children the window being wrapped has
================
*/
int rvGEWindowWrapper::GetChildCount( void ) {
if ( !CanHaveChildren() ) {
return 0;
}
return mWindow->GetChildCount();
}
/*
================
rvGEWindowWrapper::EnumChildren
Enumerates over the child windows while properly ignoring any that
are not wrapped.
================
*/
bool rvGEWindowWrapper::EnumChildren( PFNENUMCHILDRENPROC proc,void *data ) {
int count;
int i;
if ( !CanHaveChildren() ) {
return false;
}
for ( count = GetChildCount(), i = 0; i < count; i ++ ) {
if ( !proc(rvGEWindowWrapper::GetWrapper(GetChild(i)), data) ) {
return false;
}
}
return true;
}
/*
================
rvGEWindowWrapper::CanHaveChildren
Returns true if the window is allowed to have child windows
================
*/
bool rvGEWindowWrapper::CanHaveChildren( void ) {
if ( mType == WT_HTML || mType == WT_LIST ) {
return false;
}
return true;
}
/*
================
rvGEWindowWrapper::GetDepth
Returns the depth of the wrapped window
================
*/
int rvGEWindowWrapper::GetDepth( void ) {
idWindow *parent;
int depth;
for ( depth = 0, parent = mWindow->GetParent(); parent; parent = parent->GetParent(), depth++ )
;
return depth;
}
/*
================
rvGEWindowWrapper::Expand
Expand the window in the navigator and all of its parents too
================
*/
bool rvGEWindowWrapper::Expand( void ) {
bool result;
if ( mWindow->GetParent() ) {
result = rvGEWindowWrapper::GetWrapper(mWindow->GetParent())->Expand();
} else {
result = false;
}
if ( mExpanded || !CanHaveChildren() || !GetChildCount() ) {
return result;
}
mExpanded = true;
return true;
}
/*
================
rvGEWindowWrapper::Collapse
Returns the depth of the wrapped window
================
*/
bool rvGEWindowWrapper::Collapse( void ) {
bool result;
if ( mWindow->GetParent() ) {
result = rvGEWindowWrapper::GetWrapper(mWindow->GetParent())->Expand();
} else {
result = false;
}
if ( !mExpanded ) {
return result;
}
mExpanded = false;
return true;
}
/*
================
rvGEWindowWrapper::Finish
After a the windwo wrapper is attached to a window and the window is parsed
the finish method is called to finish up any last details
================
*/
void rvGEWindowWrapper::Finish( void ) {
mOldVisible = ((bool) * dynamic_cast< idWinBool*>(mWindow->GetWinVarByName("visible")));
mHidden = mOldVisible ? false : true;
UpdateRect();
}
/*
================
rvGEWindowWrapper::Finish
After a the windwo wrapper is attached to a window and the window is parsed
the finish method is called to finish up any last details
================
*/
bool rvGEWindowWrapper::VerfiyStateKey( const char *name,const char *value,idStr *result ) {
idStr old;
bool failed;
idParser src(value, strlen(value), "", LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT);
// Save the current value
old = mState.GetString(name);
failed = false;
// Try to parse in the value
try {
if ( !mWindow->ParseInternalVar(name, &src) ) {
// Kill the old register since the parse reg entry will add a new one
if ( !mWindow->ParseRegEntry(name, &src) ) {
failed = true;
}
}
} catch ( idException &) {
failed = true;
}
// Restore the old value
idParser src2(old, old.Length(), "", LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT);
if ( !mWindow->ParseInternalVar(name, &src2) ) {
if ( !mWindow->ParseRegEntry(name, &src2) ) {
}
}
// Check to see if the old value matches the new value
idStr before;
idStr after;
before = value;
before.StripTrailingWhitespace();
src.GetStringFromMarker(after);
after.StripTrailingWhitespace();
if ( result ) {
*result = after;
}
if ( failed || before.Cmp(after) ) {
return false;
}
return true;
}
|