CONTROL.CPP 15 KB

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