Gadget.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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: Gadget.h /////////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: Gadget.h
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: Game GUI user interface gadget controls
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. #pragma once
  44. #ifndef __GADGET_H_
  45. #define __GADGET_H_
  46. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  47. // USER INCLUDES //////////////////////////////////////////////////////////////
  48. #include "GameClient/GameWindow.h"
  49. #include "GameClient/Image.h"
  50. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  51. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  52. enum
  53. {
  54. GADGET_SIZE = 16,
  55. HORIZONTAL_SLIDER_THUMB_WIDTH = 13,
  56. HORIZONTAL_SLIDER_THUMB_HEIGHT = 16,
  57. ENTRY_TEXT_LEN = 256,
  58. STATIC_TEXT_LEN = 256,
  59. };
  60. // for listboxes
  61. enum
  62. {
  63. TEXT_X_OFFSET = 5,
  64. TEXT_Y_OFFSET = 2,
  65. TEXT_WIDTH_OFFSET = 7,
  66. TOTAL_OUTLINE_HEIGHT = 2 // Sum of heights of tom and bottom outline
  67. };
  68. enum
  69. {
  70. LISTBOX_TEXT = 1,
  71. LISTBOX_IMAGE = 2
  72. };
  73. // Gadget window styles, keep in same order as WindowStyleNames[]
  74. enum
  75. {
  76. GWS_PUSH_BUTTON = 0x00000001,
  77. GWS_RADIO_BUTTON = 0x00000002,
  78. GWS_CHECK_BOX = 0x00000004,
  79. GWS_VERT_SLIDER = 0x00000008,
  80. GWS_HORZ_SLIDER = 0x00000010,
  81. GWS_SCROLL_LISTBOX = 0x00000020,
  82. GWS_ENTRY_FIELD = 0x00000040,
  83. GWS_STATIC_TEXT = 0x00000080,
  84. GWS_PROGRESS_BAR = 0x00000100,
  85. GWS_USER_WINDOW = 0x00000200,
  86. GWS_MOUSE_TRACK = 0x00000400,
  87. GWS_ANIMATED = 0x00000800,
  88. GWS_TAB_STOP = 0x00001000,
  89. GWS_TAB_CONTROL = 0x00002000,
  90. GWS_TAB_PANE = 0x00004000,
  91. GWS_COMBO_BOX = 0x00008000,
  92. GWS_ALL_SLIDER = GWS_VERT_SLIDER | GWS_HORZ_SLIDER, // for convenience
  93. GWS_GADGET_WINDOW = GWS_PUSH_BUTTON |
  94. GWS_RADIO_BUTTON |
  95. GWS_TAB_CONTROL |
  96. GWS_CHECK_BOX |
  97. GWS_VERT_SLIDER |
  98. GWS_HORZ_SLIDER |
  99. GWS_SCROLL_LISTBOX |
  100. GWS_ENTRY_FIELD |
  101. GWS_STATIC_TEXT |
  102. GWS_COMBO_BOX |
  103. GWS_PROGRESS_BAR,
  104. };
  105. // Gadget paramaters
  106. enum
  107. {
  108. GP_DONT_UPDATE = 0x00000001,
  109. };
  110. // Gadget game messages (sent to their owners)
  111. enum GadgetGameMessage
  112. {
  113. // Generic messages supported by all gadgets
  114. GGM_LEFT_DRAG = 16384,
  115. GGM_SET_LABEL,
  116. GGM_GET_LABEL,
  117. GGM_FOCUS_CHANGE,
  118. GGM_RESIZED,
  119. GGM_CLOSE, // This is the message that's passed to a window if it's registered as a"right Click Menu"
  120. // Button messages
  121. GBM_MOUSE_ENTERING,
  122. GBM_MOUSE_LEAVING,
  123. GBM_SELECTED,
  124. GBM_SELECTED_RIGHT, // Right click selection
  125. GBM_SET_SELECTION,
  126. // Slider messages
  127. GSM_SLIDER_TRACK,
  128. GSM_SET_SLIDER,
  129. GSM_SET_MIN_MAX,
  130. GSM_SLIDER_DONE,
  131. // Listbox messages
  132. GLM_ADD_ENTRY,
  133. GLM_DEL_ENTRY,
  134. GLM_DEL_ALL,
  135. GLM_SELECTED,
  136. GLM_DOUBLE_CLICKED,
  137. GLM_RIGHT_CLICKED,
  138. // GLM_SET_INSERTPOS, // Not used since we now use multi column listboxes
  139. GLM_SET_SELECTION,
  140. GLM_GET_SELECTION,
  141. GLM_TOGGLE_MULTI_SELECTION,
  142. GLM_GET_TEXT,
  143. // GLM_SET_TEXT, // Not used Removed just to make sure
  144. GLM_SET_UP_BUTTON,
  145. GLM_SET_DOWN_BUTTON,
  146. GLM_SET_SLIDER,
  147. GLM_SCROLL_BUFFER,
  148. GLM_UPDATE_DISPLAY,
  149. GLM_GET_ITEM_DATA,
  150. GLM_SET_ITEM_DATA,
  151. //ComboBox Messages
  152. GCM_ADD_ENTRY,
  153. GCM_DEL_ENTRY,
  154. GCM_DEL_ALL,
  155. GCM_SELECTED,
  156. GCM_GET_TEXT,
  157. GCM_SET_TEXT,
  158. GCM_EDIT_DONE,
  159. GCM_GET_ITEM_DATA,
  160. GCM_SET_ITEM_DATA,
  161. GCM_GET_SELECTION,
  162. GCM_SET_SELECTION,
  163. GCM_UPDATE_TEXT,
  164. // Entry field messages
  165. GEM_GET_TEXT,
  166. GEM_SET_TEXT,
  167. GEM_EDIT_DONE,
  168. GEM_UPDATE_TEXT, //added so the parent will maintain real life status of the edit box.
  169. // Slider messages
  170. GPM_SET_PROGRESS,
  171. };
  172. // border types
  173. enum
  174. {
  175. BORDER_CORNER_UL = 0,
  176. BORDER_CORNER_UR,
  177. BORDER_CORNER_LL,
  178. BORDER_CORNER_LR,
  179. BORDER_VERTICAL_LEFT,
  180. BORDER_VERTICAL_LEFT_SHORT,
  181. BORDER_VERTICAL_RIGHT,
  182. BORDER_VERTICAL_RIGHT_SHORT,
  183. BORDER_HORIZONTAL_TOP,
  184. BORDER_HORIZONTAL_TOP_SHORT,
  185. BORDER_HORIZONTAL_BOTTOM,
  186. BORDER_HORIZONTAL_BOTTOM_SHORT,
  187. NUM_BORDER_PIECES
  188. };
  189. // GadgetMsg ------------------------------------------------------------------
  190. //-----------------------------------------------------------------------------
  191. typedef struct _GadgetMsg
  192. {
  193. GameWindow *window; // Originator of message
  194. Int data; // Data field
  195. Int data2; // Data field
  196. } GadgetMsgStruct, *GadgetMsg;
  197. // SliderMsg ------------------------------------------------------------------
  198. //-----------------------------------------------------------------------------
  199. typedef struct _SliderMsg
  200. {
  201. GameWindow *window; // Originator of message
  202. Int minVal; // Minimum slider value
  203. Int maxVal; // Maximum slider value
  204. Int position; // Current position of the slider
  205. } SliderMsgStruct, *SliderMsg;
  206. // ListboxMsg -----------------------------------------------------------------
  207. //-----------------------------------------------------------------------------
  208. typedef struct _ListboxMsg
  209. {
  210. GameWindow *window; // Originator of message
  211. Int position; // Position of the entry
  212. } ListboxMsgStruct, *ListboxMsg;
  213. // SliderData -----------------------------------------------------------------
  214. //-----------------------------------------------------------------------------
  215. typedef struct _SliderData
  216. {
  217. Int minVal; // Minimum slider value
  218. Int maxVal; // Maximum slider value
  219. // The following fields are for internal use and
  220. // should not be initialized by the user
  221. Real numTicks; // Number of ticks between min and max
  222. Int position; // Current position of the slider
  223. } SliderData;
  224. // EntryData ------------------------------------------------------------------
  225. //-----------------------------------------------------------------------------
  226. typedef struct _EntryData
  227. {
  228. DisplayString *text; ///< the entry text
  229. DisplayString *sText; ///< for displaying 'secret' text
  230. DisplayString *constructText; ///< for foriegn text construction
  231. Bool secretText; ///< If TRUE text appears as astericks
  232. Bool numericalOnly; ///< If TRUE only numbers are allowed as input
  233. Bool alphaNumericalOnly; ///< If TRUE only numbers and letters are allowed as input
  234. Bool aSCIIOnly; ///< If TRUE ascii allowed as input
  235. Short maxTextLen; ///< Max length of edit text
  236. // Colin: The very notion of entry width makes no sense to me since
  237. // we already have a gadget width, and the max characters for
  238. // an entry box so I am removing this.
  239. // Short entryWidth; ///< Width, in pixels, of the entry box
  240. // The following fields are for internal use and
  241. // should not be initialized by the user
  242. Bool receivedUnichar; // If TRUE system just processed a UniChar
  243. Bool drawTextFromStart; // if FALSE, make sure end of text is visible
  244. GameWindow *constructList; // Listbox for construct list.
  245. UnsignedShort charPos; // Position of current character
  246. UnsignedShort conCharPos; // Position of current contruct character
  247. } EntryData;
  248. // TextData -------------------------------------------------------------------
  249. //-----------------------------------------------------------------------------
  250. typedef struct _TextData
  251. {
  252. DisplayString *text; ///< the text data
  253. Bool centered; ///< horizontal
  254. Bool centeredVertically; ///< vertical
  255. Int leftMargin; ///< left justification margin width
  256. Int topMargin; ///< top justification margin width
  257. } TextData;
  258. // ListEntryCell --------------------------------------------------------------
  259. //-----------------------------------------------------------------------------
  260. typedef struct _ListEntryCell
  261. {
  262. Int cellType; // Holds either LISTBOX_TEXT or LISTBOX_IMAGE
  263. Color color; // use this color
  264. void *data; // pointer to either a DisplayString or an image
  265. void *userData; // Attach user data to the cell
  266. Int width; // Used if this is an image and we don't want to use the default
  267. Int height; // used if this is an image and we don't want ot use the default
  268. } ListEntryCell;
  269. // ListEntryRow ---------------------------------------------------------------
  270. //-----------------------------------------------------------------------------
  271. typedef struct _ListEntryRow
  272. {
  273. // The following fields are for internal use and
  274. // should not be initialized by the user
  275. Int listHeight; // calculated total Height at the bottom of this entry
  276. Byte height; // Maintain the height of the row
  277. ListEntryCell *cell; // Holds the array of ListEntry Cells
  278. } ListEntryRow;
  279. // ListboxData ----------------------------------------------------------------
  280. //-----------------------------------------------------------------------------
  281. typedef struct _ListboxData
  282. {
  283. Short listLength; // Max Number of entries in the list
  284. Short columns; // Number of Columns each line has
  285. Int *columnWidthPercentage; // Holds the percentage value of each column in an Int array;
  286. Bool autoScroll; // If add exceeds number of lines in display
  287. // scroll up automatically
  288. Bool autoPurge; // If add exceeds number of entries in list
  289. // delete top entry automatically
  290. Bool scrollBar; // Automatically create the up/down/slider buttons
  291. Bool multiSelect; // Allow for multiple selections
  292. Bool forceSelect; // Do not allow users to unselect from a listbox
  293. Bool scrollIfAtEnd; // If we're looking at the bottom of the listbox when a new entry is added,
  294. // scroll up automatically
  295. Bool audioFeedback; // Audio click feedback?
  296. //
  297. // The following fields are for internal use and should not be initialized
  298. // by the user
  299. //
  300. Int *columnWidth; // Pointer to array of column widths based off of user input
  301. ListEntryRow *listData; // Pointer to an array of ListEntryRows that we create when we first create the List
  302. GameWindow *upButton; // Child window for up arrow
  303. GameWindow *downButton; // Child window for down arrow
  304. GameWindow *slider; // Child window for slider bar
  305. Int totalHeight; // total height of all entries
  306. Short endPos; // End Insertion position
  307. Short insertPos; // Insertion position
  308. Int selectPos; // Position of current selected entry (for SINGLE select)
  309. Int *selections; // Pointer to array of selections (for MULTI select)
  310. Short displayHeight; // Height in pixels of listbox display region
  311. // this is computed based on the existance
  312. // of a title or not.
  313. UnsignedInt doubleClickTime; //
  314. Short displayPos; // Position of current display entry in pixels
  315. } ListboxData;
  316. // ComboBoxData ---------------------------------------------------------------
  317. //-----------------------------------------------------------------------------
  318. typedef struct _ComboBoxData
  319. {
  320. Bool isEditable; // Determines if the Combo box is a combo box or a dropdown box
  321. Int maxDisplay; // Holds the count for the maximum displayed in the lisbox before the slider appears
  322. Int maxChars; // Holds how many characters can be in the listbox/edit box.
  323. Bool asciiOnly; // Used to notify the Text Entry box if it is suppose to allow only ascii characters
  324. Bool lettersAndNumbersOnly; // Used to notify the Text Entry Box if it is to only allow letters and numbers
  325. ListboxData *listboxData; // Needed for the listbox component of the combo box
  326. EntryData *entryData; // Needed for the text entry component of the combo box
  327. //
  328. // The following fields are for internal use and should not be initialized
  329. // by the user
  330. //
  331. Bool dontHide; // A flag we'll use that'll determine if we hide the listbox or not when selected
  332. Int entryCount; // Current number of entries.
  333. GameWindow *dropDownButton; // Child window for drop down button
  334. GameWindow *editBox; // Child window for edit box
  335. GameWindow *listBox; // Child window for list box
  336. } ComboBoxData;
  337. // RadioButtonData ------------------------------------------------------------
  338. //-----------------------------------------------------------------------------
  339. typedef struct _RadioButtonData
  340. {
  341. Int screen; ///< screen identifier
  342. Int group; ///< group identifier
  343. } RadioButtonData;
  344. // PushButtonData -------------------------------------------------------------
  345. //-----------------------------------------------------------------------------
  346. #define NO_CLOCK 0
  347. #define NORMAL_CLOCK 1
  348. #define INVERSE_CLOCK 2
  349. typedef struct _PushButtonData
  350. {
  351. UnsignedByte drawClock; ///< We only want to draw the clock if, well, we want to
  352. Int percentClock; ///< The percentage of the clock we want to draw
  353. Color colorClock; ///< The color to display the clock at
  354. Bool drawBorder; ///< We only want to draw the border if we want to
  355. Color colorBorder; ///< The color for the border around the button
  356. void *userData; ///< random additional data we can set
  357. const Image *overlayImage; ///< An overlay image (like a veterancy symbol)
  358. AsciiString altSound; ///< use an alternitive sound if one is set
  359. } PushButtonData;
  360. // TabControlData ------------------------------------------------------------
  361. //-----------------------------------------------------------------------------
  362. enum //Tab Position
  363. {
  364. TP_CENTER,//Orientation
  365. TP_TOPLEFT,
  366. TP_BOTTOMRIGHT,
  367. TP_TOP_SIDE,//... on which side
  368. TP_RIGHT_SIDE,
  369. TP_LEFT_SIDE,
  370. TP_BOTTOM_SIDE
  371. };
  372. enum
  373. {
  374. NUM_TAB_PANES = 8,//(MAX_DRAW_DATA - 1)
  375. };
  376. typedef struct _TabControlData
  377. {
  378. //Set in editor
  379. Int tabOrientation;
  380. Int tabEdge;
  381. Int tabWidth;
  382. Int tabHeight;
  383. Int tabCount;
  384. GameWindow *subPanes[NUM_TAB_PANES];
  385. Bool subPaneDisabled[NUM_TAB_PANES];//tabCount will control how many even exist. Individual ones can be disabled
  386. Int paneBorder;
  387. //Working computations
  388. Int activeTab;
  389. Int tabsLeftLimit;
  390. Int tabsRightLimit;
  391. Int tabsTopLimit;
  392. Int tabsBottomLimit;
  393. } TabControlData;
  394. // INLINING ///////////////////////////////////////////////////////////////////
  395. // EXTERNALS //////////////////////////////////////////////////////////////////
  396. extern WindowMsgHandledType GadgetPushButtonSystem( GameWindow *window, UnsignedInt msg,
  397. WindowMsgData mData1, WindowMsgData mData2 );
  398. extern WindowMsgHandledType GadgetPushButtonInput( GameWindow *window, UnsignedInt msg,
  399. WindowMsgData mData1, WindowMsgData mData2 );
  400. extern WindowMsgHandledType GadgetCheckBoxInput( GameWindow *window, UnsignedInt msg,
  401. WindowMsgData mData1, WindowMsgData mData2 );
  402. extern WindowMsgHandledType GadgetCheckBoxSystem( GameWindow *window, UnsignedInt msg,
  403. WindowMsgData mData1, WindowMsgData mData2 );
  404. extern WindowMsgHandledType GadgetRadioButtonInput( GameWindow *window, UnsignedInt msg,
  405. WindowMsgData mData1, WindowMsgData mData2 );
  406. extern WindowMsgHandledType GadgetRadioButtonSystem( GameWindow *window, UnsignedInt msg,
  407. WindowMsgData mData1, WindowMsgData mData2 );
  408. extern WindowMsgHandledType GadgetTabControlInput( GameWindow *window, UnsignedInt msg,
  409. WindowMsgData mData1, WindowMsgData mData2 );
  410. extern WindowMsgHandledType GadgetTabControlSystem( GameWindow *window, UnsignedInt msg,
  411. WindowMsgData mData1, WindowMsgData mData2 );
  412. extern WindowMsgHandledType GadgetListBoxInput( GameWindow *window, UnsignedInt msg,
  413. WindowMsgData mData1, WindowMsgData mData2 );
  414. extern WindowMsgHandledType GadgetListBoxMultiInput( GameWindow *window, UnsignedInt msg,
  415. WindowMsgData mData1, WindowMsgData mData2 );
  416. extern WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
  417. WindowMsgData mData1, WindowMsgData mData2 );
  418. extern WindowMsgHandledType GadgetHorizontalSliderInput( GameWindow *window, UnsignedInt msg,
  419. WindowMsgData mData1, WindowMsgData mData2 );
  420. extern WindowMsgHandledType GadgetHorizontalSliderSystem( GameWindow *window, UnsignedInt msg,
  421. WindowMsgData mData1, WindowMsgData mData2 );
  422. extern WindowMsgHandledType GadgetVerticalSliderInput( GameWindow *window, UnsignedInt msg,
  423. WindowMsgData mData1, WindowMsgData mData2 );
  424. extern WindowMsgHandledType GadgetVerticalSliderSystem( GameWindow *window, UnsignedInt msg,
  425. WindowMsgData mData1, WindowMsgData mData2 );
  426. extern WindowMsgHandledType GadgetProgressBarSystem( GameWindow *window, UnsignedInt msg,
  427. WindowMsgData mData1, WindowMsgData mData2 );
  428. extern WindowMsgHandledType GadgetStaticTextInput( GameWindow *window, UnsignedInt msg,
  429. WindowMsgData mData1, WindowMsgData mData2 );
  430. extern WindowMsgHandledType GadgetStaticTextSystem( GameWindow *window, UnsignedInt msg,
  431. WindowMsgData mData1, WindowMsgData mData2 );
  432. extern WindowMsgHandledType GadgetTextEntryInput( GameWindow *window, UnsignedInt msg,
  433. WindowMsgData mData1, WindowMsgData mData2 );
  434. extern WindowMsgHandledType GadgetTextEntrySystem( GameWindow *window, UnsignedInt msg,
  435. WindowMsgData mData1, WindowMsgData mData2 );
  436. extern WindowMsgHandledType GadgetComboBoxInput( GameWindow *window, UnsignedInt msg,
  437. WindowMsgData mData1, WindowMsgData mData2 );
  438. extern WindowMsgHandledType GadgetComboBoxSystem( GameWindow *window, UnsignedInt msg,
  439. WindowMsgData mData1, WindowMsgData mData2 );
  440. extern Bool InitializeEntryGadget( void );
  441. extern Bool ShutdownEntryGadget( void );
  442. // Entry Gadget Functions
  443. extern void InformEntry( WideChar c );
  444. // list box stuff
  445. extern Int GetListboxTopEntry( ListboxData list );
  446. #endif // __GADGET_H_