mousemgr.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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/mousemgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/22/01 4:49p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "mousemgr.h"
  36. #include "screencursor.h"
  37. #include "assetmgr.h"
  38. #include "texture.h"
  39. ////////////////////////////////////////////////////////////////
  40. // Local constants
  41. ////////////////////////////////////////////////////////////////
  42. static const char * TEXTURE_NAME[MouseMgrClass::CURSOR_COUNT] =
  43. {
  44. "cursor_arrow.tga",
  45. "cursor_text.tga",
  46. "cursor_action.tga",
  47. "cursor_busy.tga",
  48. "cursor_pan_up.tga",
  49. "cursor_rotate.tga"
  50. };
  51. static Vector2 HOTSPOTS[MouseMgrClass::CURSOR_COUNT] =
  52. {
  53. Vector2 (0, 0),
  54. Vector2 (15, 15),
  55. Vector2 (7, 1),
  56. Vector2 (15, 15),
  57. Vector2 (15, 17),
  58. Vector2 (15, 15)
  59. };
  60. ////////////////////////////////////////////////////////////////
  61. // Local constants
  62. ////////////////////////////////////////////////////////////////
  63. TextureClass * MouseMgrClass::Textures[CURSOR_COUNT] = { 0 };
  64. ScreenCursorClass * MouseMgrClass::MouseCursor = NULL;
  65. MouseMgrClass::CURSOR_TYPE MouseMgrClass::CursorType = MouseMgrClass::CURSOR_ARROW;
  66. unsigned int MouseMgrClass::CursorWaitCount = 0;
  67. ////////////////////////////////////////////////////////////////
  68. //
  69. // Initialize
  70. //
  71. ////////////////////////////////////////////////////////////////
  72. void
  73. MouseMgrClass::Initialize (void)
  74. {
  75. //
  76. // Load each mouse cursor texture
  77. //
  78. for (int index = 0; index < CURSOR_COUNT; index ++) {
  79. Textures[index] = WW3DAssetManager::Get_Instance()->Get_Texture (TEXTURE_NAME[index], TextureClass::MIP_LEVELS_1);
  80. }
  81. return ;
  82. }
  83. ////////////////////////////////////////////////////////////////
  84. //
  85. // Shutdown
  86. //
  87. ////////////////////////////////////////////////////////////////
  88. void
  89. MouseMgrClass::Shutdown (void)
  90. {
  91. //
  92. // Free each mouse cursor texture
  93. //
  94. for (int index = 0; index < CURSOR_COUNT; index ++) {
  95. REF_PTR_RELEASE (Textures[index]);
  96. }
  97. //
  98. // This will free the cursor object
  99. //
  100. Show_Cursor (false);
  101. return ;
  102. }
  103. ////////////////////////////////////////////////////////////////
  104. //
  105. // Show_Cursor
  106. //
  107. ////////////////////////////////////////////////////////////////
  108. void
  109. MouseMgrClass::Show_Cursor (bool onoff)
  110. {
  111. if (MouseCursor == NULL && onoff) {
  112. //
  113. // Create the mouse cursor
  114. //
  115. MouseCursor = new ScreenCursorClass;
  116. MouseCursor->Set_Texture (Textures[CursorType]);
  117. MouseCursor->Set_Hotspot (HOTSPOTS[CursorType]);
  118. CursorWaitCount = 0;
  119. } else if (MouseCursor != NULL && onoff == false) {
  120. //
  121. // Free the mouse cursor
  122. //
  123. delete MouseCursor;
  124. MouseCursor = NULL;
  125. }
  126. return ;
  127. }
  128. ////////////////////////////////////////////////////////////////
  129. //
  130. // Set_Cursor
  131. //
  132. ////////////////////////////////////////////////////////////////
  133. void
  134. MouseMgrClass::Set_Cursor (CURSOR_TYPE type)
  135. {
  136. if (CursorType != type && MouseCursor != NULL && CursorWaitCount == 0) {
  137. MouseCursor->Set_Texture (Textures[type]);
  138. MouseCursor->Set_Hotspot (HOTSPOTS[type]);
  139. CursorType = type;
  140. }
  141. return ;
  142. }
  143. ////////////////////////////////////////////////////////////////
  144. //
  145. // Begin_Wait_Cursor
  146. //
  147. ////////////////////////////////////////////////////////////////
  148. void
  149. MouseMgrClass::Begin_Wait_Cursor(void)
  150. {
  151. if (CursorWaitCount == 0) {
  152. Set_Cursor(CURSOR_BUSY);
  153. }
  154. ++CursorWaitCount;
  155. }
  156. ////////////////////////////////////////////////////////////////
  157. //
  158. // End_Wait_Cursor
  159. //
  160. ////////////////////////////////////////////////////////////////
  161. void
  162. MouseMgrClass::End_Wait_Cursor(void)
  163. {
  164. assert(CursorWaitCount > 0 && "End_Wait_Cursor() mismatch");
  165. if (CursorWaitCount > 0) {
  166. --CursorWaitCount;
  167. if (CursorWaitCount == 0) {
  168. Set_Cursor(CURSOR_ARROW);
  169. }
  170. }
  171. }
  172. ////////////////////////////////////////////////////////////////
  173. //
  174. // Render
  175. //
  176. ////////////////////////////////////////////////////////////////
  177. void
  178. MouseMgrClass::Render (void)
  179. {
  180. if (MouseCursor != NULL) {
  181. MouseCursor->Render ();
  182. }
  183. return ;
  184. }