diff options
-rw-r--r-- | GLView.h | 39 | ||||
-rw-r--r-- | Preferences.cc | 1 | ||||
-rw-r--r-- | Preferences.h | 3 | ||||
-rw-r--r-- | glview.cc | 21 | ||||
-rw-r--r-- | mainwin.cc | 24 |
5 files changed, 57 insertions, 31 deletions
@@ -12,34 +12,49 @@ class GLView : public QGLWidget { Q_OBJECT + Q_PROPERTY(bool showAxes READ showAxes WRITE setShowAxes); + Q_PROPERTY(bool showCrosshairs READ showCrosshairs WRITE setShowCrosshairs); + Q_PROPERTY(bool orthoMode READ orthoMode WRITE setOrthoMode); public: - void (*renderfunc)(void*); - void *renderfunc_vp; - - bool orthomode; - bool showaxes; - bool showcrosshairs; + GLView(QWidget *parent = NULL); + void setRenderFunc(void (*func)(void*), void *userdata); +#ifdef ENABLE_OPENCSG + bool hasOpenCSGSupport() { return this->opencsg_support; } +#endif + // Properties + bool showAxes() const { return this->showaxes; } + void setShowAxes(bool enabled) { this->showaxes = enabled; } + bool showCrosshairs() const { return this->showcrosshairs; } + void setShowCrosshairs(bool enabled) { this->showcrosshairs = enabled; } + bool orthoMode() const { return this->orthomode; } + void setOrthoMode(bool enabled) { this->orthomode = enabled; } - double viewer_distance; + QLabel *statusLabel; double object_rot_x; double object_rot_y; double object_rot_z; double object_trans_x; double object_trans_y; double object_trans_z; + GLint shaderinfo[11]; + +private: + void (*renderfunc)(void*); + void *renderfunc_vp; + + bool showaxes; + bool showcrosshairs; + bool orthomode; + + double viewer_distance; double w_h_ratio; - GLint shaderinfo[11]; - QLabel *statusLabel; #ifdef ENABLE_OPENCSG bool opencsg_support; #endif - GLView(QWidget *parent = NULL); - -protected: bool mouse_drag_active; int last_mouse_x; int last_mouse_y; diff --git a/Preferences.cc b/Preferences.cc index cf3ac55..f098ab4 100644 --- a/Preferences.cc +++ b/Preferences.cc @@ -35,6 +35,7 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent) this->colormap[CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00); this->colormap[CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00); this->colormap[CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00); + this->colormap[CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00); QActionGroup *group = new QActionGroup(this); group->addAction(prefsAction3DView); diff --git a/Preferences.h b/Preferences.h index 88cd590..96ae4ca 100644 --- a/Preferences.h +++ b/Preferences.h @@ -21,7 +21,8 @@ public: CGAL_FACE_BACK_COLOR, CGAL_EDGE_FRONT_COLOR, CGAL_EDGE_BACK_COLOR, - CGAL_EDGE_2D_COLOR + CGAL_EDGE_2D_COLOR, + CROSSHAIR_COLOR }; void setColor(RenderColor idx, const QColor &color) { this->colormap[idx] = color; } const QColor &color(RenderColor idx) { return this->colormap[idx]; } @@ -20,6 +20,7 @@ #include "openscad.h" #include "GLView.h" +#include "Preferences.h" #include <QApplication> #include <QWheelEvent> @@ -61,7 +62,11 @@ GLView::GLView(QWidget *parent) : QGLWidget(parent) #endif } -extern GLint e1, e2, e3; +void GLView::setRenderFunc(void (*func)(void*), void *userdata) +{ + this->renderfunc = func; + this->renderfunc_vp = userdata; +} void GLView::initializeGL() { @@ -71,7 +76,8 @@ void GLView::initializeGL() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor(1.0, 1.0, 0.9, 0.0); + const QColor &col = Preferences::inst()->color(Preferences::BACKGROUND_COLOR); + glClearColor(col.redF(), col.greenF(), col.blueF(), 0.0); #ifdef ENABLE_OPENCSG GLenum err = glewInit(); @@ -234,7 +240,8 @@ void GLView::paintGL() if (showcrosshairs) { glLineWidth(3); - glColor3d(0.5, 0.0, 0.0); + const QColor &col = Preferences::inst()->color(Preferences::CROSSHAIR_COLOR); + glColor3f(col.redF(), col.greenF(), col.blueF()); glBegin(GL_LINES); for (double xf = -1; xf <= +1; xf += 2) for (double yf = -1; yf <= +1; yf += 2) { @@ -247,6 +254,7 @@ void GLView::paintGL() glTranslated(object_trans_x, object_trans_y, object_trans_z); + // Large gray axis cross inline with the model if (showaxes) { glLineWidth(1); @@ -271,6 +279,8 @@ void GLView::paintGL() if (renderfunc) renderfunc(renderfunc_vp); + // Small axis cross in the lower left corner + // FIXME: Adjust color to keep contrast with background if (showaxes) { glDepthFunc(GL_ALWAYS); @@ -290,10 +300,12 @@ void GLView::paintGL() glRotated(object_rot_z, 0.0, 0.0, 1.0); glLineWidth(1); - glColor3d(0.0, 0.0, 1.0); glBegin(GL_LINES); + glColor3d(1.0, 0.0, 0.0); glVertex3d(0, 0, 0); glVertex3d(10, 0, 0); + glColor3d(0.0, 1.0, 0.0); glVertex3d(0, 0, 0); glVertex3d(0, 10, 0); + glColor3d(0.0, 0.0, 1.0); glVertex3d(0, 0, 0); glVertex3d(0, 0, 10); glEnd(); @@ -326,6 +338,7 @@ void GLView::paintGL() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + // FIXME: Adjust color to keep contrast with background glColor3d(0.0, 0.0, 0.0); glBegin(GL_LINES); // X Label @@ -214,7 +214,7 @@ MainWindow::MainWindow(const char *filename) this->viewActionOpenCSG->setVisible(false); #else connect(this->viewActionOpenCSG, SIGNAL(triggered()), this, SLOT(viewModeOpenCSG())); - if (!screen->opencsg_support) { + if (!screen->hasOpenCSGSupport()) { this->viewActionOpenCSG->setEnabled(false); } #endif @@ -1293,11 +1293,10 @@ static void renderGLviaOpenCSG(void *vp) */ void MainWindow::viewModeOpenCSG() { - if (screen->opencsg_support) { + if (screen->hasOpenCSGSupport()) { viewModeActionsUncheck(); viewActionOpenCSG->setChecked(true); - screen->renderfunc = renderGLviaOpenCSG; - screen->renderfunc_vp = this; + screen->setRenderFunc(renderGLviaOpenCSG, this); screen->updateGL(); } else { viewModeThrownTogether(); @@ -1426,8 +1425,7 @@ void MainWindow::viewModeCGALSurface() { viewModeActionsUncheck(); viewActionCGALSurfaces->setChecked(true); - screen->renderfunc = renderGLviaCGAL; - screen->renderfunc_vp = this; + screen->setRenderFunc(renderGLviaCGAL, this); screen->updateGL(); } @@ -1435,8 +1433,7 @@ void MainWindow::viewModeCGALGrid() { viewModeActionsUncheck(); viewActionCGALGrid->setChecked(true); - screen->renderfunc = renderGLviaCGAL; - screen->renderfunc_vp = this; + screen->setRenderFunc(renderGLviaCGAL, this); screen->updateGL(); } @@ -1526,8 +1523,7 @@ void MainWindow::viewModeThrownTogether() { viewModeActionsUncheck(); viewActionThrownTogether->setChecked(true); - screen->renderfunc = renderGLThrownTogether; - screen->renderfunc_vp = this; + screen->setRenderFunc(renderGLThrownTogether, this); screen->updateGL(); } @@ -1538,13 +1534,13 @@ void MainWindow::viewModeShowEdges() void MainWindow::viewModeShowAxes() { - screen->showaxes = viewActionShowAxes->isChecked(); + screen->setShowAxes(viewActionShowAxes->isChecked()); screen->updateGL(); } void MainWindow::viewModeShowCrosshairs() { - screen->showcrosshairs = viewActionShowCrosshairs->isChecked(); + screen->setShowCrosshairs(viewActionShowCrosshairs->isChecked()); screen->updateGL(); } @@ -1649,7 +1645,7 @@ void MainWindow::viewPerspective() { viewActionPerspective->setChecked(true); viewActionOrthogonal->setChecked(false); - screen->orthomode = false; + screen->setOrthoMode(false); screen->updateGL(); } @@ -1657,7 +1653,7 @@ void MainWindow::viewOrthogonal() { viewActionPerspective->setChecked(false); viewActionOrthogonal->setChecked(true); - screen->orthomode = true; + screen->setOrthoMode(true); screen->updateGL(); } |