FontAsset.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _FONT_ASSET_H_
  23. #define _FONT_ASSET_H_
  24. #ifndef _ASSET_PTR_H_
  25. #include "assets/assetPtr.h"
  26. #endif
  27. #ifndef _IMAGE_ASSET_H_
  28. #include "2d/assets/ImageAsset.h"
  29. #endif
  30. #ifndef _BITMAP_FONT_H_
  31. #include "bitmapFont/BitmapFont.h"
  32. #endif
  33. //-----------------------------------------------------------------------------
  34. DefineConsoleType(TypeFontAssetPtr)
  35. //-----------------------------------------------------------------------------
  36. using namespace font;
  37. class FontAsset : public AssetBase
  38. {
  39. private:
  40. typedef AssetBase Parent;
  41. public:
  42. StringTableEntry mFontFile;
  43. AssetPtr<ImageAsset> mImageAsset;
  44. BitmapFont mBitmapFont;
  45. public:
  46. FontAsset();
  47. virtual ~FontAsset();
  48. /// Core.
  49. static void initPersistFields();
  50. virtual bool onAdd();
  51. virtual void onRemove();
  52. virtual void copyTo(SimObject* object);
  53. void setFontFile( const char* pFontFile );
  54. inline StringTableEntry getFontFile( void ) const { return mFontFile; }
  55. inline TextureHandle& getImageTexture(U16 pageID) { return mBitmapFont.mTexture[pageID]; }
  56. /// Declare Console Object.
  57. DECLARE_CONOBJECT(FontAsset);
  58. private:
  59. void buildFontData( void );
  60. protected:
  61. virtual void initializeAsset( void );
  62. virtual void onAssetRefresh( void );
  63. /// Taml callbacks.
  64. virtual void onTamlPreWrite( void );
  65. virtual void onTamlPostWrite( void );
  66. virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
  67. virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
  68. protected:
  69. static bool setFontFile( void* obj, const char* data ) { static_cast<FontAsset*>(obj)->setFontFile(data); return false; }
  70. static bool writeFontFile( void* obj, StringTableEntry pFieldName ) { return static_cast<FontAsset*>(obj)->getFontFile() != StringTable->EmptyString; }
  71. };
  72. #endif // _FONT_ASSET_H_