changeset 579:b2feacaed53c

* Added the colorbuffer patch with a small change due to SDL. Performance boost between 20-30% under OpenGL. * Improved the most renderers with setColor() function. * Fixed the genericrenderer, is now tested whether the images are in the viewport. * Fixed the gridrenderer, the grid is now drawn only up to the viewport. * Changed the vertex functions in opengl/renderbackendopengl.cpp from vertex3f() to vertex2f(). * Improved the Editor, now you can use blocking, grid and coordinate renderer over gui or keys. Additionally, the colors can be changed with the settings.xml.
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 31 Jul 2010 17:46:19 +0000
parents 54d83a0462ee
children aa813b967806
files engine/core/video/opengl/renderbackendopengl.cpp engine/core/video/opengl/renderbackendopengl.h engine/core/video/renderbackend.h engine/core/video/sdl/renderbackendsdl.cpp engine/core/video/sdl/renderbackendsdl.h engine/core/video/video.i engine/core/view/camera.cpp engine/core/view/camera.h engine/core/view/renderers/blockinginforenderer.cpp engine/core/view/renderers/blockinginforenderer.h engine/core/view/renderers/cellselectionrenderer.cpp engine/core/view/renderers/cellselectionrenderer.h engine/core/view/renderers/cellselectionrenderer.i engine/core/view/renderers/coordinaterenderer.cpp engine/core/view/renderers/coordinaterenderer.h engine/core/view/renderers/floatingtextrenderer.cpp engine/core/view/renderers/floatingtextrenderer.h engine/core/view/renderers/floatingtextrenderer.i engine/core/view/renderers/genericrenderer.cpp engine/core/view/renderers/gridrenderer.cpp engine/core/view/renderers/gridrenderer.h tools/editor/lang/infotext.txt tools/editor/scripts/editor.py tools/editor/scripts/gui/mapeditor.py tools/editor/scripts/mapcontroller.py tools/editor/settings-dist.xml
diffstat 26 files changed, 393 insertions(+), 130 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/video/opengl/renderbackendopengl.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/video/opengl/renderbackendopengl.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -43,6 +43,7 @@
 
 		m_rgba_format = *(testsurface->format);
 		SDL_FreeSurface(testsurface);
+		m_clear = true;
 	}
 
 	const std::string& RenderBackendOpenGL::getName() const {
@@ -132,9 +133,11 @@
 	}
 
 	void RenderBackendOpenGL::startFrame() {
-		glDisable(GL_SCISSOR_TEST);
-		glClear(GL_COLOR_BUFFER_BIT);
-		glEnable(GL_SCISSOR_TEST);
+		if(m_clear) {
+			glDisable(GL_SCISSOR_TEST);
+			glClear(GL_COLOR_BUFFER_BIT);
+			glEnable(GL_SCISSOR_TEST);
+		}
 	}
 
 	void RenderBackendOpenGL::endFrame() {
@@ -176,11 +179,15 @@
 		return new GLImage(data, width, height);
 	}
 
+	void RenderBackendOpenGL::isClearNeeded(bool clear) {
+		m_clear = clear;
+	}
+
 	bool RenderBackendOpenGL::putPixel(int x, int y, int r, int g, int b) {
 		if ((x < 0) || (x >= (int)getWidth()) || (y < 0) || (y >= (int)getHeight())) {
 			return false;
 		}
-		glColor4ub(r, g, b, 255);
+		glColor3ub(r, g, b);
 		glBegin(GL_POINTS);
 		glVertex2i(x, y);
 		glEnd();
@@ -188,42 +195,38 @@
 	}
 
 	void RenderBackendOpenGL::drawLine(const Point& p1, const Point& p2, int r, int g, int b) {
-		glColor4ub(r, g, b, 255);
+		glColor3ub(r, g, b);
 		glBegin(GL_LINES);
-		glVertex3f(p1.x+0.5f, p1.y+0.5f, 0);
-		glVertex3f(p2.x+0.5f, p2.y+0.5f, 0);
+		glVertex2f(p1.x+0.5f, p1.y+0.5f);
+		glVertex2f(p2.x+0.5f, p2.y+0.5f);
 		glEnd();
 
 		glBegin(GL_POINTS);
-		glVertex3f(p2.x+0.5f, p2.y+0.5f, 0);
+		glVertex2f(p2.x+0.5f, p2.y+0.5f);
 		glEnd();
 	}
 
 	void RenderBackendOpenGL::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4,  int r, int g, int b) {
 		glColor4ub(r, g, b, 165);
 		glBegin(GL_QUADS);
-		glVertex3f(p1.x, p1.y, 0);
-		glVertex3f(p2.x, p2.y, 0);
-		glVertex3f(p3.x, p3.y, 0);
-		glVertex3f(p4.x, p4.y, 0);
+		glVertex2f(p1.x, p1.y);
+		glVertex2f(p2.x, p2.y);
+		glVertex2f(p3.x, p3.y);
+		glVertex2f(p4.x, p4.y);
 		glEnd();
 	}
 
 	void RenderBackendOpenGL::drawVertex(const Point& p, const uint8_t size, int r, int g, int b){
-
 		GLfloat width;
-
 		glGetFloatv(GL_LINE_WIDTH, &width);
 		glLineWidth(1.0);
 
+		glColor3ub(r, g, b);
 		glBegin(GL_LINE_LOOP);
-		glColor4ub(r, g, b, 255);
-
-		glVertex3f(p.x-size, p.y+size, 0);
-		glVertex3f(p.x+size, p.y+size, 0);
-		glVertex3f(p.x+size, p.y-size, 0);
-		glVertex3f(p.x-size, p.y-size, 0);
-
+		glVertex2f(p.x-size, p.y+size);
+		glVertex2f(p.x+size, p.y+size);
+		glVertex2f(p.x+size, p.y-size);
+		glVertex2f(p.x-size, p.y-size);
 		glEnd();
 
 		glLineWidth(width);
--- a/engine/core/video/opengl/renderbackendopengl.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/video/opengl/renderbackendopengl.h	Sat Jul 31 17:46:19 2010 +0000
@@ -53,8 +53,11 @@
 		void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4,  int r, int g, int b);
 		void drawVertex(const Point& p, const uint8_t size, int r, int g, int b);
 
