AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzFont.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_FONT_H_)
00015 #define _CCZ_FONT_H_
00016 
00017 #include "CzUtil.h"
00018 #include "CzXoml.h"
00019 #include "IzPlatformFont.h"
00020 
00021 class CzXomlResourceManager;
00022 
00023 //
00024 //
00025 //
00026 //
00027 // CzFont - Represents a text rendering font
00028 //
00029 //
00030 //
00031 //
00032 class CzFont : public IzXomlResource
00033 {
00034 public:
00035     enum eState
00036     {
00037         State_Invalid, 
00038         State_Loading, 
00039         State_Loaded, 
00040     };
00041 
00042     // Properties
00043 protected:
00044     eState                  State;              // State of image
00045     CzFontHandle            Font;               // Font handle
00046     float                   PointSize;          // Point size of font
00047     CzString                Filename;           // Name of font file
00048     CzFont*                 UsingFont;          // Points to a font that this font is re-using
00049     uint8*                  FontBuffer;         // Holds loaded TTF font data
00050     uint                    FontBufferSize;     // Size of TTF font data
00051 public:
00052     eState                  getState() const                        { return State; }
00053     CzFontHandle            getFontHandle();
00054     void                    setPointSize(float size)                { PointSize = size; }
00055     float                   getPointSize() const                    { return PointSize; }
00056     CzFont*                 getUsingFont()                          { return UsingFont; }
00057     void                    setFilename(const char* filename)       { Filename = filename; }
00058     CzString&               getFilename()                           { return Filename; }
00059     bool                    isFontLoaded() const                    { return Font != NULL; }
00060     uint8*                  getFontBuffer()                         { return FontBuffer; }
00061     uint                    getFontBufferSize()                     { return FontBufferSize; }
00062     // Properties End
00063 protected:
00064     CzFile*                 File;               // File object (if font is file based)
00065     bool                    Delete;
00066 
00067 public:
00068     CzFont() : IzXomlResource(), Font(NULL), UsingFont(NULL), File(NULL), State(State_Invalid), PointSize(8), Delete(false), FontBuffer(NULL), FontBufferSize(0)        { setClassType("font"); }
00069     virtual ~CzFont();
00070 
00071     bool            Load(bool blocking = true);                     // Force load the image
00072 
00073     // Implementation of IzXomlClass interface
00074     int             LoadFromXoml(IzXomlResource* parebt, bool load_children, CzXmlNode* node);
00075 
00076     // Prepeared text (optimised for render)
00077     CzFontPreparedText  CreatePreparedText();
00078 
00079     // Internal
00080     void            FinishLoad();                                   // Called back when aysnc loading is completed
00081 };
00082 
00083 //
00084 //  CzFontCreator - Creates an instance of a font object
00085 //
00086 class CzFontCreator : public IzXomlClassCreator
00087 {
00088 public:
00089     CzFontCreator()
00090     {
00091         setClassName("font");
00092     }
00093     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzFont(); }
00094 };
00095 
00096 //
00097 //
00098 //
00099 //
00100 //  Helper macros
00101 //
00102 //
00103 //
00104 //
00105 
00106 #define CZ_NEW_FONT(font, name, location, point_size)       \
00107     CzFont* font = new CzFont();                            \
00108     font->setName("serif");                                 \
00109     font->setFilename(location);                            \
00110     font->setPointSize(point_size);                         \
00111     font->Load();
00112 
00113 
00114 
00115 
00116 #endif  // _CCZ_FONT_H_