Added support for overpaint-less mode since I'm having serious trouble with that

Tue, 21 May 2013 14:02:18 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 21 May 2013 14:02:18 +0300
changeset 230
43d722c255d3
parent 229
b9e101b76eb3
child 231
6ee9917b79f8

Added support for overpaint-less mode since I'm having serious trouble with that

ldforge.pro file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/gui.h file | annotate | diff | comparison | revisions
src/gui_actions.cpp file | annotate | diff | comparison | revisions
src/types.cpp file | annotate | diff | comparison | revisions
--- a/ldforge.pro	Sun May 19 15:36:01 2013 +0300
+++ b/ldforge.pro	Tue May 21 14:02:18 2013 +0300
@@ -16,4 +16,5 @@
 
 QMAKE_CXXFLAGS += -std=c++0x
 QT += opengl
-LIBS += -lGLU
\ No newline at end of file
+LIBS += -lGLU
+DEFINES += "NO_OVERPAINTING"
\ No newline at end of file
--- a/src/gldraw.cpp	Sun May 19 15:36:01 2013 +0300
+++ b/src/gldraw.cpp	Tue May 21 14:02:18 2013 +0300
@@ -154,6 +154,20 @@
 	}
 }
 
+void GLRenderer::initGLData () {
+	glEnable (GL_BLEND);
+	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+	glEnable (GL_POLYGON_OFFSET_FILL);
+	glPolygonOffset (1.0f, 1.0f);
+	
+	glEnable (GL_DEPTH_TEST);
+	glShadeModel (GL_SMOOTH);
+	glEnable (GL_MULTISAMPLE);
+	
+	glEnable (GL_LINE_SMOOTH);
+	glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
+}
+
 // =============================================================================
 void GLRenderer::resetAngles () {
 	m_rotX = 30.0f;
@@ -175,6 +189,10 @@
 	
 	glLineWidth (gl_linethickness);
 	
+#ifdef NO_OVERPAINTING
+	initGLData ();
+#endif // NO_OVERPAINTING
+	
 	setAutoFillBackground (false);
 	setMouseTracking (true);
 	setFocusPolicy (Qt::WheelFocus);
@@ -461,31 +479,22 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+#ifndef NO_OVERPAINTING
+
 void GLRenderer::paintEvent (QPaintEvent* ev) {
 	Q_UNUSED (ev)
 	m_virtWidth = m_zoom;
 	m_virtHeight = (m_height * m_virtWidth) / m_width;
 	
-	glEnable (GL_BLEND);
-	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	glEnable (GL_POLYGON_OFFSET_FILL);
-	glPolygonOffset (1.0f, 1.0f);
+	initGLData ();
+	drawGLScene ();
 	
-	glEnable (GL_DEPTH_TEST);
-	glShadeModel (GL_SMOOTH);
-	glEnable (GL_MULTISAMPLE);
-	
-	glEnable (GL_LINE_SMOOTH);
-	glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
-	
-	drawGLScene ();
+	m_hoverpos = g_origin;
 	
 	QPainter paint (this);
 	QFontMetrics metrics = QFontMetrics (QFont ());
 	paint.setRenderHint (QPainter::HighQualityAntialiasing);
 	
-	m_hoverpos = g_origin;
-	
 	if (m_camera != Free) {
 		// Paint the overlay image if we have one
 		const overlayMeta& overlay = g_overlays[m_camera];
@@ -656,6 +665,23 @@
 	}
 }
 
+#else
+
+void GLRenderer::paintGL () {
+	m_virtWidth = m_zoom;
+	m_virtHeight = (m_height * m_virtWidth) / m_width;
+	drawGLScene ();
+	
+	m_hoverpos = g_origin;
+	if (m_camera != Free)
+		m_hoverpos = coordconv2_3 (m_pos, true);
+	
+	g_win->setStatusBarText (fmt ("%s camera: X: %f, Y: %f, Z: %f",
+		g_CameraNames[camera ()], m_hoverpos[X], m_hoverpos[Y], m_hoverpos[Z]));
+}
+
+#endif // NO_OVERPAINTING
+
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
--- a/src/gldraw.h	Sun May 19 15:36:01 2013 +0300
+++ b/src/gldraw.h	Tue May 21 14:02:18 2013 +0300
@@ -83,9 +83,14 @@
 	void	mousePressEvent	(QMouseEvent* ev);
 	void	mouseMoveEvent		(QMouseEvent* ev);
 	void	mouseReleaseEvent	(QMouseEvent* ev);
-	void	paintEvent			(QPaintEvent* ev);
 	void	resizeGL			(int w, int h);
 	void	wheelEvent			(QWheelEvent* ev);
+	
+#ifndef NO_OVERPAINTING
+	void	paintEvent			(QPaintEvent* ev);
+#else
+	void	paintGL				();
+#endif // NO_OVERPAINTING
 
 private:
 	QTimer* m_toolTipTimer;
@@ -118,6 +123,7 @@
 	
 private slots:
 	void	slot_toolTipTimer	();
+	void initGLData();
 };
 
 // Alias for short namespaces
