diff --git a/src/sys/graphics/main.cpp b/src/sys/graphics/main.cpp index 3f13f9d..4608d35 100755 --- a/src/sys/graphics/main.cpp +++ b/src/sys/graphics/main.cpp @@ -23,7 +23,7 @@ TDPFont* font=0; buf = new TGfx0(); buf2 = new TGfx0(); - font = new TDPFont(buf); + font = new TDPFont(); buf->create(400,400,def_pixfmt_32bpp); // buf2->create(400,400,def_pixfmt_15bpp); // buf2->alias(*buf,0,3,8,8); @@ -31,14 +31,14 @@ buf2->putPixel(0,0,1); buf2->putPixel(buf2->getMaxX(),buf2->getMaxY(),1); buf2->clear(1); - result = font->Load("PACMAN.DPF"); - font->SetColor(1); - font->PutText(0,0," World"); + result = font->load("PACMAN.DPF"); + font->setColor(255,255,255); + font->putText(*buf,0,0," World"); // buf->copyBuf(0,0,*buf,40,0,79,8); buf->rectangle(0,0,15,7,1); for (r=0; r<8; r++) { for (g=0; g<80; g++) - if (buf->getPixel(g,r)==1) printf("*"); else printf(" "); + if (buf->getPixel(g,r)) printf("*"); else printf(" "); printf("\n"); } if (Screen) delete Screen; diff --git a/src/sys/graphics/objfont.cpp b/src/sys/graphics/objfont.cpp index 1c574c1..50b4619 100755 --- a/src/sys/graphics/objfont.cpp +++ b/src/sys/graphics/objfont.cpp @@ -4,8 +4,7 @@ #include #include -TFont::TFont(TGfx0* buffer) { - Buf = buffer; +TFont::TFont(void) { memset(FontDataIdx,0,sizeof(FontDataIdx)); memset(CharWidthTable,0,sizeof(CharWidthTable)); memset(CharHeightTable,0,sizeof(CharHeightTable)); @@ -14,24 +13,26 @@ return; } // TFont::TFont -void TFont::CenterTextX(Int32 y, const char * TextString ) { +void +TFont::centerTextX(TGfx0& Buf, Int32 y, const char * TextString ) { Int32 x; - x = ((Buf->getMaxX()+1)-TextWidth(TextString)) / 2; - PutText(x,y,TextString); + x = ((Buf.getMaxX()+1)-textWidth(TextString)) / 2; + putText(Buf,x,y,TextString); return; -} // TFont::CenterTextX +} // TFont::centerTextX -void TFont::JustifyText(UInt8 Horiz, UInt8 Vert, const char * TextString) { +void +TFont::justifyText(TGfx0& Buf, 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; + x = ((Buf.getMaxX())-textWidth(TextString)) / 2; break; case RightText: - x = (Buf->getMaxX())-TextWidth(TextString); + x = (Buf.getMaxX())-textWidth(TextString); break; default: return; @@ -42,30 +43,34 @@ y = 0; break; case CenterText: - y = ((Buf->getMaxY())-TextHeight(TextString)) / 2; + y = ((Buf.getMaxY())-textHeight(TextString)) / 2; break; case BottomText: - y = (Buf->getMaxY())-TextHeight(TextString); + y = (Buf.getMaxY())-textHeight(TextString); default: return; } // switch - PutText(x,y,TextString); + putText(Buf,x,y,TextString); return; -} // TFont::JustifyText +} // TFont::justifyText -bool TFont::Load(const char* FontFile) { - return LoadFrom(FontFile,0); +bool +TFont::load(const char* FontFile) { + return loadFrom(FontFile,0); } // TFont::Load -bool TFont::LoadFrom(const char* FontFile, UInt32 Offset) { +bool +TFont::loadFrom(const char* FontFile, UInt32 Offset) { return TRUE; -} // TFont::LoadFrom +} // TFont::loadFrom -bool TFont::Save(const char* FontFile) { - return SaveTo(FontFile,0); -} // TFont::Save +bool +TFont::save(const char* FontFile) { + return saveTo(FontFile,0); +} // TFont::save -UInt32 TFont::TextHeight(const char * TextString) { +UInt32 +TFont::textHeight(const char * TextString) { UInt32 size, tmpsize; size = 0; if (TextString) @@ -74,15 +79,16 @@ if (tmpsize>size) size = tmpsize; } return size; -} // TFont::TextHeight +} // TFont::textHeight -UInt32 TFont::TextWidth(const char * TextString) { +UInt32 +TFont::textWidth(const char * TextString) { UInt32 size=0; if (TextString) while (*TextString) size+=CharWidthTable[*TextString++]; return size; -} // TFont::TextWidth +} // TFont::textWidth TFont::~TFont(void) { if (FontDataSize) free(FontData); @@ -91,23 +97,39 @@ /* TBMFont methods */ -void TBMFont::SetColor(UInt32 colour) { - ColourTable[1] = colour; +void +TBMFont::setColor(UInt8 r, UInt8 g, UInt8 b) { + ColourTable[1].red = r; + ColourTable[1].green = g; + ColourTable[1].blue = b; return; -} // TBMFont::SetColor +} // TBMFont::setColor -void TBMFont::SetIdxColor(UInt8 idx, UInt32 colour) { - ColourTable[idx] = colour; +void +TBMFont::setIdxColor(UInt8 idx, UInt8 r, UInt8 g, UInt8 b) { + if (idx>=31) return; + ColourTable[idx].red = r; + ColourTable[idx].green = g; + ColourTable[idx].blue = b; return; -} // TBMFont::SetIdxColor +} // TBMFont::setIdxColor -void TBMFont::PutText(Int32 x, Int32 y, const char * TextString) { +void +TBMFont::putText(TGfx0& Buf, Int32 x, Int32 y, const char * TextString) { + UInt32 ct[32]; UInt32 xx, yy; UInt8 * offset; UInt8 pix; char ch; if (!FontData) return; if (!TextString) return; + + for (xx=0; xx<=31; xx++) + ct[xx]=Buf.RGB(ColourTable[xx].red, + ColourTable[xx].green, + ColourTable[xx].blue); + + while (*TextString) { ch = *TextString++; if ((CharWidthTable[ch]) && (ch!=' ')) { @@ -116,21 +138,23 @@ for (yy=0; yy<=(UInt32)(CharHeightTable[ch]-1); yy++) for (xx=0; xx<=(UInt32)(CharWidthTable[ch]-1); xx++) { pix = *offset++; - if (pix) Buf->putPixel(x+xx,y+yy,ColourTable[pix]); + if ((pix) && (pix<=31)) Buf.putPixel(x+xx,y+yy,ct[pix]); } // for xx x+=CharWidthTable[ch]; } // if charwidthtable } // while return; -} // TBMFont::PutText +} // TBMFont::putText /* TDPFont methods */ -bool TDPFont::SaveTo(const char * FontFile, Int32 Offset) { +bool +TDPFont::saveTo(const char * FontFile, Int32 Offset) { return TRUE; -} +} // TDPFont::saveTo -void TDPFont::PutText(Int32 x, Int32 y, const char * TextString) { +void +TDPFont::putText(TGfx0& Buf, Int32 x, Int32 y, const char * TextString) { UInt32 xx, xcount, ycount; UInt8 * offset; UInt8 bits; @@ -148,7 +172,9 @@ do { if ((xx & 7)==0) bits = *(offset++); if (bits & 128) - Buf->putPixel(x+xx,y+ycount,ColourTable[1]); + Buf.putPixel(x+xx,y+ycount,Buf.RGB(ColourTable[1].red, + ColourTable[1].green, + ColourTable[1].blue)); xx++; bits+=bits; } while (--xcount); @@ -156,9 +182,10 @@ } // if x+=CharWidthTable[ch]; } // while -} // TDPFont::PutText +} // TDPFont::putText -bool TDPFont::LoadFrom(const char * FontFile, UInt32 Offset) { +bool +TDPFont::loadFrom(const char * FontFile, UInt32 Offset) { FILE * infile; TDPFHeader header; UInt32 lresult, size; @@ -188,4 +215,4 @@ lresult = fread(FontData,1,FontDataSize,infile); fclose(infile); return TRUE; -} // TDPFont::LoadFrom +} // TDPFont::loadFrom diff --git a/src/sys/graphics/objfont.h b/src/sys/graphics/objfont.h index b215315..a74812c 100755 --- a/src/sys/graphics/objfont.h +++ b/src/sys/graphics/objfont.h @@ -29,9 +29,9 @@ class TFont_abstract { public: - virtual void PutText(Int32, Int32, const char *)=0; - virtual bool LoadFrom(const char *, UInt32)=0; - virtual bool SaveTo(const char *, Int32)=0; + virtual void putText(TGfx0&, Int32, Int32, const char *)=0; + virtual bool loadFrom(const char *, UInt32)=0; + virtual bool saveTo(const char *, Int32)=0; }; class TFont : public TFont_abstract { @@ -43,29 +43,33 @@ UInt32 FontDataSize; void * FontData; public: - TFont(TGfx0 *); + TFont(); // virtual void PutText(Int32, Int32,const char *); - void CenterTextX(Int32, const char *); - void JustifyText(UInt8, UInt8, const char *); - bool Load(const char *); - virtual bool LoadFrom(const char *, UInt32); - bool Save(const char *); + void centerTextX(TGfx0&, Int32, const char *); + void justifyText(TGfx0&, UInt8, UInt8, const char *); + bool load(const char *); + virtual bool loadFrom(const char *, UInt32); + bool save(const char *); // virtual bool SaveTo(const char *, Int32) = 0; - UInt32 TextHeight(const char *); - UInt32 TextWidth(const char *); + UInt32 textHeight(const char *); + UInt32 textWidth(const char *); virtual ~TFont(void); }; // TFont class TBMFont : public TFont { protected: - UInt32 ColourTable[256]; + TRGB ColourTable[32]; public: - TBMFont(TGfx0 *Buffer): TFont(Buffer) { - for (UInt32 tmp=0; tmp<=255; tmp++) ColourTable[tmp]=tmp; + TBMFont(void): TFont() { + for (UInt32 tmp=0; tmp<=31; tmp++) { + ColourTable[tmp].red = 255; + ColourTable[tmp].green = 255; + ColourTable[tmp].blue = 255; + } // for } - void SetColor(UInt32); - void SetIdxColor(UInt8, UInt32); - virtual void PutText(Int32, Int32, const char *); + void setColor(UInt8, UInt8, UInt8); + void setIdxColor(UInt8, UInt8, UInt8, UInt8); + virtual void putText(TGfx0&, Int32, Int32, const char *); }; class TDPFont : public TBMFont { @@ -74,16 +78,15 @@ UInt16 NumOfChars; UInt8 StartingChar; public: - TDPFont(TGfx0 * Buffer) : TBMFont(Buffer) { + TDPFont(void) : TBMFont() { Width = 0; Height = 0; NumOfChars = 0; StartingChar = 0; } - virtual void PutText(Int32, Int32, const char *); - virtual bool LoadFrom(const char *, UInt32); - virtual bool SaveTo(const char *, Int32); + virtual void putText(TGfx0&, Int32, Int32, const char *); + virtual bool loadFrom(const char *, UInt32); + virtual bool saveTo(const char *, Int32); }; - #endif