Mon, 20 Jun 2022 22:40:31 +0300
Make the grid black on bright backgrounds
src/gl/gridprogram.cpp | file | annotate | diff | comparison | revisions | |
src/gl/gridprogram.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions |
--- a/src/gl/gridprogram.cpp Mon Jun 20 22:22:15 2022 +0300 +++ b/src/gl/gridprogram.cpp Mon Jun 20 22:40:31 2022 +0300 @@ -17,6 +17,7 @@ */ #include "gridprogram.h" +#include "partrenderer.h" constexpr char vertexShaderSource[] = R"( #version 330 core @@ -82,6 +83,11 @@ } } +void GridLayer::settingsChanged() +{ + this->setGridColor(this->renderer->isDark() ? Qt::white : Qt::black); +} + void GridLayer::initializeGL() { this->shader.initialize( @@ -101,6 +107,7 @@ constexpr auto data = calcGridData<50>(); this->shader.setUniformVector("gridColor", this->gridColor); this->setGridMatrix(this->gridMatrix); + this->settingsChanged(); this->shader.bufferData(data.data(), data.size(), sizeof data[0]); }
--- a/src/gl/gridprogram.h Mon Jun 20 22:22:15 2022 +0300 +++ b/src/gl/gridprogram.h Mon Jun 20 22:40:31 2022 +0300 @@ -29,6 +29,7 @@ public: void setGridMatrix(const glm::mat4& newGridMatrix); void setGridColor(const QColor& newGridColor); + void settingsChanged(); protected: void initializeGL() override; void paintGL() override;
--- a/src/main.cpp Mon Jun 20 22:22:15 2022 +0300 +++ b/src/main.cpp Mon Jun 20 22:40:31 2022 +0300 @@ -49,6 +49,20 @@ std::unique_ptr<GridLayer> gridLayer; Model* model; }; + +class Signal final : public QObject +{ + Q_OBJECT +public: + Signal() : QObject{}{} + virtual ~Signal(){} + void emit() + { + Q_EMIT this->triggered(); + } +Q_SIGNALS: + void triggered(); +}; #include "main.moc" static void doQtRegistrations() @@ -359,6 +373,7 @@ ColorTable colorTable; gl::RenderPreferences renderPreferences; MessageLog messageLog; + Signal settingsChanged; ui.setupUi(&mainWindow); const uiutilities::KeySequenceMap defaultKeyboardShortcuts = uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); @@ -370,6 +385,7 @@ setSetting<Setting::DrawAxes>(renderPreferences.drawAxes); setSetting<Setting::Wireframe>(renderPreferences.wireframe); libraries.storeToSettings(); + settingsChanged.emit(); }; const auto updateRecentlyOpenedDocumentsMenu = [&]{ rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow); @@ -406,6 +422,7 @@ updateRenderPreferences(&ui, &renderPreferences, &documents); ui.mdiArea->setViewMode(setting<Setting::ViewMode>()); ui.retranslateUi(&mainWindow); + settingsChanged.emit(); }; const auto addRecentlyOpenedFile = [&](const QString& path){ constexpr int maxRecentlyOpenedFiles = 10; @@ -480,6 +497,12 @@ } } }); + QObject::connect(&settingsChanged, &Signal::triggered, [modelId, &documents]{ + ModelData* data = findModelData(&documents, modelId); + if (data != nullptr) { + data->gridLayer->settingsChanged(); + } + }); QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage); const QFileInfo fileInfo{*documents.modelPath(modelId)}; ModelSubWindow* subWindow = new ModelSubWindow{modelId, ui.mdiArea};