Improved shared selection handling; added select by color

Mon, 15 Apr 2013 04:58:33 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 15 Apr 2013 04:58:33 +0300
changeset 109
f40b35142586
parent 108
351aef26f444
child 110
a62ab18d1b80

Improved shared selection handling; added select by color

file.cpp file | annotate | diff | comparison | revisions
gldraw.cpp file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
gui_actions.cpp file | annotate | diff | comparison | revisions
gui_editactions.cpp file | annotate | diff | comparison | revisions
--- a/file.cpp	Mon Apr 15 04:00:10 2013 +0300
+++ b/file.cpp	Mon Apr 15 04:58:33 2013 +0300
@@ -245,6 +245,7 @@
 	
 	// Rebuild the object tree view now.
 	g_ForgeWindow->refresh ();
+	g_ForgeWindow->setTitle ();
 	
 	// Add it to the recent files list.
 	addRecentFile (zPath);
--- a/gldraw.cpp	Mon Apr 15 04:00:10 2013 +0300
+++ b/gldraw.cpp	Mon Apr 15 04:58:33 2013 +0300
@@ -484,11 +484,8 @@
 	if (gl_selflash && g_ForgeWindow->paSelection.size() > 0) {
 		qPulseTimer->start (g_dPulseInterval);
 		g_dPulseTick = 0;
-	} else {
-		printf ("stop pulse timer\n");
+	} else
 		qPulseTimer->stop ();
-		printf ("done\n");
-	}
 }
 
 // ========================================================================= //
@@ -528,6 +525,7 @@
 		g_ForgeWindow->paSelection.push_back (obj);
 	}
 	
+	g_ForgeWindow->buildObjList ();
 	g_ForgeWindow->updateSelection ();
 	
 	bPicking = false;
@@ -536,7 +534,7 @@
 	setBackground ();
 	updateSelFlash ();
 	
-	for (LDObject* obj : g_ForgeWindow->getSelectedObjects ())
+	for (LDObject* obj : g_ForgeWindow->selection ())
 		recompileObject (obj);
 	
 	paintGL ();
@@ -566,7 +564,7 @@
 void GLRenderer::slot_timerUpdate () {
 	++g_dPulseTick %= g_dNumPulseTicks;
 	
-	for (LDObject* obj : g_ForgeWindow->getSelectedObjects ())
+	for (LDObject* obj : g_ForgeWindow->selection ())
 		recompileObject (obj);
 	
 	paintGL ();
--- a/gui.cpp	Mon Apr 15 04:00:10 2013 +0300
+++ b/gui.cpp	Mon Apr 15 04:58:33 2013 +0300
@@ -60,7 +60,8 @@
 EXTERN_ACTION (undo)
 EXTERN_ACTION (redo)
 EXTERN_ACTION (showHistory)
-
+EXTERN_ACTION (selectByColor)
+EXTERN_ACTION (selectByType)
 EXTERN_ACTION (moveXNeg)
 EXTERN_ACTION (moveYNeg)
 EXTERN_ACTION (moveZNeg)
@@ -74,6 +75,8 @@
 
 vector<actionmeta> g_ActionMeta;
 
+static bool g_bSelectionLocked = false;
+
 cfg (bool, lv_colorize, true);
 cfg (int, gui_toolbar_iconsize, 24);
 cfg (str, gui_colortoolbar, "16:24:|:0:1:2:3:4:5:6:7");
@@ -188,6 +191,9 @@
 	qEditMenu->addAction (ACTION_NAME (paste));				// Paste
 	qEditMenu->addAction (ACTION_NAME (del));				// Delete
 	qEditMenu->addSeparator ();								// -----
+	qEditMenu->addAction (ACTION_NAME (selectByColor));		// Select by Color
+	qEditMenu->addAction (ACTION_NAME (selectByType));		// Select by Type
+	qEditMenu->addSeparator ();								// -----
 	qEditMenu->addAction (ACTION_NAME (setColor));			// Set Color
 	qEditMenu->addAction (ACTION_NAME (inlineContents));	// Inline
 	qEditMenu->addAction (ACTION_NAME (deepInline));		// Deep Inline
@@ -296,6 +302,10 @@
 	ADD_TOOLBAR_ITEM (moveZPos)
 	ADD_TOOLBAR_ITEM (moveZNeg)
 	
+	initSingleToolBar ("Select");
+	ADD_TOOLBAR_ITEM (selectByColor)
+	ADD_TOOLBAR_ITEM (selectByType)
+	
 	// ==========================================
 	// Color toolbar
 	qColorToolBar = new QToolBar ("Quick Colors");
@@ -383,7 +393,7 @@
 		{
 			// Append title
 			LDComment* comm = static_cast<LDComment*> (g_CurrentFile->objects[0]);
-			zTitle.appendformat (":%s", comm->zText.chars());
+			zTitle.appendformat (": %s", comm->zText.chars());
 		}
 	}
 	
