screencursor.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 : W3DView *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/screencursor.cpp $Modtime:: $*
  25. * *
  26. * $Revision:: 8 $*
  27. * *
  28. *---------------------------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
  32. #pragma warning(disable : 4530)
  33. #include "screencursor.h"
  34. #include "ww3d.h"
  35. #include "texture.h"
  36. #include "render2d.h"
  37. #include "rect.h"
  38. #include "dialogmgr.h"
  39. ///////////////////////////////////////////////////////////////////
  40. //
  41. // ScreenCursorClass
  42. //
  43. ///////////////////////////////////////////////////////////////////
  44. ScreenCursorClass::ScreenCursorClass (void) :
  45. Hotspot (0, 0),
  46. Texture (NULL),
  47. Width (0),
  48. Height (0)
  49. {
  50. return ;
  51. }
  52. ///////////////////////////////////////////////////////////////////
  53. //
  54. // ~ScreenCursorClass
  55. //
  56. ///////////////////////////////////////////////////////////////////
  57. ScreenCursorClass::~ScreenCursorClass (void)
  58. {
  59. REF_PTR_RELEASE (Texture);
  60. return ;
  61. }
  62. ///////////////////////////////////////////////////////////////////
  63. //
  64. // Set_Texture
  65. //
  66. ///////////////////////////////////////////////////////////////////
  67. void
  68. ScreenCursorClass::Set_Texture (TextureClass *texture)
  69. {
  70. REF_PTR_SET (Texture, texture);
  71. //
  72. // Find the dimensions of the texture:
  73. //
  74. if (Texture != NULL) {
  75. // SurfaceClass::SurfaceDescription surface_desc;
  76. // Texture->Get_Level_Description(surface_desc);
  77. // Width = surface_desc.Width;
  78. // Height = surface_desc.Height;
  79. Texture->Init();
  80. Width = Texture->Get_Width();
  81. Height = Texture->Get_Height();
  82. }
  83. Renderer.Set_Texture (Texture);
  84. Renderer.Set_Coordinate_Range (Render2DClass::Get_Screen_Resolution ());
  85. return ;
  86. }
  87. ///////////////////////////////////////////////////////////////////
  88. //
  89. // Render
  90. //
  91. ///////////////////////////////////////////////////////////////////
  92. void
  93. ScreenCursorClass::Render (void)
  94. {
  95. //
  96. // Get the cursor's position
  97. //
  98. Vector3 cursor_pos = DialogMgrClass::Get_Mouse_Pos ();
  99. //
  100. // Clamp the cursor to the screen bounds
  101. //
  102. const RectClass &screen_rect = Render2DClass::Get_Screen_Resolution ();
  103. cursor_pos.X = WWMath::Clamp (cursor_pos.X, screen_rect.Left, screen_rect.Right - 5);
  104. cursor_pos.Y = WWMath::Clamp (cursor_pos.Y, screen_rect.Top, screen_rect.Bottom - 5);
  105. DialogMgrClass::Set_Mouse_Pos (cursor_pos);
  106. //
  107. // Take the hotspot into account
  108. //
  109. cursor_pos.X -= Hotspot.X;
  110. cursor_pos.Y -= Hotspot.Y;
  111. //
  112. // Build the screen-space rectangle we'll render to
  113. //
  114. RectClass rect;
  115. rect.Left = (int)cursor_pos.X;
  116. rect.Top = (int)cursor_pos.Y;
  117. rect.Right = (int)cursor_pos.X + Width;
  118. rect.Bottom = (int)cursor_pos.Y + Height;
  119. //
  120. // Render the mouse cursor
  121. //
  122. Renderer.Reset ();
  123. Renderer.Add_Quad (rect, RectClass (0, 0, 1, 1));
  124. Renderer.Render ();
  125. return ;
  126. }