Fixed additive selection; use a green selection area background instead of blue when selecting additive; selection area borders now appear black on bright backgrounds; single additive picking an already-selected object un-selects it.

Thu, 25 Apr 2013 04:12:28 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 25 Apr 2013 04:12:28 +0300
changeset 137
2b8b63be67fb
parent 136
13db97be14cb
child 138
d22d5c1d9e8a

Fixed additive selection; use a green selection area background instead of blue when selecting additive; selection area borders now appear black on bright backgrounds; single additive picking an already-selected object un-selects it.

gldraw.cpp file | annotate | diff | comparison | revisions
gldraw.h file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
misc.cpp file | annotate | diff | comparison | revisions
misc.h file | annotate | diff | comparison | revisions
zz_colorSelectDialog.cpp file | annotate | diff | comparison | revisions
--- a/gldraw.cpp	Thu Apr 25 01:54:25 2013 +0300
+++ b/gldraw.cpp	Thu Apr 25 04:12:28 2013 +0300
@@ -49,8 +49,8 @@
 	resetAngles ();
 	picking = rangepick = false;
 	
-	qPulseTimer = new QTimer (this);
-	connect (qPulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ()));
+	pulseTimer = new QTimer (this);
+	connect (pulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ()));
 }
 
 // =============================================================================
@@ -86,6 +86,7 @@
 	glLineWidth (gl_linethickness);
 	
 	setMouseTracking (true);
+	setFocusPolicy (Qt::WheelFocus);
 	compileObjects ();
 }
 
@@ -109,6 +110,8 @@
 	if (!col.isValid ())
 		return;
 	
+	darkbg = luma (col) < 80;
+	
 	glClearColor (
 		((double)col.red()) / 255.0f,
 		((double)col.green()) / 255.0f,
@@ -286,10 +289,18 @@
 			glOrtho (.0, width, height, .0, -1.0, 1.0);
 			
 			for (int x : {GL_QUADS, GL_LINE_LOOP}) {
-				if (x == GL_QUADS)
-					glColor4f (.0, .8, 1.0, .6);
-				else
-					glColor4f (1.0, 1.0, 1.0, 1.0);
+				if (x == GL_QUADS) {
+					// Use a green color when picking additive, a blue color when normally.
+					if (addpick)
+						glColor4f (0.5f, 1.f, 0.f, 0.2f);
+					else
+						glColor4f (0.f, 0.8f, 1.f, 0.2f);
+				} else {
+					if (darkbg)
+						glColor4f (1.f, 1.f, 1.f, 0.7f);
+					else
+						glColor4f (0.f, 0.f, 0.f, 0.7f);
+				}
 				
 				glBegin (x);
 					glVertex2i (x0, y0);
@@ -308,7 +319,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void GLRenderer::compileObjects () {
-	uaObjLists.clear ();
+	objLists.clear ();
 	
 	g_faObjectOffset[0] = -(g_BBox.v0.x + g_BBox.v1.x) / 2;
 	g_faObjectOffset[1] = -(g_BBox.v0.y + g_BBox.v1.y) / 2;
@@ -338,7 +349,7 @@
 			*upMemberList = uList;
 		}
 		
-		uaObjLists.push_back (obj->uGLList);
+		objLists.push_back (obj->uGLList);
 	}
 }
 
