GADGET.H (13442B)
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: F:\projects\c&c\vcs\code\gadget.h_v 2.17 16 Oct 1995 16:46:34 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 [Ths 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 analagous 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 controlable 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 typedef enum FlagEnum { 100 LEFTPRESS = 0x0001, // Left mouse button press. 101 LEFTHELD = 0x0002, // Left mouse button is being held down. 102 LEFTRELEASE = 0x0004, // Left mouse button released. 103 LEFTUP = 0x0008, // Left mouse button is being held up. 104 RIGHTPRESS = 0x0010, // Right mouse button press. 105 RIGHTHELD = 0x0020, // Right mouse button is being held down. 106 RIGHTRELEASE = 0x0040, // Right mouse button released. 107 RIGHTUP = 0x0080, // Right mouse button is being held up. 108 KEYBOARD = 0x0100, // Keyboard input processing (maybe). 109 } FlagEnum; 110 111 GadgetClass(int x, int y, int w, int h, unsigned flags, int sticky=false); 112 GadgetClass(void) {}; 113 virtual ~GadgetClass(void); 114 // static GadgetClass * Create_One_Of(int x, int y, int w, int h, unsigned flags, int sticky=false); 115 116 /* 117 ** Gadget list management functions. 118 */ 119 virtual KeyNumType Input(void); 120 virtual void Draw_All(bool forced=true); 121 virtual void Delete_List(void); 122 virtual ControlClass * Extract_Gadget(unsigned id); 123 virtual void Flag_List_To_Redraw(void) {LastList = 0;}; 124 virtual GadgetClass * Remove(void); 125 virtual GadgetClass * Get_Next(void) const; 126 virtual GadgetClass * Get_Prev(void) const; 127 128 /* 129 ** Manages individual gadget states and actions. 130 */ 131 virtual void Disable(void); 132 virtual void Enable(void); 133 virtual unsigned Get_ID(void) const {return 0;}; 134 virtual void Flag_To_Redraw(void); 135 virtual void Peer_To_Peer(unsigned , KeyNumType & , ControlClass & ) {}; 136 virtual void Set_Focus(void); 137 virtual void Clear_Focus(void); 138 virtual bool Has_Focus(void); 139 virtual int Is_List_To_Redraw(void); 140 141 /* 142 ** General render function. 143 */ 144 virtual int Draw_Me(int forced=false); 145 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 155 protected: 156 157 /* 158 ** Processes the event flags so that if this gadget needs to "stick" or 159 ** "unstick", it will be properly flagged. Call this function if you are 160 ** going to clear the button press flags before calling the base class 161 ** Action() function. Otherwise, calling this function manually, is 162 ** unnecessary since the base class Action() function already does so. 163 */ 164 virtual void Sticky_Process(unsigned flags); 165 166 /* 167 ** This is the action functio 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 /* 174 ** If there is a sticky button being processed, then this will point to it. A sticky 175 ** button is one that will ONLY be processed while the mouse button is being 176 ** held down. 177 */ 178 static GadgetClass * StuckOn; 179 180 /* 181 ** This is a record of the last list passed to the Input() function. If a list 182 ** different than the last recorded one is detected, then the draw function is 183 ** called for every gadget in the list. This causes all buttons to be redrawn the 184 ** fire time Input() is called without forced a manual call to Draw_All(). 185 */ 186 static GadgetClass * LastList; 187 188 /* 189 ** This points to the gadget that has the keyboard focus. All keyboard only 190 ** events are fed to this gadget to the exclusion of all others. 191 */ 192 static GadgetClass * Focused; 193 194 /* 195 ** This button should call the Draw_Me function because some graphic element needs 196 ** to be redrawn. This flag is set by default if the Action function is called. 197 */ 198 unsigned IsToRepaint:1; 199 200 public: // HACK HACK HACK.. this is here becuase the sidebar buttons are static. 201 /* 202 ** A sticky button is one that is processed to the exclusion of all other buttons 203 ** IF the mouse was pressed down while over this button and the mouse continues 204 ** to remain pressed. This is the standard behavior for all normal Windows style 205 ** buttons. 206 */ 207 unsigned IsSticky:1; 208 209 protected: 210 211 /* 212 ** If the button is disabled, then it won't be processed by the input function. It will 213 ** have its Draw_Me function called as necessary. In order to not display the button 214 ** at all, the appropriate draw function should perform no action -- just return. Or, 215 ** just remove the button from the list. 216 */ 217 unsigned IsDisabled:1; 218 219 /* 220 ** These are the action flags that are used to determine when the action function 221 ** should be called. Example: If this gadget only wants the action button called when 222 ** the left mouse button is pressed over the its region, then the flag will be set 223 ** to LEFTPRESS. 224 */ 225 unsigned Flags; 226 227 private: 228 public: //ST - 1/21/2019 12:06PM 229 virtual int Clicked_On(KeyNumType & key, unsigned flags, int x, int y); 230 }; 231 232 //inline GadgetClass::FlagEnum operator |(GadgetClass::FlagEnum, GadgetClass::FlagEnum); 233 //inline GadgetClass::FlagEnum operator &(GadgetClass::FlagEnum, GadgetClass::FlagEnum); 234 //inline GadgetClass::FlagEnum operator ~(GadgetClass::FlagEnum); 235 236 inline GadgetClass::FlagEnum operator|(GadgetClass::FlagEnum a, GadgetClass::FlagEnum b) 237 {return static_cast<GadgetClass::FlagEnum>(static_cast<int>(a) | static_cast<int>(b));} 238 239 inline GadgetClass::FlagEnum operator&(GadgetClass::FlagEnum a, GadgetClass::FlagEnum b) 240 {return static_cast<GadgetClass::FlagEnum>(static_cast<int>(a) & static_cast<int>(b));} 241 242 inline GadgetClass::FlagEnum operator~(GadgetClass::FlagEnum a) 243 {return static_cast<GadgetClass::FlagEnum>(~static_cast<int>(a));} 244 245 #endif