Tue, 19 Mar 2013 16:36:08 +0200
Made the GL renderer background color configurable
cfgdef.h | file | annotate | diff | comparison | revisions | |
file.cpp | file | annotate | diff | comparison | revisions | |
gldraw.cpp | file | annotate | diff | comparison | revisions | |
gldraw.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions | |
zz_configDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_configDialog.h | file | annotate | diff | comparison | revisions | |
zz_setContentsDialog.cpp | file | annotate | diff | comparison | revisions |
--- a/cfgdef.h Tue Mar 19 15:32:16 2013 +0200 +++ b/cfgdef.h Tue Mar 19 16:36:08 2013 +0200 @@ -21,4 +21,7 @@ // --------------------------------------------------------- SECT (io, Files) -CFG (str, io, ldpath, "LDraw path", "") \ No newline at end of file +CFG (str, io, ldpath, "LDraw path", "") + +SECT (gl, GLRenderer) +CFG (str, gl, bgcolor, "Background color", "#CCCCD9") \ No newline at end of file
--- a/file.cpp Tue Mar 19 15:32:16 2013 +0200 +++ b/file.cpp Tue Mar 19 16:36:08 2013 +0200 @@ -352,6 +352,9 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void reloadAllSubfiles () { + if (!g_CurrentFile) + return; + // First, close all but the current open file. for (ushort i = 0; i < g_LoadedFiles.size(); ++i) if (g_LoadedFiles[i] != g_CurrentFile)
--- a/gldraw.cpp Tue Mar 19 15:32:16 2013 +0200 +++ b/gldraw.cpp Tue Mar 19 16:36:08 2013 +0200 @@ -23,34 +23,73 @@ #include "gldraw.h" #include "bbox.h" +#define GL_VERTEX(V) glVertex3d (V.x, V.y, V.z); + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= renderer::renderer (QWidget* parent) { parent = parent; // shhh, GCC fRotX = fRotY = fRotZ = 0.0; fZoom = 1.0; } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void renderer::initializeGL () { glLoadIdentity(); glMatrixMode (GL_MODELVIEW); - glClearColor (0.8f, 0.8f, 0.85f, 1.0f); + + setBackground (); + swapBuffers (); + glEnable (GL_DEPTH_TEST); glShadeModel (GL_SMOOTH); glEnable (GL_MULTISAMPLE); - CompileObjects (); + compileObjects (); } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void renderer::setBackground () { + QColor col (gl_bgcolor.value.chars()); + printf ("bgcolor: %s\n", gl_bgcolor.value.chars()); + if (col.isValid ()) { + printf ("was valid\n"); + glClearColor ( + ((double)col.red()) / 255.0f, + ((double)col.green()) / 255.0f, + ((double)col.blue()) / 255.0f, + 1.0f); + } else { + glClearColor (0.8f, 0.8f, 0.85f, 1.0f); + } +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void renderer::hardRefresh () { - CompileObjects (); + compileObjects (); paintGL (); } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void renderer::resizeGL (int w, int h) { glViewport (0, 0, w, h); } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void renderer::paintGL () { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + printf ("painting..\n"); glPushMatrix (); glTranslatef ( @@ -74,7 +113,10 @@ glPopMatrix (); } -void renderer::CompileObjects () { +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void renderer::compileObjects () { printf ("compile all objects\n"); objlist = glGenLists (1); @@ -91,9 +133,9 @@ glEndList (); } -#define GL_VERTEX(V) \ - glVertex3d (V.x, V.y, V.z); - +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void renderer::compileOneObject (LDObject* obj) { if (!obj) return; @@ -139,6 +181,9 @@ } } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void renderer::clampAngle (double& fAngle) { while (fAngle < 0) fAngle += 360.0; @@ -146,6 +191,9 @@ fAngle -= 360.0; } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void renderer::mouseMoveEvent (QMouseEvent *event) { int dx = event->x () - lastPos.x (); int dy = event->y () - lastPos.y ();
--- a/gldraw.h Tue Mar 19 15:32:16 2013 +0200 +++ b/gldraw.h Tue Mar 19 16:36:08 2013 +0200 @@ -27,9 +27,11 @@ Q_OBJECT public: - renderer(QWidget* parent = NULL); + renderer (QWidget* parent = nullptr); void hardRefresh (); - void CompileObjects (); + void compileObjects (); + void setBackground (); + double fRotX, fRotY, fRotZ; QPoint lastPos; double fZoom;
--- a/gui.cpp Tue Mar 19 15:32:16 2013 +0200 +++ b/gui.cpp Tue Mar 19 16:36:08 2013 +0200 @@ -26,6 +26,14 @@ #include "zz_setContentsDialog.h" #include "zz_configDialog.h" +#define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ + qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ + qAct_##OBJECT->setStatusTip (tr (DESCR)); \ + connect (qAct_##OBJECT, SIGNAL (triggered ()), this, SLOT (slot_##OBJECT ())); + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= ForgeWindow::ForgeWindow () { R = new renderer; @@ -61,11 +69,6 @@ resize (800, 600); } -#define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ - qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ - qAct_##OBJECT->setStatusTip (tr (DESCR)); \ - connect (qAct_##OBJECT, SIGNAL (triggered ()), this, SLOT (slot_##OBJECT ())); - // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= @@ -232,6 +235,9 @@ setWindowTitle (zTitle.chars()); } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void ForgeWindow::slot_new () { newFile (); } @@ -335,6 +341,9 @@ } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void ForgeWindow::slot_splitQuads () { if (qObjList->selectedItems().size() == 0) return; @@ -364,13 +373,12 @@ i++;// Skip past the second triangle } - printf ("build obj list\n"); - buildObjList (); - - printf ("refresh teh renderer\n"); - R->hardRefresh (); + refresh (); } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void ForgeWindow::slot_setContents () { if (qObjList->selectedItems().size() != 1) return; @@ -538,9 +546,7 @@ } // ============================================================================= -// ulong getInsertionPoint () -// -// Returns the index of where a new item should be placed at. +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ulong ForgeWindow::getInsertionPoint () { ulong ulIndex; @@ -559,6 +565,9 @@ return g_CurrentFile->objects.size(); } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void ForgeWindow::refresh () { buildObjList (); R->hardRefresh ();
--- a/ldtypes.cpp Tue Mar 19 15:32:16 2013 +0200 +++ b/ldtypes.cpp Tue Mar 19 16:36:08 2013 +0200 @@ -36,6 +36,8 @@ }; // ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= // LDObject constructors LDObject::LDObject () { commonInit ();
--- a/zz_configDialog.cpp Tue Mar 19 15:32:16 2013 +0200 +++ b/zz_configDialog.cpp Tue Mar 19 16:36:08 2013 +0200 @@ -21,11 +21,16 @@ #include "file.h" #include <qgridlayout.h> #include <qfiledialog.h> +#include <qcolordialog.h> + +ConfigDialog* g_ConfigDialog = nullptr; // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ConfigDialog::ConfigDialog (ForgeWindow* parent) : QDialog (parent) { + g_ConfigDialog = this; + qLDrawPath = new QLineEdit; qLDrawPath->setText (io_ldpath.value.chars()); @@ -36,6 +41,14 @@ connect (qLDrawPathFindButton, SIGNAL (clicked ()), this, SLOT (slot_findLDrawPath ())); + qGLBackgroundLabel = new QLabel ("Background color:"); + qGLBackgroundButton = new QPushButton; + qGLBackgroundButton->setIcon (QIcon ("icons/colorselect.png")); + qGLBackgroundButton->setAutoFillBackground (true); + setButtonBackground (qGLBackgroundButton, gl_bgcolor.value); + connect (qGLBackgroundButton, SIGNAL (clicked()), + this, SLOT (slot_setGLBackground ())); + qButtons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect (qButtons, SIGNAL (accepted ()), this, SLOT (accept ())); connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ())); @@ -44,6 +57,10 @@ layout->addWidget (qLDrawPathLabel, 0, 0); layout->addWidget (qLDrawPath, 0, 1); layout->addWidget (qLDrawPathFindButton, 0, 2); + + layout->addWidget (qGLBackgroundLabel, 1, 0); + layout->addWidget (qGLBackgroundButton, 1, 1); + layout->addWidget (qButtons, 2, 1, 1, 2); setLayout (layout); @@ -54,6 +71,13 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= +ConfigDialog::~ConfigDialog() { + g_ConfigDialog = nullptr; +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void ConfigDialog::slot_findLDrawPath () { str zDir = QFileDialog::getExistingDirectory (this, "Choose LDraw directory", qLDrawPath->text()); @@ -65,24 +89,42 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= +void ConfigDialog::slot_setGLBackground () { + QColorDialog dlg (QColor (gl_bgcolor.value.chars())); + + if (dlg.exec ()) { + uchar r = dlg.currentColor ().red (), + g = dlg.currentColor ().green (), + b = dlg.currentColor ().blue (); + gl_bgcolor.value.format ("#%.2X%.2X%.2X", r, g, b); + setButtonBackground (qGLBackgroundButton, gl_bgcolor.value); + } +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void ConfigDialog::setButtonBackground (QPushButton* qButton, str zValue) { + qButton->setStyleSheet ( + str::mkfmt ("background-color: %s", zValue.chars()).chars() + ); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void ConfigDialog::staticDialog (ForgeWindow* window) { ConfigDialog dlg (window); - ulong ulChange = 0; if (dlg.exec ()) { - str zOldLDPath = io_ldpath; io_ldpath = dlg.qLDrawPath->text(); - if (io_ldpath != zOldLDPath) { - ulChange |= (1 << 1); - } + // Save the config + config::save (); - if (ulChange != 0) - config::save (); + // Reload all subfiles + reloadAllSubfiles (); - if (ulChange & (1 << 1)) { - // Reload all subfiles - reloadAllSubfiles (); - } + window->R->setBackground (); } } \ No newline at end of file
--- a/zz_configDialog.h Tue Mar 19 15:32:16 2013 +0200 +++ b/zz_configDialog.h Tue Mar 19 16:36:08 2013 +0200 @@ -27,15 +27,21 @@ Q_OBJECT public: - QLabel* qLDrawPathLabel; + QLabel* qLDrawPathLabel, *qGLBackgroundLabel; QLineEdit* qLDrawPath; QPushButton* qLDrawPathFindButton; + QPushButton* qGLBackgroundButton; QDialogButtonBox* qButtons; ConfigDialog (ForgeWindow* parent); + ~ConfigDialog (); static void staticDialog (ForgeWindow* window); +private: + void setButtonBackground (QPushButton* qButton, str zValue); + private slots: void slot_findLDrawPath (); + void slot_setGLBackground (); }; \ No newline at end of file
--- a/zz_setContentsDialog.cpp Tue Mar 19 15:32:16 2013 +0200 +++ b/zz_setContentsDialog.cpp Tue Mar 19 16:36:08 2013 +0200 @@ -78,11 +78,9 @@ // Reinterpret it from the text of the input field obj = parseLine (dlg.qContents->text ().toStdString ().c_str ()); - oldobj->replace (obj); // Rebuild stuff after this - parent->buildObjList (); - parent->R->hardRefresh (); + parent->refresh (); } } \ No newline at end of file