DIAL8.CPP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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\dial8.cpv 2.18 16 Oct 1995 16:51:32 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 : DIAL8.CPP *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : February 6, 1995 *
  30. * *
  31. * Last Update : February 6, 1995 [BR] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * Functions: *
  35. * Dial8Class::Action -- action routine for Dial8Class *
  36. * Dial8Class::Dial8Class -- constructor for the facing dial *
  37. * Dial8Class::Draw_Me -- render routine for Dial8Class *
  38. * Dial8Class::Get_Direction -- retrieves direction (0-255) of dial *
  39. * Dial8Class::Set_Direction -- sets current direction (0-255) of dial *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "function.h"
  42. /***************************************************************************
  43. * Dial8Class::Dial8Class -- constructor for the facing dial *
  44. * *
  45. * INPUT: *
  46. * id button ID *
  47. * x,y,w,h dimensions in window-relative pixels *
  48. * dir numerical initial facing value (0-255); this is the *
  49. * value returned by WWLIB Desired_Facing8() *
  50. * *
  51. * OUTPUT: *
  52. * none. *
  53. * *
  54. * WARNINGS: *
  55. * none. *
  56. * *
  57. * HISTORY: *
  58. * 11/16/1994 BR : Created. *
  59. *=========================================================================*/
  60. Dial8Class::Dial8Class(int id, int x, int y, int w, int h, DirType dir) :
  61. ControlClass(id, x, y, w, h, LEFTPRESS | LEFTHELD | LEFTRELEASE, true)
  62. {
  63. /*
  64. ** Center coordinates.
  65. */
  66. FaceX = X + (Width / 2);
  67. FaceY = Y + (Height / 2);
  68. /*
  69. ** Init directions.
  70. */
  71. Direction = dir; // 0 - 255
  72. Facing = Dir_Facing(Direction); // 0 - 7
  73. OldFacing = Facing; // 0 - 7
  74. /*
  75. ** Compute the drawing dimensions: a 45-degree angle intersects a unity-
  76. ** radius circle at (.707,.707). Make the decorations 8/10 of the radius,
  77. ** and the line extend to 6/10 of the radius. Use Width/2 for x-radius,
  78. ** Height/2 for y-radius.
  79. */
  80. FacePoint[0][0] = FaceX;
  81. FacePoint[0][1] = FaceY - (h * 8 / 2) / 10;
  82. FacePoint[1][0] = FaceX + (w * 7 * 8 / 2) / 100;
  83. FacePoint[1][1] = FaceY - (h * 7 * 8 / 2) / 100;
  84. FacePoint[2][0] = FaceX + (w * 8 / 2) / 10;
  85. FacePoint[2][1] = FaceY;
  86. FacePoint[3][0] = FaceX + (w * 7 * 8 / 2) / 100;
  87. FacePoint[3][1] = FaceY + (h * 7 * 8 / 2) / 100;
  88. FacePoint[4][0] = FaceX;
  89. FacePoint[4][1] = FaceY + (h * 8 / 2) / 10;
  90. FacePoint[5][0] = FaceX - (w * 7 * 8 / 2) / 100;
  91. FacePoint[5][1] = FaceY + (h * 7 * 8 / 2) / 100;
  92. FacePoint[6][0] = FaceX - (w * 8 / 2) / 10;
  93. FacePoint[6][1] = FaceY;
  94. FacePoint[7][0] = FaceX - (w * 7 * 8 / 2) / 100;
  95. FacePoint[7][1] = FaceY - (h * 7 * 8 / 2) / 100;
  96. FaceLine[0][0] = FaceX;
  97. FaceLine[0][1] = FaceY - (h * 6 / 2) / 10;
  98. FaceLine[1][0] = FaceX + (w * 7 * 6 / 2) / 100;
  99. FaceLine[1][1] = FaceY - (h * 7 * 6 / 2) / 100;
  100. FaceLine[2][0] = FaceX + (w * 6 / 2) / 10;
  101. FaceLine[2][1] = FaceY;
  102. FaceLine[3][0] = FaceX + (w * 7 * 6 / 2) / 100;
  103. FaceLine[3][1] = FaceY + (h * 7 * 6 / 2) / 100;
  104. FaceLine[4][0] = FaceX;
  105. FaceLine[4][1] = FaceY + (h * 6 / 2) / 10;
  106. FaceLine[5][0] = FaceX - (w * 7 * 6 / 2) / 100;
  107. FaceLine[5][1] = FaceY + (h * 7 * 6 / 2) / 100;
  108. FaceLine[6][0] = FaceX - (w * 6 / 2) / 10;
  109. FaceLine[6][1] = FaceY;
  110. FaceLine[7][0] = FaceX - (w * 7 * 6 / 2) / 100;
  111. FaceLine[7][1] = FaceY - (h * 7 * 6 / 2) / 100;
  112. }
  113. /***************************************************************************
  114. * Dial8Class::Action -- activation function for Dial8Class *
  115. * *
  116. * INPUT: *
  117. * flags the reason we're being called *
  118. * key the KN_number that was pressed *
  119. * *
  120. * OUTPUT: *
  121. * true = event was processed, false = event not processed *
  122. * *
  123. * WARNINGS: *
  124. * none. *
  125. * *
  126. * HISTORY: *
  127. * 02/06/1995 BR : Created. *
  128. *=========================================================================*/
  129. int Dial8Class::Action(unsigned flags, KeyNumType &key)
  130. {
  131. static int is_sel = 0;
  132. /*
  133. ** We might end up clearing the event bits. Make sure that the sticky
  134. ** process is properly updated anyway.
  135. */
  136. Sticky_Process(flags);
  137. if (flags & LEFTPRESS) {
  138. is_sel = 1;
  139. }
  140. /*
  141. ** If left mouse is clicked or held, and the dial has changed its direction,
  142. ** invoke the parent Action routine:
  143. ** GadgetClass::Action handles Sticky processing, & sets IsToRepaint if any
  144. ** flag bits are set.
  145. ** ControlClass::Action handles Peer_To_Peer notification, and substitues
  146. ** 'key' with the button ID if any flags are set, or 0 if no flags are set
  147. */
  148. if (flags & LEFTPRESS || ((flags & LEFTHELD) && is_sel)) {
  149. /*
  150. ** Get new dial position (0-255)
  151. */
  152. Direction = (DirType)Desired_Facing8(FaceX, FaceY, Get_Mouse_X(), Get_Mouse_Y());
  153. /*
  154. ** Convert to Facing value (0-7).
  155. */
  156. Facing = Dir_Facing(Direction);
  157. /*
  158. ** If it's moved, redraw.
  159. */
  160. if (Facing!=OldFacing) {
  161. OldFacing = Facing;
  162. ControlClass::Action(flags,key);
  163. return(true);
  164. } else {
  165. /*
  166. ** Dial hasn't moved; kill the event & return
  167. */
  168. key = KN_NONE;
  169. ControlClass::Action(0,key);
  170. return(true);
  171. }
  172. } else {
  173. /*
  174. ** Otherwise, no events have occurred; kill the event if it's a LEFTRELEASE,
  175. ** and return
  176. */
  177. if (flags & LEFTRELEASE) {
  178. key = KN_NONE;
  179. is_sel = 0;
  180. }
  181. return(ControlClass::Action(0,key));
  182. }
  183. }
  184. /***************************************************************************
  185. * Dial8Class::Draw_Me -- custom render routine for Dial8Class *
  186. * *
  187. * INPUT: *
  188. * forced true = draw regardless of the current redraw flag state*
  189. * *
  190. * OUTPUT: *
  191. * true = gadget was redrawn, false = wasn't *
  192. * *
  193. * WARNINGS: *
  194. * none. *
  195. * *
  196. * HISTORY: *
  197. * 02/06/1995 BR : Created. *
  198. *=========================================================================*/
  199. int Dial8Class::Draw_Me(int forced)
  200. {
  201. /*
  202. ** Redraw if parent indicates a redraw is needed
  203. */
  204. if (ControlClass::Draw_Me(forced)) {
  205. /*
  206. ** Hide the mouse.
  207. */
  208. if (LogicPage == &SeenBuff) {
  209. Hide_Mouse();
  210. }
  211. /*
  212. ** Draw background & decorations.
  213. */
  214. Draw_Box(X, Y, Width, Height, BOXSTYLE_GREEN_DOWN, true);
  215. for (int i=0; i<8; i++) {
  216. Draw_Box(FacePoint[i][0] - 1, FacePoint[i][1] -1, 3, 3, BOXSTYLE_GREEN_RAISED, false);
  217. }
  218. /*
  219. ** Draw the hand & its shadow.
  220. */
  221. LogicPage->Draw_Line(FaceX+1, FaceY+1, FaceLine[Facing][0]+1, FaceLine[Facing][1]+1,CC_GREEN_SHADOW);
  222. LogicPage->Draw_Line(FaceX, FaceY, FaceLine[Facing][0], FaceLine[Facing][1],CC_LIGHT_GREEN);
  223. /*
  224. ** Restore the mouse.
  225. */
  226. if (LogicPage == &SeenBuff) {
  227. Show_Mouse();
  228. }
  229. return(true);
  230. }
  231. return(false);
  232. }
  233. /***************************************************************************
  234. * Dial8Class::Get_Direction -- retrieves direction (0-255) of dial *
  235. * *
  236. * INPUT: *
  237. * none. *
  238. * *
  239. * OUTPUT: *
  240. * DirType dial is pointing to *
  241. * *
  242. * WARNINGS: *
  243. * none. *
  244. * *
  245. * HISTORY: *
  246. * 11/17/1994 BR : Created. *
  247. *=========================================================================*/
  248. DirType Dial8Class::Get_Direction(void) const
  249. {
  250. return(Direction);
  251. }
  252. /***************************************************************************
  253. * Dial8Class::Set_Direction -- sets current direction (0-255) of dial *
  254. * *
  255. * INPUT: *
  256. * DirType to set dial to *
  257. * *
  258. * OUTPUT: *
  259. * none. *
  260. * *
  261. * WARNINGS: *
  262. * none. *
  263. * *
  264. * HISTORY: *
  265. * 11/17/1994 BR : Created. *
  266. *=========================================================================*/
  267. void Dial8Class::Set_Direction(DirType dir)
  268. {
  269. Direction = dir;
  270. Facing = Dir_Facing(Direction);
  271. OldFacing = Facing;
  272. Flag_To_Redraw();
  273. }