+		void isClearNeeded(bool clear);
+
 	private:
 		SDL_PixelFormat m_rgba_format;
+		bool m_clear;
 	};
 
 }
--- a/engine/core/video/renderbackend.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/video/renderbackend.h	Sat Jul 31 17:46:19 2010 +0000
@@ -102,6 +102,8 @@
 		 * @return The new Image.
 		 */
 		virtual Image* createImage(SDL_Surface* surface) = 0;
+
+		virtual void isClearNeeded(bool clear) = 0;
 		
 		/** Returns a pointer to the main screen Image
 		 * @return A pointer to the main screen Image, or 0 if no mainscreen exists.
--- a/engine/core/video/sdl/renderbackendsdl.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/video/sdl/renderbackendsdl.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -40,6 +40,7 @@
 	static Logger _log(LM_VIDEO);
 
 	RenderBackendSDL::RenderBackendSDL(const SDL_Color& colorkey) : RenderBackend(colorkey) {
+		m_clear = true;
 	}
 
 
@@ -134,6 +135,10 @@
 		return new SDLImage(data, width, height);
 	}
 
+	void RenderBackendSDL::isClearNeeded(bool clear) {
+		m_clear = clear;
+	}
+
 	bool RenderBackendSDL::putPixel(int x, int y, int r, int g, int b) {
 		return static_cast<SDLImage*>(m_screen)->putPixel(x, y, r, g, b);
 	}
--- a/engine/core/video/sdl/renderbackendsdl.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/video/sdl/renderbackendsdl.h	Sat Jul 31 17:46:19 2010 +0000
@@ -54,6 +54,11 @@
 		void drawLine(const Point& p1, const Point& p2, int r, int g, int b);
 		void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4,  int r, int g, int b);
 		void drawVertex(const Point& p, const uint8_t size, int r, int g, int b);
+
+		void isClearNeeded(bool clear);
+
+	private:
+		bool m_clear;
 	};
 
 }
--- a/engine/core/video/video.i	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/video/video.i	Sat Jul 31 17:46:19 2010 +0000
@@ -166,6 +166,7 @@
 		bool isColorKeyEnabled() const;
 		void setColorKey(const SDL_Color& colorkey);
 		const SDL_Color& getColorKey() const;
+		void isClearNeeded(bool clear);
 	};
 	
 	enum MouseCursorType {
--- a/engine/core/view/camera.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/camera.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -113,6 +113,11 @@
 		Location location;
 		location.setLayer(layer);
 		setLocation(location);
+		if(m_renderbackend->getName() == "SDL") {
+			m_backendSDL = true;
+		} else {
+			m_backendSDL = false;
+		}
 	}
 
 	Camera::~Camera() {
@@ -124,6 +129,7 @@
 			delete r_it->second;
 		}
 		m_renderers.clear();
+		m_renderbackend->isClearNeeded(true);
 		delete m_map_observer;
 	}
 
@@ -391,6 +397,59 @@
 		FL_DBG(_log, LMsg("   m_screen_cell_width=") << m_screen_cell_width);
 	}
 
+	bool Camera::testRenderedViewPort() {
+		Map* map = m_location.getMap();
+		Rect cv = m_viewport;
+		int cv2x = cv.x+cv.w;
+		int cv2y = cv.y+cv.h;
+		bool trec1 = false, trec2 = false, trec3 = false, trec4 = false;
+		Rect rec1 = Rect(cv.x, cv.y, 1, 1);
+		Rect rec2 = Rect(cv.x, cv2y, 1, 1);
+		Rect rec3 = Rect(cv2x, cv.y, 1, 1);
+		Rect rec4 = Rect(cv2x, cv2y, 1, 1);
+
+		const std::list<Layer*>& layers = map->getLayers();
+		std::list<Layer*>::const_iterator layer_it = layers.begin();
+		const RenderList& layer_instances = m_layer_to_instances[*layer_it];
+		RenderList::const_iterator instance_it = layer_instances.begin();
+		for(; instance_it != layer_instances.end(); ++instance_it) {
+			Instance* i = (*instance_it)->instance;
+			const RenderItem& vc = **instance_it;
+			if(vc.dimensions.intersects(rec1) && !trec1) {
+				trec1 = true;
+			}
+			if(vc.dimensions.intersects(rec2) && !trec2) {
+				trec2 = true;
+			}
+			if(trec1 && trec2) {
+				break;
+			}
+		}
+		if(trec1 && trec2) {
+			RenderList::const_reverse_iterator instance_itr = layer_instances.rbegin();
+			for(; instance_itr != layer_instances.rend(); ++instance_itr) {
+				Instance* i = (*instance_itr)->instance;
+				const RenderItem& vc = **instance_itr;
+				if(vc.dimensions.intersects(rec3) && !trec3) {
+					trec3 = true;
+				}
+				if(vc.dimensions.intersects(rec4) && !trec4) {
+					trec4 = true;
+				}
+				if(trec3 && trec4) {
+					break;
+				}
+			}
+		}
+
+		if(trec1 && trec2 && trec3 && trec4) {
+			m_renderbackend->isClearNeeded(false);
+			return false;
+		}
+		m_renderbackend->isClearNeeded(true);
+		return true;
+	}
+
 	void Camera::getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances) {
 		instances.clear();
 		const RenderList& layer_instances = m_layer_to_instances[&layer];
@@ -582,8 +641,12 @@
 		//	return;
 		//}
 
+		if(m_backendSDL) {
+			m_renderbackend->pushClipArea(getViewPort());
+		} else {
+			m_renderbackend->pushClipArea(getViewPort(), testRenderedViewPort());
+		}
 		// update each layer
-		m_renderbackend->pushClipArea(getViewPort());
 // 		m_layer_to_instances.clear();
 		const std::list<Layer*>& layers = map->getLayers();
 		std::list<Layer*>::const_iterator layer_it = layers.begin();
--- a/engine/core/view/camera.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/camera.h	Sat Jul 31 17:46:19 2010 +0000
@@ -279,6 +279,7 @@
 		void onRendererPipelinePositionChanged(RendererBase* renderer);
 		void onRendererEnabledChanged(RendererBase* renderer);
 
+		bool testRenderedViewPort();
 		/** Renders camera
 		 */
 		void render();
