diff --git a/src/sys/graphics/main.cpp b/src/sys/graphics/main.cpp index 4780e11..f87e098 100755 --- a/src/sys/graphics/main.cpp +++ b/src/sys/graphics/main.cpp @@ -17,13 +17,16 @@ bool result; TGfx0* buf=0; TGfx0* buf2=0; + TScreen* Screen=0; + Screen = new TScreen(); TDPFont* font=0; buf = new TGfx0(); buf2 = new TGfx0(); font = new TDPFont(buf); buf->create(400,400,def_pixfmt_8bpp); // buf2->create(400,400,def_pixfmt_15bpp); - buf2->alias(*buf,0,3,8,8); + //buf2->alias(*buf,0,3,8,8); + buf2->clone(*buf); buf2->putPixel(0,0,1); buf2->putPixel(buf2->getMaxX(),buf2->getMaxY(),1); buf2->clear(1); @@ -31,11 +34,12 @@ font->SetColor(1); font->PutText(0,0," World"); buf->copyBuf(0,0,*buf,40,0,79,8); - for (r=0; r<=15; r++) { - for (g=0; g<=79; g++) + for (r=0; r<8; r++) { + for (g=0; g<80; g++) if (buf->getPixel(g,r)) printf("*"); else printf(" "); printf("\n"); } + if (Screen) delete Screen; if (buf) delete buf; if (buf2) delete buf2; if (font) delete font; diff --git a/src/sys/graphics/objgfx30.cpp b/src/sys/graphics/objgfx30.cpp index c145c9e..38863e9 100755 --- a/src/sys/graphics/objgfx30.cpp +++ b/src/sys/graphics/objgfx30.cpp @@ -5,14 +5,17 @@ #include "objgfx30.h" #include #include +#include +#include #include // TGfx0 constructor TGfx0::TGfx0(void) { + printf("TGfx0()\n"); DataState = og_None; - Buffer = 0; - LineOfs = 0; - pal = 0; + Buffer = NULL; + LineOfs = NULL; + pal = NULL; xRes = 0; yRes = 0; MaxX = 0; @@ -72,6 +75,53 @@ void TGfx0::arc(UInt32 x_center, UInt32 y_center, UInt32 radius, UInt32 s_angle, UInt32 e_angle, UInt32 colour) { + Int32 p; + UInt32 x, y, tmp; + double alpha; + + if (radius==0) { + putPixel(x_center, y_center, colour); + return; + } // if + + s_angle%=361; + e_angle%=361; + + if (s_angle>e_angle) { + tmp = s_angle; + s_angle = e_angle; + e_angle = tmp; + } // if + + x = 0; + y = radius; + p = 3-2*radius; + + while (x<=y) { + alpha = RadToDeg(atan(x/y)); + if ((alpha>=s_angle) && (alpha<=e_angle)) + putPixel(x_center-x, y_center-y, colour); + if ((90-alpha>=s_angle) && (90-alpha<=e_angle)) + putPixel(x_center-y, y_center-x, colour); + if ((90+alpha>=s_angle) && (90+alpha<=e_angle)) + putPixel(x_center-y, y_center+x,colour); + if ((180-alpha>=s_angle) && (180-alpha<=e_angle)) + putPixel(x_center-x, y_center+y,colour); + if ((180+alpha>=s_angle) && (180+alpha<=e_angle)) + putPixel(x_center+x, y_center+y,colour); + if ((270-alpha>=s_angle) && (270-alpha<=e_angle)) + putPixel(x_center+y, y_center+x,colour); + if ((270+alpha>=s_angle) && (270+alpha<=e_angle)) + putPixel(x_center+y, y_center-x,colour); + if ((360-alpha>=s_angle) && (360-alpha<=e_angle)) + putPixel(x_center+x, y_center-y,colour); + if (p<0) p+=4*x+6; + else { + p+=4*(x-y)+10; + y--; + } + x++; + } // while } // TGfx0::arc void @@ -99,7 +149,24 @@ void TGfx0::circle(Int32 x_center, Int32 y_center, UInt32 radius, UInt32 colour) { - + Int32 x, y, d; + x = 0; + y = radius; + d = 2*(1-radius); + while (y>=0) { + putPixel(x_center+x,y_center+y,colour); + putPixel(x_center+x,y_center-y,colour); + putPixel(x_center-x,y_center+y,colour); + putPixel(x_center-x,y_center-y,colour); + if (d + y > 0) { + y--; + d -= 2*y+1; + } // if + if (x > d) { + x++; + d += 2*x+1; + } // if + } // while } // TGfx0::circle void @@ -228,79 +295,34 @@ if (SrcObject.DataState==og_None) return; SrcObject.getPixFmt(pixfmt); create(SrcObject.MaxX+1,SrcObject.MaxY+1,pixfmt); - if (pal!=NULL) pal = SrcObject.pal; + if (pal!=NULL) memcpy(pal, SrcObject.pal, sizeof(TRGB)*256); copy(SrcObject); } // TGfx0::clone -bool -TGfx0::create(UInt32 _xRes, UInt32 _yRes,TPixelFmt _pixformat) { - /* - * constructor TGfx0::create() - * Allocates memory for a buffer of size _xRes by _yRes with - * the pixel format defined in _pixformat. Allocates memory - * for pal and LineOfs. - */ - UInt32 yy; - if (DataState==og_Owner) { - if (Buffer) free(Buffer); - if (LineOfs) free(LineOfs); - if (pal) free(pal); - } // if datastate - BPP = _pixformat.BPP; - bSize=_xRes*_yRes*((BPP+7) >> 3); - Buffer = malloc(bSize); - if (!Buffer) return FALSE; - memset(Buffer,0,bSize); - lSize = _yRes*sizeof(UInt32); - LineOfs = (UInt32*)malloc(lSize); - if (!LineOfs) return FALSE; - pal = (TRGB*)malloc(256*sizeof(TRGB)); - if (!pal) return FALSE; - memset(pal,0,sizeof(TRGB)*256); - MaxX=_xRes-1; - xRes=_xRes*((BPP+7) >> 3); - MaxY=_yRes-1; - yRes=_yRes; - LineOfs[0]=0; - for (yy=1; yy<=MaxY; yy++) - LineOfs[yy]=LineOfs[yy-1]+xRes; - DataState = og_Owner; - // For 8bpp modes the next part doesn't matter - RedFieldPosition=_pixformat.RedFieldPosition; - GreenFieldPosition=_pixformat.GreenFieldPosition; - BlueFieldPosition=_pixformat.BlueFieldPosition; - // The next part is only used by 15/16hpp - RedShifter=8-_pixformat.RedMaskSize; - GreenShifter=8-_pixformat.GreenMaskSize; - BlueShifter=8-_pixformat.BlueMaskSize; - Owner = this; - return TRUE; -} // TGfx0::create - void TGfx0::copy(TGfx0& SrcObject) { UInt32 count, xCount, yCount; UInt32 xx, yy; UInt8 r, g, b; - if (Buffer==NULL) return; - if (SrcObject.Buffer==NULL) return; + if ((Buffer==NULL) || (LineOfs==NULL)) return; + if ((SrcObject.Buffer==NULL) || (SrcObject.LineOfs==NULL)) return; xCount = SrcObject.MaxX+1; if (xCount>MaxX+1) xCount=MaxX+1; yCount = SrcObject.MaxY+1; - if (yCount>MaxY+1) yCount=MaxY; + if (yCount>MaxY+1) yCount=MaxY+1; if ((BPP!=SrcObject.BPP) || (RedShifter!=SrcObject.RedShifter) || (BlueShifter!=SrcObject.BlueShifter) || (GreenShifter!=SrcObject.GreenShifter)) { - for (yy=0; yy> 3); // adjust for bpp - for (count=0; count<=yCount; count++) ; + xCount *= ((BPP+7) >> 3); // adjust for bpp + for (count=0; count<=yCount-1; count++) ; memcpy(((char*)Buffer+LineOfs[count]), // dest ((char*)SrcObject.Buffer+SrcObject.LineOfs[count]), // src xCount); // len @@ -350,6 +372,7 @@ } // if if ((DestX+xCount<0) || (DestY+yCount<0)) return; + if ((BPP!=SrcObject.BPP) || (RedShifter!=SrcObject.RedShifter) || (BlueShifter!=SrcObject.BlueShifter) || (GreenShifter!=SrcObject.GreenShifter)) { @@ -358,15 +381,15 @@ pixmap[xx] = RGB(SrcObject.pal[xx].red, SrcObject.pal[xx].green, SrcObject.pal[xx].blue); - for (yy=0; yybpp else { - for (yy=0; yy> 3); + Buffer = malloc(bSize); + if (Buffer==NULL) return FALSE; + memset(Buffer,0,bSize); + lSize = _yRes*sizeof(UInt32); + LineOfs = (UInt32*)malloc(lSize); + if (LineOfs == NULL) return FALSE; + pal = (TRGB*)malloc(256*sizeof(TRGB)); + if (pal == NULL) return FALSE; + memset(pal,0,sizeof(TRGB)*256); + MaxX=_xRes-1; + xRes=_xRes*((BPP+7) >> 3); + MaxY=_yRes-1; + yRes=_yRes; + LineOfs[0]=0; + for (yy=1; yy<=MaxY; yy++) + LineOfs[yy]=LineOfs[yy-1]+xRes; + DataState = og_Owner; + // For 8bpp modes the next part doesn't matter + RedFieldPosition=_pixformat.RedFieldPosition; + GreenFieldPosition=_pixformat.GreenFieldPosition; + BlueFieldPosition=_pixformat.BlueFieldPosition; + // The next part is only used by 15/16hpp + RedShifter=8-_pixformat.RedMaskSize; + GreenShifter=8-_pixformat.GreenMaskSize; + BlueShifter=8-_pixformat.BlueMaskSize; + Owner = this; + return TRUE; +} // TGfx0::create + void TGfx0::flipX(void) { @@ -765,5 +833,25 @@ bSize = 0; lSize = 0; DataState = og_None; + printf("~TGfx0()\n"); return; } // TGfx0::~TGfx0() + +/* + * + * TSCREEN METHODS + * + */ + +TScreen::TScreen(void) { + printf("TScreen()\n"); + InGraphics = FALSE; + VESARec = NULL; + ModeRec = NULL; + return; +} + +TScreen::~TScreen(void) { + printf("~TScreen()\n"); + return; +} diff --git a/src/sys/graphics/objgfx30.h b/src/sys/graphics/objgfx30.h index 0951889..09afc4c 100755 --- a/src/sys/graphics/objgfx30.h +++ b/src/sys/graphics/objgfx30.h @@ -5,6 +5,7 @@ #ifndef OBJGFX30_H #define OBJGFX30_H +#include // for NULL #ifndef TRUE #define TRUE 1 #endif @@ -37,6 +38,8 @@ #define gm1024x768x16m 0x118 #define gm1280x1024x16m 0x11B +#define RadToDeg 180.0/3.14159265358979; + typedef signed char Int8; typedef signed short int Int16; typedef signed long int Int32; @@ -124,7 +127,8 @@ const TPixelFmt def_pixfmt_24bpp = {24,16,8,0,8,8,8}; const TPixelFmt def_pixfmt_32bpp = {32,16,8,0,8,8,8}; -class TGfx0 { +class TGfx0 +{ protected: TGfx0* Owner; void* Buffer; @@ -185,7 +189,16 @@ void unpackRGB(UInt32, UInt8&, UInt8&, UInt8&); // vLine ~TGfx0(void); - }; // gfx0 +}; // TGfx0 - +class TScreen: public TGfx0 +{ + protected: + TVESA_Rec* VESARec; + TMode_Rec* ModeRec; + bool InGraphics; + public: + TScreen(void); + ~TScreen(void); +}; // TScreen #endif