diff options
-rw-r--r-- | graphics/VectorRenderer.cpp | 221 | ||||
-rw-r--r-- | graphics/VectorRenderer.h | 237 |
2 files changed, 263 insertions, 195 deletions
diff --git a/graphics/VectorRenderer.cpp b/graphics/VectorRenderer.cpp index 5f53c2fdf8..67a60bbde1 100644 --- a/graphics/VectorRenderer.cpp +++ b/graphics/VectorRenderer.cpp @@ -54,20 +54,24 @@ void vector_renderer_test(OSystem *_system) { _system->grabOverlay((OverlayColor*)_screen.pixels, _screen.w); vr->setSurface(&_screen); - vr->setColor(255, 0, 0); - vr->fillSurface(); - vr->setColor(255, 255, 0); + vr->clearSurface(); _system->showOverlay(); while (true) { // draw!! - vr->setColor(255, 255, 255); + vr->setFgColor(255, 255, 255); vr->fillSurface(); - vr->setColor(255, 0, 0 ); + + vr->setFgColor(255, 0, 0 ); + vr->setBgColor(25, 25, 175 ); + vr->setFillMode( VectorRenderer::kBackgroundFill ); + vr->shadowEnable( 5, 5 ); + vr->drawLine(25, 25, 125, 300); vr->drawCircle(250, 250, 100); -// vr->drawSquare(150, 25, 100, 100, true); - vr->drawRoundedSquare(150, 25, 8, 100, 75); + vr->drawSquare(150, 25, 100, 75); + vr->drawRoundedSquare(275, 25, 8, 100, 75); + _system->copyRectToOverlay((OverlayColor*)_screen.getBasePtr(0, 0), _screen.w, 0, 0, _screen.w, _screen.w); _system->updateScreen(); @@ -83,31 +87,35 @@ void vector_renderer_test(OSystem *_system) { template<typename PixelType, typename PixelFormat> void VectorRendererSpec<PixelType, PixelFormat>:: -drawSquare(int x, int y, int w, int h, bool fill) { - if ( fill ) { - PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x, y); - int pitch = Base::surfacePitch(); - +drawSquareAlg(int x, int y, int w, int h, PixelType color, bool fill) { + PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x, y); + int pitch = Base::surfacePitch(); + + if (fill) { while (h--) { - Common::set_to(ptr, ptr + w, (PixelType)_color); + Common::set_to(ptr, ptr + w, color); ptr += pitch; } } else { - drawLine(x, y, x + w, y); - drawLine(x + w, y, x + w, y + w); - drawLine(x, y + w, x + w, y + w); - drawLine(x, y, x, y + w); + Common::set_to(ptr, ptr + w, color); + Common::set_to(ptr + pitch * h, ptr + w + pitch * h, color); + + while (h--) { + *ptr = color; + *(ptr + w) = color; + ptr += pitch; + } } } template<typename PixelType, typename PixelFormat> void VectorRendererSpec<PixelType,PixelFormat>:: -drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) { +drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy, PixelType color) { PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x1, y1); int pitch = Base::surfacePitch(); int xdir = (x2 > x1) ? 1 : -1; - *ptr = (PixelType)_color; + *ptr = (PixelType)color; if (dx > dy) { int ddy = dy * 2; @@ -123,7 +131,7 @@ drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) { } ptr += xdir; - *ptr = (PixelType)_color; + *ptr = (PixelType)color; } } else { int ddx = dx * 2; @@ -139,20 +147,20 @@ drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) { } ptr += pitch; - *ptr = (PixelType)_color; + *ptr = (PixelType)color; } } ptr = (PixelType *)_activeSurface->getBasePtr(x2, y2); - *ptr = (PixelType)_color; + *ptr = (PixelType)color; } template<typename PixelType, typename PixelFormat> void VectorRendererAA<PixelType, PixelFormat>:: -blendPixelPtr(PixelType *ptr, uint8 alpha) { +blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha) { register int idst = *ptr; - register int isrc = Base::_color; + register int isrc = color; *ptr = (PixelType)( (PixelFormat::kRedMask & ((idst & PixelFormat::kRedMask) + @@ -169,7 +177,7 @@ blendPixelPtr(PixelType *ptr, uint8 alpha) { template<typename PixelType, typename PixelFormat> void VectorRendererAA<PixelType, PixelFormat>:: -drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) { +drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy, PixelType color) { PixelType *ptr = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1); int pitch = Base::surfacePitch(); @@ -177,7 +185,7 @@ drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) { uint16 error_tmp, error_acc, gradient; uint8 alpha; - *ptr = (PixelType)Base::_color; + *ptr = (PixelType)color; if (dx > dy) { gradient = (uint32)(dy << 16) / (uint32)dx; @@ -193,8 +201,8 @@ drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) { ptr += xdir; alpha = (error_acc >> 8); - blendPixelPtr(ptr, ~alpha); - blendPixelPtr(ptr + pitch, alpha); + blendPixelPtr(ptr, color, ~alpha); + blendPixelPtr(ptr + pitch, color, alpha); } } else { gradient = (uint32)(dx << 16) / (uint32)dy; @@ -210,12 +218,12 @@ drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) { ptr += pitch; alpha = (error_acc >> 8); - blendPixelPtr(ptr, ~alpha); - blendPixelPtr(ptr + xdir, alpha); + blendPixelPtr(ptr, color, ~alpha); + blendPixelPtr(ptr + xdir, color, alpha); } } - Base::putPixel(x2, y2); + Base::putPixel(x2, y2, color); } template<typename PixelType, typename PixelFormat> @@ -240,12 +248,12 @@ drawLine(int x1, int y1, int x2, int y2) { if (dy == 0) { // horizontal lines // these can be filled really fast with a single memset. // TODO: Platform specific ASM in set_to, would make this thing fly - Common::set_to(ptr, ptr + dx + 1, (PixelType)_color); + Common::set_to(ptr, ptr + dx + 1, (PixelType)_fgColor); } else if (dx == 0) { // vertical lines // these ones use a static pitch increase. while (y1++ <= y2) { - *ptr = (PixelType)_color; + *ptr = (PixelType)_fgColor; ptr += pitch; } @@ -254,12 +262,12 @@ drawLine(int x1, int y1, int x2, int y2) { pitch += (x2 > x1) ? 1 : -1; while (dy--) { - *ptr = (PixelType)_color; + *ptr = (PixelType)_fgColor; ptr += pitch; } } else { // generic lines, use the standard algorithm... - drawLineAlg(x1, y1, x2, y2, dx, dy); + drawLineAlg(x1, y1, x2, y2, dx, dy, (PixelType)_fgColor); } } @@ -288,23 +296,22 @@ inline uint32 fp_sqroot(uint32 x) { template<typename PixelType, typename PixelFormat> void VectorRendererSpec<PixelType, PixelFormat>:: -drawCircleAlg(int x1, int y1, int r) { +drawCircleAlg(int x1, int y1, int r, PixelType color, bool fill) { int f = 1 - r; int ddF_x = 0, ddF_y = -2 * r; int x = 0, y = r, px, py; int pitch = Base::surfacePitch(); PixelType *ptr = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1); - bool fill = true; px = 0; py = pitch * y; - *(ptr + y) = _color; - *(ptr - y) = _color; - *(ptr + py) = _color; - *(ptr - py) = _color; + *(ptr + y) = color; + *(ptr - y) = color; + *(ptr + py) = color; + *(ptr - py) = color; - if (fill) Common::set_to(ptr - r, ptr + r, _color); + if (fill) Common::set_to(ptr - r, ptr + r, color); while (x++ < y) { if (f >= 0) { @@ -319,33 +326,32 @@ drawCircleAlg(int x1, int y1, int r) { f += ddF_x + 1; if (fill) { - Common::set_to(ptr - x + py, ptr + x + py, _color); - Common::set_to(ptr - x - py, ptr + x - py, _color); - Common::set_to(ptr - y + px, ptr + y + px, _color); - Common::set_to(ptr - y - px, ptr + y - px, _color); + Common::set_to(ptr - x + py, ptr + x + py, color); + Common::set_to(ptr - x - py, ptr + x - py, color); + Common::set_to(ptr - y + px, ptr + y + px, color); + Common::set_to(ptr - y - px, ptr + y - px, color); } - *(ptr + x + py) = _color; - *(ptr + y - px) = _color; - *(ptr - x - py) = _color; - *(ptr - y - px) = _color; - *(ptr - y + px) = _color; - *(ptr - x + py) = _color; - *(ptr + y + px) = _color; - *(ptr + x - py) = _color; + *(ptr + x + py) = color; + *(ptr + y - px) = color; + *(ptr - x - py) = color; + *(ptr - y - px) = color; + *(ptr - y + px) = color; + *(ptr - x + py) = color; + *(ptr + y + px) = color; + *(ptr + x - py) = color; } } template<typename PixelType, typename PixelFormat> void VectorRendererAA<PixelType, PixelFormat>:: -drawRoundedSquareAlg(int x1, int y1, int r, int w, int h) { +drawRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, bool fill) { int x = r; int y = 0; int p = Base::surfacePitch(), px, py; uint32 rsq = (r * r) << 16; uint32 T = 0, oldT; uint8 a1, a2; - bool fill = true; PixelType *ptr_tl = (PixelType *)Base::_activeSurface->getBasePtr(x1 + r, y1 + r); PixelType *ptr_tr = (PixelType *)Base::_activeSurface->getBasePtr(x1 + w - r, y1 + r); @@ -353,21 +359,21 @@ drawRoundedSquareAlg(int x1, int y1, int r, int w, int h) { PixelType *ptr_br = (PixelType *)Base::_activeSurface->getBasePtr(x1 + w - r, y1 + h - r); PixelType *ptr_fill = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1); - Common::set_to(ptr_fill + r, ptr_fill + w - r + 1, Base::_color); - Common::set_to(ptr_fill + r + h*p, ptr_fill + w - r + 1 + h*p, Base::_color); + Common::set_to(ptr_fill + r, ptr_fill + w - r + 1, color); + Common::set_to(ptr_fill + r + h*p, ptr_fill + w - r + 1 + h*p, color); h -= 2*r; ptr_fill += p*r; if (!fill) { while (h-- >= 0) { - *(ptr_fill) = (PixelType)Base::_color; - *(ptr_fill + w) = (PixelType)Base::_color; + *(ptr_fill) = (PixelType)color; + *(ptr_fill + w) = (PixelType)color; ptr_fill += p; } } else { while (h-- >= 0) { - Common::set_to(ptr_fill, ptr_fill + w + 1, Base::_color); + Common::set_to(ptr_fill, ptr_fill + w + 1, color); ptr_fill += p; } } @@ -391,60 +397,59 @@ drawRoundedSquareAlg(int x1, int y1, int r, int w, int h) { a1 = ~a2; if (fill) { - Common::set_to(ptr_tl - x - py, ptr_tr + x - py, Base::_color); - Common::set_to(ptr_tl - y - px, ptr_tr + y - px, Base::_color); + Common::set_to(ptr_tl - x - py, ptr_tr + x - py, color); + Common::set_to(ptr_tl - y - px, ptr_tr + y - px, color); - Common::set_to(ptr_bl - x + py, ptr_br + x + py, Base::_color); - Common::set_to(ptr_bl - y + px, ptr_br + y + px, Base::_color); + Common::set_to(ptr_bl - x + py, ptr_br + x + py, color); + Common::set_to(ptr_bl - y + px, ptr_br + y + px, color); } else { - blendPixelPtr(ptr_tr + y - (px-p), a2); - blendPixelPtr(ptr_tr + x - 1 - py, a2); + blendPixelPtr(ptr_tr + y - (px-p), color, a2); + blendPixelPtr(ptr_tr + x - 1 - py, color, a2); - blendPixelPtr(ptr_tl - x + 1 - py, a2); - blendPixelPtr(ptr_tl - y - (px-p), a2); + blendPixelPtr(ptr_tl - x + 1 - py, color, a2); + blendPixelPtr(ptr_tl - y - (px-p), color, a2); - blendPixelPtr(ptr_bl - y + (px-p), a2); - blendPixelPtr(ptr_bl - x + 1 + py, a2); + blendPixelPtr(ptr_bl - y + (px-p), color, a2); + blendPixelPtr(ptr_bl - x + 1 + py, color, a2); - blendPixelPtr(ptr_br + x - 1 + py, a2); - blendPixelPtr(ptr_br + y + (px-p), a2); + blendPixelPtr(ptr_br + x - 1 + py, color, a2); + blendPixelPtr(ptr_br + y + (px-p), color, a2); } - blendPixelPtr(ptr_tr + y - px, a1); - blendPixelPtr(ptr_tr + x - py, a1); + blendPixelPtr(ptr_tr + y - px, color, a1); + blendPixelPtr(ptr_tr + x - py, color, a1); - blendPixelPtr(ptr_tl - x - py, a1); - blendPixelPtr(ptr_tl - y - px, a1); + blendPixelPtr(ptr_tl - x - py, color, a1); + blendPixelPtr(ptr_tl - y - px, color, a1); - blendPixelPtr(ptr_bl - y + px, a1); - blendPixelPtr(ptr_bl - x + py, a1); + blendPixelPtr(ptr_bl - y + px, color, a1); + blendPixelPtr(ptr_bl - x + py, color, a1); - blendPixelPtr(ptr_br + x + py, a1); - blendPixelPtr(ptr_br + y + px, a1); + blendPixelPtr(ptr_br + x + py, color, a1); + blendPixelPtr(ptr_br + y + px, color, a1); } } template<typename PixelType, typename PixelFormat> void VectorRendererAA<PixelType, PixelFormat>:: -drawCircleAlg(int x1, int y1, int r) { +drawCircleAlg(int x1, int y1, int r, PixelType color, bool fill) { int x = r; int y = 0; int p = Base::surfacePitch(), px = 0, py = 0; uint32 rsq = (r * r) << 16; uint32 T = 0, oldT; uint8 a1, a2; - bool fill = false; PixelType *ptr = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1); px = p * x; py = p * y; - *(ptr + x) = (PixelType)Base::_color; - *(ptr - x) = (PixelType)Base::_color; - *(ptr + px) = (PixelType)Base::_color; - *(ptr - px) = (PixelType)Base::_color; + *(ptr + x) = (PixelType)color; + *(ptr - x) = (PixelType)color; + *(ptr + px) = (PixelType)color; + *(ptr - px) = (PixelType)color; - if (fill) Common::set_to(ptr - x, ptr + x, Base::_color); + if (fill) Common::set_to(ptr - x, ptr + x, color); while (x > y++) { @@ -462,29 +467,29 @@ drawCircleAlg(int x1, int y1, int r) { a1 = ~a2; if (fill) { - Common::set_to(ptr - x + py, ptr + x + py, Base::_color); - Common::set_to(ptr - x - py, ptr + x - py, Base::_color); - Common::set_to(ptr - y + px, ptr + y + px, Base::_color); - Common::set_to(ptr - y - px, ptr + y - px, Base::_color); + Common::set_to(ptr - x + py, ptr + x + py, color); + Common::set_to(ptr - x - py, ptr + x - py, color); + Common::set_to(ptr - y + px, ptr + y + px, color); + Common::set_to(ptr - y - px, ptr + y - px, color); } else { - blendPixelPtr(ptr + x - 1 + py, a2); - blendPixelPtr(ptr + y - (px-p), a2); - blendPixelPtr(ptr - x + 1 - py, a2); - blendPixelPtr(ptr - y - (px-p), a2); - blendPixelPtr(ptr - y + (px-p), a2); - blendPixelPtr(ptr - x + 1 + py, a2); - blendPixelPtr(ptr + y + (px-p), a2); - blendPixelPtr(ptr + x - 1 - py, a2); + blendPixelPtr(ptr + x - 1 + py, color, a2); + blendPixelPtr(ptr + y - (px-p), color, a2); + blendPixelPtr(ptr - x + 1 - py, color, a2); + blendPixelPtr(ptr - y - (px-p), color, a2); + blendPixelPtr(ptr - y + (px-p), color, a2); + blendPixelPtr(ptr - x + 1 + py, color, a2); + blendPixelPtr(ptr + y + (px-p), color, a2); + blendPixelPtr(ptr + x - 1 - py, color, a2); } - blendPixelPtr(ptr + x + py, a1); - blendPixelPtr(ptr + y - px, a1); - blendPixelPtr(ptr - x - py, a1); - blendPixelPtr(ptr - y - px, a1); - blendPixelPtr(ptr - y + px, a1); - blendPixelPtr(ptr - x + py, a1); - blendPixelPtr(ptr + y + px, a1); - blendPixelPtr(ptr + x - py, a1); + blendPixelPtr(ptr + x + py, color, a1); + blendPixelPtr(ptr + y - px, color, a1); + blendPixelPtr(ptr - x - py, color, a1); + blendPixelPtr(ptr - y - px, color, a1); + blendPixelPtr(ptr - y + px, color, a1); + blendPixelPtr(ptr - x + py, color, a1); + blendPixelPtr(ptr + y + px, color, a1); + blendPixelPtr(ptr + x - py, color, a1); } } diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h index 4ab5bd5e27..bc96299fc2 100644 --- a/graphics/VectorRenderer.h +++ b/graphics/VectorRenderer.h @@ -53,8 +53,21 @@ void vector_renderer_test(OSystem *_system); class VectorRenderer { public: + VectorRenderer() : _shadows(false), _fillMode(kNoFill), _activeSurface(NULL) {} virtual ~VectorRenderer() {} + enum FillMode { + kNoFill = 0, + kForegroundFill = 1, + kBackgroundFill = 2, + kGradientFill = 3 + }; + + enum ColorMode { + kForegroundColor, + kBackgroundColor + }; + /** * Draws a line by considering the special cases for optimization. * @@ -75,7 +88,7 @@ public: virtual void drawCircle(int x, int y, int r) = 0; - virtual void drawSquare(int x, int y, int w, int h, bool fill) = 0; + virtual void drawSquare(int x, int y, int w, int h) = 0; virtual void drawRoundedSquare(int x1, int y1, int r, int w, int h) = 0; @@ -110,7 +123,8 @@ public: * @param g value of the green color byte * @param b value of the blue color byte */ - virtual void setColor(uint8 r, uint8 g, uint8 b) = 0; + virtual void setFgColor(uint8 r, uint8 g, uint8 b) = 0; + virtual void setBgColor(uint8 r, uint8 g, uint8 b) = 0; /** * Sets the active drawing surface. All drawing from this @@ -125,7 +139,7 @@ public: /** * Fills the active surface with the currently active drawing color. */ - virtual void fillSurface() = 0; + virtual void fillSurface(ColorMode mode = kForegroundColor) = 0; /** * Clears the active surface. @@ -135,54 +149,28 @@ public: memset(src, 0, _activeSurface->w * _activeSurface->h * _activeSurface->bytesPerPixel); } - /** - * Draws a single pixel on the surface with the given coordinates and - * the currently active drawing color. - * - * @param x Horizontal coordinate of the pixel. - * @param y Vertical coordinate of the pixel. - */ - inline virtual void putPixel(int x, int y) = 0; - - /** - * Blends a single pixel on the surface with the given coordinates, with - * the currently active drawing color and with the given Alpha intensity. - * - * @param x Horizontal coordinate of the pixel. - * @param y Vertical coordinate of the pixel. - * @param alpha Alpha intensity of the pixel (0-255) - */ - inline virtual void blendPixel(int x, int y, uint8 alpha) = 0; - -protected: - - /** - * Generic line drawing algorithm. May be implemented by each - * inheriting class, i.e. with platform specific code. - * - * @see VectorRenderer::drawLine() - * @param x1 Horizontal (X) coordinate for the line start - * @param x2 Horizontal (X) coordinate for the line end - * @param y1 Vertical (Y) coordinate for the line start - * @param y2 Vertical (Y) coordinate for the line end - * @param dx Horizontal (X) increasement. - * @param dy Vertical (Y) increasement. - */ - virtual void drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy) = 0; + virtual void setFillMode(VectorRenderer::FillMode mode) { + _fillMode = mode; + } - /** - * Specific circle drawing algorithm with symmetry. Must be implemented - * on each renderer. - * - * @param x Horizontal (X) coordinate for the center of the circle - * @param y Vertical (Y) coordinate for the center of the circle - * @param r Radius of the circle. - */ - virtual void drawCircleAlg(int x, int y, int r) = 0; + virtual void shadowEnable(int x_offset, int y_offset) { + _shadows = true; + _shadowXOffset = x_offset; + _shadowYOffset = y_offset; + } - virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h) = 0; + virtual void shadowDisable() { + _shadows = false; + } +protected: Surface *_activeSurface; /** Pointer to the surface currently being drawn */ + + FillMode _fillMode; + + bool _shadows; + int _shadowXOffset; + int _shadowYOffset; }; @@ -217,70 +205,147 @@ public: void drawLine(int x1, int y1, int x2, int y2); void drawCircle(int x, int y, int r) { - drawCircleAlg(x, y, r); + if (Base::_fillMode != kNoFill && Base::_shadows) { + drawCircleAlg(x + Base::_shadowXOffset, y + Base::_shadowYOffset, r, 0, true); + } + + switch(Base::_fillMode) { + case kNoFill: + drawCircleAlg(x, y, r, _fgColor, false); + break; + + case kForegroundFill: + drawCircleAlg(x, y, r, _fgColor, true); + break; + + case kBackgroundFill: + drawCircleAlg(x, y, r - 1, _bgColor, true); + drawCircleAlg(x, y, r, _fgColor, false); + break; + + case kGradientFill: + break; + } } - void drawSquare(int x, int y, int w, int h, bool fill); + void drawSquare(int x, int y, int w, int h) { + if (Base::_fillMode != kNoFill && Base::_shadows) { + drawSquareAlg(x + Base::_shadowXOffset , y + h, w, Base::_shadowYOffset, 0, true); + drawSquareAlg(x + w, y + Base::_shadowYOffset, Base::_shadowXOffset, h, 0, true); + } + + switch(Base::_fillMode) { + case kNoFill: + drawSquareAlg(x, y, w, h, _fgColor, false); + break; + + case kForegroundFill: + drawSquareAlg(x, y, w, h, _fgColor, true); + break; + + case kBackgroundFill: + drawSquareAlg(x, y, w, h, _bgColor, true); + drawSquareAlg(x, y, w, h, _fgColor, false); + break; + + case kGradientFill: + break; + } + } + + void drawRoundedSquare(int x, int y, int r, int w, int h) { + if (Base::_fillMode != kNoFill && Base::_shadows) { + drawRoundedSquareAlg(x + Base::_shadowXOffset, y + Base::_shadowYOffset, r, w, h, 0, true); + } + + switch(Base::_fillMode) { + case kNoFill: + drawRoundedSquareAlg(x, y, r, w, h, _fgColor, false); + break; + + case kForegroundFill: + drawRoundedSquareAlg(x, y, r, w, h, _fgColor, true); + break; + + case kBackgroundFill: + drawRoundedSquareAlg(x, y, r + 1, w, h, _bgColor, true); + drawRoundedSquareAlg(x, y, r, w, h, _fgColor, false); + break; - void drawRoundedSquare(int x1, int y1, int r, int w, int h) { - drawRoundedSquareAlg(x1, y1, r, w, h); + case kGradientFill: + break; + } } /** * @see VectorRenderer::setColor() */ - void setColor(uint8 r, uint8 g, uint8 b) { - this->_color = RGBToColor<PixelFormat>(r, g, b); + void setFgColor(uint8 r, uint8 g, uint8 b) { + this->_fgColor = RGBToColor<PixelFormat>(r, g, b); + } + + void setBgColor(uint8 r, uint8 g, uint8 b) { + this->_bgColor = RGBToColor<PixelFormat>(r, g, b); } /** * @see VectorRenderer::fillSurface() */ - void fillSurface() { + void fillSurface(ColorMode mode = kForegroundColor) { PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(0, 0); int s = _activeSurface->w * _activeSurface->h; - Common::set_to(ptr, ptr + s, (PixelType)_color); + + if (mode == kBackgroundColor) + Common::set_to(ptr, ptr + s, _bgColor); + else if (mode == kForegroundColor) + Common::set_to(ptr, ptr + s, _fgColor); } +protected: + /** - * @see VectorRenderer::putPixel() + * Draws a single pixel on the surface with the given coordinates and + * the given color. + * + * @param x Horizontal coordinate of the pixel. + * @param y Vertical coordinate of the pixel. + * @param color Color of the pixel */ - inline void putPixel( int x, int y ) { + virtual inline void putPixel( int x, int y, PixelType color ) { PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x, y); - *ptr = _color; + *ptr = color; } /** - * On the Specialized Renderer, alpha blending is not supported. + * Blends a single pixel on the surface with the given coordinates, color + * and Alpha intensity. * - * @see VectorRenderer::blendPixel() + * Note: Pixel blending is currently disabled on the Specialized Renderer + * because of performance issues. + * + * @param x Horizontal coordinate of the pixel. + * @param y Vertical coordinate of the pixel. + * @param color Color of the pixel + * @param alpha Alpha intensity of the pixel (0-255) */ - virtual inline void blendPixel(int x, int y, uint8 alpha) { - putPixel(x, y); + virtual inline void blendPixel(int x, int y, PixelType color, uint8 alpha) { + putPixel(x, y, color); } -protected: - /* * "Bresenham's Line Algorithm", as described in Wikipedia. * Based on the current implementation in "graphics/primitives.cpp". * * Generic line drawing algorithm for the aliased renderer. Optimized with no * floating point operations and direct access to pixel buffer, assumes no special cases. - * - * @see VectorRenderer::drawLineAlg() - */ - virtual void drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy); - - /** - * @see VectorRenderer::drawCircleAlg() */ - virtual void drawCircleAlg(int x, int y, int r); - - virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h) { - } + virtual void drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy, PixelType color); + virtual void drawCircleAlg(int x, int y, int r, PixelType color, bool fill = false); + virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, bool fill = false) {} + virtual void drawSquareAlg(int x, int y, int w, int h, PixelType color, bool fill = false); - PixelType _color; /** Color currently being used to draw on the renderer */ + PixelType _fgColor; /** Color currently being used to draw on the renderer */ + PixelType _bgColor; }; /** @@ -308,7 +373,7 @@ protected: * * @see VectorRenderer::drawLineAlg() */ - void drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy); + void drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy, PixelType color); /** * Perform alpha blending on top of a given pixel, not on a given @@ -321,7 +386,7 @@ protected: * @param ptr Pointer to the pixel where we must draw * @param alpha Intensity of the pixel (0-255). */ - inline void blendPixelPtr(PixelType *ptr, uint8 alpha); + inline void blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha); /** * @see VectorRenderer::blendPixel() @@ -329,13 +394,11 @@ protected: * The AA renderer does support alpha blending. Special cases are * handled separately. */ - inline void blendPixel(int x, int y, uint8 alpha) { - if (alpha == 0) - return; - else if (alpha < 255) - blendPixelPtr((PixelType*)Base::_activeSurface->getBasePtr(x, y), alpha); - else - Base::putPixel(x, y); + inline void blendPixel(int x, int y, PixelType color, uint8 alpha) { + if (alpha == 255) + putPixel(x, y, color); + else if (alpha > 0 ) + blendPixelPtr((PixelType*)Base::_activeSurface->getBasePtr(x, y), color, alpha); } /** @@ -347,9 +410,9 @@ protected: * * @see VectorRenderer::drawCircleAlg() */ - virtual void drawCircleAlg(int x, int y, int r); + virtual void drawCircleAlg(int x, int y, int r, PixelType color, bool fill = false); - virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h); + virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, bool fill = false); }; } // end of namespace Graphics |