@@ -331,6 +332,7 @@
 		double m_reference_scale;
 		bool m_enabled;
 		Instance* m_attachedto;
+		bool m_backendSDL;
 		// caches calculated image dimensions for already queried & calculated layers
 		std::map<Layer*, Point> m_image_dimensions;
 		bool m_iswarped;
--- a/engine/core/view/renderers/blockinginforenderer.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/blockinginforenderer.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -45,10 +45,15 @@
 	BlockingInfoRenderer::BlockingInfoRenderer(RenderBackend* renderbackend, int position):
 		RendererBase(renderbackend, position) {
 		setEnabled(false);
+		m_color.r = 0;
+		m_color.g = 255;
+		m_color.b = 0;
 	}
 
 	BlockingInfoRenderer::BlockingInfoRenderer(const BlockingInfoRenderer& old):
-		RendererBase(old) {
+		RendererBase(old),
+		m_color(old.m_color) {
+		setEnabled(false);
 	}
 
 	RendererBase* BlockingInfoRenderer::clone() {
@@ -58,6 +63,10 @@
 	BlockingInfoRenderer::~BlockingInfoRenderer() {
 	}
 
+	BlockingInfoRenderer* BlockingInfoRenderer::getInstance(IRendererContainer* cnt) {
+		return dynamic_cast<BlockingInfoRenderer*>(cnt->getRenderer("BlockingInfoRenderer"));
+	}
+
 	void BlockingInfoRenderer::render(Camera* cam, Layer* layer, RenderList& instances) {
 		CellGrid* cg = layer->getCellGrid();
 		if (!cg) {
@@ -74,12 +83,32 @@
 			}
 			std::vector<ExactModelCoordinate> vertices;
 			cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates());
+			std::vector<ExactModelCoordinate>::const_iterator it = vertices.begin();
 			int halfind = vertices.size() / 2;
+			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, m_color.r, m_color.g, m_color.b);
+				pt1 = pt2;
+			}
+			m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), m_color.r, m_color.g, m_color.b);
 			ScreenPoint spt1 = cam->toScreenCoordinates(cg->toMapCoordinates(vertices[0]));
-			Point pt1(spt1.x, spt1.y);
+			Point pt3(spt1.x, spt1.y);
 			ScreenPoint spt2 = cam->toScreenCoordinates(cg->toMapCoordinates(vertices[halfind]));
-			Point pt2(spt2.x, spt2.y);
-			m_renderbackend->drawLine(pt1, pt2, 0, 255, 0);
+			Point pt4(spt2.x, spt2.y);
+			m_renderbackend->drawLine(pt3, pt4, m_color.r, m_color.g, m_color.b);
 		}
 	}
+
+	void BlockingInfoRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) {
+		m_color.r = r;
+		m_color.g = g;
+		m_color.b = b;
+	}
 }
--- a/engine/core/view/renderers/blockinginforenderer.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/blockinginforenderer.h	Sat Jul 31 17:46:19 2010 +0000
@@ -50,12 +50,15 @@
 		 */
 		virtual ~BlockingInfoRenderer();
 
+		std::string getName() { return "BlockingInfoRenderer"; }
 		void render(Camera* cam, Layer* layer, RenderList& instances);
