Mercurial > fife-parpg
changeset 445:f855809822cf
* Fixed GenericRenderer, now it only render to a specific layer. If the node is only a point then it used the last active layer. fixes #[ticket:458]
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 24 Mar 2010 16:11:30 +0000 |
parents | 79678719d569 |
children | 2046a1f2f5f2 |
files | engine/core/view/rendererbase.h engine/core/view/renderers/genericrenderer.cpp engine/core/view/renderers/genericrenderer.h engine/core/view/renderers/genericrenderer.i |
diffstat | 4 files changed, 120 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/view/rendererbase.h Wed Mar 24 13:29:16 2010 +0000 +++ b/engine/core/view/rendererbase.h Wed Mar 24 16:11:30 2010 +0000 @@ -156,6 +156,10 @@ /** Returns if given layer is currently activated */ bool isActivedLayer(Layer* layer); + + /** Returns list of activated layer + */ + std::list<Layer*> getActiveLayers() const {return m_active_layers;} protected:
--- a/engine/core/view/renderers/genericrenderer.cpp Wed Mar 24 13:29:16 2010 +0000 +++ b/engine/core/view/renderers/genericrenderer.cpp Wed Mar 24 16:11:30 2010 +0000 @@ -49,24 +49,52 @@ namespace FIFE { static Logger _log(LM_VIEWVIEW); + GenericRendererNode::GenericRendererNode(Instance* attached_instance, Location* relative_location, Layer* relative_layer, const Point &relative_point): + m_instance(attached_instance), + m_location(relative_location), + m_layer(relative_layer), + m_point(relative_point) { + } GenericRendererNode::GenericRendererNode(Instance* attached_instance, Location* relative_location, const Point &relative_point): m_instance(attached_instance), m_location(relative_location), + m_layer(NULL), + m_point(relative_point) { + } + GenericRendererNode::GenericRendererNode(Instance* attached_instance, Layer* relative_layer, const Point &relative_point): + m_instance(attached_instance), + m_location(NULL), + m_layer(relative_layer), m_point(relative_point) { } GenericRendererNode::GenericRendererNode(Instance* attached_instance, const Point &relative_point): m_instance(attached_instance), m_location(NULL), + m_layer(NULL), + m_point(relative_point) { + } + GenericRendererNode::GenericRendererNode(Location* attached_location, Layer* relative_layer, const Point &relative_point): + m_instance(NULL), + m_location(attached_location), + m_layer(relative_layer), m_point(relative_point) { } GenericRendererNode::GenericRendererNode(Location* attached_location, const Point &relative_point): m_instance(NULL), m_location(attached_location), + m_layer(NULL), + m_point(relative_point) { + } + GenericRendererNode::GenericRendererNode(Layer* attached_layer, const Point &relative_point): + m_instance(NULL), + m_location(NULL), + m_layer(attached_layer), m_point(relative_point) { } GenericRendererNode::GenericRendererNode(const Point &attached_point): m_instance(NULL), m_location(NULL), + m_layer(NULL), m_point(attached_point) { } GenericRendererNode::~GenericRendererNode() { @@ -97,6 +125,9 @@ m_instance = NULL; m_location = attached_location; } + void GenericRendererNode::setAttached(Layer* attached_layer) { + m_layer = attached_layer; + } void GenericRendererNode::setAttached(const Point &attached_point) { m_instance = NULL; m_location = NULL; @@ -135,6 +166,12 @@ } return m_location; } + Layer* GenericRendererNode::getAttachedLayer() { + if(m_layer == NULL) { + throw NotSupported("No layer attached."); + } + return m_layer; + } Point GenericRendererNode::getAttachedPoint() { if(m_instance != NULL || m_location != NULL) { throw NotSupported("No point attached."); @@ -161,6 +198,9 @@ Location* GenericRendererNode::getLocation() { return m_location; } + Layer* GenericRendererNode::getLayer() { + return m_layer; + } Point GenericRendererNode::getPoint() { return m_point; } @@ -168,18 +208,26 @@ Point GenericRendererNode::getCalculatedPoint(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { ScreenPoint p; if(m_instance != NULL) { + if(m_layer == NULL) { + m_layer = m_instance->getLocation().getLayer(); + } if(m_location != NULL) { p = cam->toScreenCoordinates(m_instance->getLocationRef().getMapCoordinates() + m_location->getMapCoordinates()); - } - else { + } else { p = cam->toScreenCoordinates(m_instance->getLocation().getMapCoordinates()); } - } - else if(m_location != NULL) { + } else if(m_location != NULL) { + if(m_layer == NULL) { + m_layer = m_location->getLayer(); + } p = cam->toScreenCoordinates(m_location->getMapCoordinates()); + } else if(m_layer == NULL) { + const std::list<Layer*>& layers = cam->getRenderer("GenericRenderer")->getActiveLayers(); + std::list<Layer*>::const_iterator layer_it = layers.begin(); + for (; layer_it != layers.end(); ++layer_it) { + setAttached(*layer_it); + } } - else - return m_point; return Point(m_point.x + p.x, m_point.y + p.y); } @@ -194,7 +242,9 @@ void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { Point p1 = m_edge1.getCalculatedPoint(cam, layer, instances); Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances); - renderbackend->drawLine(p1, p2, m_red, m_green, m_blue); + if(m_edge1.getLayer() == layer) { + renderbackend->drawLine(p1, p2, m_red, m_green, m_blue); + } } GenericRendererPointInfo::GenericRendererPointInfo(GenericRendererNode anchor, uint8_t r, uint8_t g, uint8_t b): @@ -206,7 +256,9 @@ } void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { Point p = m_anchor.getCalculatedPoint(cam, layer, instances); - renderbackend->putPixel(p.x, p.y, m_red, m_green, m_blue); + if(m_anchor.getLayer() == layer) { + renderbackend->putPixel(p.x, p.y, m_red, m_green, m_blue); + } } GenericRendererQuadInfo::GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b): @@ -224,7 +276,9 @@ Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances); Point p3 = m_edge3.getCalculatedPoint(cam, layer, instances); Point p4 = m_edge4.getCalculatedPoint(cam, layer, instances); - renderbackend->drawQuad(p1, p2, p3, p4, m_red, m_green, m_blue); + if(m_edge1.getLayer() == layer) { + renderbackend->drawQuad(p1, p2, p3, p4, m_red, m_green, m_blue); + } } GenericRendererVertexInfo::GenericRendererVertexInfo(GenericRendererNode center, int size, uint8_t r, uint8_t g, uint8_t b): @@ -237,7 +291,9 @@ } void GenericRendererVertexInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { Point p = m_center.getCalculatedPoint(cam, layer, instances); - renderbackend->drawVertex(p, m_size, m_red, m_green, m_blue); + if(m_center.getLayer() == layer) { + renderbackend->drawVertex(p, m_size, m_red, m_green, m_blue); + } } GenericRendererImageInfo::GenericRendererImageInfo(GenericRendererNode anchor, int image): @@ -247,13 +303,15 @@ } void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { Point p = m_anchor.getCalculatedPoint(cam, layer, instances); - Image* img = &imagepool->getImage(m_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); + if(m_anchor.getLayer() == layer) { + Image* img = &imagepool->getImage(m_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 anchor, int animation): @@ -265,15 +323,17 @@ } void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { Point p = m_anchor.getCalculatedPoint(cam, layer, instances); - Animation& animation = animpool->getAnimation(m_animation); - int animtime = scaleTime(m_time_scale, TimeManager::instance()->getTime() - m_start_time) % animation.getDuration(); - Image* img = animation.getFrameByTimestamp(animtime); - 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); + if(m_anchor.getLayer() == layer) { + Animation& animation = animpool->getAnimation(m_animation); + int animtime = scaleTime(m_time_scale, TimeManager::instance()->getTime() - m_start_time) % animation.getDuration(); + Image* img = animation.getFrameByTimestamp(animtime); + 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); + } } GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode anchor, AbstractFont* font, std::string text): @@ -284,13 +344,15 @@ } void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { Point p = m_anchor.getCalculatedPoint(cam, layer, instances); - Image* img = m_font->getAsImageMultiline(m_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); + if(m_anchor.getLayer() == layer) { + Image* img = m_font->getAsImageMultiline(m_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) {
--- a/engine/core/view/renderers/genericrenderer.h Wed Mar 24 13:29:16 2010 +0000 +++ b/engine/core/view/renderers/genericrenderer.h Wed Mar 24 16:11:30 2010 +0000 @@ -40,39 +40,47 @@ class GenericRendererNode { public: + GenericRendererNode(Instance* attached_instance, Location* relative_location, Layer* relative_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(Instance* attached_instance, Location* relative_location, const Point &relative_point = Point(0,0)); + GenericRendererNode(Instance* attached_instance, Layer* relative_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(Instance* attached_instance, const Point &relative_point = Point(0,0)); + GenericRendererNode(Location* attached_location, Layer* relative_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(Location* attached_location, const Point &relative_point = Point(0,0)); + GenericRendererNode(Layer* attached_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(const Point &attached_point); ~GenericRendererNode(); - + void setAttached(Instance* attached_instance, Location* relative_location, const Point &relative_point); void setAttached(Instance* attached_instance, Location* relative_location); void setAttached(Instance* attached_instance, const Point &relative_point); void setAttached(Instance* attached_instance); void setAttached(Location* attached_location, const Point &relative_point); void setAttached(Location* attached_location); + void setAttached(Layer* attached_layer); void setAttached(const Point &attached_point); - + void setRelative(Location* relative_location); void setRelative(Location* relative_location, Point relative_point); void setRelative(const Point &relative_point); - + Instance* getAttachedInstance(); Location* getAttachedLocation(); + Layer* getAttachedLayer(); Point getAttachedPoint(); - + Location* getOffsetLocation(); Point getOffsetPoint(); - + Instance* getInstance(); Location* getLocation(); + Layer* getLayer(); Point getPoint(); Point getCalculatedPoint(Camera* cam, Layer* layer, std::vector<Instance*>& instances); private: Instance* m_instance; Location* m_location; + Layer* m_layer; Point m_point; }; class GenericRendererElementInfo {
--- a/engine/core/view/renderers/genericrenderer.i Wed Mar 24 13:29:16 2010 +0000 +++ b/engine/core/view/renderers/genericrenderer.i Wed Mar 24 16:11:30 2010 +0000 @@ -29,9 +29,13 @@ class GenericRendererNode { public: + GenericRendererNode(Instance* attached_instance, Location* relative_location, Layer* relative_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(Instance* attached_instance, Location* relative_location, const Point &relative_point = Point(0,0)); + GenericRendererNode(Instance* attached_instance, Layer* relative_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(Instance* attached_instance, const Point &relative_point = Point(0,0)); + GenericRendererNode(Location* attached_location, Layer* relative_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(Location* attached_location, const Point &relative_point = Point(0,0)); + GenericRendererNode(Layer* attached_layer, const Point &relative_point = Point(0,0)); GenericRendererNode(const Point &attached_point); ~GenericRendererNode(); @@ -41,6 +45,7 @@ void setAttached(Instance* attached_instance); void setAttached(Location* attached_location, const Point &relative_point); void setAttached(Location* attached_location); + void setAttached(Layer* attached_layer); void setAttached(const Point &attached_point); void setRelative(Location* relative_location); @@ -49,6 +54,7 @@ Instance* getAttachedInstance(); Location* getAttachedLocation(); + Layer* getAttachedLayer(); Point getAttachedPoint(); Location* getOffsetLocation(); @@ -56,12 +62,14 @@ Instance* getInstance(); Location* getLocation(); + Layer* getLayer(); Point getPoint(); Point getCalculatedPoint(Camera* cam, Layer* layer, std::vector<Instance*>& instances); private: Instance* m_instance; Location* m_location; + Layer* m_layer; Point m_point; }; class GenericRendererElementInfo {