00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "video/renderbackend.h"
00031 #include "util/math/fife_math.h"
00032 #include "util/log/logger.h"
00033 #include "model/metamodel/grids/cellgrid.h"
00034 #include "model/structures/instance.h"
00035 #include "model/structures/layer.h"
00036 #include "model/structures/location.h"
00037
00038 #include "view/camera.h"
00039 #include "blockinginforenderer.h"
00040
00041
00042 namespace FIFE {
00043 static Logger _log(LM_VIEWVIEW);
00044
00045 BlockingInfoRenderer::BlockingInfoRenderer(RenderBackend* renderbackend, int32_t position):
00046 RendererBase(renderbackend, position) {
00047 setEnabled(false);
00048 m_color.r = 0;
00049 m_color.g = 255;
00050 m_color.b = 0;
00051 }
00052
00053 BlockingInfoRenderer::BlockingInfoRenderer(const BlockingInfoRenderer& old):
00054 RendererBase(old),
00055 m_color(old.m_color) {
00056 setEnabled(false);
00057 }
00058
00059 RendererBase* BlockingInfoRenderer::clone() {
00060 return new BlockingInfoRenderer(*this);
00061 }
00062
00063 BlockingInfoRenderer::~BlockingInfoRenderer() {
00064 }
00065
00066 BlockingInfoRenderer* BlockingInfoRenderer::getInstance(IRendererContainer* cnt) {
00067 return dynamic_cast<BlockingInfoRenderer*>(cnt->getRenderer("BlockingInfoRenderer"));
00068 }
00069
00070 void BlockingInfoRenderer::render(Camera* cam, Layer* layer, RenderList& instances) {
00071 CellGrid* cg = layer->getCellGrid();
00072 if (!cg) {
00073 FL_WARN(_log, "No cellgrid assigned to layer, cannot draw grid");
00074 return;
00075 }
00076
00077 Rect cv = cam->getViewPort();
00078 RenderList::const_iterator instance_it = instances.begin();
00079 for (;instance_it != instances.end(); ++instance_it) {
00080 Instance* instance = (*instance_it)->instance;
00081 if (!instance->getObject()->isBlocking() || !instance->isBlocking()) {
00082 continue;
00083 }
00084 std::vector<ExactModelCoordinate> vertices;
00085 cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates());
00086 std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
00087 int32_t halfind = vertices.size() / 2;
00088 ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
00089 Point pt1(firstpt.x, firstpt.y);
00090 Point pt2;
00091 ++it;
00092 for (; it != vertices.end(); it++) {
00093 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
00094 pt2.x = pts.x; pt2.y = pts.y;
00095 Point cpt1 = pt1;
00096 Point cpt2 = pt2;
00097 m_renderbackend->drawLine(cpt1, cpt2, m_color.r, m_color.g, m_color.b);
00098 pt1 = pt2;
00099 }
00100 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), m_color.r, m_color.g, m_color.b);
00101 ScreenPoint spt1 = cam->toScreenCoordinates(cg->toMapCoordinates(vertices[0]));
00102 Point pt3(spt1.x, spt1.y);
00103 ScreenPoint spt2 = cam->toScreenCoordinates(cg->toMapCoordinates(vertices[halfind]));
00104 Point pt4(spt2.x, spt2.y);
00105 m_renderbackend->drawLine(pt3, pt4, m_color.r, m_color.g, m_color.b);
00106 }
00107 }
00108
00109 void BlockingInfoRenderer::setColor(uint8_t r, uint8_t g, uint8_t b) {
00110 m_color.r = r;
00111 m_color.g = g;
00112 m_color.b = b;
00113 }
00114 }