+		void setColor(Uint8 r, Uint8 g, Uint8 b);
 
-		std::string getName() { return "BlockingInfoRenderer"; }
+		static BlockingInfoRenderer* getInstance(IRendererContainer* cnt);
+
 	private:
+		SDL_Color m_color;
 	};
-
 }
 
 #endif
--- a/engine/core/view/renderers/cellselectionrenderer.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/cellselectionrenderer.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -44,12 +44,16 @@
 
 	CellSelectionRenderer::CellSelectionRenderer(RenderBackend* renderbackend, int position):
 		RendererBase(renderbackend, position) {
-		setEnabled(true);
+		setEnabled(false);
+		m_color.r = 255;
+		m_color.g = 0;
+		m_color.b = 0;
 	}
 
  	CellSelectionRenderer::CellSelectionRenderer(const CellSelectionRenderer& old):
-		RendererBase(old) {
-		setEnabled(true);
+		RendererBase(old),
+		m_color(old.m_color) {
+		setEnabled(false);
 	}
 
 	RendererBase* CellSelectionRenderer::clone() {
@@ -117,10 +121,16 @@
 				pt2.x = pts.x; pt2.y = pts.y;
 				Point cpt1 = pt1;
 				Point cpt2 = pt2;
-				m_renderbackend->drawLine(cpt1, cpt2, 255, 0, 0);
+				m_renderbackend->drawLine(cpt1, cpt2, m_color.r, m_color.g, m_color.b);
 				pt1 = pt2;
 			}
-			m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 255, 0, 0);
+			m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), m_color.r, m_color.g, m_color.b);
 		}
 	}
+
+	void CellSelectionRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) {
+		m_color.r = r;
+		m_color.g = g;
+		m_color.b = b;
+	}
 }
--- a/engine/core/view/renderers/cellselectionrenderer.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/cellselectionrenderer.h	Sat Jul 31 17:46:19 2010 +0000
@@ -76,10 +76,13 @@
 		/** Returns selected locations
 		 */
 		const std::vector<Location> getLocations() const { return m_locations; }
+
+		void setColor(Uint8 r, Uint8 g, Uint8 b);
 		
 	private:
 		// selected locations
 		std::vector<Location> m_locations;
+		SDL_Color m_color;
 	};
 
 }
--- a/engine/core/view/renderers/cellselectionrenderer.i	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/cellselectionrenderer.i	Sat Jul 31 17:46:19 2010 +0000
@@ -36,6 +36,7 @@
 		void selectLocation(const Location* loc);
 		void deselectLocation(const Location* loc);
 		const std::vector<Location> getLocations() const;
+		void setColor(Uint8 r, Uint8 g, Uint8 b);
 		
 	private:
 		CellSelectionRenderer(RenderBackend* renderbackend, int position);
--- a/engine/core/view/renderers/coordinaterenderer.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/coordinaterenderer.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -54,21 +54,30 @@
 		m_c(),
 		m_font(font) {
 		setEnabled(false);
+		m_font_color = false;
+		m_color = m_font->getColor();
 	}
 
  	CoordinateRenderer::CoordinateRenderer(const CoordinateRenderer& old):
+		RendererBase(old),
 		m_layer_area(),
 		m_tmploc(),
 		m_c(),
-		m_font(old.m_font) {
+		m_font(old.m_font),
+		m_font_color(old.m_font_color),
+		m_color(old.m_color) {
 		setEnabled(false);
 	}
+
+	RendererBase* CoordinateRenderer::clone() {
+		return new CoordinateRenderer(*this);
+	}
 	
 	CoordinateRenderer::~CoordinateRenderer() {
 	}
 
-	RendererBase* CoordinateRenderer::clone() {
-		return new CoordinateRenderer(*this);
+	CoordinateRenderer* CoordinateRenderer::getInstance(IRendererContainer* cnt) {
+		return dynamic_cast<CoordinateRenderer*>(cnt->getRenderer("CoordinateRenderer"));
 	}
 
 	void CoordinateRenderer::adjustLayerArea() {
@@ -100,6 +109,11 @@
 		adjustLayerArea();
 
 		Rect r = Rect();
+		SDL_Color old_color = m_font->getColor();
+		if(old_color.r != m_color.r || old_color.g != m_color.g || old_color.b != m_color.b) {
+			m_font->setColor(m_color.r, m_color.g, m_color.b);
+			m_font_color = true;
+		}
 		for (int x = m_layer_area.x-1; x < m_layer_area.w+1; x++) {
 			for (int y = m_layer_area.y-1; y < m_layer_area.h+1; y++) {
 				ModelCoordinate mc(x, y);
@@ -109,7 +123,6 @@
 				    (drawpt.y >= cv.y) && (drawpt.y <= cv.y + cv.h)) {
 					std::stringstream ss;
 					ss << mc.x <<","<< mc.y;
-					m_font->setColor(255,255,255);
 					Image * img = m_font->getAsImage(ss.str());
 					r.x = drawpt.x;
 					r.y = drawpt.y;
@@ -117,8 +130,17 @@
 					r.h = img->getHeight();
 					img->render(r);
 				}
-
 			}
 		}
+		if(m_font_color) {
+			m_font->setColor(old_color.r, old_color.g, old_color.b);
+			m_font_color = false;
+		}
+	}
+
+	void CoordinateRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) {
+		m_color.r = r;
+		m_color.g = g;
+		m_color.b = b;
 	}
 }
