Torque3D Documentation / _generateds / editorIconRegistry.cpp

editorIconRegistry.cpp

Engine/source/gui/worldEditor/editorIconRegistry.cpp

More...

Public Variables

The global registry of editor icons.

Public Functions

ConsoleDoc("@class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EditorIconRegistry\n</a>" "@brief This class is used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> find the correct icon <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> path <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> different <a href="/coding/class/classsimobject/">SimObject</a> class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n\n</a>" "It is typically used by the editors, not intended <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> actual game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">development\n\n</a>" " @internal" )
DefineEngineStaticMethod(EditorIconRegistry , add , void , (String className, String imageFile, bool overwrite) , (true) , "@internal" )
DefineEngineStaticMethod(EditorIconRegistry , clear , void , () , "@internal" )
DefineEngineStaticMethod(EditorIconRegistry , findIconByClassName , const char * , (String className) , "@brief Returns the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the icon <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> found." "@internal" )
DefineEngineStaticMethod(EditorIconRegistry , findIconBySimObject , const char * , (SimObject *obj) , "Returns the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the icon <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> found." "@internal" )
DefineEngineStaticMethod(EditorIconRegistry , loadFromPath , void , (String imagePath, bool overwrite) , (true) , "@internal" )

Detailed Description

Public Variables

EditorIconRegistry gEditorIcons 

The global registry of editor icons.

Public Functions

ConsoleDoc("@class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EditorIconRegistry\n</a>" "@brief This class is used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> find the correct icon <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> path <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> different <a href="/coding/class/classsimobject/">SimObject</a> class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n\n</a>" "It is typically used by the editors, not intended <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> actual game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">development\n\n</a>" " @internal" )

DefineEngineStaticMethod(EditorIconRegistry , add , void , (String className, String imageFile, bool overwrite) , (true) , "@internal" )

DefineEngineStaticMethod(EditorIconRegistry , clear , void , () , "@internal" )

DefineEngineStaticMethod(EditorIconRegistry , findIconByClassName , const char * , (String className) , "@brief Returns the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the icon <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> found." "@internal" )

DefineEngineStaticMethod(EditorIconRegistry , findIconBySimObject , const char * , (SimObject *obj) , "Returns the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the icon <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> found." "@internal" )

DefineEngineStaticMethod(EditorIconRegistry , loadFromPath , void , (String imagePath, bool overwrite) , (true) , "@internal" )

IMPLEMENT_STATIC_CLASS(EditorIconRegistry , "" )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "gui/worldEditor/editorIconRegistry.h"
 26
 27#include "console/engineAPI.h"
 28#include "console/simBase.h"
 29
 30
 31EditorIconRegistry gEditorIcons;
 32
 33ConsoleDoc(
 34   "@class EditorIconRegistry\n"
 35   "@brief This class is used to find the correct icon file path for different SimObject class types.\n\n"
 36   "It is typically used by the editors, not intended for actual game development\n\n"
 37   "@internal"
 38);
 39
 40IMPLEMENT_STATIC_CLASS(EditorIconRegistry,, "");
 41
 42EditorIconRegistry::EditorIconRegistry()
 43{
 44}
 45
 46EditorIconRegistry::~EditorIconRegistry()
 47{
 48   clear();
 49}
 50
 51void EditorIconRegistry::loadFromPath( const String &path, bool overwrite )
 52{
 53   AbstractClassRep *classRep = AbstractClassRep::getClassList();
 54   while ( classRep )
 55   {
 56      String iconFile = String::ToString( "%s%s", path.c_str(), classRep->getClassName() );
 57      add( classRep->getClassName(), iconFile.c_str(), overwrite );
 58      classRep = classRep->getNextClass();
 59   }
 60
 61   String defaultIconFile = path + "default";
 62
 63   mDefaultIcon.set( defaultIconFile,
 64                     &GFXTexturePersistentSRGBProfile,
 65                     avar("%s() - mIcons[] (line %d)", 
 66                     __FUNCTION__, __LINE__) );
 67}
 68
 69void EditorIconRegistry::add( const String &className, const String &imageFile, bool overwrite )
 70{
 71   // First see if we can load the image.
 72   GFXTexHandle icon(   imageFile, &GFXTexturePersistentSRGBProfile,
 73                        avar("%s() - mIcons[] (line %d)", __FUNCTION__, __LINE__) );
 74   if ( icon.isNull() )
 75      return;
 76
 77   // Look it up in the map.
 78   StringNoCase key( className );
 79   IconMap::Iterator iter = mIcons.find( key );
 80   if ( iter != mIcons.end() )
 81   {
 82      if ( !overwrite )
 83         return;
 84
 85      iter->value = icon;
 86   }
 87   else
 88      mIcons.insertUnique( key, icon );
 89}
 90
 91GFXTexHandle EditorIconRegistry::findIcon( AbstractClassRep *classRep )
 92{
 93   while ( classRep )
 94   {
 95      StringNoCase key( classRep->getClassName() );
 96      IconMap::Iterator icon = mIcons.find( key );
 97
 98      if ( icon != mIcons.end() && icon->value.isValid() )
 99         return icon->value;
100
101      classRep = classRep->getParentClass();
102   }
103
104   return mDefaultIcon;
105}
106
107GFXTexHandle EditorIconRegistry::findIcon( const SimObject *object )
108{
109   if( object == NULL )
110      return mDefaultIcon;
111
112   AbstractClassRep *classRep = object->getClassRep();
113
114   return findIcon( classRep );
115}   
116
117GFXTexHandle EditorIconRegistry::findIcon( const char *className )
118{   
119   // On the chance we have this className already in the map,
120   // check there first because its a lot faster...
121   
122   StringNoCase key( className );
123   IconMap::Iterator icon = mIcons.find( key );
124
125   if ( icon != mIcons.end() && icon->value.isValid() )
126      return icon->value;
127
128   // Well, we could still have an icon for a parent class,
129   // so find the AbstractClassRep for the className.
130   //
131   // Unfortunately the only way to do this is looping through
132   // the AbstractClassRep linked list.
133
134   bool found = false;
135   AbstractClassRep* pClassRep = AbstractClassRep::getClassList();
136   
137   while ( pClassRep )
138   {
139      if ( key.equal( pClassRep->getClassName(), String::NoCase ) )
140      {
141         found = true;
142         break;
143      }
144      pClassRep = pClassRep->getNextClass();
145   }
146
147   if ( !found )
148   {
149      Con::errorf( "EditorIconRegistry::findIcon, passed className %s was not an AbstractClassRep!", key.c_str() );
150      return mDefaultIcon;
151   }
152   
153   // Now do a find by AbstractClassRep recursively up the class tree...
154   return findIcon( pClassRep );
155}
156
157bool EditorIconRegistry::hasIconNoRecurse( const SimObject *object )
158{
159   AbstractClassRep *classRep = object->getClassRep();
160      
161   StringNoCase key( classRep->getClassName() );
162
163   IconMap::Iterator icon = mIcons.find( key );
164
165   return icon != mIcons.end();
166}
167
168void EditorIconRegistry::clear()
169{
170   mIcons.clear();
171   mDefaultIcon.free();
172}
173
174DefineEngineStaticMethod( EditorIconRegistry, add, void, (String className, String imageFile, bool overwrite), (true),
175               "@internal")
176{
177   gEditorIcons.add( className, imageFile, overwrite );
178}
179
180DefineEngineStaticMethod( EditorIconRegistry, loadFromPath, void, (String imagePath, bool overwrite), (true),
181               "@internal")
182{
183   gEditorIcons.loadFromPath( imagePath, overwrite );
184}
185
186DefineEngineStaticMethod( EditorIconRegistry, clear, void, (),,
187               "@internal")
188{
189   gEditorIcons.clear();
190}
191
192DefineEngineStaticMethod( EditorIconRegistry, findIconByClassName, const char*, (String className),,
193   "@brief Returns the file path to the icon file if found." 
194   "@internal")
195{
196   GFXTexHandle icon = gEditorIcons.findIcon( className );
197   if ( icon.isNull() )
198      return NULL;
199
200   return icon->mPath;
201}
202
203DefineEngineStaticMethod( EditorIconRegistry, findIconBySimObject, const char*, (SimObject* obj),,
204   "Returns the file path to the icon file if found." 
205   "@internal")
206{
207   if ( !obj )
208   {
209      Con::warnf( "EditorIconRegistry::findIcon, parameter was not a SimObject!");
210      return NULL;
211   }
212
213   GFXTexHandle icon = gEditorIcons.findIcon( obj );
214   if ( icon.isNull() )
215      return NULL;
216
217   return icon->mPath;
218}
219
220