Added wireframe mode

Mon, 13 May 2013 00:04:54 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 13 May 2013 00:04:54 +0300
changeset 193
ce8e25ccbaf6
parent 192
c414924a647c
child 194
cfe9ae5f1124

Added wireframe mode

src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/gui_actions.cpp file | annotate | diff | comparison | revisions
--- a/src/gldraw.cpp	Sun May 12 20:21:44 2013 +0300
+++ b/src/gldraw.cpp	Mon May 13 00:04:54 2013 +0300
@@ -52,6 +52,7 @@
 cfg (int, gl_camera, GLRenderer::Free);
 cfg (bool, gl_blackedges, true);
 cfg (bool, gl_axes, false);
+cfg (bool, gl_wireframe, false);
 
 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets
 // initialized before program gets to main() and constructs a QApplication
@@ -316,6 +317,9 @@
 	if (g_curfile == null)
 		return;
 	
+	if (gl_wireframe && !picking ())
+		glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+	
 	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	glEnable (GL_DEPTH_TEST);
 	
@@ -376,6 +380,7 @@
 	
 	glPopMatrix ();
 	glMatrixMode (GL_MODELVIEW);
+	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
 }
 
 // =============================================================================
--- a/src/gldraw.h	Sun May 12 20:21:44 2013 +0300
+++ b/src/gldraw.h	Mon May 13 00:04:54 2013 +0300
@@ -57,13 +57,15 @@
 	void	endPlaneDraw		(bool accept);
 	QColor	getMainColor		();
 	void	hardRefresh		();
-	bool	picking				() { return m_picking; }
+	bool	picking				() const { return m_picking; }
 	void	refresh			();
 	void	resetAngles		();
 	uchar*	screencap			(ushort& w, ushort& h);
 	void	setBackground		();
 	void	setCamera			(const GLRenderer::Camera cam);
 	void	setZoom				(const double zoom) { m_zoom = zoom; }
+	void	setWireframe		(const bool set);
+	bool	wireframe			() const;
 	double	zoom				() const { return m_zoom; }
 
 protected:
--- a/src/gui.cpp	Sun May 12 20:21:44 2013 +0300
+++ b/src/gui.cpp	Mon May 13 00:04:54 2013 +0300
@@ -48,6 +48,7 @@
 extern_cfg (bool, gl_axes);
 extern_cfg (str, gl_maincolor);
 extern_cfg (float, gl_maincolor_alpha);
+extern_cfg (bool, gl_wireframe);
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -103,7 +104,7 @@
 		connect (qAct, SIGNAL (triggered ()), this, SLOT (slot_action ()));
 	}
 	
-	// Grid actions and axes are checkable
+	// Make certain actions checkable
 	findAction ("gridCoarse")->setCheckable (true);
 	findAction ("gridMedium")->setCheckable (true);
 	findAction ("gridFine")->setCheckable (true);
@@ -111,6 +112,9 @@
 	findAction ("axes")->setCheckable (true);
 	findAction ("axes")->setChecked (gl_axes);
 	
+	findAction ("wireframe")->setCheckable (true);
+	findAction ("wireframe")->setChecked (gl_wireframe);
+	
 	// things not implemented yet
 	findAction ("help")->setEnabled (false);
 	
@@ -156,6 +160,7 @@
 	initMenu ("&View");
 	addMenuAction ("resetView");			// Reset View
 	addMenuAction ("axes");				// Draw Axes
+	addMenuAction ("wireframe");			// Wireframe
 	menu->addSeparator ();					// -----
 	addMenuAction ("screencap");			// Screencap Part
 	addMenuAction ("showHistory");		// Edit History
@@ -344,7 +349,6 @@
 	addToolBarAction ("rotateZNeg");
 	
 	// ==========================================
-	// Grid toolbar
 	initSingleToolBar ("Grids");
 	addToolBarAction ("gridCoarse");
 	addToolBarAction ("gridMedium");
@@ -354,6 +358,7 @@
 	// ==========================================
 	initSingleToolBar ("View");
 	addToolBarAction ("axes");
+	addToolBarAction ("wireframe");
 	
 	// ==========================================
 	// Color toolbar