--- a/engine/core/view/renderers/coordinaterenderer.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/coordinaterenderer.h	Sat Jul 31 17:46:19 2010 +0000
@@ -56,8 +56,10 @@
 		virtual ~CoordinateRenderer();
 
 		void render(Camera* cam, Layer* layer, RenderList& instances);
+		std::string getName() { return "CoordinateRenderer"; }
+		void setColor(Uint8 r, Uint8 g, Uint8 b);
 
-		std::string getName() { return "CoordinateRenderer"; }
+		static CoordinateRenderer* getInstance(IRendererContainer* cnt);
 
 	private:
 		void adjustLayerArea();
@@ -66,6 +68,8 @@
 		Location m_tmploc;
 		ExactModelCoordinate m_c;
 		AbstractFont* m_font;
+		bool m_font_color;
+		SDL_Color m_color;
 	};
 }
 
--- a/engine/core/view/renderers/floatingtextrenderer.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/floatingtextrenderer.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -48,13 +48,17 @@
 	FloatingTextRenderer::FloatingTextRenderer(RenderBackend* renderbackend, int position, AbstractFont* font):
 		RendererBase(renderbackend, position),
 		m_font(font) {
-		setEnabled(true);
+		setEnabled(false);
+		m_font_color = false;
+		m_color = m_font->getColor();
 	}
 
  	FloatingTextRenderer::FloatingTextRenderer(const FloatingTextRenderer& old):
 		RendererBase(old),
-		m_font(old.m_font) {
-		setEnabled(true);
+		m_font(old.m_font),
+		m_font_color(old.m_font_color),
+		m_color(old.m_color) {
+		setEnabled(false);
 	}
 
 	RendererBase* FloatingTextRenderer::clone() {
@@ -71,7 +75,11 @@
 
 		RenderList::const_iterator instance_it = instances.begin();
 		const std::string* saytext = NULL;
-
+		SDL_Color old_color = m_font->getColor();
+		if(old_color.r != m_color.r || old_color.g != m_color.g || old_color.b != m_color.b) {
+			m_font->setColor(m_color.r, m_color.g, m_color.b);
+			m_font_color = true;
+		}
 		for (;instance_it != instances.end(); ++instance_it) {
 			Instance* instance = (*instance_it)->instance;
 			saytext = instance->getSayText();
@@ -86,6 +94,16 @@
 				img->render(r);
 			}
 		}
+		if(m_font_color) {
+			m_font->setColor(old_color.r, old_color.g, old_color.b);
+			m_font_color = false;
+		}
+	}
+
+	void FloatingTextRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) {
+		m_color.r = r;
+		m_color.g = g;
+		m_color.b = b;
 	}
 
 	FloatingTextRenderer* FloatingTextRenderer::getInstance(IRendererContainer* cnt) {
--- a/engine/core/view/renderers/floatingtextrenderer.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/floatingtextrenderer.h	Sat Jul 31 17:46:19 2010 +0000
@@ -62,12 +62,15 @@
 		 */
 		void changeDefaultFont(AbstractFont* font) { m_font = font; }
 		
+		void setColor(Uint8 r, Uint8 g, Uint8 b);
 		/** returns instance used in given view
 		 */
 		static FloatingTextRenderer* getInstance(IRendererContainer* cnt);
 
 	private:
 		AbstractFont* m_font;
+		bool m_font_color;
+		SDL_Color m_color;
 	};
 
 }
--- a/engine/core/view/renderers/floatingtextrenderer.i	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/floatingtextrenderer.i	Sat Jul 31 17:46:19 2010 +0000
@@ -32,6 +32,8 @@
 	public:
 		virtual ~FloatingTextRenderer();
 		void changeDefaultFont(AbstractFont* font);
+		void setColor(Uint8 r, Uint8 g, Uint8 b);
+
 		static FloatingTextRenderer* getInstance(IRendererContainer* cnt);
 
 	private:
--- a/engine/core/view/renderers/genericrenderer.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/genericrenderer.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -223,10 +223,8 @@
 			p = cam->toScreenCoordinates(m_location->getMapCoordinates());
 		} else if(m_layer == NULL) {
 			const std::list<Layer*>& layers = cam->getRenderer("GenericRenderer")->getActiveLayers();
-			std::list<Layer*>::const_iterator layer_it = layers.begin();
-			for (; layer_it != layers.end(); ++layer_it) {
-				setAttached(*layer_it);
-			}
+			std::list<Layer*>::const_reverse_iterator layer_it = layers.rbegin();
+			setAttached(*layer_it);
 		}
 		return Point(m_point.x + p.x, m_point.y + p.y);
 	}
@@ -306,11 +304,13 @@
 		if(m_anchor.getLayer() == layer) {
 			Image* img = &imagepool->getImage(m_image);
 			Rect r;
+			Rect viewport = cam->getViewPort();
 			r.x = p.x-img->getWidth()/2;
 			r.y = p.y-img->getHeight()/2;
 			r.w = img->getWidth();
 			r.h = img->getHeight();
-			img->render(r);
+			if(r.intersects(viewport))
+				img->render(r);
 		}
 	}
 
