DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Window.h (13510B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition 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 BFG Edition 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 #ifndef __WINDOW_H__
     30 #define __WINDOW_H__
     31 
     32 #include "Rectangle.h"
     33 #include "DeviceContext.h"
     34 #include "RegExp.h"
     35 #include "Winvar.h"
     36 #include "GuiScript.h"
     37 #include "SimpleWindow.h"
     38 
     39 const int WIN_CHILD			= 0x00000001;
     40 const int WIN_CAPTION		= 0x00000002;
     41 const int WIN_BORDER		= 0x00000004;
     42 const int WIN_SIZABLE		= 0x00000008;
     43 const int WIN_MOVABLE		= 0x00000010;
     44 const int WIN_FOCUS			= 0x00000020;
     45 const int WIN_CAPTURE		= 0x00000040;
     46 const int WIN_HCENTER		= 0x00000080;
     47 const int WIN_VCENTER		= 0x00000100;
     48 const int WIN_MODAL			= 0x00000200;
     49 const int WIN_INTRANSITION	= 0x00000400;
     50 const int WIN_CANFOCUS		= 0x00000800;
     51 const int WIN_SELECTED		= 0x00001000;
     52 const int WIN_TRANSFORM		= 0x00002000;
     53 const int WIN_HOLDCAPTURE	= 0x00004000;
     54 const int WIN_NOWRAP		= 0x00008000;
     55 const int WIN_NOCLIP		= 0x00010000;
     56 const int WIN_INVERTRECT	= 0x00020000;
     57 const int WIN_NATURALMAT	= 0x00040000;
     58 const int WIN_NOCURSOR		= 0x00080000;
     59 const int WIN_MENUGUI		= 0x00100000;
     60 const int WIN_ACTIVE		= 0x00200000;
     61 const int WIN_SHOWCOORDS	= 0x00400000;
     62 const int WIN_SHOWTIME		= 0x00800000;
     63 const int WIN_WANTENTER		= 0x01000000;
     64 
     65 const int WIN_DESKTOP		= 0x10000000;
     66 
     67 const char CAPTION_HEIGHT[] = "16.0";
     68 const char SCROLLER_SIZE[] = "16.0";
     69 const int SCROLLBAR_SIZE = 16;
     70 
     71 const int MAX_WINDOW_NAME = 32;
     72 const int MAX_LIST_ITEMS = 1024;
     73 
     74 const char DEFAULT_BACKCOLOR[] = "1 1 1 1";
     75 const char DEFAULT_FORECOLOR[] = "0 0 0 1";
     76 const char DEFAULT_BORDERCOLOR[] = "0 0 0 1";
     77 const char DEFAULT_TEXTSCALE[] = "0.4";
     78 
     79 typedef enum {
     80 	WOP_TYPE_ADD,
     81 	WOP_TYPE_SUBTRACT,
     82 	WOP_TYPE_MULTIPLY,
     83 	WOP_TYPE_DIVIDE,
     84 	WOP_TYPE_MOD,
     85 	WOP_TYPE_TABLE,
     86 	WOP_TYPE_GT,
     87 	WOP_TYPE_GE,
     88 	WOP_TYPE_LT,
     89 	WOP_TYPE_LE,
     90 	WOP_TYPE_EQ,
     91 	WOP_TYPE_NE,
     92 	WOP_TYPE_AND,
     93 	WOP_TYPE_OR,
     94 	WOP_TYPE_VAR,
     95 	WOP_TYPE_VARS,
     96 	WOP_TYPE_VARF,
     97 	WOP_TYPE_VARI,
     98 	WOP_TYPE_VARB,
     99 	WOP_TYPE_COND
    100 } wexpOpType_t;
    101 
    102 typedef enum {
    103 	WEXP_REG_TIME,
    104 	WEXP_REG_NUM_PREDEFINED
    105 } wexpRegister_t;
    106 
    107 typedef struct {
    108 	wexpOpType_t opType;	
    109 	int	a, b, c, d;
    110 } wexpOp_t;
    111 
    112 struct idRegEntry {
    113 	const char *name;
    114 	idRegister::REGTYPE type;
    115 	int index;
    116 };
    117 
    118 
    119 class rvGEWindowWrapper;
    120 class idWindow;
    121 
    122 struct idTimeLineEvent {
    123 	idTimeLineEvent() {
    124 		event = new (TAG_OLD_UI) idGuiScriptList;
    125 	}
    126 	~idTimeLineEvent() {
    127 		delete event;
    128 	}
    129 	int time;
    130 	idGuiScriptList *event;
    131 	bool pending;
    132 	size_t Size() {
    133 		return sizeof(*this) + event->Size();
    134 	}
    135 };
    136 
    137 class rvNamedEvent
    138 {
    139 public:
    140 
    141 	rvNamedEvent(const char* name)
    142 	{
    143 		mEvent = new (TAG_OLD_UI) idGuiScriptList;
    144 		mName  = name;
    145 	}
    146 	~rvNamedEvent()
    147 	{
    148 		delete mEvent;
    149 	}
    150 	size_t Size() 
    151 	{
    152 		return sizeof(*this) + mEvent->Size();
    153 	}
    154 	
    155 	idStr				mName;
    156 	idGuiScriptList*	mEvent;
    157 };
    158 
    159 struct idTransitionData {
    160 	idWinVar *data;
    161 	int	offset;
    162 	idInterpolateAccelDecelLinear<idVec4> interp;
    163 };
    164 
    165 
    166 class idUserInterfaceLocal;
    167 class idWindow {
    168 public:
    169 	idWindow(idUserInterfaceLocal *gui);
    170 	virtual ~idWindow();
    171 
    172 	enum {
    173 		ON_MOUSEENTER = 0,
    174 		ON_MOUSEEXIT,
    175 		ON_ACTION,
    176 		ON_ACTIVATE,
    177 		ON_DEACTIVATE,
    178 		ON_ESC,
    179 		ON_FRAME,
    180 		ON_TRIGGER,
    181 		ON_ACTIONRELEASE,
    182 		ON_ENTER,
    183 		ON_ENTERRELEASE,
    184 		SCRIPT_COUNT
    185 	};
    186 
    187 	enum {
    188 		ADJUST_MOVE = 0,
    189 		ADJUST_TOP,
    190 		ADJUST_RIGHT,
    191 		ADJUST_BOTTOM,
    192 		ADJUST_LEFT,
    193 		ADJUST_TOPLEFT,
    194 		ADJUST_BOTTOMRIGHT,
    195 		ADJUST_TOPRIGHT,
    196 		ADJUST_BOTTOMLEFT
    197 	};
    198 
    199 	static const char *ScriptNames[SCRIPT_COUNT];
    200 
    201 	static const idRegEntry RegisterVars[];
    202 	static const int		NumRegisterVars;
    203 
    204 	idWindow *SetFocus(idWindow *w, bool scripts = true);
    205 
    206 	idWindow *SetCapture(idWindow *w);
    207 	void SetParent(idWindow *w);
    208 	void SetFlag(unsigned int f);
    209 	void ClearFlag(unsigned int f);
    210 	unsigned GetFlags() {return flags;};
    211 	void Move(float x, float y);
    212 	void BringToTop(idWindow *w);
    213 	void Adjust(float xd, float yd);
    214 	void SetAdjustMode(idWindow *child);
    215 	void Size(float x, float y, float w, float h);
    216 	void SetupFromState();
    217 	void SetupBackground();
    218 	drawWin_t *FindChildByName(const char *name);
    219 	idSimpleWindow *FindSimpleWinByName(const char *_name);
    220 	idWindow *GetParent() { return parent; }
    221 	idUserInterfaceLocal *GetGui() {return gui;};
    222 	bool Contains(float x, float y);
    223 	size_t Size();
    224 	virtual size_t Allocated();
    225 	idStr* GetStrPtrByName(const char *_name);
    226 
    227 	virtual idWinVar *GetWinVarByName	(const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
    228 
    229 	int  GetWinVarOffset( idWinVar *wv, drawWin_t *dw );
    230 	float GetMaxCharHeight();
    231 	float GetMaxCharWidth();
    232 	void SetFont();
    233 	void SetInitialState(const char *_name);
    234 	void AddChild(idWindow *win);
    235 	void DebugDraw(int time, float x, float y);
    236 	void CalcClientRect(float xofs, float yofs);
    237 	void CommonInit();
    238 	void CleanUp();
    239 	void DrawBorderAndCaption(const idRectangle &drawRect);
    240 	void DrawCaption(int time, float x, float y);
    241 	void SetupTransforms(float x, float y);
    242 	bool Contains(const idRectangle &sr, float x, float y);
    243 	const char *GetName() { return name; };
    244 
    245 	virtual bool Parse( idTokenParser *src, bool rebuild = true);
    246 	virtual const char *HandleEvent(const sysEvent_t *event, bool *updateVisuals);
    247 	void	CalcRects(float x, float y);
    248 	virtual void Redraw(float x, float y, bool hud);
    249 
    250 	virtual void ArchiveToDictionary(idDict *dict, bool useNames = true);
    251 	virtual void InitFromDictionary(idDict *dict, bool byName = true);
    252 	virtual void PostParse();
    253 	virtual void Activate( bool activate, idStr &act );
    254 	virtual void Trigger();
    255 	virtual void GainFocus();
    256 	virtual void LoseFocus();
    257 	virtual void GainCapture();
    258 	virtual void LoseCapture();
    259 	virtual void Sized();
    260 	virtual void Moved();
    261 	virtual void Draw(int time, float x, float y);
    262 	virtual void MouseExit();
    263 	virtual void MouseEnter();
    264 	virtual void DrawBackground(const idRectangle &drawRect);
    265 	virtual idWindow * GetChildWithOnAction( float xd, float yd );
    266 	virtual const char *RouteMouseCoords(float xd, float yd);
    267 	virtual void SetBuddy(idWindow *buddy) {};
    268 	virtual void HandleBuddyUpdate(idWindow *buddy) {};
    269 	virtual void StateChanged( bool redraw );
    270 	virtual void ReadFromDemoFile( class idDemoFile *f, bool rebuild = true );
    271 	virtual void WriteToDemoFile( class idDemoFile *f );
    272 
    273 	// SaveGame support
    274 	void			WriteSaveGameString( const char *string, idFile *savefile );
    275 	void			WriteSaveGameTransition( idTransitionData &trans, idFile *savefile );
    276 	virtual void	WriteToSaveGame( idFile *savefile );
    277 	void			ReadSaveGameString( idStr &string, idFile *savefile );
    278 	void			ReadSaveGameTransition( idTransitionData & trans, idFile *savefile );
    279 	virtual void	ReadFromSaveGame( idFile *savefile );
    280 	void			FixupTransitions();
    281 	virtual void HasAction(){};
    282 	virtual void HasScripts(){};
    283 
    284 	void FixupParms();
    285 	void GetScriptString(const char *name, idStr &out);
    286 	void SetScriptParams();
    287 	bool HasOps() {	return (ops.Num() > 0); };
    288 	float EvalRegs(int test = -1, bool force = false);
    289 	void StartTransition();
    290 	void AddTransition(idWinVar *dest, idVec4 from, idVec4 to, int time, float accelTime, float decelTime);
    291 	void ResetTime(int time);
    292 	void ResetCinematics();
    293 
    294 	int NumTransitions();
    295 
    296 	bool ParseScript(idTokenParser *src, idGuiScriptList &list, int *timeParm = NULL, bool allowIf = false);
    297 	bool RunScript(int n);
    298 	bool RunScriptList(idGuiScriptList *src);
    299 	void SetRegs(const char *key, const char *val);
    300 	int ParseExpression( idTokenParser *src, idWinVar *var = NULL, int component = 0 );
    301 	int ExpressionConstant(float f);
    302 	idRegisterList *RegList() { return &regList; }
    303 	void AddCommand(const char *cmd);
    304 	void AddUpdateVar(idWinVar *var);
    305 	bool Interactive();
    306 	bool ContainsStateVars();
    307 	void SetChildWinVarVal(const char *name, const char *var, const char *val);
    308 	idWindow *GetFocusedChild();
    309 	idWindow *GetCaptureChild();
    310 	const char *GetComment() { return comment;  }
    311 	void SetComment( const char * p) { comment = p; }
    312 
    313 	idStr cmd;
    314 
    315 	virtual void RunNamedEvent		( const char* eventName );
    316 
    317 	void		AddDefinedVar		( idWinVar* var );
    318 
    319 	idWindow*	FindChildByPoint	( float x, float y, idWindow* below = NULL );
    320 	int			GetChildIndex		( idWindow* window );
    321 	int			GetChildCount		();
    322 	idWindow*	GetChild			( int index );
    323 	void		RemoveChild			( idWindow *win );
    324 	bool		InsertChild			( idWindow *win, idWindow* before );
    325 
    326 	void		ScreenToClient		( idRectangle* rect );
    327 	void		ClientToScreen		( idRectangle* rect );
    328 
    329 	bool		UpdateFromDictionary ( idDict& dict );
    330 
    331 protected:
    332 
    333 	friend		class rvGEWindowWrapper;
    334 
    335 	idWindow*	FindChildByPoint	( float x, float y, idWindow** below );
    336 	void		SetDefaults			();
    337 
    338 	friend class idSimpleWindow;
    339 	friend class idUserInterfaceLocal;
    340 	bool IsSimple();
    341 	void UpdateWinVars();
    342 	void DisableRegister(const char *_name);
    343 	void Transition();
    344 	void Time();
    345 	bool RunTimeEvents(int time);
    346 	void Dump();
    347 
    348 	int ExpressionTemporary();
    349 	wexpOp_t *ExpressionOp();
    350 	int EmitOp( int a, int b, wexpOpType_t opType, wexpOp_t **opp = NULL );
    351 	int ParseEmitOp( idTokenParser *src, int a, wexpOpType_t opType, int priority, wexpOp_t **opp = NULL );
    352 	int ParseTerm( idTokenParser *src, idWinVar *var = NULL, int component = 0 );
    353 	int ParseExpressionPriority( idTokenParser *src, int priority, idWinVar *var = NULL, int component = 0 );
    354 	void EvaluateRegisters(float *registers);
    355 	void SaveExpressionParseState();
    356 	void RestoreExpressionParseState();
    357 	void ParseBracedExpression(idTokenParser *src);
    358 	bool ParseScriptEntry(const char *name, idTokenParser *src);
    359 	bool ParseRegEntry(const char *name, idTokenParser *src);
    360 	virtual bool ParseInternalVar(const char *name, idTokenParser *src);
    361 	void ParseString(idTokenParser *src, idStr &out);
    362 	void ParseVec4(idTokenParser *src, idVec4 &out);
    363 	void ConvertRegEntry(const char *name, idTokenParser *src, idStr &out, int tabs);
    364 
    365 	float actualX;					// physical coords
    366 	float actualY;					// ''
    367 	int	  childID;					// this childs id
    368 	unsigned int flags;             // visible, focus, mouseover, cursor, border, etc.. 
    369 	int lastTimeRun;				//
    370 	idRectangle drawRect;			// overall rect
    371 	idRectangle clientRect;			// client area
    372 	idVec2	origin;
    373 
    374 	int timeLine;					// time stamp used for various fx
    375 	float xOffset;			
    376 	float yOffset;
    377 	float forceAspectWidth;
    378 	float forceAspectHeight;
    379 	float matScalex;
    380 	float matScaley;
    381 	float borderSize;
    382 	float textAlignx;
    383 	float textAligny;
    384 	idStr	name;
    385 	idStr	comment;
    386 	idVec2	shear;
    387 
    388 	class idFont * font;
    389 	signed char	textShadow;
    390 	unsigned char cursor;					//
    391 	signed char	textAlign;
    392 
    393 	idWinBool	noTime;					// 
    394 	idWinBool	visible;				// 
    395 	idWinBool	noEvents;
    396 	idWinRectangle rect;				// overall rect
    397 	idWinVec4	backColor;
    398 	idWinVec4	matColor;
    399 	idWinVec4	foreColor;
    400 	idWinVec4	hoverColor;
    401 	idWinVec4	borderColor;
    402 	idWinFloat	textScale;
    403 	idWinFloat	rotate;
    404 	idWinStr	text;
    405 	idWinBackground	backGroundName;			// 
    406 
    407 	idList<idWinVar*, TAG_OLD_UI> definedVars;
    408 	idList<idWinVar*, TAG_OLD_UI> updateVars;
    409 
    410 	idRectangle textRect;			// text extented rect
    411 	const idMaterial *background;         // background asset  
    412 
    413 	idWindow *parent;				// parent window
    414 	idList<idWindow*, TAG_OLD_UI> children;		// child windows	
    415 	idList<drawWin_t, TAG_OLD_UI> drawWindows;		
    416 
    417 	idWindow *focusedChild;			// if a child window has the focus
    418 	idWindow *captureChild;			// if a child window has mouse capture
    419 	idWindow *overChild;			// if a child window has mouse capture
    420 	bool hover;
    421 
    422 	idUserInterfaceLocal *gui;
    423 
    424 	static idCVar gui_debug;
    425 	static idCVar gui_edit;
    426 
    427 	idGuiScriptList *scripts[SCRIPT_COUNT];
    428 	bool *saveTemps;
    429 
    430 	idList<idTimeLineEvent*, TAG_OLD_UI> timeLineEvents;
    431 	idList<idTransitionData, TAG_OLD_UI> transitions;
    432 
    433 	static bool registerIsTemporary[MAX_EXPRESSION_REGISTERS]; // statics to assist during parsing
    434 
    435 	idList<wexpOp_t, TAG_OLD_UI> ops;			   	// evaluate to make expressionRegisters
    436 	idList<float, TAG_OLD_UI> expressionRegisters;
    437 	idList<wexpOp_t, TAG_OLD_UI> *saveOps;			   	// evaluate to make expressionRegisters
    438 	idList<rvNamedEvent*, TAG_OLD_UI>		namedEvents;		//  added named events
    439 	idList<float, TAG_OLD_UI> *saveRegs;
    440 
    441 	idRegisterList regList;
    442 
    443 	idWinBool	hideCursor;
    444 };
    445 
    446 ID_INLINE void idWindow::AddDefinedVar( idWinVar* var ) {
    447 	definedVars.AddUnique( var );
    448 }
    449 
    450 #endif /* !__WINDOW_H__ */