CONTROL.CPP 14 KB

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