imagectrl.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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/imagectrl.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/22/01 4:12p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "imagectrl.h"
  36. #include "texture.h"
  37. #include "assetmgr.h"
  38. #include "stylemgr.h"
  39. //////////////////////////////////////////////////////////////////////
  40. //
  41. // ImageCtrlClass
  42. //
  43. //////////////////////////////////////////////////////////////////////
  44. ImageCtrlClass::ImageCtrlClass (void)
  45. {
  46. //
  47. // Configure the renderers
  48. //
  49. StyleMgrClass::Configure_Renderer (&ControlRenderer);
  50. StyleMgrClass::Configure_Renderer (&TextureRenderer);
  51. return ;
  52. }
  53. //////////////////////////////////////////////////////////////////////
  54. //
  55. // ~ImageCtrlClass
  56. //
  57. //////////////////////////////////////////////////////////////////////
  58. ImageCtrlClass::~ImageCtrlClass (void)
  59. {
  60. return ;
  61. }
  62. //////////////////////////////////////////////////////////////////////
  63. //
  64. // Create_Control_Renderer
  65. //
  66. //////////////////////////////////////////////////////////////////////
  67. void
  68. ImageCtrlClass::Create_Control_Renderer (void)
  69. {
  70. Render2DClass &renderer = ControlRenderer;
  71. //
  72. // Configure this renderer
  73. //
  74. renderer.Reset ();
  75. renderer.Enable_Texturing (false);
  76. //
  77. // Determine which color to draw the outline in
  78. //
  79. int color = StyleMgrClass::Get_Line_Color ();
  80. int bkcolor = StyleMgrClass::Get_Bk_Color ();
  81. if (IsEnabled == false) {
  82. color = StyleMgrClass::Get_Disabled_Line_Color ();
  83. bkcolor = StyleMgrClass::Get_Disabled_Bk_Color ();
  84. }
  85. //
  86. // Draw the control's outline
  87. //
  88. if ( Style & WS_BORDER == WS_BORDER ) {
  89. renderer.Add_Outline (Rect, 1.0F, color);
  90. }
  91. return ;
  92. }
  93. //////////////////////////////////////////////////////////////////////
  94. //
  95. // Create_Texture_Renderer
  96. //
  97. //////////////////////////////////////////////////////////////////////
  98. void
  99. ImageCtrlClass::Create_Texture_Renderer (void)
  100. {
  101. Render2DClass &renderer = TextureRenderer;
  102. //
  103. // Simply draw the texture inside the control
  104. //
  105. renderer.Reset ();
  106. if (renderer.Peek_Texture () != NULL) {
  107. renderer.Add_Quad (Rect);
  108. }
  109. return ;
  110. }
  111. //////////////////////////////////////////////////////////////////////
  112. //
  113. // Set_Texture
  114. //
  115. //////////////////////////////////////////////////////////////////////
  116. void
  117. ImageCtrlClass::Set_Texture (const char *texture_name)
  118. {
  119. //
  120. // Assign the texture to the renderer
  121. //
  122. TextureClass *texture = WW3DAssetManager::Get_Instance ()->Get_Texture (texture_name, TextureClass::MIP_LEVELS_1);
  123. TextureRenderer.Set_Texture (texture);
  124. REF_PTR_RELEASE (texture);
  125. //
  126. // Force an update
  127. //
  128. Set_Dirty ();
  129. return ;
  130. }
  131. ////////////////////////////////////////////////////////////////
  132. //
  133. // Render
  134. //
  135. ////////////////////////////////////////////////////////////////
  136. void
  137. ImageCtrlClass::Render (void)
  138. {
  139. //
  140. // Recreate the renderers (if necessary)
  141. //
  142. if (IsDirty) {
  143. Create_Control_Renderer ();
  144. Create_Texture_Renderer ();
  145. }
  146. //
  147. // Render the image...
  148. //
  149. TextureRenderer.Render ();
  150. ControlRenderer.Render ();
  151. DialogControlClass::Render ();
  152. return ;
  153. }