@@ -420,10 +430,10 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
 void ForgeWindow::deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects) {
-	vector<LDObject*> objs = getSelectedObjects ();
+	bool const bSelectionEmpty = (paSelection.size() == 0);
 	
 	// Delete the objects that were being selected
-	for (LDObject* obj : objs) {
+	for (LDObject* obj : paSelection) {
 		if (papObjects && ulapIndices) {
 			papObjects->push_back (obj->clone ());
 			ulapIndices->push_back (obj->getIndex (g_CurrentFile));
@@ -433,7 +443,7 @@
 		delete obj;
 	}
 	
-	if (objs.size() > 0)
+	if (bSelectionEmpty == false)
 		refresh ();
 }
 
@@ -572,6 +582,9 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
 void ForgeWindow::slot_selectionChanged () {
+	if (g_bSelectionLocked == true)
+		return;
+	
 	/*
 	// If the selection isn't 1 exact, disable setting contents
 	ACTION (setContents)->setEnabled (qObjList->selectedItems().size() == 1);
@@ -627,7 +640,7 @@
 	std::vector<short> daColors;
 	short dNewColor = col->index ();
 	
-	for (LDObject* obj : getSelectedObjects ()) {
+	for (LDObject* obj : paSelection) {
 		if (obj->dColor == -1)
 			continue; // uncolored object
 		
@@ -695,10 +708,13 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
 void ForgeWindow::updateSelection () {
-	buildObjList ();
+	g_bSelectionLocked = true;
 	
 	for (LDObject* obj : paSelection)
 		obj->qObjListEntry->setSelected (true);
+	
+	g_bSelectionLocked = false;
+	slot_selectionChanged ();
 }
 
 // ========================================================================= //
@@ -716,6 +732,34 @@
 	return false;
 }
 
+short ForgeWindow::getSelectedColor() {
+	short dResult = -1;
+	
+	for (LDObject* obj : paSelection) {
+		if (obj->dColor == -1)
+			continue; // doesn't use color
+		
+		if (dResult != -1 && obj->dColor != dResult) {
+			// No consensus in object color, therefore we don't have a
+			// proper default value to use.
+			dResult = -1;
+			break;
+		}
+		
+		if (dResult == -1)
+			dResult = obj->dColor;
+	}
+	
+	return dResult;
+}
+
+// ========================================================================= //
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// ========================================================================= //
+std::vector<LDObject*>& ForgeWindow::selection () {
+	return paSelection;
+}
+
 // ========================================================================= //
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
--- a/gui.h	Mon Apr 15 04:00:10 2013 +0300
+++ b/gui.h	Mon Apr 15 04:58:33 2013 +0300
@@ -133,12 +133,14 @@
 	void setTitle ();
 	void refresh ();
 	std::vector<LDObject*> getSelectedObjects ();
+	std::vector<LDObject*>& selection ();
 	ulong getInsertionPoint ();
 	void deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects);
 	void updateToolBars ();
 	void updateRecentFilesMenu ();
 	void updateSelection ();
 	bool isSelected (LDObject* obj);
+	short int getSelectedColor();
 
 private:
 	void createMenuActions ();
--- a/gui_actions.cpp	Mon Apr 15 04:00:10 2013 +0300
+++ b/gui_actions.cpp	Mon Apr 15 04:58:33 2013 +0300
@@ -143,6 +143,32 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+ACTION (selectByColor, "Select by Color", "select-color",
+	"Select all objects by the given color.", (0))
+{
+	short dColor = g_ForgeWindow->getSelectedColor ();
+	
+	printf ("color: %d\n", dColor);
+	
+	if (dColor == -1)
+		return; // no consensus on color
+	
+	g_ForgeWindow->paSelection.clear ();
+	for (LDObject* obj : g_CurrentFile->objects)
+		if (obj->dColor == dColor)
+			g_ForgeWindow->paSelection.push_back (obj);
+	
+	g_ForgeWindow->updateSelection ();
+}
+
+ACTION (selectByType, "Select by Type", "select-type",
+	"Select all objects by the given type.", (0))
+{
+	
+}
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 // Debug things
 #ifndef RELEASE
 ACTION (addTestQuad, "Add Test Quad", "add-quad", "Adds a test quad.", CTRL_SHIFT (Q)) {
--- a/gui_editactions.cpp	Mon Apr 15 04:00:10 2013 +0300
+++ b/gui_editactions.cpp	Mon Apr 15 04:58:33 2013 +0300
@@ -30,7 +30,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 static bool copyToClipboard () {
-	vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects ();
+	vector<LDObject*> objs = g_ForgeWindow->selection ();
 	
 	if (objs.size() == 0)
 		return false;
@@ -107,7 +107,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 static void doInline (bool bDeep) {
-	vector<LDObject*> sel = g_ForgeWindow->getSelectedObjects ();
+	vector<LDObject*> sel = g_ForgeWindow->selection ();
 	
 	// History stuff
 	vector<LDSubfile*> paRefs;
@@ -170,7 +170,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 ACTION (splitQuads, "Split Quads", "quad-split", "Split quads into triangles.", (0)) {
-	vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects ();
+	vector<LDObject*> objs = g_ForgeWindow->selection ();
 	
 	vector<ulong> ulaIndices;
 	vector<LDQuad*> paCopies;
@@ -216,7 +216,7 @@
 	if (g_ForgeWindow->qObjList->selectedItems().size() != 1)
 		return;
 	
-	LDObject* obj = g_ForgeWindow->getSelectedObjects ()[0];
+	LDObject* obj = g_ForgeWindow->selection ()[0];
 	SetContentsDialog::staticDialog (obj);
 }
 
@@ -230,24 +230,11 @@
 	short dColor;
 	short dDefault = -1;
 	
-	std::vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects ();
+	std::vector<LDObject*> objs = g_ForgeWindow->selection ();
 	
 	// If all selected objects have the same color, said color is our default
 	// value to the color selection dialog.
-	for (LDObject* obj : objs) {
-		if (obj->dColor == -1)
-			continue; // doesn't use color
-		
-		if (dDefault != -1 && obj->dColor != dDefault) {
-			// No consensus in object color, therefore we don't have a
-			// proper default value to use.
-			dDefault = -1;
-			break;
-		}
-		
-		if (dDefault == -1)
-			dDefault = obj->dColor;
-	}
+	dDefault = g_ForgeWindow->getSelectedColor ();
 	
 	// Show the dialog to the user now and ask for a color.
 	if (ColorSelectDialog::staticDialog (dColor, dDefault, g_ForgeWindow)) {
@@ -274,7 +261,7 @@
 ACTION (makeBorders, "Make Borders", "make-borders", "Add borders around given polygons.",
 	CTRL_SHIFT (B))
 {
-	vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects ();
+	vector<LDObject*> objs = g_ForgeWindow->selection ();
 	
 	vector<ulong> ulaIndices;
 	vector<LDObject*> paObjs;
@@ -327,7 +314,7 @@
 	vector<ulong> ulaIndices;
 	vector<LDObject*> paObjs;
 	
-	for (LDObject* obj : g_ForgeWindow->getSelectedObjects ()) {
+	for (LDObject* obj : g_ForgeWindow->selection ()) {
 		vertex* vaCoords = null;
 		ushort uNumCoords = 0;
 		
@@ -373,7 +360,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 static void doMoveSelection (const bool bUp) {
-	vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects ();
+	vector<LDObject*> objs = g_ForgeWindow->selection ();
 	
 	// Get the indices of the objects for history archival
 	vector<ulong> ulaIndices;
@@ -415,7 +402,7 @@
 void doMoveObjects (const vertex vVector) {
 	vector<ulong> ulaIndices;
 	
-	for (LDObject* obj : g_ForgeWindow->getSelectedObjects ()) {
+	for (LDObject* obj : g_ForgeWindow->selection ()) {
 		ulaIndices.push_back (obj->getIndex (g_CurrentFile));
 		obj->move (vVector);
 	}

mercurial