Mercurial > fife-parpg
diff engine/core/view/renderers/floatingtextrenderer.cpp @ 583:47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
* Added a triangle function to backends and genericrenderer, also added the functions to set an alpha value for geometric figures.
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 07 Aug 2010 16:36:35 +0000 |
parents | 5e04f6349894 |
children | d1df6cf5ff23 |
line wrap: on
line diff
--- a/engine/core/view/renderers/floatingtextrenderer.cpp Tue Aug 03 13:57:12 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.cpp Sat Aug 07 16:36:35 2010 +0000 @@ -61,6 +61,7 @@ m_font_color(old.m_font_color), m_color(old.m_color) { setEnabled(false); + m_font_color = m_background = m_backborder = false; } RendererBase* FloatingTextRenderer::clone() { @@ -78,9 +79,8 @@ RenderList::const_iterator instance_it = instances.begin(); const std::string* saytext = NULL; SDL_Color old_color = m_font->getColor(); - if(old_color.r != m_color.r || old_color.g != m_color.g || old_color.b != m_color.b) { - m_font->setColor(m_color.r, m_color.g, m_color.b); - m_font_color = true; + if(m_font_color) { + m_font->setColor(m_color.r, m_color.g, m_color.b, m_color.unused); } for (;instance_it != instances.end(); ++instance_it) { Instance* instance = (*instance_it)->instance; @@ -93,51 +93,67 @@ 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) { + 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); - m_renderbackend->drawQuad(p1, p2, p3, p4, m_backcolor.r, m_backcolor.g, m_backcolor.b); + if(m_background) { + m_renderbackend->drawQuad(p1, p2, p3, p4, m_backcolor.r, m_backcolor.g, m_backcolor.b, m_backcolor.unused); + } - m_renderbackend->drawLine(p1, p2, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); - m_renderbackend->drawLine(p2, p3, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); - m_renderbackend->drawLine(p3, p4, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); - m_renderbackend->drawLine(p4, p1, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); + 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); + } } img->render(r); } } if(m_font_color) { - m_font->setColor(old_color.r, old_color.g, old_color.b); - m_font_color = false; + m_font->setColor(old_color.r, old_color.g, old_color.b, old_color.unused); } } - void FloatingTextRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) { + void FloatingTextRenderer::setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { m_color.r = r; m_color.g = g; m_color.b = b; + m_color.unused = a; + + m_font_color = true; } - void FloatingTextRenderer::setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 bbr, Uint8 bbg, Uint8 bbb) { + void FloatingTextRenderer::setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba) { m_backcolor.r = br; m_backcolor.g = bg; m_backcolor.b = bb; + m_backcolor.unused = ba; + m_background = true; + } + + void FloatingTextRenderer::setDefaultBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba) { m_backbordercolor.r = bbr; m_backbordercolor.g = bbg; m_backbordercolor.b = bbb; + m_backbordercolor.unused = bba; - m_background = true; + m_backborder = true; } void FloatingTextRenderer::resetDefaultBackground() { m_background = false; } + void FloatingTextRenderer::resetDefaultBorder() { + m_backborder = false; + } + FloatingTextRenderer* FloatingTextRenderer::getInstance(IRendererContainer* cnt) { return dynamic_cast<FloatingTextRenderer*>(cnt->getRenderer("FloatingTextRenderer")); }