Skip to content

Commit

Permalink
remove draw mode flag in EditorModel
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 25, 2024
1 parent 622e30f commit 5d7fa9a
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 43 deletions.
13 changes: 10 additions & 3 deletions source/Gui/CreatorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Viewport.h"
#include "EditorModel.h"
#include "HelpStrings.h"
#include "SimulationInteractionController.h"

namespace
{
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions source/Gui/CreatorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -68,4 +70,5 @@ class _CreatorWindow : public _AlienWindow

EditorModel _editorModel;
SimulationController _simController;
SimulationInteractionControllerWeakPtr _simulationInteractionController;
};
1 change: 1 addition & 0 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
8 changes: 4 additions & 4 deletions source/Gui/EditorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -61,9 +64,6 @@ void _EditorController::process()
_creatorWindow->process();
_multiplierWindow->process();
_genomeEditorWindow->process();
if (!_creatorWindow->isOn()) {
_editorModel->setDrawMode(false);
}

processInspectorWindows();

Expand Down
4 changes: 3 additions & 1 deletion source/Gui/EditorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions source/Gui/EditorModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions source/Gui/EditorModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class _EditorModel
void setInspectedEntities(std::vector<CellOrParticleDescription> const& inspectedEntities);
bool areEntitiesInspected() const;

void setDrawMode(bool value);
bool isDrawMode() const;

void setPencilWidth(float value);
float getPencilWidth() const;

Expand All @@ -44,7 +41,6 @@ class _EditorModel

std::unordered_map<uint64_t, CellOrParticleDescription> _inspectedEntityById;

bool _drawMode = false;
float _pencilWidth = 3.0f;
int _defaultColorCode = 0;
bool _rolloutToClusters = true;
Expand Down
2 changes: 1 addition & 1 deletion source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 28 additions & 20 deletions source/Gui/SimulationInteractionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -101,6 +85,30 @@ std::optional<RealVector2D> _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();
Expand Down
1 change: 1 addition & 0 deletions source/Gui/SimulationInteractionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class _SimulationInteractionController
std::optional<RealVector2D> getPositionSelectionData() const;

private:
void processEditWidget();
void processEvents();

void leftMouseButtonPressed(IntVector2D const& mousePos);
Expand Down

0 comments on commit 5d7fa9a

Please sign in to comment.