Woopsi 1.0
GUI Framework for Nintendo DS Homebrew

packedfontbase.h

00001 /* Contributed by Jeff Laing
00002  * 20080414
00003  */
00004 
00005 #ifndef _PACKED_FONT_BASE_
00006 #define _PACKED_FONT_BASE_
00007 
00008 #include <nds.h>
00009 #include "fontbase.h"
00010 
00011 namespace WoopsiUI {
00012 
00017         class PackedFontBase : public FontBase
00018         {
00019         public:
00032                 PackedFontBase(
00033                         u8 first, u8 last,
00034                         const u16 *glyphData,
00035                         const u16 *glyphOffset,
00036                         const u8 *glyphWidth,
00037                         const u8 height,
00038                         const u8 spWidth,
00039                         const u8 fontTop,
00040                         const u8 fixedWidth = 0)
00041                         :
00042                           FontBase(height, 0),
00043                           _first(first), _last(last),
00044                           _glyphData(glyphData), _glyphOffset(glyphOffset), _glyphWidth(glyphWidth),
00045                           _fontWidth(0), _spWidth(spWidth),
00046                           _fontTop(fontTop), _widMax(fixedWidth) { };
00047 
00054                 inline void setFontWidth(u8 fontWidth) { _fontWidth = (fontWidth && (fontWidth < _widMax)) ? _widMax : fontWidth; };
00055 
00068                 virtual s16 drawChar(
00069                         MutableBitmapBase* bitmap,
00070                         u32 letter,
00071                         s16 x, s16 y,
00072                         u16 clipX1, u16 clipY1, u16 clipX2, u16 clipY2);
00073                 
00086                 virtual s16 drawBaselineChar(
00087                         MutableBitmapBase* bitmap,
00088                         u32 letter,
00089                         s16 x, s16 y,
00090                         u16 clipX1, u16 clipY1, u16 clipX2, u16 clipY2) {
00091                         return drawChar(bitmap,letter,x, y-getCharTop(y),clipX1, clipY1, clipX2, clipY2);
00092                         };                      
00093                 
00099                 virtual u16 getStringWidth(const WoopsiString& text) const;
00100 
00110                 virtual u16 getStringWidth(const WoopsiString& text, s32 startIndex, s32 length) const;
00111 
00117                 virtual u8 getCharWidth(u32 letter) const;
00118 
00124                 inline virtual s8 getCharTop(u32 letter) const {return _fontTop;};
00125 
00129                 const bool isCharBlank(const u32 letter) const;
00130 
00143                 virtual void renderChar(
00144                         const u16* pixelData, u16 pixelsPerRow,
00145                         MutableBitmapBase* bitmap,
00146                         s16 x, s16 y,
00147                         u16 clipX1, u16 clipY1, u16 clipX2, u16 clipY2) = 0;
00148 
00149         protected:
00150                 u8 _first;                                      
00151                 u8 _last;                                       
00152                 const u16 *_glyphData;          
00153                 const u16 *_glyphOffset;        
00154                 const u8 *_glyphWidth;          
00155                 u8 _fontWidth;                          
00156                 u8 _spWidth;                            
00157                 u8 _fontTop;                            
00158                 u8 _widMax;                                     
00159         };
00160 }
00161 
00162 #endif