@@ -328,11 +328,13 @@
 			int animtime = scaleTime(m_time_scale, TimeManager::instance()->getTime() - m_start_time) % animation.getDuration();
 			Image* img = animation.getFrameByTimestamp(animtime);
 			Rect r;
+			Rect viewport = cam->getViewPort();
 			r.x = p.x-img->getWidth()/2;
 			r.y = p.y-img->getHeight()/2;
 			r.w = img->getWidth();
 			r.h = img->getHeight();
-			img->render(r);
+			if(r.intersects(viewport))
+				img->render(r);
 		}
 	}
 
@@ -347,11 +349,13 @@
 		if(m_anchor.getLayer() == layer) {
 			Image* img = m_font->getAsImageMultiline(m_text);
 			Rect r;
+			Rect viewport = cam->getViewPort();
 			r.x = p.x-img->getWidth()/2;
 			r.y = p.y-img->getHeight()/2;
 			r.w = img->getWidth();
 			r.h = img->getHeight();
-			img->render(r);
+			if(r.intersects(viewport))
+				img->render(r);
 		}
 	}
 
--- a/engine/core/view/renderers/gridrenderer.cpp	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/gridrenderer.cpp	Sat Jul 31 17:46:19 2010 +0000
@@ -45,10 +45,14 @@
 	GridRenderer::GridRenderer(RenderBackend* renderbackend, int position):
 		RendererBase(renderbackend, position) {
 		setEnabled(false);
+		m_color.r = 0;
+		m_color.g = 255;
+		m_color.b = 0;
 	}
 
  	GridRenderer::GridRenderer(const GridRenderer& old):
-		RendererBase(old) {
+		RendererBase(old),
+		m_color(old.m_color) {
 		setEnabled(false);
 	}
 
@@ -59,6 +63,10 @@
 	GridRenderer::~GridRenderer() {
 	}
 
+	GridRenderer* GridRenderer::getInstance(IRendererContainer* cnt) {
+		return dynamic_cast<GridRenderer*>(cnt->getRenderer("GridRenderer"));
+	}
+
 	void GridRenderer::render(Camera* cam, Layer* layer, RenderList& instances) {
 		CellGrid* cg = layer->getCellGrid();
 		if (!cg) {
@@ -73,67 +81,70 @@
 //		//1,-1,1
 //		//-1,-1,1
 //		//-1,1,1
-		Point a,b,c,d;
-
-
-		ScreenPoint copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) );
-		ScreenPoint copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) );
-		Point coptt1(copt1.x,copt1.y);
-		Point coptt2(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
-		a = coptt1;
-
-		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) );
-		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) );
-		coptt1 = Point(copt1.x,copt1.y);
-		coptt2 = Point(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
-		b = coptt1;
-
-		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) );
-		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) );
-		coptt1 = Point(copt1.x,copt1.y);
-		coptt2 = Point(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
-		c = coptt1;
-
-		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) );
-		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) );
-		coptt1 = Point(copt1.x,copt1.y);
-		coptt2 = Point(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 20);
-		d = coptt1;
-
-		m_renderbackend->drawQuad(a,b,c,d,15, 15, 200);
+		//We don't need the elevation box atm
+//		Point a,b,c,d;
+//
+//
+//		ScreenPoint copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) );
+//		ScreenPoint copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) );
+//		Point coptt1(copt1.x,copt1.y);
+//		Point coptt2(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
+//		a = coptt1;
+//
+//		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) );
+//		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) );
+//		coptt1 = Point(copt1.x,copt1.y);
+//		coptt2 = Point(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
+//		b = coptt1;
+//
+//		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) );
+//		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) );
+//		coptt1 = Point(copt1.x,copt1.y);
+//		coptt2 = Point(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200);
+//		c = coptt1;
+//
+//		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) );
+//		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) );
+//		coptt1 = Point(copt1.x,copt1.y);
+//		coptt2 = Point(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 20);
+//		d = coptt1;
+//
+//		m_renderbackend->drawQuad(a,b,c,d,15, 15, 200);
 //
 //
 //		//draw back quad
-		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) );
-		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) );
-		coptt1 = Point(copt1.x,copt1.y);
-		coptt2 = Point(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
-
-		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) );
-		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) );
-		coptt1 = Point(copt1.x,copt1.y);
-		coptt2 = Point(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
-
-		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) );
-		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) );
-		coptt1 = Point(copt1.x,copt1.y);
-		coptt2 = Point(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
-
-		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) );
-		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) );
-		coptt1 = Point(copt1.x,copt1.y);
-		coptt2 = Point(copt2.x,copt2.y);
-		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
+//		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) );
+//		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) );
+//		coptt1 = Point(copt1.x,copt1.y);
+//		coptt2 = Point(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
+//
+//		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) );
+//		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) );
+//		coptt1 = Point(copt1.x,copt1.y);
+//		coptt2 = Point(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
+//
+//		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) );
+//		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) );
+//		coptt1 = Point(copt1.x,copt1.y);
+//		coptt2 = Point(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
+//
+//		copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) );
+//		copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) );
+//		coptt1 = Point(copt1.x,copt1.y);
+//		coptt2 = Point(copt2.x,copt2.y);
+//		m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200);
 
 
 		Rect cv = cam->getViewPort();
