diff 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
line wrap: on
line diff
--- a/engine/core/view/renderers/genericrenderer.cpp	Fri Jul 11 11:29:13 2008 +0000
+++ b/engine/core/view/renderers/genericrenderer.cpp	Fri Jul 11 11:57:48 2008 +0000
@@ -28,6 +28,11 @@
 // First block: files included from the FIFE root src directory
 // Second block: files included from the same folder
 #include "video/renderbackend.h"
+#include "video/imagepool.h"
+#include "video/animation.h"
+#include "video/animationpool.h"
+#include "video/fonts/abstractfont.h"
+#include "video/image.h"
 #include "util/math/fife_math.h"
 #include "util/log/logger.h"
 #include "model/metamodel/grids/cellgrid.h"
@@ -184,7 +189,7 @@
 		g(g),
 		b(b) {
 	}
-	void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) {
+	void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
 		Point p1 = n1.getCalculatedPoint(cam, layer, instances);
 		Point p2 = n2.getCalculatedPoint(cam, layer, instances);
 		renderbackend->drawLine(p1, p2, r, g, b);
@@ -197,7 +202,7 @@
 		g(g),
 		b(b) {
 	}
-	void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) {
+	void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
 		Point p = n.getCalculatedPoint(cam, layer, instances);
 		renderbackend->putPixel(p.x, p.y, r, g, b);
 	}
@@ -212,7 +217,7 @@
 		g(g),
 		b(b) {
 	}
-	void GenericRendererQuadInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) {
+	void GenericRendererQuadInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
 		Point p1 = n1.getCalculatedPoint(cam, layer, instances);
 		Point p2 = n2.getCalculatedPoint(cam, layer, instances);
 		Point p3 = n3.getCalculatedPoint(cam, layer, instances);
@@ -225,8 +230,15 @@
 		n(n),
 		image(image) {
 	}
-	void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) {
-		return;
+	void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
+		Point p = n.getCalculatedPoint(cam, layer, instances);
+		Image* img = &imagepool->getImage(image);
+		Rect r;
+		r.x = p.x-img->getWidth()/2;
+		r.y = p.y-img->getHeight()/2;
+		r.w = img->getWidth();
+		r.h = img->getHeight();
+		img->render(r);
 	}
 	
 	GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode n, int animation):
@@ -234,7 +246,7 @@
 		n(n),
 		animation(animation) {
 	}
-	void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) {
+	void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
 		return;
 	}
 	
@@ -244,16 +256,25 @@
 		font(font),
 		text(text) {
 	}
-	void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) {
-		return;
+	void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
+		Point p = n.getCalculatedPoint(cam, layer, instances);
+		Image* img = font->getAsImageMultiline(text);
+		Rect r;
+		r.x = p.x-img->getWidth()/2;
+		r.y = p.y-img->getHeight()/2;
+		r.w = img->getWidth();
+		r.h = img->getHeight();
+		img->render(r);
 	}
 	
 	GenericRenderer* GenericRenderer::getInstance(IRendererContainer* cnt) {
 		return dynamic_cast<GenericRenderer*>(cnt->getRenderer("GenericRenderer"));
 	}
 	
-	GenericRenderer::GenericRenderer(RenderBackend* renderbackend, int position):
+	GenericRenderer::GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool):
 		RendererBase(renderbackend, position),
+		m_imagepool(imagepool),
+		m_animationpool(animpool),
 		m_infos() {
 		setEnabled(false);
 	}
@@ -305,7 +326,7 @@
 		std::vector<GenericRendererElementInfo*>::const_iterator info_it = m_infos.begin();
 		for (;info_it != m_infos.end(); ++info_it) {
 			GenericRendererElementInfo* info = *info_it;
-			info->render(cam, layer, instances, m_renderbackend);
+			info->render(cam, layer, instances, m_renderbackend, m_imagepool, m_animationpool);
 		}
 	}
 }