mapctrl.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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/mapctrl.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/26/01 10:44a $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __MAP_CTRL_H
  39. #define __MAP_CTRL_H
  40. #include "dialogcontrol.h"
  41. #include "vector3.h"
  42. #include "vector2i.h"
  43. #include "vector.h"
  44. #include "render2dsentence.h"
  45. #include "bittype.h"
  46. ////////////////////////////////////////////////////////////////
  47. //
  48. // MapMarkerClass
  49. //
  50. ////////////////////////////////////////////////////////////////
  51. class MapMarkerClass : public DialogControlClass
  52. {
  53. public:
  54. ////////////////////////////////////////////////////////////////
  55. // Public constructors/destructors
  56. ////////////////////////////////////////////////////////////////
  57. MapMarkerClass (void) :
  58. Position (0, 0, 0),
  59. UVRect (0, 0, 0, 0),
  60. Color (0xFFFFFFFF),
  61. UserData (0) {}
  62. virtual ~MapMarkerClass (void) {}
  63. ////////////////////////////////////////////////////////////////
  64. // Public operators
  65. ////////////////////////////////////////////////////////////////
  66. bool operator== (const MapMarkerClass &src) const { return false; }
  67. bool operator!= (const MapMarkerClass &src) const { return true; }
  68. ////////////////////////////////////////////////////////////////
  69. // Public methods
  70. ////////////////////////////////////////////////////////////////
  71. //
  72. // Accessors
  73. //
  74. const Vector3 & Get_Position (void) const { return Position; }
  75. const WCHAR * Get_Name (void) const { return Name; }
  76. const RectClass & Get_Rect (void) const { return UVRect; }
  77. uint32 Get_User_Data (void) const { return UserData; }
  78. uint32 Get_Color (void) const { return Color; }
  79. void Set_Position (const Vector3 &pos) { Position = pos; }
  80. void Set_Name (const WCHAR *name) { Name = name; }
  81. void Set_Rect (const RectClass &rect) { UVRect = rect; }
  82. void Set_User_Data (uint32 data) { UserData = data; }
  83. void Set_Color (uint32 color) { Color = color; }
  84. protected:
  85. ////////////////////////////////////////////////////////////////
  86. // Protected member data
  87. ////////////////////////////////////////////////////////////////
  88. Vector3 Position;
  89. WideStringClass Name;
  90. RectClass UVRect;
  91. uint32 UserData;
  92. uint32 Color;
  93. };
  94. ////////////////////////////////////////////////////////////////
  95. //
  96. // MapCtrlClass
  97. //
  98. ////////////////////////////////////////////////////////////////
  99. class MapCtrlClass : public DialogControlClass
  100. {
  101. public:
  102. ////////////////////////////////////////////////////////////////
  103. // Public constructors/destructors
  104. ////////////////////////////////////////////////////////////////
  105. MapCtrlClass (void);
  106. virtual ~MapCtrlClass (void);
  107. ////////////////////////////////////////////////////////////////
  108. // Public methods
  109. ////////////////////////////////////////////////////////////////
  110. //
  111. // From DialogControlClass
  112. //
  113. void Render (void);
  114. //
  115. // Map configuration
  116. //
  117. void Set_Map_Texture (const char *filename);
  118. void Set_Marker_Texture (const char *filename);
  119. //
  120. // Zoom support
  121. //
  122. float Get_Zoom (void) const { return Zoom; }
  123. void Set_Zoom (float factor) { Zoom = factor; Set_Dirty (); }
  124. //
  125. // Map centering and scale.
  126. //
  127. // Note: The scale means "how many pixels (of map) per meter (of world space)".
  128. // This value can differ in the X and Y axes.
  129. //
  130. // The map center is the pixel position (x,y) where world space (0, 0, 0) is.
  131. //
  132. const Vector2 &Get_Map_Scale (void) const { return MapScale; }
  133. void Set_Map_Scale (const Vector2 &scale) { MapScale = scale; Set_Dirty (); }
  134. const Vector2 &Get_Map_Center (void) const { return MapCenterPoint; }
  135. void Set_Map_Center (const Vector2 &pos) { MapCenterPoint = pos; Set_Dirty (); }
  136. //
  137. // Marker control
  138. //
  139. int Add_Marker (const WCHAR *name, const Vector3 &pos, const RectClass &uv_rect, int color = 0xFFFFFFFF);
  140. uint32 Get_Marker_Data (int index);
  141. void Set_Marker_Data (int index, uint32 user_data);
  142. void Remove_Marker (int index);
  143. //
  144. // View support
  145. //
  146. void Center_View_About_Marker (int marker_index);
  147. //
  148. // Cloud support
  149. //
  150. void Initialize_Cloud (int cells_x, int cells_y);
  151. void Reset_Cloud (void);
  152. void Set_Cloud_Cell (int cell_x, int cell_y, bool is_visible);
  153. protected:
  154. ////////////////////////////////////////////////////////////////
  155. // Protected methods
  156. ////////////////////////////////////////////////////////////////
  157. void On_LButton_Down (const Vector2 &mouse_pos);
  158. void On_LButton_Up (const Vector2 &mouse_pos);
  159. void On_Mouse_Move (const Vector2 &mouse_pos);
  160. void On_Set_Cursor (const Vector2 &mouse_pos);
  161. void On_Set_Focus (void);
  162. void On_Kill_Focus (DialogControlClass *focus);
  163. void On_Frame_Update (void);
  164. void Update_Client_Rect (void);
  165. void Create_Control_Renderers (void);
  166. void Create_Text_Renderers (void);
  167. void Create_Cloud_Renderer (void);
  168. int Marker_From_Pos (const Vector2 &mouse_pos);
  169. void Clamp_Scroll_Pos (void);
  170. Vector3 Position_To_Coord (const Vector2 &mouse_pos);
  171. bool Is_Cell_Shrouded (int cell_x, int cell_y);
  172. void Free_Cloud_Data (void);
  173. void Update_Pulse (void);
  174. ////////////////////////////////////////////////////////////////
  175. // Protected member data
  176. ////////////////////////////////////////////////////////////////
  177. Render2DSentenceClass TextRenderer;
  178. Render2DClass ControlRenderer;
  179. Render2DClass ButtonRenderer;
  180. Render2DClass MapRenderer;
  181. Render2DClass MapOverlayRenderer;
  182. Render2DClass CloudRenderer;
  183. Render2DClass EdgeRenderer;
  184. Render2DClass IconRenderer;
  185. float Zoom;
  186. Vector2 ScrollPos;
  187. Vector2 MapSize;
  188. Vector2 IconTextureSize;
  189. bool IsDragging;
  190. bool IsZoomingIn;
  191. bool IsZoomingOut;
  192. bool IsUsingOverlay;
  193. Vector2 InitialMousePos;
  194. Vector2 InitialScrollPos;
  195. RectClass ZoomInButtonRect;
  196. RectClass ZoomOutButtonRect;
  197. float PulseDirection;
  198. float OverlayOpacity;
  199. Vector2 MapCenterPoint;
  200. Vector2 MapScale;
  201. uint32 * CloudVector;
  202. Vector2i CloudSize;
  203. DynamicVectorClass<MapMarkerClass> MarkerList;
  204. };
  205. ////////////////////////////////////////////////////////////////
  206. // Is_Cell_Shrouded
  207. ////////////////////////////////////////////////////////////////
  208. inline bool
  209. MapCtrlClass::Is_Cell_Shrouded (int cell_x, int cell_y)
  210. {
  211. bool retval = true;
  212. //
  213. // Is this cell in bounds?
  214. //
  215. if ( cell_x >= 0 && cell_x < CloudSize.I &&
  216. cell_y >= 0 && cell_y < CloudSize.J)
  217. {
  218. int bit_offset = (cell_y * CloudSize.I) + cell_x;
  219. int index = bit_offset / 32;
  220. int bit = (bit_offset - (index * 32)) + 1;
  221. //
  222. // Check this bit
  223. //
  224. retval = ((CloudVector[index] & (1 << bit)) != 0);
  225. }
  226. return retval;
  227. }
  228. #endif //__MAP_CTRL_H