inputctrl.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/inputctrl.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/17/02 11:18a $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "inputctrl.h"
  36. #include "assetmgr.h"
  37. #include "refcount.h"
  38. #include "font3d.h"
  39. #include "mousemgr.h"
  40. #include "ww3d.h"
  41. #include "dialogmgr.h"
  42. #include "dialogbase.h"
  43. #include "stylemgr.h"
  44. ////////////////////////////////////////////////////////////////
  45. //
  46. // InputCtrlClass
  47. //
  48. ////////////////////////////////////////////////////////////////
  49. InputCtrlClass::InputCtrlClass (void) :
  50. KeyAssignment (0),
  51. MouseIgnoreTime (0),
  52. UserData (0),
  53. PendingKeyID (-1)
  54. {
  55. //
  56. // Set the font for the text renderers
  57. //
  58. StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_CONTROLS);
  59. StyleMgrClass::Configure_Renderer (&ControlRenderer);
  60. return ;
  61. }
  62. ////////////////////////////////////////////////////////////////
  63. //
  64. // ~InputCtrlClass
  65. //
  66. ////////////////////////////////////////////////////////////////
  67. InputCtrlClass::~InputCtrlClass (void)
  68. {
  69. return ;
  70. }
  71. ////////////////////////////////////////////////////////////////
  72. //
  73. // Create_Text_Renderers
  74. //
  75. ////////////////////////////////////////////////////////////////
  76. void
  77. InputCtrlClass::Create_Text_Renderers (void)
  78. {
  79. HilightRenderer.Reset ();
  80. HilightRenderer.Set_Coordinate_Range (Render2DClass::Get_Screen_Resolution());
  81. StyleMgrClass::Configure_Hilighter (&HilightRenderer);
  82. //
  83. // Start fresh
  84. //
  85. TextRenderer.Reset ();
  86. //
  87. // Draw the text
  88. //
  89. StyleMgrClass::Render_Text (Title, &TextRenderer, ClientRect, true, true,
  90. StyleMgrClass::CENTER_JUSTIFY, IsEnabled);
  91. //
  92. // Do the hilight
  93. //
  94. if (HasFocus) {
  95. StyleMgrClass::Render_Hilight (&HilightRenderer, ClientRect);
  96. }
  97. return ;
  98. }
  99. ////////////////////////////////////////////////////////////////
  100. //
  101. // Create_Control_Renderers
  102. //
  103. ////////////////////////////////////////////////////////////////
  104. void
  105. InputCtrlClass::Create_Control_Renderers (void)
  106. {
  107. Render2DClass &renderer = ControlRenderer;
  108. //
  109. // Configure this renderer
  110. //
  111. renderer.Reset ();
  112. renderer.Enable_Texturing (false);
  113. //
  114. // Determine which color to draw the outline in
  115. //
  116. int color = StyleMgrClass::Get_Line_Color ();
  117. int bkcolor = StyleMgrClass::Get_Bk_Color ();
  118. if (IsEnabled == false) {
  119. color = StyleMgrClass::Get_Disabled_Line_Color ();
  120. bkcolor = StyleMgrClass::Get_Disabled_Bk_Color ();
  121. }
  122. //
  123. // Draw the outline
  124. //
  125. renderer.Add_Outline (Rect, 1.0F, color);
  126. //
  127. // Now draw the background
  128. //
  129. RectClass rect = Rect;
  130. rect.Right -= 1;
  131. rect.Bottom -= 1;
  132. renderer.Add_Quad (rect, bkcolor);
  133. return ;
  134. }
  135. ////////////////////////////////////////////////////////////////
  136. //
  137. // On_Set_Cursor
  138. //
  139. ////////////////////////////////////////////////////////////////
  140. void
  141. InputCtrlClass::On_Set_Cursor (const Vector2 &mouse_pos)
  142. {
  143. //
  144. // Change the mouse cursor
  145. //
  146. MouseMgrClass::Set_Cursor (MouseMgrClass::CURSOR_ACTION);
  147. return ;
  148. }
  149. ////////////////////////////////////////////////////////////////
  150. //
  151. // Update_Client_Rect
  152. //
  153. ////////////////////////////////////////////////////////////////
  154. void
  155. InputCtrlClass::Update_Client_Rect (void)
  156. {
  157. //
  158. // Set the client area
  159. //
  160. ClientRect = Rect;
  161. ClientRect.Inflate (Vector2 (-1, -1));
  162. Set_Dirty ();
  163. return ;
  164. }
  165. ////////////////////////////////////////////////////////////////
  166. //
  167. // Render
  168. //
  169. ////////////////////////////////////////////////////////////////
  170. void
  171. InputCtrlClass::Render (void)
  172. {
  173. if (PendingKeyID != -1) {
  174. //
  175. // Use the pending key
  176. //
  177. if (PendingKeyID >= 0 && PendingKeyID <= 256) {
  178. On_New_Key (PendingKeyID);
  179. }
  180. PendingKeyID = -1;
  181. }
  182. //
  183. // Recreate the renderers (if necessary)
  184. //
  185. if (IsDirty) {
  186. Create_Control_Renderers ();
  187. Create_Text_Renderers ();
  188. }
  189. //
  190. // Render the background and text for the current state
  191. //
  192. ControlRenderer.Render ();
  193. TextRenderer.Render ();
  194. HilightRenderer.Render ();
  195. DialogControlClass::Render ();
  196. return ;
  197. }
  198. ////////////////////////////////////////////////////////////////
  199. //
  200. // On_LButton_Down
  201. //
  202. ////////////////////////////////////////////////////////////////
  203. void
  204. InputCtrlClass::On_LButton_Down (const Vector2 &mouse_pos)
  205. {
  206. if (HasFocus && DialogMgrClass::Get_Time () > MouseIgnoreTime) {
  207. On_New_Key (VK_LBUTTON);
  208. }
  209. return ;
  210. }
  211. ////////////////////////////////////////////////////////////////
  212. //
  213. // On_RButton_Down
  214. //
  215. ////////////////////////////////////////////////////////////////
  216. void
  217. InputCtrlClass::On_RButton_Down (const Vector2 &mouse_pos)
  218. {
  219. if (HasFocus) {
  220. On_New_Key (VK_RBUTTON);
  221. }
  222. return ;
  223. }
  224. ////////////////////////////////////////////////////////////////
  225. //
  226. // On_MButton_Down
  227. //
  228. ////////////////////////////////////////////////////////////////
  229. void
  230. InputCtrlClass::On_MButton_Down (const Vector2 &mouse_pos)
  231. {
  232. if (HasFocus) {
  233. On_New_Key (VK_MBUTTON);
  234. }
  235. return ;
  236. }
  237. ////////////////////////////////////////////////////////////////
  238. //
  239. // On_LButton_Up
  240. //
  241. ////////////////////////////////////////////////////////////////
  242. void
  243. InputCtrlClass::On_LButton_Up (const Vector2 &mouse_pos)
  244. {
  245. return ;
  246. }
  247. ////////////////////////////////////////////////////////////////
  248. //
  249. // On_Set_Focus
  250. //
  251. ////////////////////////////////////////////////////////////////
  252. void
  253. InputCtrlClass::On_Set_Focus (void)
  254. {
  255. //
  256. // Ignore mouse input for one second
  257. //
  258. MouseIgnoreTime = DialogMgrClass::Get_Time () + 500;
  259. Set_Dirty ();
  260. DialogControlClass::On_Set_Focus ();
  261. return ;
  262. }
  263. ////////////////////////////////////////////////////////////////
  264. //
  265. // On_Kill_Focus
  266. //
  267. ////////////////////////////////////////////////////////////////
  268. void
  269. InputCtrlClass::On_Kill_Focus (DialogControlClass *focus)
  270. {
  271. Set_Dirty ();
  272. DialogControlClass::On_Kill_Focus (focus);
  273. return ;
  274. }
  275. ////////////////////////////////////////////////////////////////
  276. //
  277. // On_New_Key
  278. //
  279. ////////////////////////////////////////////////////////////////
  280. void
  281. InputCtrlClass::On_New_Key (int vkey_id)
  282. {
  283. if (Parent != NULL) {
  284. WideStringClass key_name;
  285. int game_key_id = 0;
  286. //
  287. // Get information about this key from the parent
  288. //
  289. if (Parent->On_InputCtrl_Get_Key_Info (this, Get_ID (), vkey_id, key_name, &game_key_id)) {
  290. //
  291. // Display this information in the control
  292. //
  293. Set_Key_Assignment (game_key_id, key_name);
  294. }
  295. }
  296. return ;
  297. }
  298. ////////////////////////////////////////////////////////////////
  299. //
  300. // Set_Key_Assignment
  301. //
  302. ////////////////////////////////////////////////////////////////
  303. void
  304. InputCtrlClass::Set_Key_Assignment (int game_key_id, const WideStringClass &key_name)
  305. {
  306. KeyAssignment = game_key_id;
  307. Title = key_name;
  308. Set_Dirty ();
  309. return ;
  310. }
  311. ////////////////////////////////////////////////////////////////
  312. //
  313. // On_Key_Down
  314. //
  315. ////////////////////////////////////////////////////////////////
  316. bool
  317. InputCtrlClass::On_Key_Down (uint32 key_id, uint32 key_data)
  318. {
  319. PendingKeyID = key_id;
  320. return false;
  321. }
  322. ////////////////////////////////////////////////////////////////
  323. //
  324. // On_Create
  325. //
  326. ////////////////////////////////////////////////////////////////
  327. void
  328. InputCtrlClass::On_Create (void)
  329. {
  330. Title = L"";
  331. return ;
  332. }
  333. ////////////////////////////////////////////////////////////////
  334. //
  335. // On_Mouse_Wheel
  336. //
  337. ////////////////////////////////////////////////////////////////
  338. void
  339. InputCtrlClass::On_Mouse_Wheel (int direction)
  340. {
  341. if (HasFocus) {
  342. if (direction < 0) {
  343. On_New_Key (VK_MOUSEWHEEL_UP);
  344. } else {
  345. On_New_Key (VK_MOUSEWHEEL_DOWN);
  346. }
  347. }
  348. return ;
  349. }