GUIEdit.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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: GUIEdit.h ////////////////////////////////////////////////////////////////////////////////
  24. // Created: Colin Day, July 2001
  25. // Desc: GUI Edit and window layout entry point
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __GUIEDIT_H_
  29. #define __GUIEDIT_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include <windows.h>
  32. #include <stdio.h>
  33. #include "GameClient/GameWindow.h"
  34. #include "GameClient/WindowLayout.h"
  35. #include "GameClient/GameWindowManager.h"
  36. #include "GUIEditColor.h"
  37. #include "Common/AsciiString.h"
  38. // TYPE DEFINES ///////////////////////////////////////////////////////////////////////////////////
  39. #define GUIEDIT_CONFIG_FILENAME "GUIEdit.cfg"
  40. #define GUIEDIT_FONT_FILENAME "GUIEFont.txt"
  41. #define GUIEDIT_NONE_STRING "[None]"
  42. #define STATUS_BAR_ID 1
  43. #define TOOLBAR_ID 2
  44. //-------------------------------------------------------------------------------------------------
  45. /** Edit mode states for editor */
  46. //-------------------------------------------------------------------------------------------------
  47. typedef enum
  48. {
  49. MODE_UNDEFINED = 0, ///< undefined mode
  50. MODE_EDIT, ///< normal edit mode
  51. MODE_TEST_RUN, ///< test input like ingame
  52. MODE_DRAG_MOVE, ///< moving windows with the mouse
  53. MODE_RESIZE_TOP_LEFT, ///< resize dragging top left corner
  54. MODE_RESIZE_TOP_RIGHT, ///< resize dragging top right cornder
  55. MODE_RESIZE_BOTTOM_RIGHT, ///< resize dragging bottom right corner
  56. MODE_RESIZE_BOTTOM_LEFT, ///< resize dragging bottom left corner
  57. MODE_RESIZE_TOP, ///< resize dragging top horizontal
  58. MODE_RESIZE_RIGHT, ///< resize dragging right vertical
  59. MODE_RESIZE_BOTTOM, ///< resize dragging bottom horizontal
  60. MODE_RESIZE_LEFT, ///< resize dragging left vertical
  61. MODE_KEYBOARD_MOVE, ///< moving windows with the Keyboard
  62. MODE_NUM_MODES ///< keep this last!
  63. } EditMode;
  64. //-------------------------------------------------------------------------------------------------
  65. /** The status bar is this many pieces and we can access them this way */
  66. //-------------------------------------------------------------------------------------------------
  67. typedef enum
  68. {
  69. STATUS_MODE = 0,
  70. STATUS_PART2, /// change to meaningful name when decided what goes here
  71. STATUS_PART3, /// change to meaningful name when decided what goes here
  72. STATUS_PART4, /// change to meaningful name when decided what goes here
  73. STATUS_MOUSE_COORDS,
  74. STATUS_NUM_PARTS ///< keep this last!
  75. } StatusPart;
  76. //-------------------------------------------------------------------------------------------------
  77. /** Types of pointing cursors */
  78. //-------------------------------------------------------------------------------------------------
  79. typedef enum
  80. {
  81. CURSOR_NORMAL,
  82. CURSOR_MOVE,
  83. CURSOR_SIZE_NESW,
  84. CURSOR_SIZE_NS,
  85. CURSOR_SIZE_NWSE,
  86. CURSOR_SIZE_WE,
  87. CURSOR_WAIT,
  88. CURSOR_NUM_CURSORS // keep last
  89. } CursorType;
  90. //-------------------------------------------------------------------------------------------------
  91. /** These entrys make up the selection list of windows */
  92. //-------------------------------------------------------------------------------------------------
  93. struct WindowSelectionEntry
  94. {
  95. GameWindow *window; ///< the window
  96. WindowSelectionEntry *next;
  97. WindowSelectionEntry *prev;
  98. };
  99. //-------------------------------------------------------------------------------------------------
  100. /** Framework for GUI editor data */
  101. //-------------------------------------------------------------------------------------------------
  102. class GUIEdit
  103. {
  104. public:
  105. GUIEdit( void );
  106. ~GUIEdit( void );
  107. void init( void ); ///< initialize data
  108. void shutdown( void ); ///< shutdown all our data
  109. void update( void ); ///< process the universe
  110. Bool readConfigFile( char *filename ); ///< read the configuration file
  111. Bool writeConfigFile( char *filename ); ///< write the configuration file
  112. void readFontFile( char *filename ); ///< read file with available font definitions
  113. void writeFontFile( char *filename ); ///< write all loaded fonts to a file
  114. char *getSaveFilename( void );
  115. char *getSavePathAndFilename( void );
  116. void setSaveFile( char *fullPathAndFilename ); ///< set filename to use for saving
  117. HWND getWindowHandle( void ); ///< get window handle
  118. HINSTANCE getInstance( void ); ///< get application instance
  119. HWND getStatusBarWindowHandle( void ); ///< get status bar HWND
  120. void createStatusBar( void ); ///< create status bar
  121. void statusMessage( StatusPart part, char *message ); ///< set status bar textl
  122. void createToolbar( void ); ///< create the toolbar
  123. void setCursor( CursorType type ); ///< set cursor
  124. void setPropertyTarget( GameWindow *window ); ///< set window for property editing
  125. GameWindow *getPropertyTarget( void ); ///< get window editing properties
  126. void loadGUIEditFontLibrary( FontLibrary *library ); ///< fonts available in the editor
  127. Bool isNameDuplicate( GameWindow *root, GameWindow *ignore, AsciiString name );
  128. EditMode getMode( void ); ///< return the current mode
  129. void setMode( EditMode mode ); ///< set the new mode
  130. void setUnsaved( Bool unsaved ); ///< set unsaved flag to FALSE or TRUE
  131. Bool newLayout( void ); ///< reset editor for new layout
  132. // grid settings
  133. void setGridResolution( Int res );
  134. Int getGridResolution( void );
  135. void setGridVisible( Bool visible );
  136. Bool isGridVisible( void );
  137. void setGridSnap( Bool on );
  138. Bool isGridSnapOn( void );
  139. void setGridColor( RGBColorInt *color );
  140. RGBColorInt *getGridColor( void );
  141. void gridSnapLocation( ICoord2D *source, ICoord2D *snapped );
  142. // display options for hidden/see thru windows
  143. void setShowHiddenOutlines( Bool show );
  144. Bool getShowHiddenOutlines( void );
  145. void setShowSeeThruOutlines( Bool show );
  146. Bool getShowSeeThruOutlines( void );
  147. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148. // manipulating windows ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. Bool windowIsGadget( GameWindow *window ); ///< is the window a gadget
  151. // selection help ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  152. WindowSelectionEntry *getSelectList( void ); ///< get the selected list head
  153. GameWindow *getFirstSelected( void ); ///< get first selected window
  154. void moveWindowTo( GameWindow *window, Int x, Int y ); ///< move window
  155. Bool isWindowSelected( GameWindow *window ); ///< is window selected
  156. void selectWindow( GameWindow *window ); ///< add to selection list
  157. void unSelectWindow( GameWindow *window ); ///< remove from selection list
  158. void clearSelections( void ); ///< clear selection list
  159. Int selectionCount( void ); ///< return # of selected windows
  160. void deleteSelected( void ); ///< delete selected windows
  161. void bringSelectedToTop( void ); ///< bring selected windows to top
  162. /// select the windows that are FULLY in the region specified
  163. void selectWindowsInRegion( IRegion2D *region );
  164. // resizing/moving help ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165. void dragMoveSelectedWindows( ICoord2D *dragOrigin, ICoord2D *dragDest ); ///< move windows via drag move
  166. /// given a position to move a window to, keep it onscreen and inside parent
  167. void computeSafeLocation( GameWindow *window, Int x, Int y,
  168. Int *safeX, Int *safeY );
  169. /// given position and size to move a window to, keep it inside parent and on screen
  170. void computeSafeSizeLocation( GameWindow *window,
  171. Int newX, Int newY,
  172. Int newWidth, Int newHeight,
  173. Int *safeX, Int *safeY,
  174. Int *safeWidth, Int *safeHeight );
  175. /// compute new size of window using drag-resize logic
  176. void computeResizeLocation( EditMode resizeMode,
  177. GameWindow *window,
  178. ICoord2D *resizeOrigin,
  179. ICoord2D *resizeDest,
  180. ICoord2D *resultLoc,
  181. ICoord2D *resultSize );
  182. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183. // creating new windows and controls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  184. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185. /** this is called after a window is added to the editor, the window may
  186. contain children so this might be recursively called from inside */
  187. void notifyNewWindow( GameWindow *window );
  188. GameWindow *getWindowAtPos( Int x, Int y ); ///< get topmost window at pos
  189. void deleteAllWindows( void ); ///< delete all windows in the editor
  190. void removeWindowCleanup( GameWindow *window ); ///< to cleanup before delete
  191. void deleteWindow( GameWindow *window ); ///< delete a game window
  192. /** when creating child windows we don't want them to exist outside the
  193. parent so we use this to clip them to the the parent size and locations */
  194. void clipCreationParamsToParent( GameWindow *parent,
  195. Int *x, Int *y, Int *width, Int *height );
  196. GameWindow *newWindow( UnsignedInt windowStyle,
  197. GameWindow *parent,
  198. Int x, Int y,
  199. Int width, Int height );
  200. GameWindow *newUserWindow( GameWindow *parent,
  201. Int x, Int y,
  202. Int width, Int height );
  203. GameWindow *newPushButton( GameWindow *parent,
  204. Int x, Int y,
  205. Int width, Int height );
  206. GameWindow *newCheckBox( GameWindow *parent,
  207. Int x, Int y,
  208. Int width, Int height );
  209. GameWindow *newRadioButton( GameWindow *parent,
  210. Int x, Int y,
  211. Int width, Int height );
  212. GameWindow *newTabControl( GameWindow *parent,
  213. Int x, Int y,
  214. Int width, Int height );
  215. GameWindow *newHorizontalSlider( GameWindow *parent,
  216. Int x, Int y,
  217. Int width, Int height );
  218. GameWindow *newVerticalSlider( GameWindow *parent,
  219. Int x, Int y,
  220. Int width, Int height );
  221. GameWindow *newProgressBar( GameWindow *parent,
  222. Int x, Int y,
  223. Int width, Int height );
  224. GameWindow *newListbox( GameWindow *parent,
  225. Int x, Int y,
  226. Int width, Int height );
  227. GameWindow *newTextEntry( GameWindow *parent,
  228. Int x, Int y,
  229. Int width, Int height );
  230. GameWindow *newStaticText( GameWindow *parent,
  231. Int x, Int y,
  232. Int width, Int height );
  233. GameWindow *newComboBox( GameWindow *parent,
  234. Int x, Int y,
  235. Int width, Int height );
  236. // menu options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237. Bool menuNew( void ); ///< start a new layout process
  238. Bool menuOpen( void ); ///< hit open on menu
  239. void stripNameDecorations( GameWindow *root ); ///< after a load
  240. void revertDefaultCallbacks( GameWindow *root ); ///< after a load
  241. Bool menuSave( void ); ///< hit save on menu
  242. Bool menuSaveAs( void ); ///< hit save as on menu
  243. Bool menuExit( void ); ///< exit application
  244. Bool menuCopy( void ); ///< copy selected windows into copy buffer
  245. Bool menuPaste( void ); ///< paste contents of copy buffer
  246. Bool menuCut( void ); ///< cut selected windows into copy buffer
  247. void checkMenuItem( Int item );
  248. void unCheckMenuItem( Int item );
  249. // global layout functions callbacks ------------------------------------------------------------
  250. void setLayoutInit( AsciiString init ); ///< set layout init function name
  251. void setLayoutUpdate( AsciiString update ); ///< set layout update function name
  252. void setLayoutShutdown( AsciiString shutdown ); ///< set layout shutdown function name
  253. AsciiString getLayoutInit( void ); ///< get layout init function name
  254. AsciiString getLayoutUpdate( void ); ///< get layout update function name
  255. AsciiString getLayoutShutdown( void ); ///< get layout shutdown function name
  256. protected:
  257. char *saveAsDialog( void ); ///< save as standard browser
  258. char *openDialog( void ); ///< open standard browser
  259. void validateNames( GameWindow *root, char *filename, Bool *valid );
  260. void updateRadioScreenIdentifiers( GameWindow *window, Int screenID );
  261. Bool saveData( char *filePathAndFilename, char *filename ); ///< save data to file in filePath
  262. Bool validateParentForCreate( GameWindow *parent ); ///< validate parent OK
  263. /// normalize a region so that lo and hi are really lo and hi
  264. void normalizeRegion( IRegion2D *region );
  265. /// find selection entry associated with this window
  266. WindowSelectionEntry *findSelectionEntry( GameWindow *window );
  267. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  268. HINSTANCE m_appInst; ///< main application hInstance
  269. HWND m_appHWnd; ///< main application hWnd
  270. HWND m_statusBarHWnd; ///< status bar window handle
  271. HWND m_toolbarHWnd; ///< toolbar window handle
  272. EditMode m_mode; ///< the current editor "mode"
  273. Bool m_unsaved; ///< TRUE when contents are unsaved
  274. char m_savePathAndFilename[ _MAX_PATH ]; ///< full path and filename to file
  275. char m_saveFilename[ _MAX_PATH ]; ///< filename only with extension
  276. WindowSelectionEntry *m_selectList; ///< list of "selected" windows
  277. GameWindow *m_propertyTarget; ///< the window to edit properties on
  278. Bool m_gridVisible; ///< TRUE when grid is visible
  279. Int m_gridResolution; ///< pixels between the grid marks
  280. Bool m_snapToGrid; ///< TRUE when it's on
  281. RGBColorInt m_gridColor; ///< the grid draw color
  282. Bool m_showHiddenOutlines; ///< show outlines around hidden windows
  283. Bool m_showSeeThruOutlines; ///< show outliens around see-thru windows
  284. AsciiString m_layoutInitString; ///< layout initi function name
  285. AsciiString m_layoutUpdateString; ///< layout update function name
  286. AsciiString m_layoutShutdownString;///< layout shutdown function name
  287. }; // end GUIEdit
  288. // INLINING ///////////////////////////////////////////////////////////////////////////////////////
  289. inline HWND GUIEdit::getWindowHandle( void ) { return m_appHWnd; }
  290. inline HINSTANCE GUIEdit::getInstance( void ) { return m_appInst; }
  291. inline HWND GUIEdit::getStatusBarWindowHandle( void ) { return m_statusBarHWnd; }
  292. inline EditMode GUIEdit::getMode( void ) { return m_mode; }
  293. inline void GUIEdit::setPropertyTarget( GameWindow *window ) { m_propertyTarget = window; }
  294. inline GameWindow *GUIEdit::getPropertyTarget( void ) { return m_propertyTarget; }
  295. inline char *GUIEdit::getSaveFilename( void ) { return m_saveFilename; }
  296. inline char *GUIEdit::getSavePathAndFilename( void ) { return m_savePathAndFilename; }
  297. inline void GUIEdit::setGridResolution( Int res ) { m_gridResolution = res; }
  298. inline Int GUIEdit::getGridResolution( void ) { return m_gridResolution; }
  299. inline void GUIEdit::setGridVisible( Bool visible ) { m_gridVisible = visible; }
  300. inline Bool GUIEdit::isGridVisible( void ) { return m_gridVisible; }
  301. inline void GUIEdit::setGridSnap( Bool on ) { m_snapToGrid = on; }
  302. inline Bool GUIEdit::isGridSnapOn( void ) { return m_snapToGrid; }
  303. inline void GUIEdit::setGridColor( RGBColorInt *color ) { m_gridColor = *color; }
  304. inline RGBColorInt *GUIEdit::getGridColor( void ) { return &m_gridColor; }
  305. inline Bool GUIEdit::getShowHiddenOutlines( void ) { return m_showHiddenOutlines; }
  306. inline Bool GUIEdit::getShowSeeThruOutlines( void ) { return m_showSeeThruOutlines; }
  307. inline void GUIEdit::setLayoutInit( AsciiString init ) { m_layoutInitString = init; }
  308. inline void GUIEdit::setLayoutUpdate( AsciiString update ) { m_layoutUpdateString = update; }
  309. inline void GUIEdit::setLayoutShutdown( AsciiString shutdown ) { m_layoutShutdownString = shutdown; }
  310. inline AsciiString GUIEdit::getLayoutInit( void ) { return m_layoutInitString; }
  311. inline AsciiString GUIEdit::getLayoutUpdate( void ) { return m_layoutUpdateString; }
  312. inline AsciiString GUIEdit::getLayoutShutdown( void ) { return m_layoutShutdownString; }
  313. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  314. extern GUIEdit *TheEditor; ///< editor application singleton
  315. #endif // __GUIEDIT_H_