diff --git a/src/sys/graphics/objfont.cpp b/src/sys/graphics/objfont.cpp index 2d759b9..051b7de 100755 --- a/src/sys/graphics/objfont.cpp +++ b/src/sys/graphics/objfont.cpp @@ -1,2 +1,77 @@ #include "objfont.h" +#include "objgfx30.h" +#include +#include +TFont::TFont(TGfx0* buffer) { + Buf = buffer; + FontDataSize = 0; + memset(FontDataIdx,0,sizeof(FontDataIdx)); + memset(CharWidthTable,0,sizeof(CharWidthTable)); + memset(CharHeightTable,0,sizeof(CharHeightTable)); + FontData = 0; + return; +} // TFont::TFont + +void TFont::CenterTextX(Int32 y, const char * TextString ) { + Int32 x; + x = ((Buf->getMaxX()+1)-TextWidth(TextString)) / 2; + PutText(x,y,TextString); + return; +} // TFont::CenterTextX + +void TFont::JustifyText(UInt8 Horiz, UInt8 Vert, const char * TextString) { + UInt32 x,y; + switch (Horiz) { + case LeftText: + x = 0; + break; + case CenterText: + x = ((Buf->getMaxX())-TextWidth(TextString)) / 2; + break; + case RightText: + x = (Buf->getMaxX())-TextWidth(TextString); + break; + default: + return; + } // switch + + switch (Vert) { + case TopText: + y = 0; + break; + case CenterText: + y = ((Buf->getMaxY())-TextHeight(TextString)) / 2; + break; + case BottomText: + y = (Buf->getMaxY())-TextHeight(TextString); + default: + return; + } // switch + PutText(x,y,TextString); + return; +} // TFont::JustifyText + +UInt32 TFont::TextHeight(const char * TextString) { + UInt32 size, tmpsize; + size = 0; + if (TextString) + while (*TextString) { + tmpsize = CharHeightTable[*TextString++]; + if (tmpsize>size) size = tmpsize; + } + return size; +} // TFont::TextHeight + +UInt32 TFont::TextWidth(const char * TextString) { + UInt32 size=0; + if (TextString) + while (*TextString) + size+=CharWidthTable[*TextString++]; + return size; +} // TFont::TextWidth + +TFont::~TFont(void) { + if (FontDataSize) free(FontData); + return; +} // TFont::~TFont diff --git a/src/sys/graphics/objfont.h b/src/sys/graphics/objfont.h index ce14e76..580b42d 100755 --- a/src/sys/graphics/objfont.h +++ b/src/sys/graphics/objfont.h @@ -28,6 +28,22 @@ } TDPFHeader; class TFont { - + protected: + UInt32 FontDataIdx[256]; + UInt16 CharWidthTable[256]; + UInt16 CharHeightTable[256]; + TGfx0* Buf; + UInt32 FontDataSize; + void * FontData; + public: + TFont(TGfx0 *); + virtual void PutText(Int32, Int32,const char *)=0; + void CenterTextX(Int32 Y, const char *); + void JustifyText(UInt8, UInt8, const char *); + UInt32 TextHeight(const char *); + UInt32 TextWidth(const char *); + virtual ~TFont(void); }; + + #endif diff --git a/src/sys/graphics/objgfx30.h b/src/sys/graphics/objgfx30.h index 403af6f..59b21a4 100755 --- a/src/sys/graphics/objgfx30.h +++ b/src/sys/graphics/objgfx30.h @@ -119,7 +119,7 @@ const TPixelFmt def_pixfmt_32bpp = {32,16,8,0,8,8,8}; class TGfx0 { - public: + protected: TGfx0* Owner; void* Buffer; UInt32* LineOfs;