Torque3D Documentation / _generateds / guiImageList.cpp

guiImageList.cpp

Engine/source/gui/editor/guiImageList.cpp

More...

Public Functions

ConsoleDocClass(GuiImageList , "@brief GUI <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> which displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">images.\n\n</a>" "Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> part of an old editor system <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> previous Torque systems. " "Doesn'<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1aded116371789db1fd63c90ef00c95a3d">t</a> appear <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be used anymore, will most likely be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deprecated.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" " @internal" )
DefineEngineMethod(GuiImageList , clear , bool , () )
DefineEngineMethod(GuiImageList , getImage , const char * , (int index) , "@brief Get <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the texture at the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n\n</a>" "@param index Index of the image in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the image index/<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% index)
DefineEngineMethod(GuiImageList , getIndex , S32 , (const char *imagePath) , "@brief Retrieves the imageindex of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specified texture in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list.\n\n</a>" "@param imagePath Imagemap including filepath of image <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> search <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">for\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the imagemap <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> search <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">for\n</a>" "% imagePath)
DefineEngineMethod(GuiImageList , insert , S32 , (const char *imagePath) , "@brief Insert an image into imagelist- returns the image index or -1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">failure.\n\n</a>" "@param imagePath Imagemap, with path, <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> add <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Define the imagemap <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> add <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list\n</a>" "% imagePath)
DefineEngineMethod(GuiImageList , remove , bool , (S32 index) , "@brief Removes an image from the list by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n\n</a>" "@param index Image index <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">remove.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the image <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n</a>" "% imageIndex)

Detailed Description

Public Functions

ConsoleDocClass(GuiImageList , "@brief GUI <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> which displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">images.\n\n</a>" "Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> part of an old editor system <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> previous Torque systems. " "Doesn'<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1aded116371789db1fd63c90ef00c95a3d">t</a> appear <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be used anymore, will most likely be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deprecated.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" " @internal" )

DefineEngineMethod(GuiImageList , clear , bool , () )

DefineEngineMethod(GuiImageList , count , S32 , () )

DefineEngineMethod(GuiImageList , getImage , const char * , (int index) , "@brief Get <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the texture at the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n\n</a>" "@param index Index of the image in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the image index/<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% index)

DefineEngineMethod(GuiImageList , getIndex , S32 , (const char *imagePath) , "@brief Retrieves the imageindex of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specified texture in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list.\n\n</a>" "@param imagePath Imagemap including filepath of image <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> search <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">for\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the imagemap <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> search <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">for\n</a>" "% imagePath)

DefineEngineMethod(GuiImageList , insert , S32 , (const char *imagePath) , "@brief Insert an image into imagelist- returns the image index or -1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">failure.\n\n</a>" "@param imagePath Imagemap, with path, <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> add <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Define the imagemap <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> add <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">list\n</a>" "% imagePath)

DefineEngineMethod(GuiImageList , remove , bool , (S32 index) , "@brief Removes an image from the list by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n\n</a>" "@param index Image index <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">remove.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the image <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n</a>" "% imageIndex)

IMPLEMENT_CONOBJECT(GuiImageList )

  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 "console/consoleTypes.h"
 26#include "console/console.h"
 27#include "gfx/gfxDevice.h"
 28#include "gui/editor/guiImageList.h"
 29#include "console/engineAPI.h"
 30
 31IMPLEMENT_CONOBJECT(GuiImageList);
 32
 33ConsoleDocClass( GuiImageList,
 34   "@brief GUI control which displays a list of images.\n\n"
 35   "Used to be a part of an old editor system for previous Torque systems. "
 36   "Doesn't appear to be used anymore, will most likely be deprecated.\n\n"
 37   "@ingroup GuiCore\n"
 38   "@internal");
 39
 40GuiImageList::GuiImageList()
 41{
 42  VECTOR_SET_ASSOCIATION(mTextures);
 43  mTextures.clear();
 44  mUniqueId = 0;
 45}
 46
 47U32 GuiImageList::Insert( const char* texturePath, GFXTextureProfile *Type )
 48{
 49  TextureEntry *t = new TextureEntry;
 50
 51  t->TexturePath = StringTable->insert(texturePath);
 52  if ( *t->TexturePath ) 
 53  {
 54    t->Handle = GFXTexHandle(t->TexturePath, Type, avar("%s() - t->Handle (line %d)", __FUNCTION__, __LINE__));
 55
 56    if ( t->Handle )
 57    {
 58      t->id = ++mUniqueId;
 59
 60      mTextures.push_back( t );
 61
 62      return t->id;
 63
 64    }
 65  }
 66
 67  // Free Texture Entry.
 68  delete t;
 69
 70  // Return Failure.
 71  return -1;
 72
 73}
 74
 75bool GuiImageList::Clear()
 76{
 77  while ( mTextures.size() )
 78    FreeTextureEntry( mTextures[0] );
 79  mTextures.clear();
 80
 81  mUniqueId = 0;
 82
 83  return true;
 84}
 85
 86bool GuiImageList::FreeTextureEntry( U32 Index )
 87{
 88  U32 Id = IndexFromId( Index );
 89  if ( Id != -1 )
 90     return FreeTextureEntry( mTextures[ Id ] );
 91  else
 92    return false;
 93}
 94
 95bool GuiImageList::FreeTextureEntry( PTextureEntry Entry )
 96{
 97  if ( ! Entry )
 98    return false;
 99
100  U32 id = IndexFromId( Entry->id );
101
102  delete Entry;
103
104  mTextures.erase ( id );
105
106  return true;
107}
108
109U32 GuiImageList::IndexFromId ( U32 Id )
110{
111  if ( !mTextures.size() ) return -1;
112  Vector<PTextureEntry>::iterator i = mTextures.begin();
113  U32 j = 0;
114  for ( ; i != mTextures.end(); i++ )
115  {
116    if ( i )
117    {
118    if ( (*i)->id == Id )
119      return j;
120    j++;
121    }
122  }
123
124  return -1;
125}
126
127U32 GuiImageList::IndexFromPath ( const char* Path )
128{
129  if ( !mTextures.size() ) return -1;
130  Vector<PTextureEntry>::iterator i = mTextures.begin();
131  for ( ; i != mTextures.end(); i++ )
132  {
133    if ( dStricmp( Path, (*i)->TexturePath ) == 0 )
134      return (*i)->id;
135  }
136
137  return -1;
138}
139
140void GuiImageList::initPersistFields()
141{
142  Parent::initPersistFields();
143}
144
145DefineEngineMethod( GuiImageList, getImage, const char*, (int index),,
146   "@brief Get a path to the texture at the specified index.\n\n"
147   "@param index Index of the image in the list.\n"
148   "@tsexample\n"
149   "// Define the image index/n"
150   "%index = \"5\";\n\n"
151   "// Request the image path location from the control.\n"
152   "%imagePath = %thisGuiImageList.getImage(%index);\n"
153   "@endtsexample\n\n"
154   "@return File path to the image map for the specified index.\n\n"
155   "@see SimObject")
156{
157  return object->GetTexturePath(index);
158}
159
160DefineEngineMethod(GuiImageList, clear, bool, (),,
161   "@brief Clears the imagelist\n\n"
162   "@tsexample\n"
163   "// Inform the GuiImageList control to clear itself.\n"
164   "%isFinished = %thisGuiImageList.clear();\n"
165   "@endtsexample\n\n"
166   "@return Returns true when finished.\n\n"
167   "@see SimObject")
168{
169  return object->Clear();
170}
171
172DefineEngineMethod( GuiImageList, count, S32, (),,
173   "@brief Gets the number of images in the list.\n\n"
174   "@tsexample\n"
175   "// Request the number of images from the GuiImageList control.\n"
176   "%imageCount = %thisGuiImageList.count();\n"
177   "@endtsexample\n\n"
178   "@return Number of images in the control.\n\n"
179   "@see SimObject")
180{
181  return object->Count();
182}
183
184DefineEngineMethod( GuiImageList, remove, bool, (S32 index),,
185   "@brief Removes an image from the list by index.\n\n"
186   "@param index Image index to remove.\n"
187   "@tsexample\n"
188   "// Define the image index.\n"
189   "%imageIndex = \"4\";\n\n"
190   "// Inform the GuiImageList control to remove the image at the defined index.\n"
191   "%wasSuccessful = %thisGuiImageList.remove(%imageIndex);\n"
192   "@endtsexample\n\n"
193   "@return True if the operation was successful, false if it was not.\n\n"
194   "@see SimObject")
195{
196  return object->FreeTextureEntry( index );
197}
198
199DefineEngineMethod( GuiImageList, getIndex, S32, (const char* imagePath),,
200   "@brief Retrieves the imageindex of a specified texture in the list.\n\n"
201   "@param imagePath Imagemap including filepath of image to search for\n"
202   "@tsexample\n"
203   "// Define the imagemap to search for\n"
204   "%imagePath = \"./game/client/data/images/thisImage\";\n\n"
205   "// Request the index entry for the defined imagemap\n"
206   "%imageIndex = %thisGuiImageList.getIndex(%imagePath);\n"
207   "@endtsexample\n\n"
208   "@return Index of the imagemap matching the defined image path.\n\n"
209   "@see SimObject")
210{
211  return object->IndexFromPath( imagePath );
212}
213
214DefineEngineMethod(GuiImageList, insert, S32, (const char* imagePath),,
215   "@brief Insert an image into imagelist- returns the image index or -1 for failure.\n\n"
216   "@param imagePath Imagemap, with path, to add to the list.\n"
217   "@tsexample\n"
218   "// Define the imagemap to add to the list\n"
219   "%imagePath = \"./game/client/data/images/thisImage\";\n\n"
220   "// Request the GuiImageList control to add the defined image to its list.\n"
221   "%imageIndex = %thisGuiImageList.insert(%imagePath);\n"
222   "@endtsexample\n\n"
223   "@return The index of the newly inserted imagemap, or -1 if the insertion failed.\n\n"
224   "@see SimObject")
225{
226  return object->Insert( imagePath );
227}
228
229GFXTexHandle GuiImageList::GetTextureHandle( U32 Index )
230{
231  U32 ItemIndex = IndexFromId(Index);
232  if ( ItemIndex != -1 )
233    return mTextures[ItemIndex]->Handle;
234  else
235    return NULL;
236
237}
238GFXTexHandle GuiImageList::GetTextureHandle( const char* TexturePath )
239{
240  Vector<PTextureEntry>::iterator i = mTextures.begin();
241  for ( ; i != mTextures.end(); i++ )
242  {
243    if ( dStricmp( TexturePath, (*i)->TexturePath ) == 0 )
244      return (*i)->Handle;
245  }
246
247  return NULL;
248}
249
250
251const char *GuiImageList::GetTexturePath( U32 Index )
252{
253  U32 ItemIndex = IndexFromId(Index);
254  if ( ItemIndex != -1 )
255    return mTextures[ItemIndex]->TexturePath;
256  else
257    return "";
258}
259