diff 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
line wrap: on
line diff
--- a/engine/core/view/renderers/cellselectionrenderer.cpp	Wed Jun 03 19:29:52 2009 +0000
+++ b/engine/core/view/renderers/cellselectionrenderer.cpp	Mon Jun 08 16:00:02 2009 +0000
@@ -43,14 +43,12 @@
 	static Logger _log(LM_VIEWVIEW);
 
 	CellSelectionRenderer::CellSelectionRenderer(RenderBackend* renderbackend, int position):
-		RendererBase(renderbackend, position),
-		m_loc(NULL) {
+		RendererBase(renderbackend, position) {
 		setEnabled(true);
 	}
 
  	CellSelectionRenderer::CellSelectionRenderer(const CellSelectionRenderer& old):
-		RendererBase(old),
-		m_loc(NULL) {
+		RendererBase(old) {
 		setEnabled(true);
 	}
 
@@ -66,48 +64,63 @@
 	}
 	
 	void CellSelectionRenderer::reset() {
-		delete m_loc;
-		m_loc = NULL;
+		m_locations.clear();
 	}
 
-	void CellSelectionRenderer::selectLocation(Location* loc) {
-		delete m_loc;
-		m_loc = NULL;
+	void CellSelectionRenderer::selectLocation(const Location* loc) {
 		if (loc) {
-			m_loc = new Location(*loc);
+			std::vector<Location>::const_iterator it = m_locations.begin();
+			for (; it != m_locations.end(); it++) {
+				if (*it == *loc) return;
+			}
+
+			m_locations.push_back(Location(*loc));
+		}
+	}
+
+	void CellSelectionRenderer::deselectLocation(const Location* loc) {
+		if (loc) {
+			std::vector<Location>::iterator it = m_locations.begin();
+			for (; it != m_locations.end(); it++) {
+				if (*it == *loc) {
+					m_locations.erase(it);
+					break;
+				}
+			}
 		}
 	}
 
 	void CellSelectionRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) {
-		if (!m_loc) {
-			return;
-		}
-		
-		if (layer != m_loc->getLayer()) {
-			return;
-		}
-		
-		CellGrid* cg = layer->getCellGrid();
-		if (!cg) {
-			FL_WARN(_log, "No cellgrid assigned to layer, cannot draw selection");
-			return;
-		}
+		std::vector<Location>::const_iterator locit = m_locations.begin();
+
+		for (; locit != m_locations.end(); locit++) {
+			const Location loc = *locit;
+			if (layer != loc.getLayer()) {
+				continue;
+			}
+			
+			CellGrid* cg = layer->getCellGrid();
+			if (!cg) {
+				FL_WARN(_log, "No cellgrid assigned to layer, cannot draw selection");
+				continue;
+			}
 
-		std::vector<ExactModelCoordinate> vertices;
-		cg->getVertices(vertices, m_loc->getLayerCoordinates());
-		std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
-		ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
-		Point pt1(firstpt.x, firstpt.y);
-		Point pt2;
-		++it;
-		for (; it != vertices.end(); it++) {
-			ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
-			pt2.x = pts.x; pt2.y = pts.y;
-			Point cpt1 = pt1;
-			Point cpt2 = pt2;
-			m_renderbackend->drawLine(cpt1, cpt2, 255, 0, 0);
-			pt1 = pt2;
+			std::vector<ExactModelCoordinate> vertices;
+			cg->getVertices(vertices, loc.getLayerCoordinates());
+			std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
+			ScreenPoint firstpt = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
+			Point pt1(firstpt.x, firstpt.y);
+			Point pt2;
+			++it;
+			for (; it != vertices.end(); it++) {
+				ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
+				pt2.x = pts.x; pt2.y = pts.y;
+				Point cpt1 = pt1;
+				Point cpt2 = pt2;
+				m_renderbackend->drawLine(cpt1, cpt2, 255, 0, 0);
+				pt1 = pt2;
+			}
+			m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 255, 0, 0);
 		}
-		m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 255, 0, 0);
 	}
 }