# HG changeset patch # User Teemu Piippo # Date 1681125491 -10800 # Node ID b2f9ded235a684054a2d9fb293fcdd35240c866f # Parent 57de8fab22371f56755e8759bddce05f0fd9f759 Grid scaling buttons now work diff -r 57de8fab2237 -r b2f9ded235a6 src/main.cpp --- a/src/main.cpp Mon Apr 10 12:40:49 2023 +0300 +++ b/src/main.cpp Mon Apr 10 14:18:11 2023 +0300 @@ -478,6 +478,30 @@ } } +static void update_model_grid_matrix(MainState* state) +{ + const glm::mat4 new_grid_matrix = state->mainWindow.gridMatrix->value(); + forEachModel(&state->documents, [&](const void*, const ModelData* data) + { + if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr) + { + data->gridLayer->setGridMatrix(new_grid_matrix); + data->tools->setGridMatrix(new_grid_matrix); + data->canvas->setModelViewOrigin(new_grid_matrix[3]); + data->canvas->update(); + } + }); +} + +static void set_grid_scale(MainState* state, const float factor) +{ + const glm::mat4 original = state->mainWindow.gridMatrix->value(); + const glm::mat4 unscaled = extractScaling(original).unscaled; + const glm::mat4 rescaled = factor * unscaled; + state->mainWindow.gridMatrix->setValue(rescaled); + update_model_grid_matrix(state); +} + int main(int argc, char *argv[]) { doQtRegistrations(); @@ -655,18 +679,9 @@ QObject::connect( state.mainWindow.gridMatrix, &MatrixEditor::valueChanged, - [&](const glm::mat4& newGridMatrix) + [&state] { - forEachModel(&state.documents, [&](const void*, const ModelData* data) - { - if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr) - { - data->gridLayer->setGridMatrix(newGridMatrix); - data->tools->setGridMatrix(newGridMatrix); - data->canvas->setModelViewOrigin(newGridMatrix[3]); - data->canvas->update(); - } - }); + update_model_grid_matrix(&state); } ); QObject::connect( @@ -677,6 +692,27 @@ cursor.removeSelectedText(); } ); + QObject::connect( + state.mainWindow.actionGridCoarse, + &QAction::triggered, + [&state]{ + set_grid_scale(&state, 5.0f); + } + ); + QObject::connect( + state.mainWindow.actionGridMedium, + &QAction::triggered, + [&state]{ + set_grid_scale(&state, 1.0f); + } + ); + QObject::connect( + state.mainWindow.actionGridFine, + &QAction::triggered, + [&state]{ + set_grid_scale(&state, 0.1f); + } + ); restoreSettings(&state); updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); const int result = app.exec(); diff -r 57de8fab2237 -r b2f9ded235a6 src/mainwindow.ui --- a/src/mainwindow.ui Mon Apr 10 12:40:49 2023 +0300 +++ b/src/mainwindow.ui Mon Apr 10 14:18:11 2023 +0300 @@ -482,34 +482,34 @@ - - true - Fine grid + + Set grid scaling to 0.1 + Ctrl+1 - - true - Medium grid + + Set grid scaling to 1 + Ctrl+2 - - true - Coarse grid + + Set grid scaling to 5 + Ctrl+3