- pressing ctrl while drawing now locks the draw to cardinal directions

Tue, 21 Oct 2014 20:35:37 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 21 Oct 2014 20:35:37 +0300
changeset 897
ef9e4469975a
parent 896
4988666b5e3c
child 898
4dea33733251

- pressing ctrl while drawing now locks the draw to cardinal directions

changelog.txt file | annotate | diff | comparison | revisions
src/editmodes/drawMode.cc file | annotate | diff | comparison | revisions
src/editmodes/drawMode.h file | annotate | diff | comparison | revisions
src/glRenderer.cc file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
--- a/changelog.txt	Wed Sep 10 14:02:31 2014 +0300
+++ b/changelog.txt	Tue Oct 21 20:35:37 2014 +0300
@@ -1,6 +1,14 @@
 
 
 
+		Changes in version 0.4
+
+
+
++	- Pressing Ctrl while drawing now causes the new line to become locked to cardinal directions, ala Gimp.
+-	- Selecting an invertnext'd object no longer selects the invertnext (reverted feature from 0.3, caused too many problems).
+
+
 		Changes in version 0.3
 
 
--- a/src/editmodes/drawMode.cc	Wed Sep 10 14:02:31 2014 +0300
+++ b/src/editmodes/drawMode.cc	Tue Oct 21 20:35:37 2014 +0300
@@ -21,6 +21,7 @@
 #include "drawMode.h"
 #include "../ldObject.h"
 #include "../glRenderer.h"
+#include "../miscallenous.h"
 
 DrawMode::DrawMode (GLRenderer* renderer) :
 	Super (renderer) {}
@@ -40,7 +41,7 @@
 
 	// Draw the cursor vertex as the last one in the list.
 	if (poly.size() < 4)
-		poly << renderer()->position3D();
+		poly << getCursorVertex();
 
 	renderPolygon (painter, poly, true, true);
 }
@@ -74,7 +75,7 @@
 			return true;
 		}
 
-		addDrawnVertex (renderer()->position3D());
+		addDrawnVertex (getCursorVertex());
 		return true;
 	}
 
@@ -127,3 +128,36 @@
 
 	finishDraw (objs);
 }
+
+template<typename _Type>
+_Type IntervalClamp (_Type a, _Type interval)
+{
+	_Type remainder = a % interval;
+
+	if (remainder >= float (interval / 2))
+		a += interval;
+
+	a -= remainder;
+	return a;
+}
+
+Vertex DrawMode::getCursorVertex() const
+{
+	Vertex result = renderer()->position3D();
+
+	if (renderer()->keyboardModifiers() & Qt::ControlModifier
+		and not m_drawedVerts.isEmpty())
+	{
+		Vertex const& v0 = m_drawedVerts.last();
+		Vertex const& v1 = result;
+		Axis relX, relY;
+
+		renderer()->getRelativeAxes (relX, relY);
+		QLineF ln (v0[relX], v0[relY], v1[relX], v1[relY]);
+		ln.setAngle (IntervalClamp<int> (ln.angle(), 45));
+		result.setCoordinate (relX, Grid::Snap (ln.x2(), Grid::Coordinate));
+		result.setCoordinate (relY, Grid::Snap (ln.y2(), Grid::Coordinate));
+	}
+
+	return result;
+}
--- a/src/editmodes/drawMode.h	Wed Sep 10 14:02:31 2014 +0300
+++ b/src/editmodes/drawMode.h	Tue Oct 21 20:35:37 2014 +0300
@@ -32,4 +32,5 @@
 	bool mouseReleased (MouseEventData const& data) override;
 	void endDraw();
 	bool preAddVertex (Vertex const&);
+	Vertex getCursorVertex() const;
 };
--- a/src/glRenderer.cc	Wed Sep 10 14:02:31 2014 +0300
+++ b/src/glRenderer.cc	Tue Oct 21 20:35:37 2014 +0300
@@ -1650,6 +1650,11 @@
 	return g_FixedCameras[camera()].negatedDepth ? -1 : 1;
 }
 
+Qt::KeyboardModifiers GLRenderer::keyboardModifiers() const
+{
+	return m_keymods;
+}
+
 LDFixedCamera const& GetFixedCamera (ECamera cam)
 {
 	assert (cam != EFreeCamera);
--- a/src/glRenderer.h	Wed Sep 10 14:02:31 2014 +0300
+++ b/src/glRenderer.h	Tue Oct 21 20:35:37 2014 +0300
@@ -169,6 +169,7 @@
 	Axis					getRelativeZ() const;
 	LDGLOverlay&			getOverlay (int newcam);
 	uchar*					getScreencap (int& w, int& h);
+	Qt::KeyboardModifiers	keyboardModifiers() const;
 	void					hardRefresh();
 	void					highlightCursorObject();
 	void					initGLData();

mercurial