GADGET.H 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/GADGET.H 1 3/03/97 10:24a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : GADGET.H *
  26. * *
  27. * Programmer : Maria del Mar McCready Legg *
  28. * *
  29. * Start Date : January 3, 1995 *
  30. * *
  31. * Last Update : January 3, 1995 [MML] *
  32. * *
  33. * *
  34. * LinkClass [This is the linked list manager class. It keeps a record *
  35. * ³ of the next and previous gadget in the list. It is possible *
  36. * ³ delete a gadget out of the middle of the list with this *
  37. * ³ class.] *
  38. * ³ *
  39. * GadgetClass [The is the basic gadget class. It handles processing of *
  40. * ³ input events and dispatching the appropriate functions. *
  41. * ³ All gadgets must be derived from this class.] *
  42. * ÃÄÄÄÄ¿ *
  43. * ³ ³ *
  44. * ³ ListClass [This list class functions like a list box does in Windows. It *
  45. * ³ keeps track of a list of text strings. This list can be *
  46. * ³ scrolled and an item selected. If the list becomes larger than *
  47. * ³ can be completely displayed, it will automatically create a *
  48. * ³ slider (at the right edge) to manage the scrolling.] *
  49. * ³ *
  50. * ControlClass [This class adds the concept of giving an ID number to the *
  51. * ³ gadget. This ID can then be returned from the Input() *
  52. * ³ function as if it were a pseudo-keystroke. Additionally, *
  53. * ³ the ability to inform another button that this button has *
  54. * ³ been actioned is allowed. This ability allows one button *
  55. * ³ to watch what happens to another button. Example: a list *
  56. * ³ box gadget can tell when an attached slider has been *
  57. * ³ touched.] *
  58. * ÚÄÄÄÄÄÄÄÅÄÄÄÄ¿ *
  59. * ³ ³ ³ *
  60. * ³ ³ GaugeClass [This class looks similar to Windows slider, but has *
  61. * ³ ³ ³ a different controlling logic. There is no thumb and *
  62. * ³ ³ ³ it serves as a simple variable control setting. This *
  63. * ³ ³ ³ is analogous to a volume slider.] *
  64. * ³ ³ ³ *
  65. * ³ ³ SliderClass [The slider class is similar to the typical Windows slider. It *
  66. * ³ ³ has a current setting, a thumb, and a controllable scale. This *
  67. * ³ ³ is the object created to handle a scrolling list box.] *
  68. * ³ ³ *
  69. * ³ EditClass *
  70. * ³ *
  71. * ³ *
  72. * ToggleClass [The toggle class is used for buttons that have an image and behave just *
  73. * ³ like the buttons in Windows do. That is, they have a separate visual for *
  74. * ³ when they are pressed and raised. They are officially triggered (return *
  75. * ³ their ID number) when the mouse button is released while over the button. *
  76. * ³ This class doesn't perform any rendering itself. It merely provides the *
  77. * ³ logic so that the derived classes will function correctly.] *
  78. * ÚÄÁÄÄÄÄ¿ *
  79. * ³ ³ *
  80. * ³ TextButtonClass [The text button functions like a normal Windows style button, but *
  81. * ³ the imagery is based on text that is displayed on the button. A *
  82. * ³ typical example would be the "OK" or "Cancel" buttons.] *
  83. * ³ *
  84. * ShapeButtonClass [The shape buttons is similar to the TextButton but instead of text *
  85. * being used to give the button its imagery, an actual shape is used *
  86. * instead. This allows graphic buttons. These are similar to the up/down *
  87. * arrows seen in a Windows slider.] *
  88. * *
  89. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  90. #ifndef GADGET_H
  91. #define GADGET_H
  92. #include "link.h"
  93. class ControlClass;
  94. class GadgetClass : public LinkClass
  95. {
  96. public:
  97. typedef enum FlagEnum {
  98. LEFTPRESS = 0x0001, // Left mouse button press.
  99. LEFTHELD = 0x0002, // Left mouse button is being held down.
  100. LEFTRELEASE = 0x0004, // Left mouse button released.
  101. LEFTUP = 0x0008, // Left mouse button is being held up.
  102. RIGHTPRESS = 0x0010, // Right mouse button press.
  103. RIGHTHELD = 0x0020, // Right mouse button is being held down.
  104. RIGHTRELEASE = 0x0040, // Right mouse button released.
  105. RIGHTUP = 0x0080, // Right mouse button is being held up.
  106. KEYBOARD = 0x0100 // Keyboard input processing (maybe).
  107. } FlagEnum;
  108. GadgetClass(int x, int y, int w, int h, unsigned flags, int sticky=false);
  109. GadgetClass(NoInitClass const & x) : LinkClass(x) {};
  110. GadgetClass(void) {};
  111. GadgetClass(GadgetClass const & gadget);
  112. virtual ~GadgetClass(void);
  113. /*
  114. ** Gadget list management functions.
  115. */
  116. virtual KeyNumType Input(void);
  117. virtual void Draw_All(bool forced=true);
  118. virtual void Delete_List(void);
  119. virtual ControlClass * Extract_Gadget(unsigned id);
  120. virtual void Flag_List_To_Redraw(void) {LastList = 0;};
  121. virtual GadgetClass * Remove(void);
  122. virtual GadgetClass * Get_Next(void) const;
  123. virtual GadgetClass * Get_Prev(void) const;
  124. /*
  125. ** Manages individual gadget states and actions.
  126. */
  127. virtual void Disable(void);
  128. virtual void Enable(void);
  129. virtual unsigned Get_ID(void) const {return 0;};
  130. virtual void Flag_To_Redraw(void);
  131. virtual void Peer_To_Peer(unsigned , KeyNumType & , ControlClass & ) {};
  132. virtual void Set_Focus(void);
  133. virtual void Clear_Focus(void);
  134. virtual bool Has_Focus(void);
  135. virtual int Is_List_To_Redraw(void);
  136. virtual bool Is_To_Redraw(void) {return (IsToRepaint);}
  137. virtual void Set_Position(int x, int y);
  138. /*
  139. ** General render function.
  140. */
  141. virtual int Draw_Me(int forced=false);
  142. /*
  143. ** Sets the current color scheme
  144. */
  145. static void Set_Color_Scheme(RemapControlType *scheme)
  146. { ColorScheme = scheme; }
  147. static RemapControlType * Get_Color_Scheme(void)
  148. { return (ColorScheme); }
  149. /*
  150. ** This is the coordinates and dimensions of the gadget region. These are in
  151. ** absolute screen pixel coordinates.
  152. */
  153. int X;
  154. int Y;
  155. int Width;
  156. int Height;
  157. protected:
  158. /*
  159. ** Processes the event flags so that if this gadget needs to "stick" or
  160. ** "unstick", it will be properly flagged. Call this function if you are
  161. ** going to clear the button press flags before calling the base class
  162. ** Action() function. Otherwise, calling this function manually, is
  163. ** unnecessary since the base class Action() function already does so.
  164. */
  165. virtual void Sticky_Process(unsigned flags);
  166. /*
  167. ** This is the action function that will be called whenever the flags and mouse
  168. ** input indicates. This is the main method by which this button performs a useful
  169. ** function.
  170. */
  171. virtual int Action(unsigned flags, KeyNumType & key);
  172. /*
  173. ** This is a record of the last list passed to the Input() function. If a list
  174. ** different than the last recorded one is detected, then the draw function is
  175. ** called for every gadget in the list. This causes all buttons to be redrawn the
  176. ** fire time Input() is called without forced a manual call to Draw_All().
  177. */
  178. static GadgetClass * LastList;
  179. /*
  180. ** This points to the gadget that has the keyboard focus. All keyboard only
  181. ** events are fed to this gadget to the exclusion of all others.
  182. */
  183. static GadgetClass * Focused;
  184. /*
  185. ** This button should call the Draw_Me function because some graphic element needs
  186. ** to be redrawn. This flag is set by default if the Action function is called.
  187. */
  188. unsigned IsToRepaint:1;
  189. public: // HACK HACK HACK.. this is here because the sidebar buttons are static.
  190. /*
  191. ** A sticky button is one that is processed to the exclusion of all other buttons
  192. ** IF the mouse was pressed down while over this button and the mouse continues
  193. ** to remain pressed. This is the standard behavior for all normal Windows style
  194. ** buttons.
  195. */
  196. unsigned IsSticky:1;
  197. // ajw - Publicized StuckOn 7/30/98 (was protected)
  198. /*
  199. ** If there is a sticky button being processed, then this will point to it. A sticky
  200. ** button is one that will ONLY be processed while the mouse button is being
  201. ** held down.
  202. */
  203. static GadgetClass * StuckOn;
  204. protected:
  205. /*
  206. ** If the button is disabled, then it won't be processed by the input function. It will
  207. ** have its Draw_Me function called as necessary. In order to not display the button
  208. ** at all, the appropriate draw function should perform no action -- just return. Or,
  209. ** just remove the button from the list.
  210. */
  211. unsigned IsDisabled:1;
  212. /*
  213. ** These are the action flags that are used to determine when the action function
  214. ** should be called. Example: If this gadget only wants the action button called when
  215. ** the left mouse button is pressed over the its region, then the flag will be set
  216. ** to LEFTPRESS.
  217. */
  218. unsigned Flags;
  219. /*
  220. ** This is the current color scheme; it must be initialized by the app.
  221. */
  222. static RemapControlType *ColorScheme;
  223. private:
  224. virtual int Clicked_On(KeyNumType & key, unsigned flags, int x, int y);
  225. };
  226. inline GadgetClass::FlagEnum operator |(GadgetClass::FlagEnum, GadgetClass::FlagEnum);
  227. inline GadgetClass::FlagEnum operator &(GadgetClass::FlagEnum, GadgetClass::FlagEnum);
  228. inline GadgetClass::FlagEnum operator ~(GadgetClass::FlagEnum);
  229. #endif