Wed, 20 Mar 2013 19:41:37 +0200
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
colors.cpp | file | annotate | diff | comparison | revisions | |
colors.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
icons/checkerboard.png | file | annotate | diff | comparison | revisions | |
icons/palette.png | file | annotate | diff | comparison | revisions | |
ldforge.pro | file | annotate | diff | comparison | revisions | |
main.cpp | file | annotate | diff | comparison | revisions | |
zz_colorSelectDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_colorSelectDialog.h | file | annotate | diff | comparison | revisions |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/colors.cpp Wed Mar 20 19:41:37 2013 +0200 @@ -0,0 +1,84 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` 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 "common.h" +#include "colors.h" + +// Placeholder static color table until I make an LDConfig.ldr parser +static TemporaryColorMeta g_LDColorInfo[] = { + {0, "Black", "#101010", 1.0}, + {1, "Blue", "#0000FF", 1.0}, + {2, "Green", "#008000", 1.0}, + {3, "Teal", "#008080", 1.0}, + {4, "Red", "#C00000", 1.0}, + {5, "Dark pink", "#C00060", 1.0}, + {6, "Brown", "#604000", 1.0}, + {7, "Gray", "#989890", 1.0}, + {8, "Dark Gray", "#6E6D62", 1.0}, + {9, "Light Blue", "#60A0C0", 1.0}, + {10, "Bright Green", "#40C040", 1.0}, + {11, "Cyan", "#00FFFF", 1.0}, + {12, "Salmon", "#FF8080", 1.0}, + {13, "Pink", "#FF2080", 1.0}, + {14, "Yellow", "#FFEE00", 1.0}, + {15, "White", "#FFFFFF", 1.0}, + {16, "Main Color", "#808080", 1.0}, + {17, "Light Green", "#80FF80", 1.0}, + {18, "Light Yellow", "#FFFF80", 1.0}, + {19, "Tan", "#EECC99", 1.0}, + {22, "Purple", "#A000A0", 1.0}, + {24, "Edge Color", "#000000", 1.0}, + {27, "Lime", "#00FF00", 1.0}, + {28, "Sand", "#989070", 1.0}, + {32, "Smoke", "#101010", 0.5}, + {33, "Trans Blue", "#0000FF", 0.5}, + {34, "Trans Green", "#008000", 0.5}, + {35, "Trans Teal", "#008080", 0.5}, + {36, "Trans Red", "#C00000", 0.5}, + {37, "Trans Dk Pink", "#C00060", 0.5}, + {38, "Trans Brown", "#604000", 0.5}, + {39, "Trans Gray", "#989890", 0.5}, + {40, "Trans Dk Gray", "#6E6D62", 0.5}, + {41, "Trans Lt Blue", "#60A0C0", 0.5}, + {42, "Trans Bt Green", "#40C040", 0.5}, + {43, "Trans Cyan", "#00FFFF", 0.5}, + {44, "Trans Salmon", "#FF8080", 0.5}, + {45, "Trans Pink", "#FF2080", 0.5}, + {46, "Trans Yellow", "#FFEE00", 0.5}, + {47, "Clear", "#FFFFFF", 0.5}, +}; + +color* g_LDColors[MAX_COLORS]; +static bool g_bColorsInit = false; + +void initColors () { + if (g_bColorsInit) + return; + + memset (g_LDColors, 0, sizeof g_LDColors); + for (ulong i = 0; i < sizeof g_LDColorInfo / sizeof *g_LDColorInfo; ++i) { + color* col = new color; + col->zColor = g_LDColorInfo[i].sColor; + col->zName = g_LDColorInfo[i].sName; + col->fAlpha = g_LDColorInfo[i].fAlpha; + + g_LDColors[g_LDColorInfo[i].dIndex] = col; + } + + g_bColorsInit = true; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/colors.h Wed Mar 20 19:41:37 2013 +0200 @@ -0,0 +1,42 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` 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/>. + */ + +#ifndef __COLORS_H__ +#define __COLORS_H__ + +#include "common.h" + +#define MAX_COLORS 512 + +class color { +public: + str zName; + str zColor; + float fAlpha; +}; + +typedef struct { + const short dIndex; + const char* sName, *sColor; + const float fAlpha; +} TemporaryColorMeta; + +void initColors (); +extern color* g_LDColors[MAX_COLORS]; + +#endif // __COLORS_H__ \ No newline at end of file
--- a/gui.cpp Wed Mar 20 13:41:08 2013 +0200 +++ b/gui.cpp Wed Mar 20 19:41:37 2013 +0200 @@ -27,6 +27,7 @@ #include "zz_configDialog.h" #include "zz_addObjectDialog.h" #include "misc.h" +#include "zz_colorSelectDialog.h" #define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ @@ -108,6 +109,8 @@ MAKE_ACTION (about, sAboutText, "ldforge", "Shows information about " APPNAME_DISPLAY ".") MAKE_ACTION (aboutQt, "About Qt", "aboutQt", "Shows information about Qt.") + MAKE_ACTION (testColorSelect, "Test colors", "palette", "Test the color selection dialog") + // Keyboard shortcuts qAct_new->setShortcut (Qt::CTRL | Qt::Key_N); qAct_open->setShortcut (Qt::CTRL | Qt::Key_O); @@ -203,6 +206,7 @@ qEditToolBar->addAction (qAct_inline); qEditToolBar->addAction (qAct_splitQuads); qEditToolBar->addAction (qAct_setContents); + qEditToolBar->addAction (qAct_testColorSelect); addToolBar (qEditToolBar); } @@ -541,4 +545,9 @@ void ForgeWindow::refresh () { buildObjList (); R->hardRefresh (); +} + +void ForgeWindow::slot_testColorSelect () { + ColorSelectDialog dlg; + dlg.exec (); } \ No newline at end of file
--- a/gui.h Wed Mar 20 13:41:08 2013 +0200 +++ b/gui.h Wed Mar 20 19:41:37 2013 +0200 @@ -62,6 +62,7 @@ QAction* qAct_splitQuads, *qAct_setContents, *qAct_inline; QAction* qAct_settings; QAction* qAct_help, *qAct_about, *qAct_aboutQt; + QAction* qAct_testColorSelect; ForgeWindow (); void buildObjList (); @@ -106,6 +107,8 @@ void slot_help (); void slot_about (); void slot_aboutQt (); + + void slot_testColorSelect (); }; enum {
--- a/ldforge.pro Wed Mar 20 13:41:08 2013 +0200 +++ b/ldforge.pro Wed Mar 20 19:41:37 2013 +0200 @@ -20,9 +20,11 @@ str.h \ config.h \ cfgdef.h \ + colors.h \ zz_setContentsDialog.h \ zz_configDialog.h \ - zz_addObjectDialog.h + zz_addObjectDialog.h \ + zz_colorSelectDialog.h \ SOURCES += bbox.cpp \ gldraw.cpp \ @@ -33,9 +35,11 @@ misc.cpp \ str.cpp \ config.cpp \ + colors.cpp \ zz_setContentsDialog.cpp \ zz_configDialog.cpp \ - zz_addObjectDialog.cpp + zz_addObjectDialog.cpp \ + zz_colorSelectDialog.cpp QMAKE_CXXFLAGS += -std=c++0x QT += opengl
--- a/main.cpp Wed Mar 20 13:41:08 2013 +0200 +++ b/main.cpp Wed Mar 20 19:41:37 2013 +0200 @@ -22,6 +22,7 @@ #include "bbox.h" #include "misc.h" #include "config.h" +#include "colors.h" vector<OpenFile*> g_LoadedFiles; OpenFile* g_CurrentFile = nullptr; @@ -39,6 +40,8 @@ printf ("failed to create configuration file!\n"); } + initColors (); + QApplication app (dArgC, saArgV); ForgeWindow* win = new ForgeWindow;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zz_colorSelectDialog.cpp Wed Mar 20 19:41:37 2013 +0200 @@ -0,0 +1,104 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` 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 "common.h" +#include "gui.h" +#include <qgraphicsscene.h> +#include <qgraphicsview.h> +#include <qicon.h> +#include <qboxlayout.h> +#include <qgraphicsitem.h> +#include "zz_colorSelectDialog.h" +#include "colors.h" + +static const short g_dNumColumns = 8; +static const short g_dNumRows = 10; +static const short g_dSquareSize = 32; +static const long g_lWidth = (g_dNumColumns * g_dSquareSize); +static const long g_lHeight = (g_dNumRows * g_dSquareSize); +static const long g_lMaxHeight = ((MAX_COLORS / g_dNumColumns) * g_dSquareSize); + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +ColorSelectDialog::ColorSelectDialog (QWidget* parent) { + qScene = new QGraphicsScene; + qView = new QGraphicsView (qScene); + + // not really an icon but eh + qScene->setBackgroundBrush (QPixmap ("icons/checkerboard.png")); + + qScene->setSceneRect (0, 0, g_lWidth, g_lMaxHeight); + qView->setSceneRect (0, 0, g_lWidth, g_lMaxHeight); + + const double fPenWidth = 1.0f; + QPen qPen (Qt::black, fPenWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); + + // Draw the color rectangles. + for (ulong i = 0; i < MAX_COLORS; ++i) { + color* meta = g_LDColors[i]; + if (!meta) + continue; + + const double x = (i % g_dNumColumns) * g_dSquareSize; + const double y = (i / g_dNumColumns) * g_dSquareSize; + const double w = (g_dSquareSize) - (fPenWidth / 2); + + QColor qColor (meta->zColor.chars ()); + qColor.setAlpha (meta->fAlpha * 255.0); + + uchar ucLuma = (0.2126f * qColor.red()) + + (0.7152f * qColor.green()) + (0.0722 * qColor.blue()); + bool bDark = (ucLuma < 80); + + qScene->addRect (x, y, w, w, qPen, qColor); + QGraphicsTextItem* qText = qScene->addText (str::mkfmt ("%lu", i).chars()); + qText->setDefaultTextColor ((bDark) ? Qt::white : Qt::black); + qText->setPos (x, y); + } + + IMPLEMENT_DIALOG_BUTTONS + + // Set the size of the view + const long lWidth = g_lWidth + 21; // HACK + qView->setMaximumWidth (lWidth); + qView->setMinimumWidth (lWidth); + qView->setMaximumHeight (g_lHeight); + qView->setMinimumHeight (g_lHeight); + + QVBoxLayout* qLayout = new QVBoxLayout; + qLayout->addWidget (qView); + qLayout->addWidget (qButtons); + setLayout (qLayout); + + setWindowIcon (QIcon ("icons/palette.png")); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +bool ColorSelectDialog::staticDialog (short& dValue, QWidget* parent) { + ColorSelectDialog dlg; + + if (dlg.exec ()) { + dValue = dValue; + return true; + } + + return false; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zz_colorSelectDialog.h Wed Mar 20 19:41:37 2013 +0200 @@ -0,0 +1,30 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` 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 <qdialog.h> +#include <qdialogbuttonbox.h> + +class ColorSelectDialog : public QDialog { +public: + explicit ColorSelectDialog (QWidget* parent = nullptr); + static bool staticDialog (short& dValue, QWidget* parent = nullptr); + + QGraphicsScene* qScene; + QGraphicsView* qView; + QDialogButtonBox* qButtons; +}; \ No newline at end of file