comparison engine/core/view/renderers/cellselectionrenderer.cpp @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE Team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 // Standard C++ library includes
23
24 // 3rd party library includes
25
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
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"
37
38 #include "view/camera.h"
39 #include "cellselectionrenderer.h"
40
41
42 namespace FIFE {
43 static Logger _log(LM_VIEWVIEW);
44
45 CellSelectionRenderer::CellSelectionRenderer(RenderBackend* renderbackend, int position):
46 RendererBase(renderbackend, position),
47 m_loc(NULL) {
48 setEnabled(true);
49 }
50
51 CellSelectionRenderer::CellSelectionRenderer(const CellSelectionRenderer& old):
52 RendererBase(old),
53 m_loc(NULL) {
54 setEnabled(true);
55 }
56
57 RendererBase* CellSelectionRenderer::clone() {
58 return new CellSelectionRenderer(*this);
59 }
60
61 CellSelectionRenderer::~CellSelectionRenderer() {
62 }
63
64 CellSelectionRenderer* CellSelectionRenderer::getInstance(IRendererContainer* cnt) {
65 return dynamic_cast<CellSelectionRenderer*>(cnt->getRenderer("CellSelectionRenderer"));
66 }
67
68 void CellSelectionRenderer::reset() {
69 delete m_loc;
70 m_loc = NULL;
71 }
72
73 void CellSelectionRenderer::selectLocation(Location* loc) {
74 delete m_loc;
75 m_loc = NULL;
76 if (loc) {
77 m_loc = new Location(*loc);
78 }
79 }
80
81 void CellSelectionRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) {
82 if (!m_loc) {
83 return;
84 }
85
86 if (layer != m_loc->getLayer()) {
87 return;
88 }
89
90 CellGrid* cg = layer->getCellGrid();
91 if (!cg) {
92 FL_WARN(_log, "No cellgrid assigned to layer, cannot draw selection");
93 return;
94 }
95
96 std::vector<ExactModelCoordinate> vertices;
97 cg->getVertices(vertices, m_loc->getLayerCoordinates());
98 std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
99 ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
100 Point pt1(firstpt.x, firstpt.y);
101 Point pt2;
102 ++it;
103 for (; it != vertices.end(); it++) {
104 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
105 pt2.x = pts.x; pt2.y = pts.y;
106 Point cpt1 = pt1;
107 Point cpt2 = pt2;
108 m_renderbackend->drawLine(cpt1, cpt2, 255, 0, 0);
109 pt1 = pt2;
110 }
111 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 255, 0, 0);
112 }
113 }