comparison engine/core/view/renderers/cellselectionrenderer.cpp @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents 90005975cdbb
children 16c2b3ee59ce
comparison
equal deleted inserted replaced
254:10b5f7f36dd4 255:51cc05d862f2
41 41
42 namespace FIFE { 42 namespace FIFE {
43 static Logger _log(LM_VIEWVIEW); 43 static Logger _log(LM_VIEWVIEW);
44 44
45 CellSelectionRenderer::CellSelectionRenderer(RenderBackend* renderbackend, int position): 45 CellSelectionRenderer::CellSelectionRenderer(RenderBackend* renderbackend, int position):
46 RendererBase(renderbackend, position), 46 RendererBase(renderbackend, position) {
47 m_loc(NULL) {
48 setEnabled(true); 47 setEnabled(true);
49 } 48 }
50 49
51 CellSelectionRenderer::CellSelectionRenderer(const CellSelectionRenderer& old): 50 CellSelectionRenderer::CellSelectionRenderer(const CellSelectionRenderer& old):
52 RendererBase(old), 51 RendererBase(old) {
53 m_loc(NULL) {
54 setEnabled(true); 52 setEnabled(true);
55 } 53 }
56 54
57 RendererBase* CellSelectionRenderer::clone() { 55 RendererBase* CellSelectionRenderer::clone() {
58 return new CellSelectionRenderer(*this); 56 return new CellSelectionRenderer(*this);
64 CellSelectionRenderer* CellSelectionRenderer::getInstance(IRendererContainer* cnt) { 62 CellSelectionRenderer* CellSelectionRenderer::getInstance(IRendererContainer* cnt) {
65 return dynamic_cast<CellSelectionRenderer*>(cnt->getRenderer("CellSelectionRenderer")); 63 return dynamic_cast<CellSelectionRenderer*>(cnt->getRenderer("CellSelectionRenderer"));
66 } 64 }
67 65
68 void CellSelectionRenderer::reset() { 66 void CellSelectionRenderer::reset() {
69 delete m_loc; 67 m_locations.clear();
70 m_loc = NULL;
71 } 68 }
72 69
73 void CellSelectionRenderer::selectLocation(Location* loc) { 70 void CellSelectionRenderer::selectLocation(const Location* loc) {
74 delete m_loc;
75 m_loc = NULL;
76 if (loc) { 71 if (loc) {
77 m_loc = new Location(*loc); 72 std::vector<Location>::const_iterator it = m_locations.begin();
73 for (; it != m_locations.end(); it++) {
74 if (*it == *loc) return;
75 }
76
77 m_locations.push_back(Location(*loc));
78 }
79 }
80
81 void CellSelectionRenderer::deselectLocation(const Location* loc) {
82 if (loc) {
83 std::vector<Location>::iterator it = m_locations.begin();
84 for (; it != m_locations.end(); it++) {
85 if (*it == *loc) {
86 m_locations.erase(it);
87 break;
88 }
89 }
78 } 90 }
79 } 91 }
80 92
81 void CellSelectionRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { 93 void CellSelectionRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) {
82 if (!m_loc) { 94 std::vector<Location>::const_iterator locit = m_locations.begin();
83 return; 95
96 for (; locit != m_locations.end(); locit++) {
97 const Location loc = *locit;
98 if (layer != loc.getLayer()) {
99 continue;
100 }
101
102 CellGrid* cg = layer->getCellGrid();
103 if (!cg) {
104 FL_WARN(_log, "No cellgrid assigned to layer, cannot draw selection");
105 continue;
106 }
107
108 std::vector<ExactModelCoordinate> vertices;
109 cg->getVertices(vertices, loc.getLayerCoordinates());
110 std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
111 ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
112 Point pt1(firstpt.x, firstpt.y);
113 Point pt2;
114 ++it;
115 for (; it != vertices.end(); it++) {
116 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
117 pt2.x = pts.x; pt2.y = pts.y;
118 Point cpt1 = pt1;
119 Point cpt2 = pt2;
120 m_renderbackend->drawLine(cpt1, cpt2, 255, 0, 0);
121 pt1 = pt2;
122 }
123 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 255, 0, 0);
84 } 124 }
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 } 125 }
113 } 126 }