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,
int 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");
76 m_renderbackend->disableLighting();
146 Rect cv = cam->getViewPort();
147 int cvx2 = cv.
x+cv.w;
148 int cvy2 = cv.y+cv.h;
149 RenderList::const_iterator instance_it = instances.begin();
150 for (;instance_it != instances.end(); ++instance_it) {
151 Instance* instance = (*instance_it)->instance;
152 std::vector<ExactModelCoordinate> vertices;
153 cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates());
154 std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
155 ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
156 Point pt1(firstpt.x, firstpt.y);
159 for (; it != vertices.end(); it++) {
160 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
166 if (cpt1.x < cv.x) cpt1.x = cv.x;
167 if (cpt2.x < cv.x) cpt2.x = cv.x;
168 if (cpt1.y < cv.y) cpt1.y = cv.y;
169 if (cpt2.y < cv.y) cpt2.y = cv.y;
170 if (cpt1.x > cvx2) cpt1.x = cvx2;
171 if (cpt2.x > cvx2) cpt2.x = cvx2;
172 if (cpt1.y > cvy2) cpt1.y = cvy2;
173 if (cpt2.y > cvy2) cpt2.y = cvy2;
175 m_renderbackend->drawLine(cpt1, cpt2, m_color.r, m_color.g, m_color.b);
178 if ((pt2.x >= cv.x) && (pt2.x <= cvx2) && (pt2.y >= cv.y) && (pt2.y <= cvy2)) {
179 if ((firstpt.x >= cv.x) && (firstpt.x <= cvx2) && (firstpt.y >= cv.y) && (firstpt.y <= cvy2)) {
180 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), m_color.r, m_color.g, m_color.b);
184 m_renderbackend->enableLighting();
187 void GridRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) {