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 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
|
/*
===========================================================================
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.
===========================================================================
*/
#ifndef __WINVAR_H__
#define __WINVAR_H__
#include "framework/File.h"
#include "ui/Rectangle.h"
extern const char *VAR_GUIPREFIX;
class idWindow;
class idWinVar {
public:
idWinVar();
virtual ~idWinVar();
void SetGuiInfo(idDict *gd, const char *_name);
const char *GetName() const {
if (name) {
if (guiDict && *name == '*') {
return guiDict->GetString(&name[1]);
}
return name;
}
return "";
}
void SetName(const char *_name) {
delete[] name;
name = NULL;
if (_name) {
name = new char[strlen(_name)+1];
strcpy(name, _name);
}
}
idWinVar &operator=( const idWinVar &other ) {
guiDict = other.guiDict;
SetName(other.name);
return *this;
}
idDict *GetDict() const { return guiDict; }
bool NeedsUpdate() { return (guiDict != NULL); }
virtual void Init(const char *_name, idWindow* win) = 0;
virtual void Set(const char *val) = 0;
virtual void Update() = 0;
virtual const char *c_str() const = 0;
virtual size_t Size() { size_t sz = (name) ? strlen(name) : 0; return sz + sizeof(*this); }
virtual void WriteToSaveGame( idFile *savefile ) = 0;
virtual void ReadFromSaveGame( idFile *savefile ) = 0;
virtual float x( void ) const = 0;
void SetEval(bool b) {
eval = b;
}
bool GetEval() {
return eval;
}
protected:
idDict *guiDict;
char *name;
bool eval;
};
class idWinBool : public idWinVar {
public:
idWinBool() : idWinVar() {};
~idWinBool() {};
virtual void Init(const char *_name, idWindow *win) { idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetBool(GetName());
}
}
int operator==( const bool &other ) { return (other == data); }
bool &operator=( const bool &other ) {
data = other;
if (guiDict) {
guiDict->SetBool(GetName(), data);
}
return data;
}
idWinBool &operator=( const idWinBool &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
operator bool() const { return data; }
virtual void Set(const char *val) {
data = ( atoi( val ) != 0 );
if (guiDict) {
guiDict->SetBool(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetBool( s );
}
}
virtual const char *c_str() const {return va("%i", data); }
// SaveGames
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
virtual float x( void ) const { return data ? 1.0f : 0.0f; };
protected:
bool data;
};
class idWinStr : public idWinVar {
public:
idWinStr() : idWinVar() {};
~idWinStr() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetString(GetName());
}
}
int operator==( const idStr &other ) const {
return (other == data);
}
int operator==( const char *other ) const {
return (data == other);
}
idStr &operator=( const idStr &other ) {
data = other;
if (guiDict) {
guiDict->Set(GetName(), data);
}
return data;
}
idWinStr &operator=( const idWinStr &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
operator const char *() const {
return data.c_str();
}
operator const idStr &() const {
return data;
}
int LengthWithoutColors() {
if (guiDict && name && *name) {
data = guiDict->GetString(GetName());
}
return data.LengthWithoutColors();
}
int Length() {
if (guiDict && name && *name) {
data = guiDict->GetString(GetName());
}
return data.Length();
}
void RemoveColors() {
if (guiDict && name && *name) {
data = guiDict->GetString(GetName());
}
data.RemoveColors();
}
virtual const char *c_str() const {
return data.c_str();
}
virtual void Set(const char *val) {
data = val;
if ( guiDict ) {
guiDict->Set(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetString( s );
}
}
virtual size_t Size() {
size_t sz = idWinVar::Size();
return sz +data.Allocated();
}
// SaveGames
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
int len = data.Length();
savefile->Write( &len, sizeof( len ) );
if ( len > 0 ) {
savefile->Write( data.c_str(), len );
}
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
int len;
savefile->Read( &len, sizeof( len ) );
if ( len > 0 ) {
data.Fill( ' ', len );
savefile->Read( &data[0], len );
}
}
// return wether string is emtpy
virtual float x( void ) const { return data[0] ? 1.0f : 0.0f; };
protected:
idStr data;
};
class idWinInt : public idWinVar {
public:
idWinInt() : idWinVar() {};
~idWinInt() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetInt(GetName());
}
}
int &operator=( const int &other ) {
data = other;
if (guiDict) {
guiDict->SetInt(GetName(), data);
}
return data;
}
idWinInt &operator=( const idWinInt &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
operator int () const {
return data;
}
virtual void Set(const char *val) {
data = atoi(val);;
if (guiDict) {
guiDict->SetInt(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetInt( s );
}
}
virtual const char *c_str() const {
return va("%i", data);
}
// SaveGames
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
// no suitable conversion
virtual float x( void ) const { assert( false ); return 0.0f; };
protected:
int data;
};
class idWinFloat : public idWinVar {
public:
idWinFloat() : idWinVar() {};
~idWinFloat() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetFloat(GetName());
}
}
idWinFloat &operator=( const idWinFloat &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
float &operator=( const float &other ) {
data = other;
if (guiDict) {
guiDict->SetFloat(GetName(), data);
}
return data;
}
operator float() const {
return data;
}
virtual void Set(const char *val) {
data = atof(val);
if (guiDict) {
guiDict->SetFloat(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetFloat( s );
}
}
virtual const char *c_str() const {
return va("%f", data);
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
virtual float x( void ) const { return data; };
protected:
float data;
};
class idWinRectangle : public idWinVar {
public:
idWinRectangle() : idWinVar() {};
~idWinRectangle() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
idVec4 v = guiDict->GetVec4(GetName());
data.x = v.x;
data.y = v.y;
data.w = v.z;
data.h = v.w;
}
}
int operator==( const idRectangle &other ) const {
return (other == data);
}
idWinRectangle &operator=( const idWinRectangle &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idRectangle &operator=( const idVec4 &other ) {
data = other;
if (guiDict) {
guiDict->SetVec4(GetName(), other);
}
return data;
}
idRectangle &operator=( const idRectangle &other ) {
data = other;
if (guiDict) {
idVec4 v = data.ToVec4();
guiDict->SetVec4(GetName(), v);
}
return data;
}
operator const idRectangle&() const {
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
float w() const {
return data.w;
}
float h() const {
return data.h;
}
float Right() const {
return data.Right();
}
float Bottom() const {
return data.Bottom();
}
idVec4 &ToVec4() {
static idVec4 ret;
ret = data.ToVec4();
return ret;
}
virtual void Set(const char *val) {
if ( strchr ( val, ',' ) ) {
sscanf( val, "%f,%f,%f,%f", &data.x, &data.y, &data.w, &data.h );
} else {
sscanf( val, "%f %f %f %f", &data.x, &data.y, &data.w, &data.h );
}
if (guiDict) {
idVec4 v = data.ToVec4();
guiDict->SetVec4(GetName(), v);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
idVec4 v = guiDict->GetVec4( s );
data.x = v.x;
data.y = v.y;
data.w = v.z;
data.h = v.w;
}
}
virtual const char *c_str() const {
return data.ToVec4().ToString();
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idRectangle data;
};
class idWinVec2 : public idWinVar {
public:
idWinVec2() : idWinVar() {};
~idWinVec2() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetVec2(GetName());
}
}
int operator==( const idVec2 &other ) const {
return (other == data);
}
idWinVec2 &operator=( const idWinVec2 &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idVec2 &operator=( const idVec2 &other ) {
data = other;
if (guiDict) {
guiDict->SetVec2(GetName(), data);
}
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
virtual void Set(const char *val) {
if ( strchr ( val, ',' ) ) {
sscanf( val, "%f,%f", &data.x, &data.y );
} else {
sscanf( val, "%f %f", &data.x, &data.y);
}
if (guiDict) {
guiDict->SetVec2(GetName(), data);
}
}
operator const idVec2&() const {
return data;
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetVec2( s );
}
}
virtual const char *c_str() const {
return data.ToString();
}
void Zero() {
data.Zero();
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idVec2 data;
};
class idWinVec4 : public idWinVar {
public:
idWinVec4() : idWinVar() {};
~idWinVec4() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetVec4(GetName());
}
}
int operator==( const idVec4 &other ) const {
return (other == data);
}
idWinVec4 &operator=( const idWinVec4 &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idVec4 &operator=( const idVec4 &other ) {
data = other;
if (guiDict) {
guiDict->SetVec4(GetName(), data);
}
return data;
}
operator const idVec4&() const {
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
float z() const {
return data.z;
}
float w() const {
return data.w;
}
virtual void Set(const char *val) {
if ( strchr ( val, ',' ) ) {
sscanf( val, "%f,%f,%f,%f", &data.x, &data.y, &data.z, &data.w );
} else {
sscanf( val, "%f %f %f %f", &data.x, &data.y, &data.z, &data.w);
}
if ( guiDict ) {
guiDict->SetVec4( GetName(), data );
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetVec4( s );
}
}
virtual const char *c_str() const {
return data.ToString();
}
void Zero() {
data.Zero();
if ( guiDict ) {
guiDict->SetVec4(GetName(), data);
}
}
const idVec3 &ToVec3() const {
return data.ToVec3();
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idVec4 data;
};
class idWinVec3 : public idWinVar {
public:
idWinVec3() : idWinVar() {};
~idWinVec3() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetVector(GetName());
}
}
int operator==( const idVec3 &other ) const {
return (other == data);
}
idWinVec3 &operator=( const idWinVec3 &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idVec3 &operator=( const idVec3 &other ) {
data = other;
if (guiDict) {
guiDict->SetVector(GetName(), data);
}
return data;
}
operator const idVec3&() const {
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
float z() const {
return data.z;
}
virtual void Set(const char *val) {
sscanf( val, "%f %f %f", &data.x, &data.y, &data.z);
if (guiDict) {
guiDict->SetVector(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetVector( s );
}
}
virtual const char *c_str() const {
return data.ToString();
}
void Zero() {
data.Zero();
if (guiDict) {
guiDict->SetVector(GetName(), data);
}
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idVec3 data;
};
class idWinBackground : public idWinStr {
public:
idWinBackground() : idWinStr() {
mat = NULL;
};
~idWinBackground() {};
virtual void Init(const char *_name, idWindow *win) {
idWinStr::Init(_name, win);
if (guiDict) {
data = guiDict->GetString(GetName());
}
}
int operator==( const idStr &other ) const {
return (other == data);
}
int operator==( const char *other ) const {
return (data == other);
}
idStr &operator=( const idStr &other ) {
data = other;
if (guiDict) {
guiDict->Set(GetName(), data);
}
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
return data;
}
idWinBackground &operator=( const idWinBackground &other ) {
idWinVar::operator=(other);
data = other.data;
mat = other.mat;
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
return *this;
}
operator const char *() const {
return data.c_str();
}
operator const idStr &() const {
return data;
}
int Length() {
if (guiDict) {
data = guiDict->GetString(GetName());
}
return data.Length();
}
virtual const char *c_str() const {
return data.c_str();
}
virtual void Set(const char *val) {
data = val;
if (guiDict) {
guiDict->Set(GetName(), data);
}
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetString( s );
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
}
}
virtual size_t Size() {
size_t sz = idWinVar::Size();
return sz +data.Allocated();
}
void SetMaterialPtr( const idMaterial **m ) {
mat = m;
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
int len = data.Length();
savefile->Write( &len, sizeof( len ) );
if ( len > 0 ) {
savefile->Write( data.c_str(), len );
}
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
int len;
savefile->Read( &len, sizeof( len ) );
if ( len > 0 ) {
data.Fill( ' ', len );
savefile->Read( &data[0], len );
}
if ( mat ) {
if ( len > 0 ) {
(*mat) = declManager->FindMaterial( data );
} else {
(*mat) = NULL;
}
}
}
protected:
idStr data;
const idMaterial **mat;
};
/*
================
idMultiWinVar
multiplexes access to a list if idWinVar*
================
*/
class idMultiWinVar : public idList< idWinVar * > {
public:
void Set( const char *val );
void Update( void );
void SetGuiInfo( idDict *dict );
};
#endif /* !__WINVAR_H__ */
|