GADGET.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. ** Command & Conquer(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: F:\projects\c&c\vcs\code\gadget.h_v 2.17 16 Oct 1995 16:46:34 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 [Ths 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 analagous 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 controlable 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(void) {};
  110. virtual ~GadgetClass(void);
  111. // static GadgetClass * Create_One_Of(int x, int y, int w, int h, unsigned flags, int sticky=false);
  112. /*
  113. ** Gadget list management functions.
  114. */
  115. virtual KeyNumType Input(void);
  116. virtual void Draw_All(bool forced=true);
  117. virtual void Delete_List(void);
  118. virtual ControlClass * Extract_Gadget(unsigned id);
  119. virtual void Flag_List_To_Redraw(void) {LastList = 0;};
  120. virtual GadgetClass * Remove(void);
  121. virtual GadgetClass * Get_Next(void) const;
  122. virtual GadgetClass * Get_Prev(void) const;
  123. /*
  124. ** Manages individual gadget states and actions.
  125. */
  126. virtual void Disable(void);
  127. virtual void Enable(void);
  128. virtual unsigned Get_ID(void) const {return 0;};
  129. virtual void Flag_To_Redraw(void);
  130. virtual void Peer_To_Peer(unsigned , KeyNumType & , ControlClass & ) {};
  131. virtual void Set_Focus(void);
  132. virtual void Clear_Focus(void);
  133. virtual bool Has_Focus(void);
  134. virtual int Is_List_To_Redraw(void);
  135. /*
  136. ** General render function.
  137. */
  138. virtual int Draw_Me(int forced=false);
  139. /*
  140. ** This is the coordinates and dimensions of the gadget region. These are in
  141. ** absolute screen pixel coordinates.
  142. */
  143. int X;
  144. int Y;
  145. int Width;
  146. int Height;
  147. protected:
  148. /*
  149. ** Processes the event flags so that if this gadget needs to "stick" or
  150. ** "unstick", it will be properly flagged. Call this function if you are
  151. ** going to clear the button press flags before calling the base class
  152. ** Action() function. Otherwise, calling this function manually, is
  153. ** unnecessary since the base class Action() function already does so.
  154. */
  155. virtual void Sticky_Process(unsigned flags);
  156. /*
  157. ** This is the action functio that will be called whenever the flags and mouse
  158. ** input indicates. This is the main method by which this button performs a useful
  159. ** function.
  160. */
  161. virtual int Action(unsigned flags, KeyNumType & key);
  162. /*
  163. ** If there is a sticky button being processed, then this will point to it. A sticky
  164. ** button is one that will ONLY be processed while the mouse button is being
  165. ** held down.
  166. */
  167. static GadgetClass * StuckOn;
  168. /*
  169. ** This is a record of the last list passed to the Input() function. If a list
  170. ** different than the last recorded one is detected, then the draw function is
  171. ** called for every gadget in the list. This causes all buttons to be redrawn the
  172. ** fire time Input() is called without forced a manual call to Draw_All().
  173. */
  174. static GadgetClass * LastList;
  175. /*
  176. ** This points to the gadget that has the keyboard focus. All keyboard only
  177. ** events are fed to this gadget to the exclusion of all others.
  178. */
  179. static GadgetClass * Focused;
  180. /*
  181. ** This button should call the Draw_Me function because some graphic element needs
  182. ** to be redrawn. This flag is set by default if the Action function is called.
  183. */
  184. unsigned IsToRepaint:1;
  185. public: // HACK HACK HACK.. this is here becuase the sidebar buttons are static.
  186. /*
  187. ** A sticky button is one that is processed to the exclusion of all other buttons
  188. ** IF the mouse was pressed down while over this button and the mouse continues
  189. ** to remain pressed. This is the standard behavior for all normal Windows style
  190. ** buttons.
  191. */
  192. unsigned IsSticky:1;
  193. protected:
  194. /*
  195. ** If the button is disabled, then it won't be processed by the input function. It will
  196. ** have its Draw_Me function called as necessary. In order to not display the button
  197. ** at all, the appropriate draw function should perform no action -- just return. Or,
  198. ** just remove the button from the list.
  199. */
  200. unsigned IsDisabled:1;
  201. /*
  202. ** These are the action flags that are used to determine when the action function
  203. ** should be called. Example: If this gadget only wants the action button called when
  204. ** the left mouse button is pressed over the its region, then the flag will be set
  205. ** to LEFTPRESS.
  206. */
  207. unsigned Flags;
  208. private:
  209. virtual int Clicked_On(KeyNumType & key, unsigned flags, int x, int y);
  210. };
  211. inline GadgetClass::FlagEnum operator |(GadgetClass::FlagEnum, GadgetClass::FlagEnum);
  212. inline GadgetClass::FlagEnum operator &(GadgetClass::FlagEnum, GadgetClass::FlagEnum);
  213. inline GadgetClass::FlagEnum operator ~(GadgetClass::FlagEnum);
  214. #endif