More selection work - selecting from GUI updates the GL renderer now

Mon, 15 Apr 2013 04:00:10 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 15 Apr 2013 04:00:10 +0300
changeset 108
351aef26f444
parent 107
195aa036da7f
child 109
f40b35142586

More selection work - selecting from GUI updates the GL renderer now

gldraw.cpp file | annotate | diff | comparison | revisions
gldraw.h file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
main.cpp file | annotate | diff | comparison | revisions
--- a/gldraw.cpp	Mon Apr 15 02:56:42 2013 +0300
+++ b/gldraw.cpp	Mon Apr 15 04:00:10 2013 +0300
@@ -29,7 +29,6 @@
 
 static double g_faObjectOffset[3];
 static double g_StoredBBoxSize;
-static bool g_bPicking = false;
 
 static short g_dPulseTick = 0;
 static const short g_dNumPulseTicks = 8;
@@ -49,6 +48,7 @@
 	parent = parent; // shhh, GCC
 	fRotX = fRotY = fRotZ = 0.0f;
 	fZoom = 1.0f;
+	bPicking = false;
 	
 	qPulseTimer = new QTimer (this);
 	connect (qPulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ()));
@@ -116,7 +116,7 @@
 void GLRenderer::setObjectColor (LDObject* obj) {
 	QColor qCol;
 	
-	if (g_bPicking) {
+	if (bPicking) {
 		// Make the color by the object's index color if we're picking, so we can
 		// make the index from the color we get from the picking results.
 		long i = obj->getIndex (g_CurrentFile);
@@ -202,7 +202,7 @@
 		g = min (g + lAdd, 255l);
 		b = min (b + lAdd, 255l);
 		
-		a = 255;
+		// a = 255;
 	}
 	
 	glColor4f (
@@ -215,10 +215,15 @@
 // ========================================================================= //
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
+void GLRenderer::refresh () {
+	paintGL ();
+	swapBuffers ();
+}
+
+// ========================================================================= //
 void GLRenderer::hardRefresh () {
 	compileObjects ();
-	paintGL ();
-	swapBuffers ();
+	refresh ();
 	
 	glLineWidth (gl_linethickness);
 }
@@ -254,7 +259,7 @@
 		glRotatef (fRotZ, 0.0f, 0.0f, 1.0f);
 		
 		for (LDObject* obj : g_CurrentFile->objects)
-			glCallList ((g_bPicking == false) ? obj->uGLList : obj->uGLPickList);
+			glCallList ((bPicking == false) ? obj->uGLList : obj->uGLPickList);
 	glPopMatrix ();
 }
 
@@ -284,9 +289,9 @@
 			GLuint uList = glGenLists (1);
 			glNewList (uList, GL_COMPILE);
 			
-			g_bPicking = (upMemberList == &obj->uGLPickList);
+			bPicking = (upMemberList == &obj->uGLPickList);
 			compileOneObject (obj);
-			g_bPicking = false;
+			bPicking = false;
 			
 			glEndList ();
 			*upMemberList = uList;
@@ -475,6 +480,20 @@
 // ========================================================================= //
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
+void GLRenderer::updateSelFlash () {
+	if (gl_selflash && g_ForgeWindow->paSelection.size() > 0) {
+		qPulseTimer->start (g_dPulseInterval);
+		g_dPulseTick = 0;
+	} else {
+		printf ("stop pulse timer\n");
+		qPulseTimer->stop ();
+		printf ("done\n");
+	}
+}
+
+// ========================================================================= //
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// ========================================================================= //
 void GLRenderer::pick (uint uMouseX, uint uMouseY, bool bAdd) {
 	if (bAdd == false) {
 		// Clear the selection if we don't wish to add to it.
@@ -489,7 +508,7 @@
 	glDisable (GL_DITHER);
 	glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
 	
-	g_bPicking = true;
+	bPicking = true;
 	
 	paintGL ();
 	
@@ -509,20 +528,13 @@
 		g_ForgeWindow->paSelection.push_back (obj);
 	}
 	
-	if (gl_selflash) {
-		if (bHasSelection) {
-			qPulseTimer->start (g_dPulseInterval);
-			g_dPulseTick = 0;
-		} else
-			qPulseTimer->stop ();
-	}
+	g_ForgeWindow->updateSelection ();
 	
-	g_bPicking = false;
+	bPicking = false;
 	glEnable (GL_DITHER);
 	
-	g_ForgeWindow->updateSelection ();
-	
 	setBackground ();
+	updateSelFlash ();
 	
 	for (LDObject* obj : g_ForgeWindow->getSelectedObjects ())
 		recompileObject (obj);
--- a/gldraw.h	Mon Apr 15 02:56:42 2013 +0300
+++ b/gldraw.h	Mon Apr 15 04:00:10 2013 +0300
@@ -41,10 +41,14 @@
 	void setBackground ();
 	void pick (uint uMouseX, uint uMouseY, bool bAdd);
 	QColor getMainColor ();
+	void recompileObject (LDObject* obj);
+	void refresh ();
+	void updateSelFlash();
 	
 	double fRotX, fRotY, fRotZ;
 	QPoint lastPos;
 	double fZoom;
+	bool bPicking;
 
 protected:
 	void initializeGL ();
@@ -65,7 +69,6 @@
 	void compileVertex (vertex& vrt);
 	void clampAngle (double& fAngle);
 	void setObjectColor (LDObject* obj);
-	void recompileObject (LDObject* obj);
 	
 	QTimer* qPulseTimer;
 	
--- a/gui.cpp	Mon Apr 15 02:56:42 2013 +0300
+++ b/gui.cpp	Mon Apr 15 04:00:10 2013 +0300
@@ -83,6 +83,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
 ForgeWindow::ForgeWindow () {
+	g_ForgeWindow = this;
 	R = new GLRenderer;
 	
 	qObjList = new QTreeWidget;
@@ -578,6 +579,23 @@
 	// If we have no selection, disable splitting quads
 	ACTION (splitQuads)->setEnabled (qObjList->selectedItems().size() > 0);
 	*/
+	
+	// Update the shared selection array, unless this was called during GL picking,
+	// in which case the GL renderer takes care of the selection.
+	if (R->bPicking == false) {
+		std::vector<LDObject*> paPriorSelection = paSelection;
+		paSelection = getSelectedObjects ();
+		
+		// Update the GL renderer
+		for (LDObject* obj : paSelection)
+			R->recompileObject (obj);
+		
+		for (LDObject* obj : paPriorSelection)
+			R->recompileObject (obj);
+		
+		R->updateSelFlash ();
+		R->refresh ();
+	}
 }
 
 // ========================================================================= //
@@ -657,7 +675,11 @@
 std::vector<LDObject*> ForgeWindow::getSelectedObjects () {
 	std::vector<LDObject*> objs;
 	
-	QList<QTreeWidgetItem*> const qaItems = qObjList->selectedItems();
+	if (g_CurrentFile == nullptr)
+		return objs;
+	
+	QList<QTreeWidgetItem*> const qaItems = qObjList->selectedItems ();
+	
 	for (LDObject* obj : g_CurrentFile->objects)
 	for (QTreeWidgetItem* qItem : qaItems) {
 		if (qItem == obj->qObjListEntry) {
--- a/ldtypes.cpp	Mon Apr 15 02:56:42 2013 +0300
+++ b/ldtypes.cpp	Mon Apr 15 04:00:10 2013 +0300
@@ -20,6 +20,7 @@
 #include "ldtypes.h"
 #include "file.h"
 #include "misc.h"
+#include "gui.h"
 
 char const* g_saObjTypeNames[] = {
 	"subfile",
@@ -255,7 +256,13 @@
 	vaCoords[1] = v2;
 }
 
-LDObject::~LDObject () {}
+LDObject::~LDObject () {
+	// Remove this object from the selection array if it is there.
+	for (ulong i = 0; i < g_ForgeWindow->paSelection.size(); ++i)
+		if (g_ForgeWindow->paSelection[i] == this)
+			g_ForgeWindow->paSelection.erase (g_ForgeWindow->paSelection.begin() + i);
+}
+
 LDComment::~LDComment () {}
 LDCondLine::~LDCondLine () {}
 LDEmpty::~LDEmpty () {}
--- a/main.cpp	Mon Apr 15 02:56:42 2013 +0300
+++ b/main.cpp	Mon Apr 15 04:00:10 2013 +0300
@@ -50,7 +50,6 @@
 	ForgeWindow* win = new ForgeWindow;
 	
 	g_qMainApp = &app;
-	g_ForgeWindow = win;
 	
 	newFile ();
 	

mercurial