Window.h 13 KB

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