From 3b37b4e4c25065a2dd53a1fb91ce4f46907dd3fb Mon Sep 17 00:00:00 2001
From: Krisjanis Rijnieks <krisjanis.rijnieks@gmail.com>
Date: Tue, 25 Oct 2016 17:39:39 +0300
Subject: [PATCH] Improve SurfaceHighlightWidget

Add drawing other surface outlines as sometimes parts of them overlap with the background
and it is not possible to see where are the other surfaces.
---
 src/Gui/Widgets/SurfaceHighlightWidget.cpp | 45 ++++++++++++++++------
 src/Gui/Widgets/SurfaceHighlightWidget.h   |  2 +
 2 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/src/Gui/Widgets/SurfaceHighlightWidget.cpp b/src/Gui/Widgets/SurfaceHighlightWidget.cpp
index beddbb4..ccaec16 100644
--- a/src/Gui/Widgets/SurfaceHighlightWidget.cpp
+++ b/src/Gui/Widgets/SurfaceHighlightWidget.cpp
@@ -12,6 +12,8 @@ void SurfaceHighlightWidget::draw(){
 		return;
 	}
 	
+	drawAllSurfaceOutlines();
+	
 	if(_sm->getSelectedSurface() == 0){
 		return;
 	}
@@ -20,28 +22,49 @@ void SurfaceHighlightWidget::draw(){
 	ofSetLineWidth(2);
 	ofSetColor(255);
 	
-	if(_sm->getSelectedSurface()->getType() == SurfaceType::QUAD_SURFACE &&
-		((QuadSurface *)_sm->getSelectedSurface())->getPerspectiveWarping()){
-		ofPolyline line = _sm->getSelectedSurface()->getHitArea();
+	drawSurfaceOutlines(_sm->getSelectedSurface());
+	
+	ofPopStyle();
+}
+
+void SurfaceHighlightWidget::drawAllSurfaceOutlines(){
+	if(_sm == 0){
+		return;
+	}
+	
+	ofPushStyle();
+	ofSetColor(255, 255, 255, 150);
+	ofSetLineWidth(2);
+	for(unsigned int i = 0; i < _sm->size(); ++i){
+		if(_sm->getSurface(i) != _sm->getSelectedSurface()){
+			drawSurfaceOutlines(_sm->getSurface(i));
+		}
+	}
+	ofPopStyle();
+}
+
+void SurfaceHighlightWidget::drawSurfaceOutlines(BaseSurface * s){
+	// TODO: Use Surface::drawOutline here
+	if(s->getType() == SurfaceType::QUAD_SURFACE &&
+		((QuadSurface *)s)->getPerspectiveWarping()){
+		ofPolyline line = s->getHitArea();
 		line.draw();
-	}else if(_sm->getSelectedSurface()->getType() == SurfaceType::GRID_WARP_SURFACE){
-		_sm->getSelectedSurface()->getMesh().drawWireframe();
-	}else if(_sm->getSelectedSurface()->getType() == SurfaceType::HEXAGON_SURFACE){
-		_sm->getSelectedSurface()->getMesh().drawWireframe();
+	}else if(s->getType() == SurfaceType::GRID_WARP_SURFACE){
+		s->getMesh().drawWireframe();
+	}else if(s->getType() == SurfaceType::HEXAGON_SURFACE){
+		s->getMesh().drawWireframe();
 	}else{
 		ofPolyline p;
 		for(unsigned int i = 0;
-			i < _sm->getSelectedSurface()->getMesh().getVertices().size();
+			i < s->getMesh().getVertices().size();
 			++i){
 			
 			p.addVertex(ofPoint(
-				_sm->getSelectedSurface()->getMesh().getVertices()[i]));
+				s->getMesh().getVertices()[i]));
 		}
 		p.close();
 		p.draw();
 	}
-	
-	ofPopStyle();
 }
 
 } // namespace piMapper
diff --git a/src/Gui/Widgets/SurfaceHighlightWidget.h b/src/Gui/Widgets/SurfaceHighlightWidget.h
index 4eb7032..00c8c6b 100644
--- a/src/Gui/Widgets/SurfaceHighlightWidget.h
+++ b/src/Gui/Widgets/SurfaceHighlightWidget.h
@@ -21,6 +21,8 @@ class SurfaceHighlightWidget : public GuiBaseWidget {
 		bool inside(float x, float y){ return false; }
 	
 		void setSurfaceManager(SurfaceManager * sm){ _sm = sm; }
+		void drawAllSurfaceOutlines();
+		void drawSurfaceOutlines(BaseSurface * s);
 	
 	private:
 		SurfaceManager * _sm;