SHAPEBTN.CPP 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/SHAPEBTN.CPP 1 3/03/97 10:25a 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 : SHAPEBTN.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 01/15/95 *
  26. * *
  27. * Last Update : September 20, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * ShapeButtonClass::Draw_Me -- Renders the shape button's imagery. *
  32. * ShapeButtonClass::Set_Shape -- Assigns a shape to this shape button. *
  33. * ShapeButtonClass::ShapeButtonClass -- Constructor for a shape type button. *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "function.h"
  36. #include "shapebtn.h"
  37. /***********************************************************************************************
  38. * ShapeButtonClass::ShapeButtonClass -- Default Constructor for a shape type button. *
  39. * *
  40. * INPUT: none *
  41. * *
  42. * OUTPUT: none *
  43. * *
  44. * WARNINGS: You must call Set_Shape() before using a button constructed with this function, *
  45. * and you must set X & Y, and ID. *
  46. * *
  47. * HISTORY: *
  48. * 01/15/1995 JLB : Created. *
  49. *=============================================================================================*/
  50. ShapeButtonClass::ShapeButtonClass(void) :
  51. ToggleClass(0, 0, 0, 0, 0),
  52. ReflectButtonState(false)
  53. {
  54. }
  55. /***********************************************************************************************
  56. * ShapeButtonClass::ShapeButtonClass -- Constructor for a shape type button. *
  57. * *
  58. * This is the normal constructor for a shape type button. Shape buttons are ones that *
  59. * have their imagery controlled by a shape file. The various states of the button are *
  60. * given a visual form as one of these shapes. Button dimensions are controlled by the *
  61. * first shape. *
  62. * *
  63. * INPUT: id -- The button ID. *
  64. * *
  65. * shape -- Pointer to the shape file that controls the button's display. *
  66. * *
  67. * x,y -- The pixel coordinate of the upper left corner of the button. *
  68. * *
  69. * OUTPUT: none *
  70. * *
  71. * WARNINGS: The width and height of the shape is controlled by the first shape in the *
  72. * shape file provided. This means that all the shapes in the shape file must be *
  73. * the same size. *
  74. * *
  75. * HISTORY: *
  76. * 01/15/1995 JLB : Created. *
  77. *=============================================================================================*/
  78. ShapeButtonClass::ShapeButtonClass(unsigned id, void const * shape, int x, int y) :
  79. ToggleClass(id, x, y, 0, 0),
  80. ReflectButtonState(false)
  81. {
  82. // Width = 0;
  83. // Height = 0;
  84. Set_Shape(shape);
  85. }
  86. /***********************************************************************************************
  87. * ShapeButtonClass::Set_Shape -- Assigns a shape to this shape button. *
  88. * *
  89. * This routine will assign the specified shape to this shape object. *
  90. * *
  91. * INPUT: data -- Pointer to the shape to assign. *
  92. * *
  93. * OUTPUT: none *
  94. * *
  95. * WARNINGS: none *
  96. * *
  97. * HISTORY: *
  98. * 09/20/1995 JLB : Created. *
  99. *=============================================================================================*/
  100. void ShapeButtonClass::Set_Shape(void const * data)
  101. {
  102. ShapeData = data;
  103. if (ShapeData) {
  104. Width = Get_Build_Frame_Width(ShapeData);
  105. Height = Get_Build_Frame_Height(ShapeData);
  106. }
  107. }
  108. /***********************************************************************************************
  109. * ShapeButtonClass::Draw_Me -- Renders the shape button's imagery. *
  110. * *
  111. * This function is called when the button detects that it must be redrawn. The actual *
  112. * shape to use is controled by the button's state and the shape file provided when then *
  113. * button was constructed. *
  114. * *
  115. * INPUT: forced -- Should the button be redrawn regardless of the redraw flag? *
  116. * *
  117. * OUTPUT: bool; Was the shape redrawn? *
  118. * *
  119. * WARNINGS: none *
  120. * *
  121. * HISTORY: *
  122. * 01/15/1995 JLB : Created. *
  123. *=============================================================================================*/
  124. int ShapeButtonClass::Draw_Me(int forced)
  125. {
  126. if (ControlClass::Draw_Me(forced) && ShapeData) {
  127. /*
  128. ** Hide the mouse.
  129. */
  130. if (LogicPage == &SeenBuff) {
  131. Conditional_Hide_Mouse(X, Y, X+Width-1, Y+Height-1);
  132. }
  133. /*
  134. ** Draw the body & set text color.
  135. */
  136. int shapenum = 0;
  137. if (IsDisabled) {
  138. shapenum = DISABLED_SHAPE;
  139. } else {
  140. if (!ReflectButtonState) {
  141. if (IsPressed) {
  142. shapenum = DOWN_SHAPE;
  143. } else {
  144. shapenum = UP_SHAPE;
  145. }
  146. } else {
  147. shapenum = IsOn;
  148. }
  149. }
  150. CC_Draw_Shape(ShapeData, shapenum, X, Y, WINDOW_MAIN, SHAPE_NORMAL);
  151. /*
  152. ** Display the mouse.
  153. */
  154. if (LogicPage == &SeenBuff) {
  155. Conditional_Show_Mouse();
  156. }
  157. return(true);
  158. }
  159. return(false);
  160. }