30 #include "video/renderbackend.h"
31 #include "util/math/fife_math.h"
32 #include "util/log/logger.h"
33 #include "model/metamodel/grids/cellgrid.h"
34 #include "model/structures/instance.h"
35 #include "model/structures/layer.h"
36 #include "model/structures/location.h"
38 #include "view/camera.h"
39 #include "gridrenderer.h"
43 static Logger _log(LM_VIEWVIEW);
45 GridRenderer::GridRenderer(RenderBackend* renderbackend, int32_t position):
46 RendererBase(renderbackend, position) {
53 GridRenderer::GridRenderer(
const GridRenderer& old):
55 m_color(old.m_color) {
59 RendererBase* GridRenderer::clone() {
60 return new GridRenderer(*
this);
63 GridRenderer::~GridRenderer() {
66 GridRenderer* GridRenderer::getInstance(IRendererContainer* cnt) {
67 return dynamic_cast<GridRenderer*
>(cnt->getRenderer(
"GridRenderer"));
70 void GridRenderer::render(Camera* cam, Layer* layer, RenderList& instances) {
71 CellGrid* cg = layer->getCellGrid();
73 FL_WARN(_log,
"No cellgrid assigned to layer, cannot draw grid");
146 Rect cv = cam->getViewPort();
147 int32_t cvx2 = round((cv.x+cv.w) * 1.25);
148 int32_t cvy2 = round((cv.y+cv.h) * 1.25);
149 cv.x -= round((cv.x+cv.w) * 0.125);
150 cv.y -= round((cv.y+cv.h) * 0.125);
151 RenderList::const_iterator instance_it = instances.begin();
152 for (;instance_it != instances.end(); ++instance_it) {
153 Instance* instance = (*instance_it)->instance;
154 std::vector<ExactModelCoordinate> vertices;
155 cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates());
156 std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
157 ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
158 Point pt1(firstpt.x, firstpt.y);
161 for (; it != vertices.end(); it++) {
162 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
168 if (cpt1.x < cv.x) cpt1.x = cv.x;
169 if (cpt2.x < cv.x) cpt2.x = cv.x;
170 if (cpt1.y < cv.y) cpt1.y = cv.y;
171 if (cpt2.y < cv.y) cpt2.y = cv.y;
172 if (cpt1.x > cvx2) cpt1.x = cvx2;
173 if (cpt2.x > cvx2) cpt2.x = cvx2;
174 if (cpt1.y > cvy2) cpt1.y = cvy2;
175 if (cpt2.y > cvy2) cpt2.y = cvy2;
177 m_renderbackend->drawLine(cpt1, cpt2, m_color.r, m_color.g, m_color.b);
180 if ((pt2.x >= cv.x) && (pt2.x <= cvx2) && (pt2.y >= cv.y) && (pt2.y <= cvy2)) {
181 if ((firstpt.x >= cv.x) && (firstpt.x <= cvx2) && (firstpt.y >= cv.y) && (firstpt.y <= cvy2)) {
182 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), m_color.r, m_color.g, m_color.b);
188 void GridRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) {
virtual void setEnabled(bool enabled)