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 "ui/UserInterface.h"
30 
31 class idWindow;
32 
33 class idUserInterfaceLocal : public idUserInterface {
34 	friend class idUserInterfaceManagerLocal;
35 public:
36 								idUserInterfaceLocal();
37 	virtual						~idUserInterfaceLocal();
38 
39 	virtual const char *		Name() const;
40 	virtual const char *		Comment() const;
41 	virtual bool				IsInteractive() const;
42 	virtual bool				InitFromFile( const char *qpath, bool rebuild = true, bool cache = true );
43 	virtual const char *		HandleEvent( const sysEvent_t *event, int time, bool *updateVisuals );
44 	virtual void				HandleNamedEvent( const char* namedEvent );
45 	virtual void				Redraw( int time );
46 	virtual void				DrawCursor();
47 	virtual const idDict &		State() const;
48 	virtual void				DeleteStateVar( const char *varName );
49 	virtual void				SetStateString( const char *varName, const char *value );
50 	virtual void				SetStateBool( const char *varName, const bool value );
51 	virtual void				SetStateInt( const char *varName, const int value );
52 	virtual void				SetStateFloat( const char *varName, const float value );
53 
54 	// Gets a gui state variable
55 	virtual const char*			GetStateString( const char *varName, const char* defaultString = "" ) const;
56 	virtual bool				GetStateBool( const char *varName, const char* defaultString = "0" ) const;
57 	virtual int					GetStateInt( const char *varName, const char* defaultString = "0" ) const;
58 	virtual float				GetStateFloat( const char *varName, const char* defaultString = "0" ) const;
59 
60 	virtual void				StateChanged( int time, bool redraw );
61 	virtual const char *		Activate( bool activate, int time );
62 	virtual void				Trigger( int time );
63 	virtual void				ReadFromDemoFile( class idDemoFile *f );
64 	virtual void				WriteToDemoFile( class idDemoFile *f );
65 	virtual bool				WriteToSaveGame( idFile *savefile ) const;
66 	virtual bool				ReadFromSaveGame( idFile *savefile );
67 	virtual void				SetKeyBindingNames( void );
IsUniqued()68 	virtual bool				IsUniqued() const { return uniqued; };
SetUniqued(bool b)69 	virtual void				SetUniqued( bool b ) { uniqued = b; };
70 	virtual void				SetCursor( float x, float y );
71 
CursorX()72 	virtual float				CursorX() { return cursorX; }
CursorY()73 	virtual float				CursorY() { return cursorY; }
74 
75 	size_t						Size();
76 
GetStateDict()77 	idDict *					GetStateDict() { return &state; }
78 
GetSourceFile(void)79 	const char *				GetSourceFile( void ) const { return source; }
GetTimeStamp(void)80 	ID_TIME_T						GetTimeStamp( void ) const { return timeStamp; }
81 
GetDesktop()82 	idWindow *					GetDesktop() const { return desktop; }
SetBindHandler(idWindow * win)83 	void						SetBindHandler( idWindow *win ) { bindHandler = win; }
Active()84 	bool						Active() const { return active; }
GetTime()85 	int							GetTime() const { return time; }
SetTime(int _time)86 	void						SetTime( int _time ) { time = _time; }
87 
ClearRefs()88 	void						ClearRefs() { refs = 0; }
AddRef()89 	void						AddRef() { refs++; }
GetRefs()90 	int							GetRefs() { return refs; }
91 
92 	void						RecurseSetKeyBindingNames( idWindow *window );
GetPendingCmd()93 	idStr						&GetPendingCmd() { return pendingCmd; };
GetReturnCmd()94 	idStr						&GetReturnCmd() { return returnCmd; };
95 
96 private:
97 	bool						active;
98 	bool						loading;
99 	bool						interactive;
100 	bool						uniqued;
101 
102 	idDict						state;
103 	idWindow *					desktop;
104 	idWindow *					bindHandler;
105 
106 	idStr						source;
107 	idStr						activateStr;
108 	idStr						pendingCmd;
109 	idStr						returnCmd;
110 	ID_TIME_T						timeStamp;
111 
112 	float						cursorX;
113 	float						cursorY;
114 
115 	int							time;
116 
117 	int							refs;
118 };
119 
120 class idUserInterfaceManagerLocal : public idUserInterfaceManager {
121 	friend class idUserInterfaceLocal;
122 
123 public:
124 	virtual void				Init();
125 	virtual void				Shutdown();
126 	virtual void				Touch( const char *name );
127 	virtual void				WritePrecacheCommands( idFile *f );
128 	virtual void				SetSize( float width, float height );
129 	virtual void				BeginLevelLoad();
130 	virtual void				EndLevelLoad();
131 	virtual void				Reload( bool all );
132 	virtual void				ListGuis() const;
133 	virtual bool				CheckGui( const char *qpath ) const;
134 	virtual idUserInterface *	Alloc( void ) const;
135 	virtual void				DeAlloc( idUserInterface *gui );
136 	virtual idUserInterface *	FindGui( const char *qpath, bool autoLoad = false, bool needInteractive = false, bool forceUnique = false );
137 	virtual idUserInterface *	FindDemoGui( const char *qpath );
138 	virtual	idListGUI *			AllocListGUI( void ) const;
139 	virtual void				FreeListGUI( idListGUI *listgui );
140 
141 private:
142 	idRectangle					screenRect;
143 	idDeviceContext				dc;
144 
145 	idList<idUserInterfaceLocal*> guis;
146 	idList<idUserInterfaceLocal*> demoGuis;
147 
148 };
149