123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- /*
- ===========================================================================
- 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 "Rectangle.h"
- static const char *VAR_GUIPREFIX = "gui::";
- static const int VAR_GUIPREFIX_LEN = strlen(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__ */
|