| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : wwui *
- * *
- * $Archive:: /Commando/Code/wwui/listiconmgr.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 10/26/01 2:48p $*
- * *
- * $Revision:: 3 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "listiconmgr.h"
- #include "stylemgr.h"
- #include "assetmgr.h"
- #include "texture.h"
- #include "render2d.h"
- ////////////////////////////////////////////////////////////////
- //
- // ListIconMgrClass
- //
- ////////////////////////////////////////////////////////////////
- ListIconMgrClass::ListIconMgrClass (void) :
- IconWidth (16),
- IconHeight (16)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Add_Icon
- //
- ////////////////////////////////////////////////////////////////
- void
- ListIconMgrClass::Add_Icon (const char *texture_name)
- {
- //
- // Make sure this texture isn't already in our lists
- //
- int index = Find_Texture (texture_name);
- if (index == -1) {
- //
- // Load the texture
- //
- TextureClass *texture = WW3DAssetManager::Get_Instance ()->Get_Texture (texture_name, TextureClass::MIP_LEVELS_1);
- if (texture != NULL) {
- //
- // Create a new renderer and assign it the texture
- //
- Render2DClass *renderer = new Render2DClass;
- StyleMgrClass::Configure_Renderer (renderer);
- renderer->Set_Texture (texture);
- renderer->Enable_Alpha (true);
- //
- // Add this renderer to our list
- //
- Renderers.Add (renderer);
- TextureNames.Add (texture_name);
- //
- // Release our hold on the texture
- //
- REF_PTR_RELEASE (texture);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Remove_Icon
- //
- ////////////////////////////////////////////////////////////////
- void
- ListIconMgrClass::Remove_Icon (const char *texture_name)
- {
- //
- // Try to find the texture in our list
- //
- int index = Find_Texture (texture_name);
- if (index >= 0) {
- //
- // Remove this entry from out lists
- //
- delete Renderers[index];
- Renderers.Delete (index);
- TextureNames.Delete (index);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Reset_Icons
- //
- ////////////////////////////////////////////////////////////////
- void
- ListIconMgrClass::Reset_Icons (void)
- {
- //
- // First, free each renderer
- //
- for (int index = 0; index < Renderers.Count (); index ++) {
- delete Renderers[index];
- }
- //
- // Now, reset the lists
- //
- Renderers.Delete_All ();
- TextureNames.Delete_All ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Render_Icon
- //
- ////////////////////////////////////////////////////////////////
- void
- ListIconMgrClass::Render_Icon (const RectClass &clip_rect, const char *texture_name)
- {
- //
- // Try to find the texture in our list
- //
- int index = Find_Texture (texture_name);
- if (index >= 0) {
- float icon_size_x = IconWidth * StyleMgrClass::Get_X_Scale ();
- float icon_size_y = IconHeight * StyleMgrClass::Get_Y_Scale ();
- //
- // Render the texture left-aligned and v-centered in the clip rectangle
- //
- RectClass rect;
- rect.Left = clip_rect.Left;
- rect.Right = clip_rect.Left + icon_size_x;
- rect.Top = int (clip_rect.Center ().Y - (icon_size_y * 0.5F));
- rect.Bottom = int (clip_rect.Center ().Y + (icon_size_y * 0.5F));
- Renderers[index]->Add_Quad (rect);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Render_Icons
- //
- ////////////////////////////////////////////////////////////////
- void
- ListIconMgrClass::Render_Icons (void)
- {
- for (int index = 0; index < Renderers.Count (); index ++) {
- Renderers[index]->Render ();
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Find_Texture
- //
- ////////////////////////////////////////////////////////////////
- int
- ListIconMgrClass::Find_Texture (const char *texture_name)
- {
- int retval = -1;
- //
- // Try to find a texture with this name in our list
- //
- for (int index = 0; index < TextureNames.Count (); index ++) {
- if (::lstrcmpi (texture_name, TextureNames[index]) == 0) {
- retval = index;
- break;
- }
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Reset_Renderers
- //
- ////////////////////////////////////////////////////////////////
- void
- ListIconMgrClass::Reset_Renderers (void)
- {
- for (int index = 0; index < Renderers.Count (); index ++) {
- Renderers[index]->Reset ();
- }
- return ;
- }
|