src/main.cpp

changeset 370
b2f9ded235a6
parent 368
9444de9762c3
child 371
171d3f9638a9
--- 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();

mercurial