@@ -473,23 +484,28 @@
 // =============================================================================
 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) {
 	if ((lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton)) {
-		if (ulTotalMouseMove < 10 || rangepick)
-			pick (ev->x (), ev->y (), (qKeyMods & Qt::ControlModifier));
+		if (!rangepick)
+			addpick = (keymods & Qt::ControlModifier);
+		
+		if (totalmove < 10 || rangepick)
+			pick (ev->x (), ev->y ());
 		
 		rangepick = false;
-		ulTotalMouseMove = 0;
+		totalmove = 0;
 	}
 }
 
 // =============================================================================
 void GLRenderer::mousePressEvent (QMouseEvent* ev) {
 	if (ev->buttons () & Qt::LeftButton)
-		ulTotalMouseMove = 0;
+		totalmove = 0;
 	
 	if (ev->modifiers () & Qt::ShiftModifier) {
 		rangepick = true;
 		rangeStart.setX (ev->x ());
 		rangeStart.setY (ev->y ());
+		
+		addpick = (keymods & Qt::ControlModifier);
 	}
 	
 	lastButtons = ev->buttons ();
@@ -501,7 +517,7 @@
 void GLRenderer::mouseMoveEvent (QMouseEvent* ev) {
 	int dx = ev->x () - pos.x ();
 	int dy = ev->y () - pos.y ();
-	ulTotalMouseMove += abs (dx) + abs (dy);
+	totalmove += abs (dx) + abs (dy);
 	
 	if (ev->buttons () & Qt::LeftButton && !rangepick) {
 		rotX = rotX + (dy);
@@ -524,11 +540,11 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void GLRenderer::keyPressEvent (QKeyEvent* ev) {
-	qKeyMods = ev->modifiers ();
+	keymods = ev->modifiers ();
 }
 
 void GLRenderer::keyReleaseEvent (QKeyEvent* ev) {
-	qKeyMods = ev->modifiers ();
+	keymods = ev->modifiers ();
 }
 
 // =============================================================================
@@ -544,20 +560,21 @@
 // =============================================================================
 void GLRenderer::updateSelFlash () {
 	if (gl_selflash && g_ForgeWindow->sel.size() > 0) {
-		qPulseTimer->start (g_dPulseInterval);
+		pulseTimer->start (g_dPulseInterval);
 		g_dPulseTick = 0;
 	} else
-		qPulseTimer->stop ();
+		pulseTimer->stop ();
 }
 
 // ========================================================================= //
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
-void GLRenderer::pick (uint mx, uint my, bool add) {
+void GLRenderer::pick (uint mouseX, uint mouseY) {
 	GLint viewport[4];
+	LDObject* removedObject = null;
 	
 	// Clear the selection if we do not wish to add to it.
-	if (add == false) {
+	if (addpick == false) {
 		std::vector<LDObject*> paOldSelection = g_ForgeWindow->sel;
 		g_ForgeWindow->sel.clear ();
 		
@@ -575,8 +592,8 @@
 	
 	glGetIntegerv (GL_VIEWPORT, viewport);
 	
-	short x0 = mx,
-		y0 = my;
+	short x0 = mouseX,
+		y0 = mouseY;
 	short x1, y1;
 	
 	// Determine how big an area to read - with range picking, we pick by
@@ -627,6 +644,24 @@
 			continue; // White is background; skip
 		
 		LDObject* obj = g_CurrentFile->object (idx);
+		
+		// If this is an additive single pick and the object is currently selected,
+		// we remove it from selection instead.
+		if (!rangepick && addpick) {
+			bool removed = false;
+			
+			for (ulong i = 0; i < g_ForgeWindow->sel.size(); ++i) {
+				if (g_ForgeWindow->sel[i] == obj) {
+					g_ForgeWindow->sel.erase (g_ForgeWindow->sel.begin () + i);
+					removedObject = obj;
+					removed = true;
+				}
+			}
+			
+			if (removed)
+				break;
+		}
+		
 		g_ForgeWindow->sel.push_back (obj);
 	}
 	
@@ -652,6 +687,9 @@
 	for (LDObject* obj : g_ForgeWindow->sel)
 		recompileObject (obj);
 	
+	if (removedObject != null)
+		recompileObject (removedObject);
+	
 	paintGL ();
 	swapBuffers ();
 }
@@ -661,9 +699,9 @@
 // ========================================================================= //
 void GLRenderer::recompileObject (LDObject* obj) {
 	// Replace the old list with the new one.
-	for (ulong i = 0; i < uaObjLists.size(); ++i)
-		if (uaObjLists[i] == obj->uGLList)
-			uaObjLists.erase (uaObjLists.begin() + i);
+	for (ulong i = 0; i < objLists.size(); ++i)
+		if (objLists[i] == obj->uGLList)
+			objLists.erase (objLists.begin() + i);
 	
 	GLuint uList = glGenLists (1);
 	glNewList (uList, GL_COMPILE);
@@ -671,7 +709,7 @@
 	compileOneObject (obj);
 	
 	glEndList ();
-	uaObjLists.push_back (uList);
+	objLists.push_back (uList);
 	obj->uGLList = uList;
 }
 
--- a/gldraw.h	Thu Apr 25 01:54:25 2013 +0300
+++ b/gldraw.h	Thu Apr 25 04:12:28 2013 +0300
@@ -39,7 +39,7 @@
 	void hardRefresh ();
 	void compileObjects ();
 	void setBackground ();
-	void pick (uint mouseX, uint mouseY, bool add);
+	void pick (uint mouseX, uint mouseY);
 	QColor getMainColor ();
 	void recompileObject (LDObject* obj);
 	void refresh ();
@@ -52,6 +52,7 @@
 	double zoom;
 	bool picking;
 	bool rangepick;
+	bool addpick;
 	short width, height;
 	QPoint rangeStart;
 
@@ -68,7 +69,13 @@
 	void wheelEvent (QWheelEvent* ev);
 
 private:
-	std::vector<GLuint> uaObjLists;
+	std::vector<GLuint> objLists;
+	QTimer* pulseTimer;
+	Qt::MouseButtons lastButtons;
+	Qt::KeyboardModifiers keymods;
+	ulong totalmove;
+	bool darkbg;
+	
 	void compileOneObject (LDObject* obj);
 	template<class T> void compileSubObject (LDObject* obj, const GLenum eGLType,
 		const short dVerts);
@@ -76,12 +83,6 @@
 	void clampAngle (double& fAngle);
 	void setObjectColor (LDObject* obj);
 	
-	QTimer* qPulseTimer;
-	
-	Qt::MouseButtons lastButtons;
-	Qt::KeyboardModifiers qKeyMods;
-	ulong ulTotalMouseMove;
-	
 private slots:
 	void slot_timerUpdate ();
 };
--- a/gui.cpp	Thu Apr 25 01:54:25 2013 +0300
+++ b/gui.cpp	Thu Apr 25 04:12:28 2013 +0300
@@ -16,8 +16,11 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <QtGui>
-
+#include <qgridlayout.h>
+#include <qmessagebox.h>
+#include <qevent.h>
+#include <qmenubar.h>
+#include <qstatusbar.h>
 #include "common.h"
 #include "gldraw.h"
 #include "gui.h"
--- a/gui.h	Thu Apr 25 01:54:25 2013 +0300
+++ b/gui.h	Thu Apr 25 04:12:28 2013 +0300
@@ -27,7 +27,6 @@
 #include <QToolBar>
 #include <QTextEdit>
 #include <qpushbutton.h>
-#include <qbuttongroup.h>
 #include "gldraw.h"
 #include "config.h"
 
--- a/misc.cpp	Thu Apr 25 01:54:25 2013 +0300
+++ b/misc.cpp	Thu Apr 25 04:12:28 2013 +0300
@@ -18,6 +18,7 @@
 
 #include <math.h>
 #include <locale.h>
+#include <qcolor.h>
 #include "common.h"
 #include "misc.h"
 
@@ -181,6 +182,13 @@
 }
 
 // =============================================================================
+uchar luma (QColor& col) {
+	return (0.2126f * col.red ()) +
+		(0.7152f * col.green ()) +
+		(0.0722f * col.blue ());
+}
+
+// =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 StringParser::StringParser (str zInText, char cSeparator) {
--- a/misc.h	Thu Apr 25 01:54:25 2013 +0300
+++ b/misc.h	Thu Apr 25 04:12:28 2013 +0300
@@ -24,6 +24,7 @@
 
 #define NUM_PRIMES 500
 
+class QColor;
 // Prime numbers
 extern const ushort g_uaPrimes[NUM_PRIMES];
 
@@ -71,6 +72,8 @@
 	b = c;
 }
 
+uchar luma (QColor& col);
+
 // =============================================================================
 // StringParser
 //
--- a/zz_colorSelectDialog.cpp	Thu Apr 25 01:54:25 2013 +0300
+++ b/zz_colorSelectDialog.cpp	Thu Apr 25 04:12:28 2013 +0300
@@ -28,6 +28,7 @@
 #include "zz_colorSelectDialog.h"
 #include "colors.h"
 #include "config.h"
+#include "misc.h"
 
 static const short g_dNumColumns = 8;
 static const short g_dNumRows = 10;
@@ -115,13 +116,11 @@
 			qColor.setAlpha (gl_maincolor_alpha * 255.0f);
 		}
 		
-		uchar ucLuma = (0.2126f * qColor.red()) +
-			(0.7152f * qColor.green()) + (0.0722f * qColor.blue());
-		bool bDark = (ucLuma < 80);
+		bool dark = (luma (qColor) < 80);
 		
 		gs_scene->addRect (x, y, w, w, qPen, qColor);
 		QGraphicsTextItem* qText = gs_scene->addText (format ("%lu", i).chars());
-		qText->setDefaultTextColor ((bDark) ? Qt::white : Qt::black);
+		qText->setDefaultTextColor ((dark) ? Qt::white : Qt::black);
 		qText->setPos (x, y);
 		
 		if (i == selColor) {

mercurial