From 5d7fa9a32d93c934e359a8dcdfe5ad2174c2e12d Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Wed, 25 Sep 2024 20:32:12 +0200 Subject: [PATCH] remove draw mode flag in EditorModel --- source/Gui/CreatorWindow.cpp | 13 +++-- source/Gui/CreatorWindow.h | 3 ++ source/Gui/Definitions.h | 1 + source/Gui/EditorController.cpp | 8 ++-- source/Gui/EditorController.h | 4 +- source/Gui/EditorModel.cpp | 10 ---- source/Gui/EditorModel.h | 4 -- source/Gui/MainWindow.cpp | 2 +- .../Gui/SimulationInteractionController.cpp | 48 +++++++++++-------- source/Gui/SimulationInteractionController.h | 1 + 10 files changed, 51 insertions(+), 43 deletions(-) diff --git a/source/Gui/CreatorWindow.cpp b/source/Gui/CreatorWindow.cpp index f8868a764..43952f4a2 100644 --- a/source/Gui/CreatorWindow.cpp +++ b/source/Gui/CreatorWindow.cpp @@ -19,6 +19,7 @@ #include "Viewport.h" #include "EditorModel.h" #include "HelpStrings.h" +#include "SimulationInteractionController.h" namespace { @@ -40,6 +41,11 @@ _CreatorWindow::_CreatorWindow(EditorModel const& editorModel, SimulationControl { } +void _CreatorWindow::registerCyclicReferences(SimulationInteractionControllerWeakPtr const& simulationInteractionController) +{ + _simulationInteractionController = simulationInteractionController; +} + void _CreatorWindow::processIntern() { AlienImGui::SelectableToolbarButton(ICON_FA_SUN, _mode, CreationMode_CreateParticle, CreationMode_CreateParticle); @@ -148,13 +154,14 @@ void _CreatorWindow::processIntern() ImGui::EndChild(); AlienImGui::Separator(); + auto simInteractionController = _simulationInteractionController.lock(); if (_mode == CreationMode_Drawing) { - auto text = _editorModel->isDrawMode() ? "End drawing" : "Start drawing"; + auto text = simInteractionController->isDrawMode() ? "End drawing" : "Start drawing"; if (AlienImGui::Button(text)) { - _editorModel->setDrawMode(!_editorModel->isDrawMode()); + simInteractionController->setDrawMode(!simInteractionController->isDrawMode()); } } else { - _editorModel->setDrawMode(false); + simInteractionController->setDrawMode(false); if (AlienImGui::Button("Build")) { if (_mode == CreationMode_CreateCell) { createCell(); diff --git a/source/Gui/CreatorWindow.h b/source/Gui/CreatorWindow.h index fafabb836..57ea0f08a 100644 --- a/source/Gui/CreatorWindow.h +++ b/source/Gui/CreatorWindow.h @@ -22,6 +22,8 @@ class _CreatorWindow : public _AlienWindow public: _CreatorWindow(EditorModel const& editorModel, SimulationController const& simController); + void registerCyclicReferences(SimulationInteractionControllerWeakPtr const& simulationInteractionController); + void onDrawing(); void finishDrawing(); @@ -68,4 +70,5 @@ class _CreatorWindow : public _AlienWindow EditorModel _editorModel; SimulationController _simController; + SimulationInteractionControllerWeakPtr _simulationInteractionController; }; diff --git a/source/Gui/Definitions.h b/source/Gui/Definitions.h index 3878c7608..ef96cc826 100644 --- a/source/Gui/Definitions.h +++ b/source/Gui/Definitions.h @@ -35,6 +35,7 @@ using StatisticsWindow = std::shared_ptr<_StatisticsWindow>; class _SimulationInteractionController; using SimulationInteractionController = std::shared_ptr<_SimulationInteractionController>; +using SimulationInteractionControllerWeakPtr = std::weak_ptr<_SimulationInteractionController>; class _GpuSettingsDialog; using GpuSettingsDialog = std::shared_ptr<_GpuSettingsDialog>; diff --git a/source/Gui/EditorController.cpp b/source/Gui/EditorController.cpp index 1318f763f..25fd98b1e 100644 --- a/source/Gui/EditorController.cpp +++ b/source/Gui/EditorController.cpp @@ -35,9 +35,12 @@ _EditorController::_EditorController(SimulationController const& simController) _multiplierWindow = std::make_shared<_MultiplierWindow>(_editorModel, _simController); } -void _EditorController::registerCyclicReferences(UploadSimulationDialogWeakPtr const& uploadSimulationDialog) +void _EditorController::registerCyclicReferences( + UploadSimulationDialogWeakPtr const& uploadSimulationDialog, + SimulationInteractionControllerWeakPtr const& simulationInteractionController) { _genomeEditorWindow->registerCyclicReferences(uploadSimulationDialog); + _creatorWindow->registerCyclicReferences(simulationInteractionController); } bool _EditorController::isOn() const @@ -61,9 +64,6 @@ void _EditorController::process() _creatorWindow->process(); _multiplierWindow->process(); _genomeEditorWindow->process(); - if (!_creatorWindow->isOn()) { - _editorModel->setDrawMode(false); - } processInspectorWindows(); diff --git a/source/Gui/EditorController.h b/source/Gui/EditorController.h index bf483d1df..9e1b363f7 100644 --- a/source/Gui/EditorController.h +++ b/source/Gui/EditorController.h @@ -10,7 +10,9 @@ class _EditorController public: _EditorController(SimulationController const& simController); - void registerCyclicReferences(UploadSimulationDialogWeakPtr const& uploadSimulationDialog); + void registerCyclicReferences( + UploadSimulationDialogWeakPtr const& uploadSimulationDialog, + SimulationInteractionControllerWeakPtr const& simulationInteractionController); bool isOn() const; void setOn(bool value); diff --git a/source/Gui/EditorModel.cpp b/source/Gui/EditorModel.cpp index 10095a84c..6935daa2a 100644 --- a/source/Gui/EditorModel.cpp +++ b/source/Gui/EditorModel.cpp @@ -63,16 +63,6 @@ bool _EditorModel::areEntitiesInspected() const return !_inspectedEntityById.empty(); } -void _EditorModel::setDrawMode(bool value) -{ - _drawMode = value; -} - -bool _EditorModel::isDrawMode() const -{ - return _drawMode; -} - void _EditorModel::setPencilWidth(float value) { _pencilWidth = value; diff --git a/source/Gui/EditorModel.h b/source/Gui/EditorModel.h index 69aa3bf3e..59b7fc77f 100644 --- a/source/Gui/EditorModel.h +++ b/source/Gui/EditorModel.h @@ -24,9 +24,6 @@ class _EditorModel void setInspectedEntities(std::vector const& inspectedEntities); bool areEntitiesInspected() const; - void setDrawMode(bool value); - bool isDrawMode() const; - void setPencilWidth(float value); float getPencilWidth() const; @@ -44,7 +41,6 @@ class _EditorModel std::unordered_map _inspectedEntityById; - bool _drawMode = false; float _pencilWidth = 3.0f; int _defaultColorCode = 0; bool _rolloutToClusters = true; diff --git a/source/Gui/MainWindow.cpp b/source/Gui/MainWindow.cpp index fbb100a49..9fb5e0fc5 100644 --- a/source/Gui/MainWindow.cpp +++ b/source/Gui/MainWindow.cpp @@ -160,7 +160,7 @@ _MainWindow::_MainWindow(SimulationController const& simController, GuiLogger co //cyclic references _browserWindow->registerCyclicReferences(_loginDialog, _uploadSimulationDialog, _editSimulationDialog, _editorController->getGenomeEditorWindow()); _activateUserDialog->registerCyclicReferences(_createUserDialog); - _editorController->registerCyclicReferences(_uploadSimulationDialog); + _editorController->registerCyclicReferences(_uploadSimulationDialog, _simInteractionController); ifd::FileDialog::Instance().CreateTexture = [](uint8_t* data, int w, int h, char fmt) -> void* { GLuint tex; diff --git a/source/Gui/SimulationInteractionController.cpp b/source/Gui/SimulationInteractionController.cpp index ab96c50d6..023edec99 100644 --- a/source/Gui/SimulationInteractionController.cpp +++ b/source/Gui/SimulationInteractionController.cpp @@ -33,30 +33,14 @@ _SimulationInteractionController::_SimulationInteractionController( void _SimulationInteractionController::process() { - ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + viewport->Size.y - scale(120.0f))); - ImGui::SetNextWindowSize(ImVec2(scale(160.0f), scale(100.0f))); - - ImGuiWindowFlags windowFlags = 0 | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove - | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBackground; - ImGui::Begin("TOOLBAR", NULL, windowFlags); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor()); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor()); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor()); - - auto actionTexture = _editMode ? _editorOn.textureId : _editorOff.textureId; - if (ImGui::ImageButton((void*)(intptr_t)actionTexture, {scale(80.0f), scale(80.0f)}, {0, 0}, {1.0f, 1.0f})) { - _editMode = !_editMode; - _editorController->setOn(!_editorController->isOn()); - } - - ImGui::PopStyleColor(3); - ImGui::End(); + processEditWidget(); if (_editMode) { processSelectionRect(); } + if (!_editorController->getCreatorWindow()->isOn()) { + _drawMode = false; + } processEvents(); } @@ -101,6 +85,30 @@ std::optional _SimulationInteractionController::getPositionSelecti return Viewport::mapViewToWorldPosition({mousePos.x, mousePos.y}); } +void _SimulationInteractionController::processEditWidget() +{ + ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + viewport->Size.y - scale(120.0f))); + ImGui::SetNextWindowSize(ImVec2(scale(160.0f), scale(100.0f))); + + ImGuiWindowFlags windowFlags = 0 | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar + | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBackground; + ImGui::Begin("TOOLBAR", NULL, windowFlags); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor()); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor()); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor()); + + auto actionTexture = _editMode ? _editorOn.textureId : _editorOff.textureId; + if (ImGui::ImageButton((void*)(intptr_t)actionTexture, {scale(80.0f), scale(80.0f)}, {0, 0}, {1.0f, 1.0f})) { + _editMode = !_editMode; + _editorController->setOn(!_editorController->isOn()); + } + + ImGui::PopStyleColor(3); + ImGui::End(); +} + void _SimulationInteractionController::processEvents() { auto mousePos = ImGui::GetMousePos(); diff --git a/source/Gui/SimulationInteractionController.h b/source/Gui/SimulationInteractionController.h index b17ad0889..69805165f 100644 --- a/source/Gui/SimulationInteractionController.h +++ b/source/Gui/SimulationInteractionController.h @@ -24,6 +24,7 @@ class _SimulationInteractionController std::optional getPositionSelectionData() const; private: + void processEditWidget(); void processEvents(); void leftMouseButtonPressed(IntVector2D const& mousePos);