Mercurial > fife-parpg
changeset 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 | 1e3b68c260a6 |
files | doc/dependencies/filedeps.dot doc/dependencies/moduledeps.png engine/core/controller/engine.cpp engine/core/view/renderers/genericrenderer.cpp engine/core/view/renderers/genericrenderer.h engine/core/view/renderers/genericrenderer.i |
diffstat | 6 files changed, 63 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/dependencies/filedeps.dot Fri Jul 11 11:29:13 2008 +0000 +++ b/doc/dependencies/filedeps.dot Fri Jul 11 11:57:48 2008 +0000 @@ -65,6 +65,7 @@ "engine/core/controller/engine.cpp" -> "view/renderers/cellselectionrenderer.h" "engine/core/controller/engine.cpp" -> "view/renderers/coordinaterenderer.h" "engine/core/controller/engine.cpp" -> "view/renderers/floatingtextrenderer.h" + "engine/core/controller/engine.cpp" -> "view/renderers/genericrenderer.h" "engine/core/controller/engine.cpp" -> "view/renderers/geometricrenderer.h" "engine/core/controller/engine.cpp" -> "view/renderers/gridrenderer.h" "engine/core/controller/engine.cpp" -> "view/renderers/instancerenderer.h" @@ -623,6 +624,16 @@ "engine/core/view/renderers/floatingtextrenderer.cpp" -> "view/camera.h" "engine/core/view/renderers/floatingtextrenderer.cpp" -> "view/visual.h" "engine/core/view/renderers/floatingtextrenderer.h" -> "view/rendererbase.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "genericrenderer.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "model/metamodel/grids/cellgrid.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "model/structures/instance.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "model/structures/layer.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "model/structures/location.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "util/log/logger.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "util/math/fife_math.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "video/renderbackend.h" + "engine/core/view/renderers/genericrenderer.cpp" -> "view/camera.h" + "engine/core/view/renderers/genericrenderer.h" -> "view/rendererbase.h" "engine/core/view/renderers/geometricrenderer.cpp" -> "geometricrenderer.h" "engine/core/view/renderers/geometricrenderer.cpp" -> "model/metamodel/grids/cellgrid.h" "engine/core/view/renderers/geometricrenderer.cpp" -> "model/structures/instance.h"
--- a/engine/core/controller/engine.cpp Fri Jul 11 11:29:13 2008 +0000 +++ b/engine/core/controller/engine.cpp Fri Jul 11 11:57:48 2008 +0000 @@ -246,7 +246,7 @@ m_view->addRenderer(new QuadTreeRenderer(m_renderbackend, 60)); m_view->addRenderer(new CoordinateRenderer(m_renderbackend, 70, dynamic_cast<AbstractFont*>(m_defaultfont))); m_view->addRenderer(new GeometricRenderer(m_renderbackend, 80)); - m_view->addRenderer(new GenericRenderer(m_renderbackend, 100)); + m_view->addRenderer(new GenericRenderer(m_renderbackend, 100, m_imagepool, m_animpool)); m_cursor = new Cursor(m_imagepool, m_animpool, m_renderbackend); FL_LOG(_log, "Engine intialized"); }
--- 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); } } }
--- a/engine/core/view/renderers/genericrenderer.h Fri Jul 11 11:29:13 2008 +0000 +++ b/engine/core/view/renderers/genericrenderer.h Fri Jul 11 11:57:48 2008 +0000 @@ -35,6 +35,8 @@ namespace FIFE { class RenderBackend; class AbstractFont; + class ImagePool; + class AnimationPool; class GenericRendererNode { public: @@ -75,7 +77,7 @@ }; class GenericRendererElementInfo { public: - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) { }; + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { }; virtual ~GenericRendererElementInfo() {}; }; @@ -86,7 +88,7 @@ uint8_t r; uint8_t g; uint8_t b; - void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererLineInfo(GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b); virtual ~GenericRendererLineInfo() {}; }; @@ -96,7 +98,7 @@ uint8_t r; uint8_t g; uint8_t b; - void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererPointInfo(GenericRendererNode n, uint8_t r, uint8_t g, uint8_t b); virtual ~GenericRendererPointInfo() {}; }; @@ -109,7 +111,7 @@ uint8_t r; uint8_t g; uint8_t b; - void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b); virtual ~GenericRendererQuadInfo() {}; }; @@ -117,7 +119,7 @@ public: GenericRendererNode n; int image; - void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererImageInfo(GenericRendererNode n, int image); virtual ~GenericRendererImageInfo() {}; }; @@ -125,7 +127,7 @@ public: GenericRendererNode n; int animation; - void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererAnimationInfo(GenericRendererNode n, int animation); virtual ~GenericRendererAnimationInfo() {}; }; @@ -134,7 +136,7 @@ GenericRendererNode n; AbstractFont* font; std::string text; - void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererTextInfo(GenericRendererNode n, AbstractFont* font, std::string text); virtual ~GenericRendererTextInfo() {}; }; @@ -144,7 +146,7 @@ * @param renderbackend to use * @param position position for this renderer in rendering pipeline */ - GenericRenderer(RenderBackend* renderbackend, int position); + GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool); GenericRenderer(const GenericRenderer& old); @@ -170,6 +172,8 @@ private: std::vector<GenericRendererElementInfo*> m_infos; + ImagePool* m_imagepool; + AnimationPool* m_animationpool; }; }
--- a/engine/core/view/renderers/genericrenderer.i Fri Jul 11 11:29:13 2008 +0000 +++ b/engine/core/view/renderers/genericrenderer.i Fri Jul 11 11:57:48 2008 +0000 @@ -45,7 +45,7 @@ }; class GenericRendererElementInfo { public: - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend) = 0; + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) = 0; virtual ~GenericRendererElementInfo() {}; }; @@ -56,7 +56,7 @@ uint8_t r; uint8_t g; uint8_t b; - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererLineInfo(GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b); virtual ~GenericRendererLineInfo() {}; }; @@ -66,7 +66,7 @@ uint8_t r; uint8_t g; uint8_t b; - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererPointInfo(GenericRendererNode n, uint8_t r, uint8_t g, uint8_t b); virtual ~GenericRendererPointInfo() {}; }; @@ -79,7 +79,7 @@ uint8_t r; uint8_t g; uint8_t b; - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b); virtual ~GenericRendererQuadInfo() {}; }; @@ -87,7 +87,7 @@ public: GenericRendererNode n; int image; - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererImageInfo(GenericRendererNode n, int image); virtual ~GenericRendererImageInfo() {}; }; @@ -95,7 +95,7 @@ public: GenericRendererNode n; int animation; - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererAnimationInfo(GenericRendererNode n, int animation); virtual ~GenericRendererAnimationInfo() {}; }; @@ -104,13 +104,13 @@ GenericRendererNode n; AbstractFont* font; std::string text; - virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend); + virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); GenericRendererTextInfo(GenericRendererNode n, AbstractFont* font, std::string text); virtual ~GenericRendererTextInfo() {}; }; class GenericRenderer: public RendererBase { public: - GenericRenderer(RenderBackend* renderbackend, int position); + GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool); ~GeometricRenderer(); std::string getName(); static GenericRenderer* getInstance(IRendererContainer* cnt);