comparison engine/core/view/renderers/genericrenderer.cpp @ 27:788cb9525b2f

add image and text renderer to generic renderer
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 11 Jul 2008 11:57:48 +0000
parents 70f41ea8e7db
children 0cb049f291e1
comparison
equal deleted inserted replaced
26:70f41ea8e7db 27:788cb9525b2f
26 // FIFE includes 26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line 27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory 28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder 29 // Second block: files included from the same folder
30 #include "video/renderbackend.h" 30 #include "video/renderbackend.h"
31 #include "video/imagepool.h"
32 #include "video/animation.h"
33 #include "video/animationpool.h"
34 #include "video/fonts/abstractfont.h"
35 #include "video/image.h"
31 #include "util/math/fife_math.h" 36 #include "util/math/fife_math.h"
32 #include "util/log/logger.h" 37 #include "util/log/logger.h"
33 #include "model/metamodel/grids/cellgrid.h" 38 #include "model/metamodel/grids/cellgrid.h"
34 #include "model/structures/instance.h" 39 #include "model/structures/instance.h"
35 #include "model/structures/layer.h" 40 #include "model/structures/layer.h"
182 n2(n2), 187 n2(n2),
183 r(r), 188 r(r),
184 g(g), 189 g(g),
185 b(b) { 190 b(b) {
186 } 191 }
187 void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) { 192 void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
188 Point p1 = n1.getCalculatedPoint(cam, layer, instances); 193 Point p1 = n1.getCalculatedPoint(cam, layer, instances);
189 Point p2 = n2.getCalculatedPoint(cam, layer, instances); 194 Point p2 = n2.getCalculatedPoint(cam, layer, instances);
190 renderbackend->drawLine(p1, p2, r, g, b); 195 renderbackend->drawLine(p1, p2, r, g, b);
191 } 196 }
192 197
195 n(n), 200 n(n),
196 r(r), 201 r(r),
197 g(g), 202 g(g),
198 b(b) { 203 b(b) {
199 } 204 }
200 void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) { 205 void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
201 Point p = n.getCalculatedPoint(cam, layer, instances); 206 Point p = n.getCalculatedPoint(cam, layer, instances);
202 renderbackend->putPixel(p.x, p.y, r, g, b); 207 renderbackend->putPixel(p.x, p.y, r, g, b);
203 } 208 }
204 209
205 GenericRendererQuadInfo::GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b): 210 GenericRendererQuadInfo::GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b):
210 n4(n4), 215 n4(n4),
211 r(r), 216 r(r),
212 g(g), 217 g(g),
213 b(b) { 218 b(b) {
214 } 219 }
215 void GenericRendererQuadInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) { 220 void GenericRendererQuadInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
216 Point p1 = n1.getCalculatedPoint(cam, layer, instances); 221 Point p1 = n1.getCalculatedPoint(cam, layer, instances);
217 Point p2 = n2.getCalculatedPoint(cam, layer, instances); 222 Point p2 = n2.getCalculatedPoint(cam, layer, instances);
218 Point p3 = n3.getCalculatedPoint(cam, layer, instances); 223 Point p3 = n3.getCalculatedPoint(cam, layer, instances);
219 Point p4 = n4.getCalculatedPoint(cam, layer, instances); 224 Point p4 = n4.getCalculatedPoint(cam, layer, instances);
220 renderbackend->drawQuad(p1, p2, p3, p4, r, g, b); 225 renderbackend->drawQuad(p1, p2, p3, p4, r, g, b);
223 GenericRendererImageInfo::GenericRendererImageInfo(GenericRendererNode n, int image): 228 GenericRendererImageInfo::GenericRendererImageInfo(GenericRendererNode n, int image):
224 GenericRendererElementInfo(), 229 GenericRendererElementInfo(),
225 n(n), 230 n(n),
226 image(image) { 231 image(image) {
227 } 232 }
228 void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) { 233 void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
229 return; 234 Point p = n.getCalculatedPoint(cam, layer, instances);
235 Image* img = &imagepool->getImage(image);
236 Rect r;
237 r.x = p.x-img->getWidth()/2;
238 r.y = p.y-img->getHeight()/2;
239 r.w = img->getWidth();
240 r.h = img->getHeight();
241 img->render(r);
230 } 242 }
231 243
232 GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode n, int animation): 244 GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode n, int animation):
233 GenericRendererElementInfo(), 245 GenericRendererElementInfo(),
234 n(n), 246 n(n),
235 animation(animation) { 247 animation(animation) {
236 } 248 }
237 void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) { 249 void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
238 return; 250 return;
239 } 251 }
240 252
241 GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode n, AbstractFont* font, std::string text): 253 GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode n, AbstractFont* font, std::string text):
242 GenericRendererElementInfo(), 254 GenericRendererElementInfo(),
243 n(n), 255 n(n),
244 font(font), 256 font(font),
245 text(text) { 257 text(text) {
246 } 258 }
247 void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) { 259 void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
248 return; 260 Point p = n.getCalculatedPoint(cam, layer, instances);
261 Image* img = font->getAsImageMultiline(text);
262 Rect r;
263 r.x = p.x-img->getWidth()/2;
264 r.y = p.y-img->getHeight()/2;
265 r.w = img->getWidth();
266 r.h = img->getHeight();
267 img->render(r);
249 } 268 }
250 269
251 GenericRenderer* GenericRenderer::getInstance(IRendererContainer* cnt) { 270 GenericRenderer* GenericRenderer::getInstance(IRendererContainer* cnt) {
252 return dynamic_cast<GenericRenderer*>(cnt->getRenderer("GenericRenderer")); 271 return dynamic_cast<GenericRenderer*>(cnt->getRenderer("GenericRenderer"));
253 } 272 }
254 273
255 GenericRenderer::GenericRenderer(RenderBackend* renderbackend, int position): 274 GenericRenderer::GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool):
256 RendererBase(renderbackend, position), 275 RendererBase(renderbackend, position),
276 m_imagepool(imagepool),
277 m_animationpool(animpool),
257 m_infos() { 278 m_infos() {
258 setEnabled(false); 279 setEnabled(false);
259 } 280 }
260 281
261 GenericRenderer::GenericRenderer(const GenericRenderer& old): 282 GenericRenderer::GenericRenderer(const GenericRenderer& old):
303 324
304 void GenericRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { 325 void GenericRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) {
305 std::vector<GenericRendererElementInfo*>::const_iterator info_it = m_infos.begin(); 326 std::vector<GenericRendererElementInfo*>::const_iterator info_it = m_infos.begin();
306 for (;info_it != m_infos.end(); ++info_it) { 327 for (;info_it != m_infos.end(); ++info_it) {
307 GenericRendererElementInfo* info = *info_it; 328 GenericRendererElementInfo* info = *info_it;
308 info->render(cam, layer, instances, m_renderbackend); 329 info->render(cam, layer, instances, m_renderbackend, m_imagepool, m_animationpool);
309 } 330 }
310 } 331 }
311 } 332 }