listiconmgr.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 : wwui *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/listiconmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/26/01 2:48p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "listiconmgr.h"
  36. #include "stylemgr.h"
  37. #include "assetmgr.h"
  38. #include "texture.h"
  39. #include "render2d.h"
  40. ////////////////////////////////////////////////////////////////
  41. //
  42. // ListIconMgrClass
  43. //
  44. ////////////////////////////////////////////////////////////////
  45. ListIconMgrClass::ListIconMgrClass (void) :
  46. IconWidth (16),
  47. IconHeight (16)
  48. {
  49. return ;
  50. }
  51. ////////////////////////////////////////////////////////////////
  52. //
  53. // Add_Icon
  54. //
  55. ////////////////////////////////////////////////////////////////
  56. void
  57. ListIconMgrClass::Add_Icon (const char *texture_name)
  58. {
  59. //
  60. // Make sure this texture isn't already in our lists
  61. //
  62. int index = Find_Texture (texture_name);
  63. if (index == -1) {
  64. //
  65. // Load the texture
  66. //
  67. TextureClass *texture = WW3DAssetManager::Get_Instance ()->Get_Texture (texture_name, TextureClass::MIP_LEVELS_1);
  68. if (texture != NULL) {
  69. //
  70. // Create a new renderer and assign it the texture
  71. //
  72. Render2DClass *renderer = new Render2DClass;
  73. StyleMgrClass::Configure_Renderer (renderer);
  74. renderer->Set_Texture (texture);
  75. renderer->Enable_Alpha (true);
  76. //
  77. // Add this renderer to our list
  78. //
  79. Renderers.Add (renderer);
  80. TextureNames.Add (texture_name);
  81. //
  82. // Release our hold on the texture
  83. //
  84. REF_PTR_RELEASE (texture);
  85. }
  86. }
  87. return ;
  88. }
  89. ////////////////////////////////////////////////////////////////
  90. //
  91. // Remove_Icon
  92. //
  93. ////////////////////////////////////////////////////////////////
  94. void
  95. ListIconMgrClass::Remove_Icon (const char *texture_name)
  96. {
  97. //
  98. // Try to find the texture in our list
  99. //
  100. int index = Find_Texture (texture_name);
  101. if (index >= 0) {
  102. //
  103. // Remove this entry from out lists
  104. //
  105. delete Renderers[index];
  106. Renderers.Delete (index);
  107. TextureNames.Delete (index);
  108. }
  109. return ;
  110. }
  111. ////////////////////////////////////////////////////////////////
  112. //
  113. // Reset_Icons
  114. //
  115. ////////////////////////////////////////////////////////////////
  116. void
  117. ListIconMgrClass::Reset_Icons (void)
  118. {
  119. //
  120. // First, free each renderer
  121. //
  122. for (int index = 0; index < Renderers.Count (); index ++) {
  123. delete Renderers[index];
  124. }
  125. //
  126. // Now, reset the lists
  127. //
  128. Renderers.Delete_All ();
  129. TextureNames.Delete_All ();
  130. return ;
  131. }
  132. ////////////////////////////////////////////////////////////////
  133. //
  134. // Render_Icon
  135. //
  136. ////////////////////////////////////////////////////////////////
  137. void
  138. ListIconMgrClass::Render_Icon (const RectClass &clip_rect, const char *texture_name)
  139. {
  140. //
  141. // Try to find the texture in our list
  142. //
  143. int index = Find_Texture (texture_name);
  144. if (index >= 0) {
  145. float icon_size_x = IconWidth * StyleMgrClass::Get_X_Scale ();
  146. float icon_size_y = IconHeight * StyleMgrClass::Get_Y_Scale ();
  147. //
  148. // Render the texture left-aligned and v-centered in the clip rectangle
  149. //
  150. RectClass rect;
  151. rect.Left = clip_rect.Left;
  152. rect.Right = clip_rect.Left + icon_size_x;
  153. rect.Top = int (clip_rect.Center ().Y - (icon_size_y * 0.5F));
  154. rect.Bottom = int (clip_rect.Center ().Y + (icon_size_y * 0.5F));
  155. Renderers[index]->Add_Quad (rect);
  156. }
  157. return ;
  158. }
  159. ////////////////////////////////////////////////////////////////
  160. //
  161. // Render_Icons
  162. //
  163. ////////////////////////////////////////////////////////////////
  164. void
  165. ListIconMgrClass::Render_Icons (void)
  166. {
  167. for (int index = 0; index < Renderers.Count (); index ++) {
  168. Renderers[index]->Render ();
  169. }
  170. return ;
  171. }
  172. ////////////////////////////////////////////////////////////////
  173. //
  174. // Find_Texture
  175. //
  176. ////////////////////////////////////////////////////////////////
  177. int
  178. ListIconMgrClass::Find_Texture (const char *texture_name)
  179. {
  180. int retval = -1;
  181. //
  182. // Try to find a texture with this name in our list
  183. //
  184. for (int index = 0; index < TextureNames.Count (); index ++) {
  185. if (::lstrcmpi (texture_name, TextureNames[index]) == 0) {
  186. retval = index;
  187. break;
  188. }
  189. }
  190. return retval;
  191. }
  192. ////////////////////////////////////////////////////////////////
  193. //
  194. // Reset_Renderers
  195. //
  196. ////////////////////////////////////////////////////////////////
  197. void
  198. ListIconMgrClass::Reset_Renderers (void)
  199. {
  200. for (int index = 0; index < Renderers.Count (); index ++) {
  201. Renderers[index]->Reset ();
  202. }
  203. return ;
  204. }