Gadget.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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: 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;
  254. } TextData;
  255. // ListEntryCell --------------------------------------------------------------
  256. //-----------------------------------------------------------------------------
  257. typedef struct _ListEntryCell
  258. {
  259. Int cellType; // Holds either LISTBOX_TEXT or LISTBOX_IMAGE
  260. Color color; // use this color
  261. void *data; // pointer to either a DisplayString or an image
  262. void *userData; // Attach user data to the cell
  263. Int width; // Used if this is an image and we don't want to use the default
  264. Int height; // used if this is an image and we don't want ot use the default
  265. } ListEntryCell;
  266. // ListEntryRow ---------------------------------------------------------------
  267. //-----------------------------------------------------------------------------
  268. typedef struct _ListEntryRow
  269. {
  270. // The following fields are for internal use and
  271. // should not be initialized by the user
  272. Int listHeight; // calculated total Height at the bottom of this entry
  273. Byte height; // Maintain the height of the row
  274. ListEntryCell *cell; // Holds the array of ListEntry Cells
  275. } ListEntryRow;
  276. // ListboxData ----------------------------------------------------------------
  277. //-----------------------------------------------------------------------------
  278. typedef struct _ListboxData
  279. {
  280. Short listLength; // Max Number of entries in the list
  281. Short columns; // Number of Columns each line has
  282. Int *columnWidthPercentage; // Holds the percentage value of each column in an Int array;
  283. Bool autoScroll; // If add exceeds number of lines in display
  284. // scroll up automatically
  285. Bool autoPurge; // If add exceeds number of entries in list
  286. // delete top entry automatically
  287. Bool scrollBar; // Automatically create the up/down/slider buttons
  288. Bool multiSelect; // Allow for multiple selections
  289. Bool forceSelect; // Do not allow users to unselect from a listbox
  290. Bool scrollIfAtEnd; // If we're looking at the bottom of the listbox when a new entry is added,
  291. // scroll up automatically
  292. Bool audioFeedback; // Audio click feedback?
  293. //
  294. // The following fields are for internal use and should not be initialized
  295. // by the user
  296. //
  297. Int *columnWidth; // Pointer to array of column widths based off of user input
  298. ListEntryRow *listData; // Pointer to an array of ListEntryRows that we create when we first create the List
  299. GameWindow *upButton; // Child window for up arrow
  300. GameWindow *downButton; // Child window for down arrow
  301. GameWindow *slider; // Child window for slider bar
  302. Int totalHeight; // total height of all entries
  303. Short endPos; // End Insertion position
  304. Short insertPos; // Insertion position
  305. Int selectPos; // Position of current selected entry (for SINGLE select)
  306. Int *selections; // Pointer to array of selections (for MULTI select)
  307. Short displayHeight; // Height in pixels of listbox display region
  308. // this is computed based on the existance
  309. // of a title or not.
  310. UnsignedInt doubleClickTime; //
  311. Short displayPos; // Position of current display entry in pixels
  312. } ListboxData;
  313. // ComboBoxData ---------------------------------------------------------------
  314. //-----------------------------------------------------------------------------
  315. typedef struct _ComboBoxData
  316. {
  317. Bool isEditable; // Determines if the Combo box is a combo box or a dropdown box
  318. Int maxDisplay; // Holds the count for the maximum displayed in the lisbox before the slider appears
  319. Int maxChars; // Holds how many characters can be in the listbox/edit box.
  320. Bool asciiOnly; // Used to notify the Text Entry box if it is suppose to allow only ascii characters
  321. Bool lettersAndNumbersOnly; // Used to notify the Text Entry Box if it is to only allow letters and numbers
  322. ListboxData *listboxData; // Needed for the listbox component of the combo box
  323. EntryData *entryData; // Needed for the text entry component of the combo box
  324. //
  325. // The following fields are for internal use and should not be initialized
  326. // by the user
  327. //
  328. Bool dontHide; // A flag we'll use that'll determine if we hide the listbox or not when selected
  329. Int entryCount; // Current number of entries.
  330. GameWindow *dropDownButton; // Child window for drop down button
  331. GameWindow *editBox; // Child window for edit box
  332. GameWindow *listBox; // Child window for list box
  333. } ComboBoxData;
  334. // RadioButtonData ------------------------------------------------------------
  335. //-----------------------------------------------------------------------------
  336. typedef struct _RadioButtonData
  337. {
  338. Int screen; ///< screen identifier
  339. Int group; ///< group identifier
  340. } RadioButtonData;
  341. // PushButtonData -------------------------------------------------------------
  342. //-----------------------------------------------------------------------------
  343. #define NO_CLOCK 0
  344. #define NORMAL_CLOCK 1
  345. #define INVERSE_CLOCK 2
  346. typedef struct _PushButtonData
  347. {
  348. UnsignedByte drawClock; ///< We only want to draw the clock if, well, we want to
  349. Int percentClock; ///< The percentage of the clock we want to draw
  350. Color colorClock; ///< The color to display the clock at
  351. Bool drawBorder; ///< We only want to draw the border if we want to
  352. Color colorBorder; ///< The color for the border around the button
  353. void *userData; ///< random additional data we can set
  354. const Image *overlayImage; ///< An overlay image (like a veterancy symbol)
  355. AsciiString altSound; ///< use an alternitive sound if one is set
  356. } PushButtonData;
  357. // TabControlData ------------------------------------------------------------
  358. //-----------------------------------------------------------------------------
  359. enum //Tab Position
  360. {
  361. TP_CENTER,//Orientation
  362. TP_TOPLEFT,
  363. TP_BOTTOMRIGHT,
  364. TP_TOP_SIDE,//... on which side
  365. TP_RIGHT_SIDE,
  366. TP_LEFT_SIDE,
  367. TP_BOTTOM_SIDE
  368. };
  369. enum
  370. {
  371. NUM_TAB_PANES = 8,//(MAX_DRAW_DATA - 1)
  372. };
  373. typedef struct _TabControlData
  374. {
  375. //Set in editor
  376. Int tabOrientation;
  377. Int tabEdge;
  378. Int tabWidth;
  379. Int tabHeight;
  380. Int tabCount;
  381. GameWindow *subPanes[NUM_TAB_PANES];
  382. Bool subPaneDisabled[NUM_TAB_PANES];//tabCount will control how many even exist. Individual ones can be disabled
  383. Int paneBorder;
  384. //Working computations
  385. Int activeTab;
  386. Int tabsLeftLimit;
  387. Int tabsRightLimit;
  388. Int tabsTopLimit;
  389. Int tabsBottomLimit;
  390. } TabControlData;
  391. // INLINING ///////////////////////////////////////////////////////////////////
  392. // EXTERNALS //////////////////////////////////////////////////////////////////
  393. extern WindowMsgHandledType GadgetPushButtonSystem( GameWindow *window, UnsignedInt msg,
  394. WindowMsgData mData1, WindowMsgData mData2 );
  395. extern WindowMsgHandledType GadgetPushButtonInput( GameWindow *window, UnsignedInt msg,
  396. WindowMsgData mData1, WindowMsgData mData2 );
  397. extern WindowMsgHandledType GadgetCheckBoxInput( GameWindow *window, UnsignedInt msg,
  398. WindowMsgData mData1, WindowMsgData mData2 );
  399. extern WindowMsgHandledType GadgetCheckBoxSystem( GameWindow *window, UnsignedInt msg,
  400. WindowMsgData mData1, WindowMsgData mData2 );
  401. extern WindowMsgHandledType GadgetRadioButtonInput( GameWindow *window, UnsignedInt msg,
  402. WindowMsgData mData1, WindowMsgData mData2 );
  403. extern WindowMsgHandledType GadgetRadioButtonSystem( GameWindow *window, UnsignedInt msg,
  404. WindowMsgData mData1, WindowMsgData mData2 );
  405. extern WindowMsgHandledType GadgetTabControlInput( GameWindow *window, UnsignedInt msg,
  406. WindowMsgData mData1, WindowMsgData mData2 );
  407. extern WindowMsgHandledType GadgetTabControlSystem( GameWindow *window, UnsignedInt msg,
  408. WindowMsgData mData1, WindowMsgData mData2 );
  409. extern WindowMsgHandledType GadgetListBoxInput( GameWindow *window, UnsignedInt msg,
  410. WindowMsgData mData1, WindowMsgData mData2 );
  411. extern WindowMsgHandledType GadgetListBoxMultiInput( GameWindow *window, UnsignedInt msg,
  412. WindowMsgData mData1, WindowMsgData mData2 );
  413. extern WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
  414. WindowMsgData mData1, WindowMsgData mData2 );
  415. extern WindowMsgHandledType GadgetHorizontalSliderInput( GameWindow *window, UnsignedInt msg,
  416. WindowMsgData mData1, WindowMsgData mData2 );
  417. extern WindowMsgHandledType GadgetHorizontalSliderSystem( GameWindow *window, UnsignedInt msg,
  418. WindowMsgData mData1, WindowMsgData mData2 );
  419. extern WindowMsgHandledType GadgetVerticalSliderInput( GameWindow *window, UnsignedInt msg,
  420. WindowMsgData mData1, WindowMsgData mData2 );
  421. extern WindowMsgHandledType GadgetVerticalSliderSystem( GameWindow *window, UnsignedInt msg,
  422. WindowMsgData mData1, WindowMsgData mData2 );
  423. extern WindowMsgHandledType GadgetProgressBarSystem( GameWindow *window, UnsignedInt msg,
  424. WindowMsgData mData1, WindowMsgData mData2 );
  425. extern WindowMsgHandledType GadgetStaticTextInput( GameWindow *window, UnsignedInt msg,
  426. WindowMsgData mData1, WindowMsgData mData2 );
  427. extern WindowMsgHandledType GadgetStaticTextSystem( GameWindow *window, UnsignedInt msg,
  428. WindowMsgData mData1, WindowMsgData mData2 );
  429. extern WindowMsgHandledType GadgetTextEntryInput( GameWindow *window, UnsignedInt msg,
  430. WindowMsgData mData1, WindowMsgData mData2 );
  431. extern WindowMsgHandledType GadgetTextEntrySystem( GameWindow *window, UnsignedInt msg,
  432. WindowMsgData mData1, WindowMsgData mData2 );
  433. extern WindowMsgHandledType GadgetComboBoxInput( GameWindow *window, UnsignedInt msg,
  434. WindowMsgData mData1, WindowMsgData mData2 );
  435. extern WindowMsgHandledType GadgetComboBoxSystem( GameWindow *window, UnsignedInt msg,
  436. WindowMsgData mData1, WindowMsgData mData2 );
  437. extern Bool InitializeEntryGadget( void );
  438. extern Bool ShutdownEntryGadget( void );
  439. // Entry Gadget Functions
  440. extern void InformEntry( WideChar c );
  441. // list box stuff
  442. extern Int GetListboxTopEntry( ListboxData list );
  443. #endif // __GADGET_H_