--- a/src/gui.cpp	Sun May 19 15:36:01 2013 +0300
+++ b/src/gui.cpp	Tue May 21 14:02:18 2013 +0300
@@ -124,6 +124,11 @@
 	findAction ("wireframe")->setCheckable (true);
 	findAction ("wireframe")->setChecked (gl_wireframe);
 	
+#ifdef NO_OVERPAINTING
+	for (int i = 0; i < 7; ++i)
+		findAction (fmt ("camera%s", g_CameraNames[i]))->setCheckable (true);
+#endif
+	
 	updateEditModeActions ();
 	
 	// things not implemented yet
@@ -418,6 +423,13 @@
 	addToolBarAction ("modeSelect");
 	addToolBarAction ("modeDraw");
 	
+#ifdef NO_OVERPAINTING
+	g_CurrentToolBar->addSeparator ();
+	
+	for (int i = 0; i < 7; ++i)
+		addToolBarAction (fmt ("camera%s", g_CameraNames[i]));
+#endif // NO_OVERPAINTING
+	
 	updateToolBars ();
 }
 
@@ -984,6 +996,11 @@
 		if (i != GL::Select)
 			act->setEnabled (R ()->camera () != GL::Free);
 	}
+	
+#ifdef NO_OVERPAINTING
+	for (int i = 0; i < 7; ++i)
+		findAction (fmt ("camera%s", g_CameraNames[i]))->setChecked (i == (R ()->camera ()));
+#endif
 }
 
 // ========================================================================================================================================
@@ -1101,4 +1118,8 @@
 	cbg_axes->addCheckBox ("Y", Y);
 	cbg_axes->addCheckBox ("Z", Z);
 	return cbg_axes;
+}
+
+void ForgeWindow::setStatusBarText (str text) {
+	statusBar ()->showMessage (text);
 }
\ No newline at end of file
--- a/src/gui.h	Sun May 19 15:36:01 2013 +0300
+++ b/src/gui.h	Tue May 21 14:02:18 2013 +0300
@@ -145,6 +145,7 @@
 	void setQuickColorMeta (std::vector<quickColorMetaEntry>& quickColorMeta) {
 		m_colorMeta = quickColorMeta;
 	}
+	void setStatusBarText (str text);
 	
 protected:
 	void closeEvent (QCloseEvent* ev);
--- a/src/gui_actions.cpp	Sun May 19 15:36:01 2013 +0300
+++ b/src/gui_actions.cpp	Tue May 21 14:02:18 2013 +0300
@@ -449,4 +449,20 @@
 	
 	if (ok)
 		g_win->R ()->setDepthValue (depth);
-}
\ No newline at end of file
+}
+
+#ifdef NO_OVERPAINTING
+#define CAMERA_ACTION(NAME,LOWERNAME) \
+MAKE_ACTION (camera##NAME, #NAME " Camera", "camera-" #LOWERNAME, "Change to the " #LOWERNAME " camera", (0)) { \
+	g_win->R ()->setCamera (GL::NAME); \
+}
+
+CAMERA_ACTION (Top, top)
+CAMERA_ACTION (Bottom, bottom)
+CAMERA_ACTION (Left, left)
+CAMERA_ACTION (Right, right)
+CAMERA_ACTION (Front, front)
+CAMERA_ACTION (Back, back)
+CAMERA_ACTION (Free, free)
+
+#endif // NO_OVERPAINTING
\ No newline at end of file
--- a/src/types.cpp	Sun May 19 15:36:01 2013 +0300
+++ b/src/types.cpp	Tue May 21 14:02:18 2013 +0300
@@ -1,3 +1,21 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 Santeri Piippo
+ *  
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <assert.h>
 #include "common.h"
 #include "types.h"

mercurial