@@ -548,6 +553,7 @@
 	
 	for (LDObject* obj : g_curfile->m_objs) {
 		str descr;
+		
 		switch (obj->getType ()) {
 		case LDObject::Comment:
 			descr = static_cast<LDComment*> (obj)->text.chars();
@@ -561,43 +567,14 @@
 			break; // leave it empty
 		
 		case LDObject::Line:
-			{
-				LDLine* line = static_cast<LDLine*> (obj);
-				descr.format ("%s, %s",
-					line->coords[0].stringRep (true).chars(),
-					line->coords[1].stringRep (true).chars());
-			}
-			break;
-		
 		case LDObject::Triangle:
-			{
-				LDTriangle* triangle = static_cast<LDTriangle*> (obj);
-				descr.format ("%s, %s, %s",
-					triangle->coords[0].stringRep (true).chars(),
-					triangle->coords[1].stringRep (true).chars(),
-					triangle->coords[2].stringRep (true).chars());
-			}
-			break;
-		
 		case LDObject::Quad:
-			{
-				LDQuad* quad = static_cast<LDQuad*> (obj);
-				descr.format ("%s, %s, %s, %s",
-					quad->coords[0].stringRep (true).chars(),
-					quad->coords[1].stringRep (true).chars(),
-					quad->coords[2].stringRep (true).chars(),
-					quad->coords[3].stringRep (true).chars());
-			}
-			break;
-		
 		case LDObject::CondLine:
-			{
-				LDCondLine* line = static_cast<LDCondLine*> (obj);
-				descr.format ("%s, %s, %s, %s",
-					line->coords[0].stringRep (true).chars(),
-					line->coords[1].stringRep (true).chars(),
-					line->coords[2].stringRep (true).chars(),
-					line->coords[3].stringRep (true).chars());
+			for (short i = 0; i < obj->vertices (); ++i) {
+				if (i != 0)
+					descr += ", ";
+				
+				descr += obj->coords[i].stringRep (true).chars();
 			}
 			break;
 		
@@ -627,11 +604,8 @@
 			break;
 		
 		case LDObject::BFC:
-			{
-				LDBFC* bfc = static_cast<LDBFC*> (obj);
-				descr = LDBFC::statements[bfc->type];
-			}
-			break;
+			descr = LDBFC::statements[static_cast<LDBFC*> (obj)->type];
+		break;
 		
 		case LDObject::Radial:
 			{
--- a/src/gui_actions.cpp	Sun May 12 20:21:44 2013 +0300
+++ b/src/gui_actions.cpp	Mon May 13 00:04:54 2013 +0300
@@ -28,6 +28,8 @@
 #include "misc.h"
 #include "ldrawPathDialog.h"
 
+extern_cfg (bool, gl_wireframe);
+
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
@@ -359,9 +361,7 @@
 	}
 }
 
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
+// =========================================================================================================================================
 MAKE_ACTION (screencap, "Screencap Part", "screencap", "Save a picture of the model", (0)) {
 	setlocale (LC_ALL, "C");
 	
@@ -385,9 +385,7 @@
 	delete[] imagedata;
 }
 
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
+// =========================================================================================================================================
 extern_cfg (bool, gl_axes);
 MAKE_ACTION (axes, "Draw Axes", "axes", "Toggles drawing of axes", (0)) {
 	gl_axes = !gl_axes;
@@ -395,7 +393,7 @@
 	g_win->R ()->update ();
 }
 
-// =============================================================================
+// =========================================================================================================================================
 MAKE_ACTION (beginDraw, "Begin Drawing", "draw", "Begin drawing geometry", KEY (Insert)) {
 	g_win->R ()->beginPlaneDraw ();
 }
@@ -408,12 +406,16 @@
 	g_win->R ()->endPlaneDraw (true);
 }
 
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
+// =========================================================================================================================================
 MAKE_ACTION (visibility, "Toggle Visibility", "visibility", "Toggles visibility/hiding on objects.", (0)) {
 	for (LDObject* obj : g_win->sel ())
 		obj->setHidden (!obj->hidden ());
 	
 	g_win->fullRefresh ();
+}
+
+// =========================================================================================================================================
+MAKE_ACTION (wireframe, "Toggle Wireframe", "wireframe", "Toggle wireframe view", (0)) {
+	gl_wireframe = !gl_wireframe;
+	g_win->R ()->refresh ();
 }
\ No newline at end of file

mercurial