Added icons to the renderer for switching between cameras. It works! Yay!

Fri, 03 May 2013 15:14:01 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 03 May 2013 15:14:01 +0300
changeset 148
ecfbb598db14
parent 147
291a1fe2d278
child 149
96b14d5e7365

Added icons to the renderer for switching between cameras. It works! Yay!

common.h file | annotate | diff | comparison | revisions
gldraw.cpp file | annotate | diff | comparison | revisions
gldraw.h file | annotate | diff | comparison | revisions
icons/camera-back.png file | annotate | diff | comparison | revisions
icons/camera-bottom.png file | annotate | diff | comparison | revisions
icons/camera-free.png file | annotate | diff | comparison | revisions
icons/camera-front.png file | annotate | diff | comparison | revisions
icons/camera-left.png file | annotate | diff | comparison | revisions
icons/camera-right.png file | annotate | diff | comparison | revisions
icons/camera-top.png file | annotate | diff | comparison | revisions
zz_addObjectDialog.cpp file | annotate | diff | comparison | revisions
--- a/common.h	Fri May 03 03:55:21 2013 +0300
+++ b/common.h	Fri May 03 15:14:01 2013 +0300
@@ -62,9 +62,8 @@
 #ifdef null
 #undef null
 #endif // null
-#define null nullptr
 
-static const double fMaxCoord = 10000.0;
+static const std::nullptr_t null = nullptr;
 static const short maincolor = 16;
 static const short edgecolor = 24;
 
--- a/gldraw.cpp	Fri May 03 03:55:21 2013 +0300
+++ b/gldraw.cpp	Fri May 03 15:14:01 2013 +0300
@@ -55,6 +55,15 @@
 cfg (bool, gl_colorbfc, true);
 cfg (bool, gl_selflash, false);
 
+struct CameraIcon {
+	QPixmap* img;
+	QRect srcRect, destRect, selRect;
+	GLRenderer::Camera cam;
+} g_CameraIcons[7];
+
+const QBrush g_CameraIconSelBG (QColor (0, 0, 0, 128));
+const char* g_CameraNames[] = { "Front", "Top", "Left", "Back", "Bottom", "Right", "Free" };
+
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
@@ -65,6 +74,49 @@
 	
 	pulseTimer = new QTimer (this);
 	connect (pulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ()));
+	
+	thickBorderPen = QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
+	thinBorderPen = thickBorderPen;
+	thinBorderPen.setWidth (1);
+	
+	// Init camera icons
+	ushort i = 0;
+	for (str name : g_CameraNames) {
+		str path;
+		path.format ("./icons/camera-%s.png", name.tolower ().chars ());
+		
+		CameraIcon* info = &g_CameraIcons[i];
+		info->img = new QPixmap (path);
+		info->cam = (GLRenderer::Camera) i;
+		
+		++i;
+	}
+	
+	calcCameraIconRects ();
+}
+
+// =============================================================================
+GLRenderer::~GLRenderer() {
+	for (CameraIcon& info : g_CameraIcons)
+		delete info.img;
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+void GLRenderer::calcCameraIconRects () {
+	ushort i = 0;
+	
+	for (CameraIcon& info : g_CameraIcons) {
+		const long x1 = width - (((i % 3) + 1) * 16) - 1,
+			y1 = ((i / 3) * 16);
+		
+		info.srcRect = QRect (0, 0, 16, 16);
+		info.destRect = QRect (x1, y1, 16, 16);
+		info.selRect = QRect (info.destRect.x (), info.destRect.y (),
+			info.destRect.width () + 1, info.destRect.height () + 1);
+		++i;
+	}
 }
 
 // =============================================================================
@@ -141,8 +193,9 @@
 		long i = obj->getIndex (g_CurrentFile);
 		
 		// If we couldn't find the index, this object must not be from this file,
-		// therefore it must be an object inlined from another file through a
-		// subfile reference. Use the reference's index.
+		// therefore it must be an object inlined from a subfile reference or
+		// decomposed from a radial. Find the top level parent object and use
+		// its index.
 		if (i == -1)
 			i = obj->topLevelParent ()->getIndex (g_CurrentFile);
 		
@@ -156,7 +209,7 @@
 			g = (i / 256) % 256,
 			b = i % 256;
 		
-		glColor3f (r / 255.f, g / 255.f, b / 255.f);
+		qglColor (QColor (r, g, b, 255));
 		return;
 	}
 	
@@ -254,6 +307,8 @@
 	width = w;
 	height = h;
 	