+		int cvx2 = cv.x+cv.w;
+		int cvy2 = cv.y+cv.h;
 		RenderList::const_iterator instance_it = instances.begin();
 		for (;instance_it != instances.end(); ++instance_it) {
 			Instance* instance = (*instance_it)->instance;
@@ -146,22 +157,10 @@
 			++it;
 			for (; it != vertices.end(); it++) {
 				ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it));
-				pt2.x = pts.x; pt2.y = pts.y;
+				pt2.x = pts.x;
+				pt2.y = pts.y;
 				Point cpt1 = pt1;
 				Point cpt2 = pt2;
-				/* FIXME: limit grid drawing to current camera view port
-				   code below does not do it, but may act as a starting point
-
-				int cvx2 = cv.x+cv.w;
-				int cvy2 = cv.y+cv.h;
-
-				if (((pt1.x < cv.x) && (pt2.x < cv.x)) ||
-				    ((pt1.x > cvx2) && (pt2.x > cvx2)) ||
-				    ((pt1.y < cv.y) && (pt2.y < cv.y)) ||
-				    ((pt1.y > cvy2) && (pt2.y > cvy2))) {
-				    pt1 = pt2;
-				    continue;
-				}
 
 				if (cpt1.x < cv.x) cpt1.x = cv.x;
 				if (cpt2.x < cv.x) cpt2.x = cv.x;
@@ -171,11 +170,21 @@
 				if (cpt2.x > cvx2) cpt2.x = cvx2;
 				if (cpt1.y > cvy2) cpt1.y = cvy2;
 				if (cpt2.y > cvy2) cpt2.y = cvy2;
-				*/
-				m_renderbackend->drawLine(cpt1, cpt2, 0, 255, 0);
+				
+				m_renderbackend->drawLine(cpt1, cpt2, m_color.r, m_color.g, m_color.b);
 				pt1 = pt2;
 			}
-			m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 0, 255, 0);
+			if ((pt2.x >= cv.x) && (pt2.x <= cvx2) && (pt2.y >= cv.y) && (pt2.y <= cvy2)) {
+				if ((firstpt.x >= cv.x) && (firstpt.x <= cvx2) && (firstpt.y >= cv.y) && (firstpt.y <= cvy2)) {
+					m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), m_color.r, m_color.g, m_color.b);
+				}
+			}
 		}
 	}
+
+	void GridRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) {
+		m_color.r = r;
+		m_color.g = g;
+		m_color.b = b;
+	}
 }
--- a/engine/core/view/renderers/gridrenderer.h	Fri Jul 30 23:48:26 2010 +0000
+++ b/engine/core/view/renderers/gridrenderer.h	Sat Jul 31 17:46:19 2010 +0000
@@ -51,12 +51,14 @@
 		virtual ~GridRenderer();
 
 		void render(Camera* cam, Layer* layer, RenderList& instances);
+		std::string getName() { return "GridRenderer"; }
+		void setColor(Uint8 r, Uint8 g, Uint8 b);
 
-		std::string getName() { return "GridRenderer"; }
+		static GridRenderer* getInstance(IRendererContainer* cnt);
 
 	private:
+		SDL_Color m_color;
 	};
-
 }
 
 #endif
--- a/tools/editor/lang/infotext.txt	Fri Jul 30 23:48:26 2010 +0000
+++ b/tools/editor/lang/infotext.txt	Sat Jul 31 17:46:19 2010 +0000
@@ -75,6 +75,7 @@
         selection (toggle).
 - T   = shows / hides grid
 - B   = shows / hides blocking info
+- C   = shows / hides coordinates
 
 
 http://www.fifengine.de
--- a/tools/editor/scripts/editor.py	Fri Jul 30 23:48:26 2010 +0000
+++ b/tools/editor/scripts/editor.py	Sat Jul 31 17:46:19 2010 +0000
@@ -189,6 +189,21 @@
 		test_action1.helptext = u"Cycles button styles. There are currently four button styles."
 		action.activated.connect(self._actionActivated, sender=test_action1)
 		self._view_menu.addAction(test_action1)
+
+		test_action2 = Action(u"Toggle Blocking")
+		test_action2.helptext = u"Toggles the blocking infos for the instances."
+		action.activated.connect(self.toggleBlocking, sender=test_action2)
+		self._view_menu.addAction(test_action2)
+
+		test_action3 = Action(u"Toggle Grid")
+		test_action3.helptext = u"Toggles the grids of the map."
+		action.activated.connect(self.toggleGrid, sender=test_action3)
+		self._view_menu.addAction(test_action3)
+
+		test_action4 = Action(u"Toggle Coordinates")
+		test_action4.helptext = u"Toggles the coordinates of the map."
+		action.activated.connect(self.toggleCoordinates, sender=test_action4)
+		self._view_menu.addAction(test_action4)		
 		
 		self._mapgroup = ActionGroup(exclusive=True, name="Mapgroup")
 		self._mapbar.addAction(self._mapgroup)
@@ -267,7 +282,34 @@
 			toolbox.y = ty
 			self._action_show_toolbox.setChecked(True)
 		toolbox.adaptLayout()
