CONTROL.CPP (15787B)
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/CONTROL.CPP 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 : CONTROL.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 01/15/95 * 28 * * 29 * Last Update : December 5, 1995 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * ControlClass::Action -- Normal action for control gadget objects. * 34 * ControlClass::ControlClass -- Constructor for control class objects. * 35 * ControlClass::ControlClass -- Copy constructor for control gadget. * 36 * ControlClass::Draw_Me -- Draw logic for the control class object. * 37 * ControlClass::Get_ID -- Gets the ID number for this gadget. * 38 * ControlClass::Make_Peer -- Assigns a peer gadget to this gadget. * 39 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 40 41 #include "function.h" 42 43 44 /*********************************************************************************************** 45 * ControlClass::ControlClass -- Constructor for control class objects. * 46 * * 47 * This is the normal constructor for control class objects. At this level, it only needs * 48 * to record the ID number assigned to this button. * 49 * * 50 * INPUT: id -- The ID number for this gadget. If the ID number specified is 0, then * 51 * this tells the system that no special ID code should be returned. * 52 * * 53 * x,y -- Pixel coordinate of upper left corner of gadget's region. * 54 * * 55 * w,h -- Pixel dimensions of the gadget's region. * 56 * * 57 * flags -- The input event flags that this gadget recognizes. * 58 * * 59 * sticky-- This this a "sticky" gadget? A sticky gadget is one that takes over the * 60 * gadget list while the mouse button is held down, if the mouse button was * 61 * initially clicked over its region. This is the behavior of "normal" * 62 * buttons in Windows. * 63 * * 64 * OUTPUT: none * 65 * * 66 * WARNINGS: none * 67 * * 68 * HISTORY: * 69 * 01/15/1995 JLB : Created. * 70 *=============================================================================================*/ 71 ControlClass::ControlClass(unsigned id, int x, int y, int w, int h, unsigned flags, int sticky) : 72 GadgetClass(x, y, w, h, flags, sticky), 73 ID(id), 74 Peer(0) 75 { 76 } 77 78 79 /*********************************************************************************************** 80 * ControlClass::ControlClass -- Copy constructor for control gadget. * 81 * * 82 * This copy constructor for a control gadget is used create a duplicate gadget that * 83 * is functionally similar. * 84 * * 85 * INPUT: control -- Reference to the gadget that is to be copied. * 86 * * 87 * OUTPUT: none * 88 * * 89 * WARNINGS: none * 90 * * 91 * HISTORY: * 92 * 12/05/1995 JLB : Created. * 93 *=============================================================================================*/ 94 ControlClass::ControlClass(ControlClass const & control) : 95 GadgetClass(control), 96 ID(control.ID), 97 Peer(control.Peer) 98 { 99 } 100 101 /*********************************************************************************************** 102 * ControlClass::Action -- Normal action for control gadget objects. * 103 * * 104 * This function gets called when the input event that this control gadget is looking for * 105 * occurs. In such a case, the return key code value is changed to the gadget's ID number * 106 * with the special button bit flag attached. * 107 * * 108 * INPUT: flags -- The event that triggered this function call. If this value is NULL, then * 109 * this is a forced (probably due to the sticky flag) call and the key code * 110 * is not altered. * 111 * * 112 * key -- Reference to the key code that will be returned by the controlling * 113 * Input() function. * 114 * * 115 * OUTPUT: bool; Should further list processing be aborted? * 116 * * 117 * WARNINGS: none * 118 * * 119 * HISTORY: * 120 * 01/15/1995 JLB : Created. * 121 *=============================================================================================*/ 122 int ControlClass::Action(unsigned flags, KeyNumType & key) 123 { 124 125 /* 126 ** Only if the flags indicate that a recognized action has occurred, do the 127 ** normal processing of this gadget and set return value to the gadget ID. 128 */ 129 if (flags) { 130 if (ID) { 131 key = (KeyNumType)(ID | KN_BUTTON); 132 } else { 133 key = KN_NONE; 134 } 135 } 136 137 /* 138 ** If there is a peer link established, inform that gadget of this 139 ** action call. 140 */ 141 if (Peer) { 142 Peer->Peer_To_Peer(flags, key, *this); 143 } 144 145 return(GadgetClass::Action(flags, key)); 146 } 147 148 149 /*********************************************************************************************** 150 * ControlClass::Make_Peer -- Assigns a peer gadget to this gadget. * 151 * * 152 * This function will assign another gadget to this one. That other gadget will receive * 153 * notification of any Action() call to this gadget. Presumably, this is how one gadget * 154 * can automatically adapt to changes in another. Say for example, a slider bar can affect * 155 * the list box it is attached to. * 156 * * 157 * INPUT: gadget -- The gadget to inform when any Action() function is called. * 158 * * 159 * OUTPUT: none * 160 * * 161 * WARNINGS: none * 162 * * 163 * HISTORY: * 164 * 01/16/1995 JLB : Created. * 165 *=============================================================================================*/ 166 void ControlClass::Make_Peer(GadgetClass & gadget) 167 { 168 Peer = &gadget; 169 } 170 171 172 /*********************************************************************************************** 173 * ControlClass::Get_ID -- Gets the ID number for this gadget. * 174 * * 175 * This function will query and return with the ID number for this gadget. It is primarily * 176 * used by the Extract_Gadget() function. * 177 * * 178 * INPUT: none * 179 * * 180 * OUTPUT: Returns with the ID number for this gadget. If zero is returned, this means that * 181 * no ID was assigned to this gadget. This is a special case since a zero value will * 182 * never be returned as a pseudo-key as is done with non-zero values. * 183 * * 184 * WARNINGS: none * 185 * * 186 * HISTORY: * 187 * 01/16/1995 JLB : Created. * 188 *=============================================================================================*/ 189 unsigned ControlClass::Get_ID(void) const 190 { 191 return(ID); 192 } 193 194 195 /*********************************************************************************************** 196 * ControlClass::Draw_Me -- Draw logic for the control class object. * 197 * * 198 * This is called when the control object might need to be redrawn or when redrawing is * 199 * necessary. Since at this level of the class hierarchy, no actual drawing occurs, this * 200 * routine doesn't perform any rendering. It does, however, inform any peer attached * 201 * object that a Draw_Me function has been called. Presumably, the attached peer gadget * 202 * might very well need to be redrawn as a result of some action by this gadget. Since this * 203 * gadget might, more than likely, be of the "sticky" variety, a normal call to Draw_Me * 204 * for the other gadget will not occur. It must rely on the call by this routine in order * 205 * to update correctly. A typical example of this would be a slider that is attached to * 206 * a list box. As the slider is being drug around, the attached list box must be redrawn. * 207 * * 208 * INPUT: forced -- Should the redraw be forced regardless of the redraw flag? * 209 * * 210 * OUTPUT: bool; Was the gadget redrawn? * 211 * * 212 * WARNINGS: none * 213 * * 214 * HISTORY: * 215 * 01/16/1995 JLB : Created. * 216 *=============================================================================================*/ 217 int ControlClass::Draw_Me(int forced) 218 { 219 if (Peer) { 220 Peer->Draw_Me(); 221 } 222 return(GadgetClass::Draw_Me(forced)); 223 }