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