DIAL8.CPP 13 KB

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