Allow addition of dummy lines..

Sat, 16 Mar 2013 03:42:04 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 16 Mar 2013 03:42:04 +0200
changeset 17
5606eebd0b90
parent 16
7e604baff022
child 18
a6732098fed8

Allow addition of dummy lines..

gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
io.cpp file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
--- a/gui.cpp	Sat Mar 16 03:24:50 2013 +0200
+++ b/gui.cpp	Sat Mar 16 03:42:04 2013 +0200
@@ -15,6 +15,7 @@
 	qObjList->setHeaderHidden (true);
 	qObjList->setMaximumWidth (256);
 	qObjList->setSelectionMode (QTreeWidget::MultiSelection);
+	connect (qObjList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selectionChanged ()));
 	
 	qMessageLog = new QTextEdit;
 	qMessageLog->setReadOnly (true);
@@ -88,7 +89,6 @@
 		qAct_save,
 		qAct_saveAs,
 		qAct_newSubfile,
-		qAct_newLine,
 		qAct_newTriangle,
 		qAct_newQuad,
 		qAct_newCondLine,
@@ -220,7 +220,16 @@
 }
 
 void LDForgeWindow::slot_newLine () {
+	LDLine* line = new LDLine;
+	const ulong ulSpot = getInsertionPoint ();
 	
+	memset (line->vaCoords, 0, sizeof line->vaCoords);
+	line->dColor = 24;
+	
+	g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulSpot, line);
+	
+	buildObjList ();
+	R->hardRefresh ();
 }
 
 void LDForgeWindow::slot_newTriangle () {
@@ -417,5 +426,28 @@
 }
 
 void LDForgeWindow::slot_selectionChanged () {
+	// If the selection isn't 1 exact, disable setting contents
+	qAct_setContents->setEnabled (qObjList->selectedItems().size() == 1);
+}
+
+// =============================================================================
+// ulong getInsertionPoint ()
+// 
+// Returns the index of where a new item should be placed at.
+// =============================================================================
+ulong LDForgeWindow::getInsertionPoint () {
+	ulong ulIndex;
 	
+	if (qObjList->selectedItems().size() == 1) {
+		// If we have a selection, put the item after it.
+		for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex)
+			if (g_CurrentFile->objects[ulIndex]->qObjListEntry == qObjList->selectedItems()[0])
+				break;
+		
+		if (ulIndex >= g_CurrentFile->objects.size())
+			return ulIndex + 1;
+	}
+	
+	// Otherwise place the object at the end.
+	return g_CurrentFile->objects.size();
 }
\ No newline at end of file
--- a/gui.h	Sat Mar 16 03:24:50 2013 +0200
+++ b/gui.h	Sat Mar 16 03:42:04 2013 +0200
@@ -41,6 +41,9 @@
 	void buildObjList ();
 	void setTitle ();
 	
+	// Where would a new item be inserted into?
+	ulong getInsertionPoint ();
+	
 private:
 	void createMenuActions ();
 	void createMenus ();
--- a/io.cpp	Sat Mar 16 03:24:50 2013 +0200
+++ b/io.cpp	Sat Mar 16 03:42:04 2013 +0200
@@ -158,7 +158,7 @@
 		{
 			// Comment
 			LDComment* obj = new LDComment;
-			obj->zText = zLine.substr (1, -1);
+			obj->zText = zLine.substr (2, -1);
 			return obj;
 		}
 	
--- a/ldtypes.cpp	Sat Mar 16 03:24:50 2013 +0200
+++ b/ldtypes.cpp	Sat Mar 16 03:42:04 2013 +0200
@@ -88,7 +88,7 @@
 
 // =============================================================================
 str LDComment::getContents () {
-	return str::mkfmt ("0%s", zText.chars ());
+	return str::mkfmt ("0 %s", zText.chars ());
 }
 
 str LDLine::getContents () {
@@ -106,7 +106,7 @@
 
 str LDQuad::getContents () {
 	// Oh, Jesus.
-	return str::mkfmt ("3 %d %f %f %f %f %f %f %f %f %f %f %f %f", dColor,
+	return str::mkfmt ("4 %d %f %f %f %f %f %f %f %f %f %f %f %f", dColor,
 		vaCoords[0].x, vaCoords[0].y, vaCoords[0].z,
 		vaCoords[1].x, vaCoords[1].y, vaCoords[1].z,
 		vaCoords[2].x, vaCoords[2].y, vaCoords[2].z,
@@ -114,7 +114,7 @@
 }
 
 str LDCondLine::getContents () {
-	return str::mkfmt ("3 %d %f %f %f %f %f %f %f %f %f %f %f %f", dColor,
+	return str::mkfmt ("5 %d %f %f %f %f %f %f %f %f %f %f %f %f", dColor,
 		vaCoords[0].x, vaCoords[0].y, vaCoords[0].z,
 		vaCoords[1].x, vaCoords[1].y, vaCoords[1].z,
 		vaControl[0].x, vaControl[0].y, vaControl[0].z,

mercurial