comparison 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
comparison
equal deleted inserted replaced
582:5e04f6349894 583:47b49b9b0c0a
59 m_renderbackend(old.m_renderbackend), 59 m_renderbackend(old.m_renderbackend),
60 m_font(old.m_font), 60 m_font(old.m_font),
61 m_font_color(old.m_font_color), 61 m_font_color(old.m_font_color),
62 m_color(old.m_color) { 62 m_color(old.m_color) {
63 setEnabled(false); 63 setEnabled(false);
64 m_font_color = m_background = m_backborder = false;
64 } 65 }
65 66
66 RendererBase* FloatingTextRenderer::clone() { 67 RendererBase* FloatingTextRenderer::clone() {
67 return new FloatingTextRenderer(*this); 68 return new FloatingTextRenderer(*this);
68 } 69 }
76 } 77 }
77 78
78 RenderList::const_iterator instance_it = instances.begin(); 79 RenderList::const_iterator instance_it = instances.begin();
79 const std::string* saytext = NULL; 80 const std::string* saytext = NULL;
80 SDL_Color old_color = m_font->getColor(); 81 SDL_Color old_color = m_font->getColor();
81 if(old_color.r != m_color.r || old_color.g != m_color.g || old_color.b != m_color.b) { 82 if(m_font_color) {
82 m_font->setColor(m_color.r, m_color.g, m_color.b); 83 m_font->setColor(m_color.r, m_color.g, m_color.b, m_color.unused);
83 m_font_color = true;
84 } 84 }
85 for (;instance_it != instances.end(); ++instance_it) { 85 for (;instance_it != instances.end(); ++instance_it) {
86 Instance* instance = (*instance_it)->instance; 86 Instance* instance = (*instance_it)->instance;
87 saytext = instance->getSayText(); 87 saytext = instance->getSayText();
88 if (saytext) { 88 if (saytext) {
91 Rect r; 91 Rect r;
92 r.x = (ir.x + ir.w/2) - img->getWidth()/2; /// the center of the text rect is always aligned to the instance's rect center. 92 r.x = (ir.x + ir.w/2) - img->getWidth()/2; /// the center of the text rect is always aligned to the instance's rect center.
93 r.y = ir.y- img->getHeight(); /// make the text rect floating higher than the instance. 93 r.y = ir.y- img->getHeight(); /// make the text rect floating higher than the instance.
94 r.w = img->getWidth(); 94 r.w = img->getWidth();
95 r.h = img->getHeight(); 95 r.h = img->getHeight();
96 if(m_background) { 96 if(m_background || m_backborder) {
97 const int overdraw = 5; 97 const int overdraw = 5;
98 Point p1 = Point(r.x-overdraw, r.y-overdraw); 98 Point p1 = Point(r.x-overdraw, r.y-overdraw);
99 Point p2 = Point(r.x+r.w+overdraw, r.y-overdraw); 99 Point p2 = Point(r.x+r.w+overdraw, r.y-overdraw);
100 Point p3 = Point(r.x+r.w+overdraw, r.y+r.h+overdraw); 100 Point p3 = Point(r.x+r.w+overdraw, r.y+r.h+overdraw);
101 Point p4 = Point(r.x-overdraw, r.y+r.h+overdraw); 101 Point p4 = Point(r.x-overdraw, r.y+r.h+overdraw);
102 102
103 m_renderbackend->drawQuad(p1, p2, p3, p4, m_backcolor.r, m_backcolor.g, m_backcolor.b); 103 if(m_background) {
104 m_renderbackend->drawQuad(p1, p2, p3, p4, m_backcolor.r, m_backcolor.g, m_backcolor.b, m_backcolor.unused);
105 }
104 106
105 m_renderbackend->drawLine(p1, p2, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); 107 if(m_backborder) {
106 m_renderbackend->drawLine(p2, p3, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); 108 m_renderbackend->drawLine(p1, p2, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused);
107 m_renderbackend->drawLine(p3, p4, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); 109 m_renderbackend->drawLine(p2, p3, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused);
108 m_renderbackend->drawLine(p4, p1, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); 110 m_renderbackend->drawLine(p3, p4, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused);
111 m_renderbackend->drawLine(p4, p1, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b, m_backbordercolor.unused);
112 }
109 } 113 }
110 img->render(r); 114 img->render(r);
111 } 115 }
112 } 116 }
113 if(m_font_color) { 117 if(m_font_color) {
114 m_font->setColor(old_color.r, old_color.g, old_color.b); 118 m_font->setColor(old_color.r, old_color.g, old_color.b, old_color.unused);
115 m_font_color = false;
116 } 119 }
117 } 120 }
118 121
119 void FloatingTextRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) { 122 void FloatingTextRenderer::setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
120 m_color.r = r; 123 m_color.r = r;
121 m_color.g = g; 124 m_color.g = g;
122 m_color.b = b; 125 m_color.b = b;
126 m_color.unused = a;
127
128 m_font_color = true;
123 } 129 }
124 130
125 void FloatingTextRenderer::setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 bbr, Uint8 bbg, Uint8 bbb) { 131 void FloatingTextRenderer::setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba) {
126 m_backcolor.r = br; 132 m_backcolor.r = br;
127 m_backcolor.g = bg; 133 m_backcolor.g = bg;
128 m_backcolor.b = bb; 134 m_backcolor.b = bb;
135 m_backcolor.unused = ba;
129 136
137 m_background = true;
138 }
139
140 void FloatingTextRenderer::setDefaultBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba) {
130 m_backbordercolor.r = bbr; 141 m_backbordercolor.r = bbr;
131 m_backbordercolor.g = bbg; 142 m_backbordercolor.g = bbg;
132 m_backbordercolor.b = bbb; 143 m_backbordercolor.b = bbb;
144 m_backbordercolor.unused = bba;
133 145
134 m_background = true; 146 m_backborder = true;
135 } 147 }
136 148
137 void FloatingTextRenderer::resetDefaultBackground() { 149 void FloatingTextRenderer::resetDefaultBackground() {
138 m_background = false; 150 m_background = false;
139 } 151 }
140 152
153 void FloatingTextRenderer::resetDefaultBorder() {
154 m_backborder = false;
155 }
156
141 FloatingTextRenderer* FloatingTextRenderer::getInstance(IRendererContainer* cnt) { 157 FloatingTextRenderer* FloatingTextRenderer::getInstance(IRendererContainer* cnt) {
142 return dynamic_cast<FloatingTextRenderer*>(cnt->getRenderer("FloatingTextRenderer")); 158 return dynamic_cast<FloatingTextRenderer*>(cnt->getRenderer("FloatingTextRenderer"));
143 } 159 }
144 } 160 }