CONTROL.CPP 15 KB

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