-			
+
+	def toggleBlocking(self, sender):
+		if self._mapview != None:
+			for cam in self._mapview.getMap().getCameras():			
+				r = fife.BlockingInfoRenderer.getInstance(cam)
+				r.setEnabled(not r.isEnabled())
+
+	def toggleGrid(self, sender):
+		if self._mapview != None:
+			for cam in self._mapview.getMap().getCameras():			
+				r = fife.GridRenderer.getInstance(cam)
+				r.setEnabled(not r.isEnabled())
+
+	def toggleCoordinates(self, sender):
+		if self._mapview != None:
+			for cam in self._mapview.getMap().getCameras():
+				r = fife.CoordinateRenderer.getInstance(cam)
+				if not r.isEnabled():
+					r.clearActiveLayers()
+					color = str(self._settings.get("Colors", "Coordinate", "255,255,255"))
+					r.setColor(*[int(c) for c in color.split(',')])
+					for layer in self._mapview.getMap().getLayers():
+						if layer.areInstancesVisible():
+							r.addActiveLayer(layer)
+					r.setEnabled(True)
+				else:
+					r.setEnabled(False)
+
 	def getToolbox(self): 
 		return self._toolbox
 	
--- a/tools/editor/scripts/gui/mapeditor.py	Fri Jul 30 23:48:26 2010 +0000
+++ b/tools/editor/scripts/gui/mapeditor.py	Sat Jul 31 17:46:19 2010 +0000
@@ -594,6 +594,11 @@
 			blockrenderer = self._controller._camera.getRenderer('BlockingInfoRenderer')
 			blockrenderer.setEnabled(not blockrenderer.isEnabled())
 
+		elif keystr == 'c':
+			#coordinaterenderer = self._controller._camera.getRenderer('CoordinateRenderer')
+			#coordinaterenderer.setEnabled(not coordinaterenderer.isEnabled())
+			self._editor.toggleCoordinates("Toggle Coordinates")
+			
 		elif keystr == 'z':
 			if self._eventlistener.controlPressed:
 				if self._eventlistener.altPressed:
--- a/tools/editor/scripts/mapcontroller.py	Fri Jul 30 23:48:26 2010 +0000
+++ b/tools/editor/scripts/mapcontroller.py	Sat Jul 31 17:46:19 2010 +0000
@@ -32,6 +32,9 @@
 import undomanager
 
 from fife.extensions.pychan.tools import callbackWithArguments as cbwa
+from fife.extensions.fife_settings import Setting
+
+TDS = Setting(app_name="editor")
 
 class MapController(object):
 	""" MapController provides an interface for editing maps """
@@ -51,6 +54,7 @@
 		undomanager.postUndo.connect(self._endUndo, sender=self._undomanager)
 		undomanager.postRedo.connect(self._endUndo, sender=self._undomanager)
 		self.debug = False
+		self._settings = TDS
 		
 		self.overwriteInstances = True # Remove instances on cell before placing new instance
 		
@@ -89,14 +93,25 @@
 
 		self._layer = self._map.getLayers()[0]
 		
-		gridrenderer = self._camera.getRenderer('GridRenderer')
+		gridrenderer = fife.GridRenderer.getInstance(self._camera)
 		gridrenderer.activateAllLayers(self._map)
+		color = str(self._settings.get("Colors", "Grid", "0,255,0"))
+		gridrenderer.setColor(*[int(c) for c in color.split(',')])
+
+		blockrenderer = fife.BlockingInfoRenderer.getInstance(self._camera)
+		blockrenderer.activateAllLayers(self._map)
+		color = str(self._settings.get("Colors", "Blocking", "0,255,0"))
+		blockrenderer.setColor(*[int(c) for c in color.split(',')])
 
-		blockrenderer = self._camera.getRenderer('BlockingInfoRenderer')
-		blockrenderer.activateAllLayers(self._map)
+		coordinaterenderer = fife.CoordinateRenderer.getInstance(self._camera)
+		coordinaterenderer.activateAllLayers(self._map)
+		color = str(self._settings.get("Colors", "Coordinate", "255,255,255"))
+		coordinaterenderer.setColor(*[int(c) for c in color.split(',')])		
 
-		cellrenderer = self._camera.getRenderer('CellSelectionRenderer')
+		cellrenderer = fife.CellSelectionRenderer.getInstance(self._camera)
 		cellrenderer.activateAllLayers(self._map)
+		color = str(self._settings.get("Colors", "CellSelection", "255,0,0"))
+		cellrenderer.setEnabled(True)
 
 	def getMap(self):
 		return self._map
--- a/tools/editor/settings-dist.xml	Fri Jul 30 23:48:26 2010 +0000
+++ b/tools/editor/settings-dist.xml	Sat Jul 31 17:46:19 2010 +0000
@@ -25,4 +25,10 @@
 		<Setting name="ObjectEdit" type="bool">True</Setting>
 		<Setting name="ObjectSelector" type="bool">True</Setting>
 	</Module>
+  <Module name="Colors">
+    <Setting name="Blocking" type="str">0,255,0</Setting>
+    <Setting name="Grid" type="str">0,255,0</Setting>
+    <Setting name="Coordinate" type="str">255,255,255</Setting>
+    <Setting name="CellSelection" type="str">255,0,0</Setting>
+  </Module>
 </Settings>