WindowLayout.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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: WindowLayout.h ///////////////////////////////////////////////////////////////////////////
  24. // Created: Colin Day, September 2001
  25. // Desc: Encapsulation of all windows loaded from a .wnd file for
  26. // purposes of a "shell" layout screen
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. #ifndef __WINDOWLAYOUT_H_
  30. #define __WINDOWLAYOUT_H_
  31. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  32. #include "Common/GameMemory.h"
  33. #include "GameClient/GameWindow.h"
  34. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  35. class GameWindow;
  36. class WindowLayout;
  37. // TYPE DEFINES ///////////////////////////////////////////////////////////////////////////////////
  38. typedef void (*WindowLayoutInitFunc)( WindowLayout *layout, void *userData );
  39. typedef void (*WindowLayoutUpdateFunc)( WindowLayout *layout, void *userData );
  40. typedef void (*WindowLayoutShutdownFunc)( WindowLayout *layout, void *userData );
  41. //-------------------------------------------------------------------------------------------------
  42. /** The representation of a screen layout loaded from a .wnd layout
  43. * script file */
  44. //-------------------------------------------------------------------------------------------------
  45. class WindowLayout : public MemoryPoolObject
  46. {
  47. // memory pool for screen layouts
  48. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( WindowLayout, "WindowLayoutPool" );
  49. public:
  50. WindowLayout( void );
  51. // ~WindowLayout( void ); ///< defined by memory pool glue
  52. // manipulating screen properties ---------------------------------------------------------------
  53. AsciiString getFilename( void ); ///< return source window filename
  54. Bool load( AsciiString filename ); ///< create windows and load from .wnd file
  55. void hide( Bool hide ); ///< hide/unhide all windows on this screen
  56. Bool isHidden( void ); ///< return visible state of screen
  57. void bringForward( void ); ///< bring all windows in this screen forward
  58. // manipulating window lists --------------------------------------------------------------------
  59. void addWindow( GameWindow *window ); ///< add window to screen
  60. void removeWindow( GameWindow *window ); ///< remove window from screen
  61. void destroyWindows( void ); ///< destroy all windows in this screen
  62. GameWindow *getFirstWindow( void ); ///< get first window in list for screen
  63. // accessing layout callbacks ------------------------------------------------------------------
  64. void runInit( void *userData = NULL ); ///< run the init method if available
  65. void runUpdate( void *userData = NULL ); ///< run the update method if available
  66. void runShutdown( void *userData = NULL ); ///< run the shutdown method if available
  67. void setInit( WindowLayoutInitFunc init ); ///< set the init callback
  68. void setUpdate( WindowLayoutUpdateFunc update ); ///< set the update callback
  69. void setShutdown( WindowLayoutShutdownFunc shutdown); ///< set the shutdown callback
  70. protected:
  71. // internal helpers -----------------------------------------------------------------------------
  72. GameWindow *findWindow( GameWindow *window ); ///< find window in this layout
  73. //===============================================================================================
  74. // protected data ===============================================================================
  75. //===============================================================================================
  76. AsciiString m_filenameString; ///< layout filename
  77. GameWindow *m_windowList; ///< list of windows in this layout
  78. GameWindow *m_windowTail; ///< end of m_windowList
  79. Int m_windowCount; ///< how man windows are in the list
  80. Bool m_hidden; ///< visible state of this screen
  81. //
  82. // These are callbacks you can attach to a "layout file" ... they are not
  83. // automatically called when using the WindowManager to load and create
  84. // the layout. You can incorporate when and where init, shutdown and update should
  85. // be called for any system or code that is uses these window layouts
  86. //
  87. WindowLayoutInitFunc m_init; ///< init callback
  88. WindowLayoutUpdateFunc m_update; ///< update callback
  89. WindowLayoutShutdownFunc m_shutdown; ///< shutdown callback
  90. }; // end class WindowLayout
  91. // INLINING ///////////////////////////////////////////////////////////////////////////////////////
  92. inline AsciiString WindowLayout::getFilename( void ) { return m_filenameString; }
  93. inline GameWindow *WindowLayout::getFirstWindow( void ) { return m_windowList; }
  94. inline Bool WindowLayout::isHidden( void ) { return m_hidden; }
  95. inline void WindowLayout::runInit( void *userData ) { if( m_init ) m_init( this, userData ); }
  96. inline void WindowLayout::runUpdate( void *userData ) { if( m_update ) m_update( this, userData ); }
  97. inline void WindowLayout::runShutdown( void *userData ) { if( m_shutdown ) m_shutdown( this, userData ); }
  98. inline void WindowLayout::setInit( WindowLayoutInitFunc init ) { m_init = init; }
  99. inline void WindowLayout::setUpdate( WindowLayoutUpdateFunc update ) { m_update = update; }
  100. inline void WindowLayout::setShutdown( WindowLayoutShutdownFunc shutdown ) {m_shutdown = shutdown;}
  101. #endif // __WINDOWLAYOUT_H_