GameWindowManager.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: GameWindowManager.h //////////////////////////////////////////////////////////////////////
  24. // Created: Colin Day, June 2001
  25. // Desc: The game window manager is the interface for interacting with
  26. // the windowing system for purposes of any menus, or GUI
  27. // controls.
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. #pragma once
  30. #ifndef __GAMEWINDOWMANAGER_H_
  31. #define __GAMEWINDOWMANAGER_H_
  32. #include "Common/STLTypedefs.h"
  33. #include "Common/SubsystemInterface.h"
  34. #include "GameClient/WindowLayout.h"
  35. #include "GameClient/KeyDefs.h"
  36. #include "GameClient/Gadget.h"
  37. class GameWindow;
  38. //-------------------------------------------------------------------------------------------------
  39. /** Window layout info is a structure that can be passed to the load function of
  40. * a window script. After the script is loaded, this parameter (if present)
  41. * will contain information about the script file at a global level such
  42. * as what file version was loaded, global layout callbacks, etc */
  43. //-------------------------------------------------------------------------------------------------
  44. enum { MAX_LAYOUT_FUNC_LEN = 256 };
  45. typedef std::list <GameWindow *> GameWindowList;
  46. class WindowLayoutInfo
  47. {
  48. public:
  49. WindowLayoutInfo();
  50. UnsignedInt version; ///< file version that was loaded
  51. WindowLayoutInitFunc init; ///< init method (if specified)
  52. WindowLayoutUpdateFunc update; ///< update method (if specified)
  53. WindowLayoutShutdownFunc shutdown; ///< shutdown method (if specified)
  54. AsciiString initNameString; ///< init method in flavor of string name
  55. AsciiString updateNameString; ///< update method in string flavor
  56. AsciiString shutdownNameString; ///< shutdown method in string flavor, mmm!
  57. std::list<GameWindow *> windows; ///< list of top-level windows in the layout
  58. };
  59. //-------------------------------------------------------------------------------------------------
  60. /** There exists a singleton GameWindowManager that defines how we can
  61. * interact with the game windowing system */
  62. //-------------------------------------------------------------------------------------------------
  63. class GameWindowManager : public SubsystemInterface
  64. {
  65. friend class GameWindow;
  66. public:
  67. GameWindowManager( void );
  68. virtual ~GameWindowManager( void );
  69. //-----------------------------------------------------------------------------------------------
  70. virtual void init( void ); ///< initialize function
  71. virtual void reset( void ); ///< reset the system
  72. virtual void update( void ); ///< update method, called once per frame
  73. virtual GameWindow *allocateNewWindow( void ) = 0; ///< new game window
  74. void linkWindow( GameWindow *window ); ///< link into master list
  75. void unlinkWindow( GameWindow *window ); ///< unlink from master list
  76. void unlinkChildWindow( GameWindow *window ); ///< remove child from parent list
  77. void insertWindowAheadOf( GameWindow *window, GameWindow *aheadOf ); ///< add window to list 'ahead of'
  78. virtual GameWinDrawFunc getPushButtonImageDrawFunc( void ) = 0;
  79. virtual GameWinDrawFunc getPushButtonDrawFunc( void ) = 0;
  80. virtual GameWinDrawFunc getCheckBoxImageDrawFunc( void ) = 0;
  81. virtual GameWinDrawFunc getCheckBoxDrawFunc( void ) = 0;
  82. virtual GameWinDrawFunc getRadioButtonImageDrawFunc( void ) = 0;
  83. virtual GameWinDrawFunc getRadioButtonDrawFunc( void ) = 0;
  84. virtual GameWinDrawFunc getTabControlImageDrawFunc( void ) = 0;
  85. virtual GameWinDrawFunc getTabControlDrawFunc( void ) = 0;
  86. virtual GameWinDrawFunc getListBoxImageDrawFunc( void ) = 0;
  87. virtual GameWinDrawFunc getListBoxDrawFunc( void ) = 0;
  88. virtual GameWinDrawFunc getComboBoxImageDrawFunc( void ) = 0;
  89. virtual GameWinDrawFunc getComboBoxDrawFunc( void ) = 0;
  90. virtual GameWinDrawFunc getHorizontalSliderImageDrawFunc( void ) = 0;
  91. virtual GameWinDrawFunc getHorizontalSliderDrawFunc( void ) = 0;
  92. virtual GameWinDrawFunc getVerticalSliderImageDrawFunc( void ) = 0;
  93. virtual GameWinDrawFunc getVerticalSliderDrawFunc( void ) = 0;
  94. virtual GameWinDrawFunc getProgressBarImageDrawFunc( void ) = 0;
  95. virtual GameWinDrawFunc getProgressBarDrawFunc( void ) = 0;
  96. virtual GameWinDrawFunc getStaticTextImageDrawFunc( void ) = 0;
  97. virtual GameWinDrawFunc getStaticTextDrawFunc( void ) = 0;
  98. virtual GameWinDrawFunc getTextEntryImageDrawFunc( void ) = 0;
  99. virtual GameWinDrawFunc getTextEntryDrawFunc( void ) = 0;
  100. //---------------------------------------------------------------------------
  101. virtual GameWinDrawFunc getDefaultDraw( void ); ///< return default draw func
  102. virtual GameWinSystemFunc getDefaultSystem( void ); ///< return default system func
  103. virtual GameWinInputFunc getDefaultInput( void ); ///< return default input func
  104. virtual GameWinTooltipFunc getDefaultTooltip( void ); ///< return default tooltip func
  105. //---------------------------------------------------------------------------
  106. // MessageBox creation
  107. virtual GameWindow *gogoMessageBox(Int x, Int y, Int width, Int height, UnsignedShort buttonFlags,
  108. UnicodeString titleString, UnicodeString bodyString,
  109. GameWinMsgBoxFunc yesCallback,
  110. GameWinMsgBoxFunc noCallback,
  111. GameWinMsgBoxFunc okCallback,
  112. GameWinMsgBoxFunc cancelCallback );
  113. virtual GameWindow *gogoMessageBox(Int x, Int y, Int width, Int height, UnsignedShort buttonFlags,
  114. UnicodeString titleString, UnicodeString bodyString,
  115. GameWinMsgBoxFunc yesCallback,
  116. GameWinMsgBoxFunc noCallback,
  117. GameWinMsgBoxFunc okCallback,
  118. GameWinMsgBoxFunc cancelCallback, Bool useLogo );
  119. //---------------------------------------------------------------------------
  120. // gadget creation
  121. virtual GameWindow *gogoGadgetPushButton( GameWindow *parent, UnsignedInt status,
  122. Int x, Int y, Int width, Int height,
  123. WinInstanceData *instData,
  124. GameFont *defaultFont, Bool defaultVisual );
  125. virtual GameWindow *gogoGadgetCheckbox( GameWindow *parent, UnsignedInt status,
  126. Int x, Int y, Int width, Int height,
  127. WinInstanceData *instData,
  128. GameFont *defaultFont, Bool defaultVisual );
  129. virtual GameWindow *gogoGadgetRadioButton( GameWindow *parent, UnsignedInt status,
  130. Int x, Int y, Int width, Int height,
  131. WinInstanceData *instData,
  132. RadioButtonData *rData,
  133. GameFont *defaultFont, Bool defaultVisual );
  134. virtual GameWindow *gogoGadgetTabControl( GameWindow *parent, UnsignedInt status,
  135. Int x, Int y, Int width, Int height,
  136. WinInstanceData *instData,
  137. TabControlData *rData,
  138. GameFont *defaultFont, Bool defaultVisual );
  139. virtual GameWindow *gogoGadgetListBox( GameWindow *parent, UnsignedInt status,
  140. Int x, Int y, Int width, Int height,
  141. WinInstanceData *instData,
  142. ListboxData *listboxData,
  143. GameFont *defaultFont, Bool defaultVisual );
  144. virtual GameWindow *gogoGadgetSlider( GameWindow *parent, UnsignedInt status,
  145. Int x, Int y, Int width, Int height,
  146. WinInstanceData *instData,
  147. SliderData *sliderData,
  148. GameFont *defaultFont, Bool defaultVisual );
  149. virtual GameWindow *gogoGadgetProgressBar( GameWindow *parent, UnsignedInt status,
  150. Int x, Int y, Int width, Int height,
  151. WinInstanceData *instData,
  152. GameFont *defaultFont, Bool defaultVisual );
  153. virtual GameWindow *gogoGadgetStaticText( GameWindow *parent, UnsignedInt status,
  154. Int x, Int y, Int width, Int height,
  155. WinInstanceData *instData,
  156. TextData *textData,
  157. GameFont *defaultFont, Bool defaultVisual );
  158. virtual GameWindow *gogoGadgetTextEntry( GameWindow *parent, UnsignedInt status,
  159. Int x, Int y, Int width, Int height,
  160. WinInstanceData *instData,
  161. EntryData *entryData,
  162. GameFont *defaultFont, Bool defaultVisual );
  163. virtual GameWindow *gogoGadgetComboBox( GameWindow *parent, UnsignedInt status,
  164. Int x, Int y, Int width, Int height,
  165. WinInstanceData *instData,
  166. ComboBoxData *comboBoxDataTemplate,
  167. GameFont *defaultFont, Bool defaultVisual );
  168. /** Use this method to assign the default images to gadgets as
  169. * they area created */
  170. virtual void assignDefaultGadgetLook( GameWindow *gadget,
  171. GameFont *defaultFont,
  172. Bool assignVisual );
  173. //---------------------------------------------------------------------------
  174. // Creating windows
  175. /// create new window(s) from .wnd file ... see definition for what is returned
  176. virtual GameWindow *winCreateFromScript( AsciiString filename, WindowLayoutInfo *info = NULL );
  177. /// create new window(s) from .wnd file and wrap in a WindowLayout
  178. virtual WindowLayout *winCreateLayout( AsciiString filename );
  179. /// free temporary strings to make the memory leak manager happy.
  180. virtual void freeStaticStrings(void);
  181. /// create a new window by setting up parameters and callbacks
  182. virtual GameWindow *winCreate( GameWindow *parent, UnsignedInt status,
  183. Int x, Int y, Int width, Int height,
  184. GameWinSystemFunc system,
  185. WinInstanceData *instData = NULL );
  186. //---------------------------------------------------------------------------
  187. // Manipulating windows in the system
  188. virtual Int winDestroy( GameWindow *window ); ///< destroy this window
  189. virtual Int winDestroyAll( void ); ///< destroy all windows in the system
  190. virtual GameWindow *winGetWindowList( void ); ///< get head of master list
  191. /// hide all windows in a certain range of id's (inclusinve );
  192. virtual void hideWindowsInRange( GameWindow *baseWindow, Int first, Int last,
  193. Bool hideFlag );
  194. /// enable all windows in a range of id's (inclusive)
  195. virtual void enableWindowsInRange( GameWindow *baseWindow, Int first, Int last,
  196. Bool enableFlag );
  197. /// this gets called from winHide() when a window hides itself
  198. virtual void windowHiding( GameWindow *window );
  199. virtual void winRepaint( void ); ///< draw GUI in reverse order
  200. virtual void winNextTab( GameWindow *window ); ///< give keyboard focus to the next window in the tab list
  201. virtual void winPrevTab( GameWindow *window ); ///< give keyboard focus to the previous window in the tab list
  202. virtual void registerTabList( GameWindowList tabList ); ///< we have to register a Tab List
  203. virtual void clearTabList( void ); ///< we's gotz ta clear the tab list yo!
  204. // --------------------------------------------------------------------------
  205. /// process a single mouse event
  206. virtual WinInputReturnCode winProcessMouseEvent( GameWindowMessage msg,
  207. ICoord2D *mousePos,
  208. void *data );
  209. /// process a singke key event
  210. virtual WinInputReturnCode winProcessKey( UnsignedByte key,
  211. UnsignedByte state );
  212. // --------------------------------------------------------------------------
  213. virtual GameWindow *winGetFocus( void ); ///< return window that has the focus
  214. virtual Int winSetFocus( GameWindow *window ); ///< set this window as has focus
  215. virtual void winSetGrabWindow( GameWindow *window ); ///< set the grab window
  216. virtual GameWindow *winGetGrabWindow( void ); ///< who is currently 'held' by mouse
  217. virtual void winSetLoneWindow( GameWindow *window ); ///< set the open window
  218. virtual Bool isEnabled( GameWindow *win ); ///< is window or parents enabled
  219. virtual Bool isHidden( GameWindow *win ); ///< is parent or parents hidden
  220. virtual void addWindowToParent( GameWindow *window, GameWindow *parent );
  221. virtual void addWindowToParentAtEnd( GameWindow *window, GameWindow *parent );
  222. /// sends a system message to specified window
  223. virtual WindowMsgHandledType winSendSystemMsg( GameWindow *window, UnsignedInt msg,
  224. WindowMsgData mData1, WindowMsgData mData2 );
  225. /// sends an input message to the specified window
  226. virtual WindowMsgHandledType winSendInputMsg( GameWindow *window, UnsignedInt msg,
  227. WindowMsgData mData1, WindowMsgData mData2 );
  228. /** get the window pointer from id, starting at 'window' and searching
  229. down the heirarchy. If 'window' is NULL then all windows will
  230. be searched */
  231. virtual GameWindow *winGetWindowFromId( GameWindow *window, Int id );
  232. virtual Int winCapture( GameWindow *window ); ///< captures the mouse
  233. virtual Int winRelease( GameWindow *window ); ///< release mouse capture
  234. virtual GameWindow *winGetCapture( void ); ///< current mouse capture settings
  235. virtual Int winSetModal( GameWindow *window ); ///< put at top of modal stack
  236. virtual Int winUnsetModal( GameWindow *window ); /**< take window off modal stack, if window is
  237. not at top of stack and error will occur */
  238. //---------------------------------------------------------------------------
  239. /////////////////////////////////////////////////////////////////////////////
  240. //---------------------------------------------------------------------------
  241. //---------------------------------------------------------------------------
  242. // The following public functions you should implement change the guts
  243. // for to work with your application. Rather than draw images, or do string
  244. // operations with native methods, the game window system will always call
  245. // these methods to get the work done it needs
  246. //---------------------------------------------------------------------------
  247. //---------------------------------------------------------------------------
  248. /////////////////////////////////////////////////////////////////////////////
  249. //---------------------------------------------------------------------------
  250. /// draw image, coord are in screen and should be kepth within that box specified
  251. virtual void winDrawImage( const Image *image, Int startX, Int startY, Int endX, Int endY, Color color = 0xFFFFFFFF );
  252. /// draw filled rect, coords are absolute screen coords
  253. virtual void winFillRect( Color color, Real width, Int startX, Int startY, Int endX, Int endY );
  254. /// draw rect outline, coords are absolute screen coords
  255. virtual void winOpenRect( Color color, Real width, Int startX, Int startY, Int endX, Int endY );
  256. /// draw line, coords are absolute screen coords
  257. virtual void winDrawLine( Color color, Real width, Int startX, Int startY, Int endX, Int endY );
  258. /// Make a color representation out of RGBA components
  259. virtual Color winMakeColor( UnsignedByte red, UnsignedByte green, UnsignedByte blue, UnsignedByte alpha );
  260. /** Find an image reference and return a pointer to its image, you may
  261. recreate all Image structs to suit your project */
  262. virtual const Image *winFindImage( const char *name );
  263. virtual Int winFontHeight( GameFont *font ); ///< get height of font in pixels
  264. virtual Int winIsDigit( Int c ); ///< is character a digit
  265. virtual Int winIsAscii( Int c ); ///< is character a digit
  266. virtual Int winIsAlNum( Int c ); ///< is character alpha-numeric
  267. virtual void winFormatText( GameFont *font, UnicodeString text, Color color,
  268. Int x, Int y, Int width, Int height );
  269. virtual void winGetTextSize( GameFont *font, UnicodeString text,
  270. Int *width, Int *height, Int maxWidth );
  271. virtual UnicodeString winTextLabelToText( AsciiString label ); ///< convert localizable text label to real text
  272. virtual GameFont *winFindFont( AsciiString fontName, Int pointSize, Bool bold ); ///< get a font given a name
  273. /// @todo just for testing, remov this
  274. Bool initTestGUI( void );
  275. virtual GameWindow *getWindowUnderCursor( Int x, Int y, Bool ignoreEnabled = FALSE ); ///< find the top window at the given coordinates
  276. //---------------------------------------------------------------------------
  277. /////////////////////////////////////////////////////////////////////////////
  278. //---------------------------------------------------------------------------
  279. //---------------------------------------------------------------------------
  280. //---------------------------------------------------------------------------
  281. //---------------------------------------------------------------------------
  282. /////////////////////////////////////////////////////////////////////////////
  283. //---------------------------------------------------------------------------
  284. protected:
  285. void processDestroyList( void ); ///< process windows waiting to be killed
  286. Int drawWindow( GameWindow *window ); ///< draw this window
  287. void dumpWindow( GameWindow *window ); ///< for debugging
  288. GameWindow *m_windowList; // list of all top level windows
  289. GameWindow *m_windowTail; // last in windowList
  290. GameWindow *m_destroyList; // list of windows to destroy
  291. GameWindow *m_currMouseRgn; // window that mouse is over
  292. GameWindow *m_mouseCaptor; // window that captured mouse
  293. GameWindow *m_keyboardFocus; // window that has input focus
  294. ModalWindow *m_modalHead; // top of windows in the modal stack
  295. GameWindow *m_grabWindow; // window that grabbed the last down event
  296. GameWindow *m_loneWindow; // Set if we just opened a Lone Window
  297. GameWindowList m_tabList; // we have to register a tab list to make a tab list.
  298. const Image *m_cursorBitmap;
  299. UnsignedInt m_captureFlags;
  300. }; // end GameWindowManager
  301. // INLINE /////////////////////////////////////////////////////////////////////////////////////////
  302. inline GameWinDrawFunc GameWindowManager::getDefaultDraw( void ) { return GameWinDefaultDraw; }
  303. inline GameWinSystemFunc GameWindowManager::getDefaultSystem( void ) { return GameWinDefaultSystem; }
  304. inline GameWinInputFunc GameWindowManager::getDefaultInput( void ) { return GameWinDefaultInput; }
  305. inline GameWinTooltipFunc GameWindowManager::getDefaultTooltip( void ) { return GameWinDefaultTooltip; }
  306. // EXTERN /////////////////////////////////////////////////////////////////////////////////////////
  307. extern GameWindowManager *TheWindowManager; ///< singleton extern definition
  308. extern UnsignedInt WindowLayoutCurrentVersion; ///< current version of our window layouts
  309. // this function lets us generically pass button selections to our parent, we may
  310. // frequently want to do this because we want windows grouped on child windows for
  311. // convenience, but only want one logical system procedure responding to them all
  312. extern WindowMsgHandledType PassSelectedButtonsToParentSystem( GameWindow *window,
  313. UnsignedInt msg,
  314. WindowMsgData mData1,
  315. WindowMsgData mData2 );
  316. extern WindowMsgHandledType PassMessagesToParentSystem( GameWindow *window,
  317. UnsignedInt msg,
  318. WindowMsgData mData1,
  319. WindowMsgData mData2 );
  320. #endif // __GAMEWINDOWMANAGER_H_