+	calcCameraIconRects ();
+	
 	glViewport (0, 0, w, h);
 	glMatrixMode (GL_PROJECTION);
 	glLoadIdentity ();
@@ -311,6 +366,7 @@
 	drawGLScene ();
 	
 	QPainter paint (this);
+	
 	vw = zoom;
 	vh = (height * vw) / width;
 	
@@ -343,6 +399,17 @@
 			textSize.height (), Qt::AlignCenter, text);
 	}
 	
+	// Camera icons
+	if (!picking) {
+		// Draw a background for the selected camera
+		paint.setPen (thinBorderPen);
+		paint.setBrush (g_CameraIconSelBG);
+		paint.drawRect (g_CameraIcons[camera ()].selRect);
+		
+		for (CameraIcon& info : g_CameraIcons)
+			paint.drawPixmap (info.destRect, *info.img, info.srcRect);
+	}
+	
 	// If we're range-picking, draw a rectangle encompassing the selection area.
 	if (rangepick && !picking) {
 		const short x0 = rangeStart.x (),
@@ -352,12 +419,9 @@
 		
 		QRect rect (x0, y0, x1 - x0, y1 - y0);
 		QColor fillColor = (addpick ? "#80FF00" : "#00CCFF");
-		QColor borderColor = Qt::black;
 		fillColor.setAlphaF (0.2f);
-		borderColor.setAlphaF (0.8f);
-		QPen borderPen (borderColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
 		
-		paint.setPen (borderPen);
+		paint.setPen (thickBorderPen);
 		paint.setBrush (QBrush (fillColor));
 		paint.drawRect (rect);
 	}
@@ -624,11 +688,24 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void GLRenderer::pick (uint mouseX, uint mouseY) {
+	// Check if we selected a camera icon
+	if (!rangepick) {
+		QPoint pos (mouseX, mouseY);
+		
+		for (CameraIcon& info : g_CameraIcons) {
+			if (info.destRect.contains (pos)) {
+				setCamera (info.cam);
+				update ();
+				return;
+			}
+		}
+	}
+	
 	GLint viewport[4];
 	LDObject* removedObject = null;
 	
 	// Clear the selection if we do not wish to add to it.
-	if (addpick == false) {
+	if (!addpick) {
 		std::vector<LDObject*> paOldSelection = g_ForgeWindow->sel;
 		g_ForgeWindow->sel.clear ();
 		
--- a/gldraw.h	Fri May 03 03:55:21 2013 +0300
+++ b/gldraw.h	Fri May 03 15:14:01 2013 +0300
@@ -46,6 +46,8 @@
 	};
 	
 	GLRenderer (QWidget* parent = null);
+	~GLRenderer ();
+	
 	void hardRefresh ();
 	void compileObjects ();
 	void setBackground ();
@@ -89,6 +91,7 @@
 	double rotX, rotY, rotZ, panX, panY, zoom;
 	bool rangepick, addpick;
 	QPoint pos, rangeStart;
+	QPen thinBorderPen, thickBorderPen;
 	
 	void compileOneObject (LDObject* obj);
 	template<class T> void compileSubObject (LDObject* obj, const GLenum eGLType,
@@ -97,6 +100,7 @@
 	void clampAngle (double& fAngle);
 	void setObjectColor (LDObject* obj);
 	void drawGLScene ();
+	void calcCameraIconRects ();
 	
 private slots:
 	void slot_timerUpdate ();
Binary file icons/camera-back.png has changed
Binary file icons/camera-bottom.png has changed
Binary file icons/camera-free.png has changed
Binary file icons/camera-front.png has changed
Binary file icons/camera-left.png has changed
Binary file icons/camera-right.png has changed
Binary file icons/camera-top.png has changed
--- a/zz_addObjectDialog.cpp	Fri May 03 03:55:21 2013 +0300
+++ b/zz_addObjectDialog.cpp	Fri May 03 15:14:01 2013 +0300
@@ -177,8 +177,8 @@
 	
 	for (short i = 0; i < coordCount; ++i) {
 		dsb_coords[i] = new QDoubleSpinBox;
-		dsb_coords[i]->setMinimum (-fMaxCoord);
-		dsb_coords[i]->setMaximum (fMaxCoord);
+		dsb_coords[i]->setMinimum (-10000.0);
+		dsb_coords[i]->setMaximum (10000.0);
 	}
 	
 	IMPLEMENT_DIALOG_BUTTONS

mercurial