# HG changeset patch # User Teemu Piippo # Date 1655754031 -10800 # Node ID 959469a7e149dbc1e1c24219a786bc58c70e2adb # Parent 16855456992dd5e4ffaa97328e9e2d78ff316252 Make the grid black on bright backgrounds diff -r 16855456992d -r 959469a7e149 src/gl/gridprogram.cpp --- 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]); } diff -r 16855456992d -r 959469a7e149 src/gl/gridprogram.h --- 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; diff -r 16855456992d -r 959469a7e149 src/main.cpp --- 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; 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(renderPreferences.drawAxes); setSetting(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()); 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};