GADGET.H 14 KB

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