Mercurial > fife-parpg
changeset 631:f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
* Modified FIFE::FloatingTextRenderer to use the new functions
* Updated some data types in FIFE::FloatingTextRenderer to use integer types defined in fife_stdint.h
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 05 Oct 2010 15:44:16 +0000 |
parents | 010da1d1ee1c |
children | a7909cdcdc85 |
files | engine/core/video/image.h engine/core/video/opengl/glimage.cpp engine/core/video/opengl/glimage.h engine/core/video/opengl/renderbackendopengl.cpp engine/core/video/opengl/renderbackendopengl.h engine/core/video/sdl/renderbackendsdl.cpp engine/core/video/sdl/renderbackendsdl.h engine/core/video/sdl/sdlimage.cpp engine/core/video/sdl/sdlimage.h engine/core/video/video.i engine/core/view/renderers/floatingtextrenderer.cpp engine/core/view/renderers/floatingtextrenderer.h engine/core/view/renderers/floatingtextrenderer.i |
diffstat | 13 files changed, 108 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/video/image.h Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/image.h Tue Oct 05 15:44:16 2010 +0000 @@ -77,6 +77,14 @@ */ virtual void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255) = 0; + /** Draws an axis parallel rectangle. + */ + virtual void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0; + + /** Draws a filled axis parallel rectangle. + */ + virtual void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0; + /** Draws quad between given points with given RGBA */ virtual void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255) = 0;
--- a/engine/core/video/opengl/glimage.cpp Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/opengl/glimage.cpp Tue Oct 05 15:44:16 2010 +0000 @@ -254,6 +254,16 @@ m_sdlimage->drawTriangle(p1, p2, p3, r, g, b, a); } + void GLImage::drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + cleanup(); + m_sdlimage->drawRectangle(p, w, h, r, g, b, a); + } + + void GLImage::fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + cleanup(); + m_sdlimage->fillRectangle(p, w, h, r, g, b, a); + } + void GLImage::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a) { cleanup(); m_sdlimage->drawQuad(p1, p2, p3, p4, r, g, b, a);
--- a/engine/core/video/opengl/glimage.h Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/opengl/glimage.h Tue Oct 05 15:44:16 2010 +0000 @@ -65,6 +65,8 @@ bool putPixel(int x, int y, int r, int g, int b, int a = 255); void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255); void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255); + void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); + void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255); void drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a = 255);
--- a/engine/core/video/opengl/renderbackendopengl.cpp Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/opengl/renderbackendopengl.cpp Tue Oct 05 15:44:16 2010 +0000 @@ -218,6 +218,28 @@ glEnd(); } + void RenderBackendOpenGL::drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + glColor4ub(r, g, b, a); + + glBegin(GL_LINE_LOOP); + glVertex2f(p.x, p.y); + glVertex2f(p.x+w, p.y); + glVertex2f(p.x+w, p.y+h); + glVertex2f(p.x, p.y+h); + glEnd(); + } + + void RenderBackendOpenGL::fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + glColor4ub(r, g, b, a); + + glBegin(GL_QUADS); + glVertex2f(p.x, p.y); + glVertex2f(p.x+w, p.y); + glVertex2f(p.x+w, p.y+h); + glVertex2f(p.x, p.y+h); + glEnd(); + } + void RenderBackendOpenGL::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a) { glColor4ub(r, g, b, a);
--- a/engine/core/video/opengl/renderbackendopengl.h Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/opengl/renderbackendopengl.h Tue Oct 05 15:44:16 2010 +0000 @@ -51,6 +51,8 @@ bool putPixel(int x, int y, int r, int g, int b, int a = 255); void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255); void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255); + void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); + void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255); void drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a = 255);
--- a/engine/core/video/sdl/renderbackendsdl.cpp Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/sdl/renderbackendsdl.cpp Tue Oct 05 15:44:16 2010 +0000 @@ -157,6 +157,14 @@ static_cast<SDLImage*>(m_screen)->drawTriangle(p1, p2, p3, r, g, b, a); } + void RenderBackendSDL::drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + static_cast<SDLImage*>(m_screen)->drawRectangle(p, w, h, r, g, b, a); + } + + void RenderBackendSDL::fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + static_cast<SDLImage*>(m_screen)->fillRectangle(p, w, h, r, g, b, a); + } + void RenderBackendSDL::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a) { static_cast<SDLImage*>(m_screen)->drawQuad(p1, p2, p3, p4, r, g, b, a); }
--- a/engine/core/video/sdl/renderbackendsdl.h Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/sdl/renderbackendsdl.h Tue Oct 05 15:44:16 2010 +0000 @@ -53,6 +53,8 @@ bool putPixel(int x, int y, int r, int g, int b, int a = 255); void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255); void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255); + void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); + void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255); void drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a = 255);
--- a/engine/core/video/sdl/sdlimage.cpp Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/sdl/sdlimage.cpp Tue Oct 05 15:44:16 2010 +0000 @@ -759,6 +759,35 @@ drawLine(p3, p1, r, g, b, a); } + void SDLImage::drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + Point p1, p2, p3, p4; + + p1.x = p.x; + p1.y = p.y; + p2.x = p.x+w; + p2.y = p.y; + p3.x = p.x+w; + p3.y = p.y+h; + p4.x = p.x; + p4.y = p.y+h; + + drawLine(p1, p2, r, g, b, a); + drawLine(p2, p3, r, g, b, a); + drawLine(p3, p4, r, g, b, a); + drawLine(p4, p1, r, g, b, a); + } + + void SDLImage::fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + SDL_Rect rect; + rect.x = p.x; + rect.y = p.y; + rect.w = w; + rect.h = h; + + Uint32 color = SDL_MapRGBA(m_surface->format, r, g, b, a); + SDL_FillRect(m_surface, &rect, color); + } + void SDLImage::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a) { drawLine(p1, p2, r, g, b, a); drawLine(p2, p3, r, g, b, a);
--- a/engine/core/video/sdl/sdlimage.h Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/sdl/sdlimage.h Tue Oct 05 15:44:16 2010 +0000 @@ -47,6 +47,8 @@ bool putPixel(int x, int y, int r, int g, int b, int a = 255); void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255); void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255); + void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); + void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255); void drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a = 255);
--- a/engine/core/video/video.i Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/video/video.i Tue Oct 05 15:44:16 2010 +0000 @@ -52,6 +52,8 @@ virtual bool putPixel(int x, int y, int r, int g, int b, int a = 255) = 0; virtual void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255) = 0; virtual void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255) = 0; + virtual void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0; + virtual void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0; virtual void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255) = 0; virtual void pushClipArea(const Rect& cliparea, bool clear=true) = 0; virtual void popClipArea() = 0; @@ -156,6 +158,8 @@ bool putPixel(int x, int y, int r, int g, int b, int a = 255); void drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a = 255); void drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a = 255); + void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); + void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a = 255); void drawVertex(const Point& p, int size, int r, int g, int b, int a = 255); void pushClipArea(const Rect& cliparea, bool clear=true);
--- a/engine/core/view/renderers/floatingtextrenderer.cpp Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.cpp Tue Oct 05 15:44:16 2010 +0000 @@ -93,22 +93,18 @@ r.y = ir.y- img->getHeight(); /// make the text rect floating higher than the instance. r.w = img->getWidth(); r.h = img->getHeight(); + if(m_background || m_backborder) { const int overdraw = 5; - Point p1 = Point(r.x-overdraw, r.y-overdraw); - Point p2 = Point(r.x+r.w+overdraw, r.y-overdraw); - Point p3 = Point(r.x+r.w+overdraw, r.y+r.h+overdraw); - Point p4 = Point(r.x-overdraw, r.y+r.h+overdraw); + + Point p = Point(r.x-overdraw, r.y-overdraw); if(m_background) { - m_renderbackend->drawQuad(p1, p2, p3, p4, m_backcolor.r, m_backcolor.g, m_backcolor.b, m_backcolor.unused); + m_renderbackend->fillRectangle(p, r.w+2*overdraw, r.h+2*overdraw, m_backcolor.r, m_backcolor.g, m_backcolor.b, m_backcolor.unused); } if(m_backborder) { - m_renderbackend->drawLine(p1, p2, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused); - m_renderbackend->drawLine(p2, p3, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused); - m_renderbackend->drawLine(p3, p4, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused); - m_renderbackend->drawLine(p4, p1, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused); + m_renderbackend->drawRectangle(p, r.w+2*overdraw, r.h+2*overdraw, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused); } } img->render(r); @@ -119,7 +115,7 @@ } } - void FloatingTextRenderer::setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { + void FloatingTextRenderer::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { m_color.r = r; m_color.g = g; m_color.b = b; @@ -128,7 +124,7 @@ m_font_color = true; } - void FloatingTextRenderer::setBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba) { + void FloatingTextRenderer::setBackground(uint8_t br, uint8_t bg, uint8_t bb, uint8_t ba) { m_backcolor.r = br; m_backcolor.g = bg; m_backcolor.b = bb; @@ -137,7 +133,7 @@ m_background = true; } - void FloatingTextRenderer::setBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba) { + void FloatingTextRenderer::setBorder(uint8_t bbr, uint8_t bbg, uint8_t bbb, uint8_t bba) { m_backbordercolor.r = bbr; m_backbordercolor.g = bbg; m_backbordercolor.b = bbb;
--- a/engine/core/view/renderers/floatingtextrenderer.h Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.h Tue Oct 05 15:44:16 2010 +0000 @@ -44,9 +44,9 @@ * @param font default font used to render the texts */ FloatingTextRenderer(RenderBackend* renderbackend, int position, AbstractFont* font); - + FloatingTextRenderer(const FloatingTextRenderer& old); - + RendererBase* clone(); /** Destructor. @@ -56,27 +56,27 @@ void render(Camera* cam, Layer* layer, RenderList& instances); std::string getName() { return "FloatingTextRenderer"; } - + /** Changes default font in the renderer * Note that this does not change the font ownership */ void changeDefaultFont(AbstractFont* font) { m_font = font; } - + /** Changes default font color * Only usefull for .ttf fonts */ - void setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255); + void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); /** Set default background quad * r,g,b,a values for background */ - void setBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba = 255); + void setBackground(uint8_t br, uint8_t bg, uint8_t bb, uint8_t ba = 255); /** Set default border * r,g,b,a values for border */ - void setBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba = 255); - + void setBorder(uint8_t bbr, uint8_t bbg, uint8_t bbb, uint8_t bba = 255); + /** Disable the default background */ void resetBackground();
--- a/engine/core/view/renderers/floatingtextrenderer.i Mon Oct 04 21:29:12 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.i Tue Oct 05 15:44:16 2010 +0000 @@ -32,9 +32,9 @@ public: virtual ~FloatingTextRenderer(); void changeDefaultFont(AbstractFont* font); - void setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255); - void setBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba = 255); - void setBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba = 255); + void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); + void setBackground(uint8_t br, uint8_t bg, uint8_t bb, uint8_t ba = 255); + void setBorder(uint8_t bbr, uint8_t bbg, uint8_t bbb, uint8_t bba = 255); void resetBackground(); void resetBorder();