Skip to content

Commit

Permalink
+ cursor for position selection and editing changed
Browse files Browse the repository at this point in the history
+ tooltip for revert and position select button
+ setting 20 creatures per colony
  • Loading branch information
chrxh committed Sep 26, 2024
1 parent a490a7d commit be4d5a7
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 65 deletions.
15 changes: 9 additions & 6 deletions source/Gui/AlienImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@

namespace
{
bool revertButton(std::string const& id)
{
return ImGui::Button((ICON_FA_UNDO "##" + id).c_str());
}

auto constexpr HoveredTimer = 0.5f;
}

Expand Down Expand Up @@ -79,6 +74,7 @@ bool AlienImGui::SliderFloat2(SliderFloat2Parameters const& parameters, float& v
if (AlienImGui::SelectableButton(AlienImGui::SelectableButtonParameters().name(ICON_FA_CROSSHAIRS), mousePickerEnabled)) {
parameters._setMousePickerEnabledFunc.value()(mousePickerEnabled);
}
AlienImGui::Tooltip("Select a position with the mouse");
if (parameters._getMousePickerEnabledFunc.value()()) {
if (auto pos = parameters._getMousePickerPositionFunc.value()()) {
valueX = pos->x;
Expand All @@ -92,7 +88,7 @@ bool AlienImGui::SliderFloat2(SliderFloat2Parameters const& parameters, float& v
ImGui::SameLine();

ImGui::BeginDisabled(valueX == parameters._defaultValue->x && valueY == parameters._defaultValue->y);
if (revertButton(parameters._name)) {
if (AlienImGui::revertButton(parameters._name)) {
valueX = parameters._defaultValue->x;
valueY = parameters._defaultValue->y;
}
Expand Down Expand Up @@ -2000,6 +1996,13 @@ ImVec2 AlienImGui::RotationCenter(ImDrawList* drawList)
return ImVec2((l.x + u.x) / 2, (l.y + u.y) / 2); // or use _ClipRectStack?
}

bool AlienImGui::revertButton(std::string const& id)
{
auto result = ImGui::Button((ICON_FA_UNDO "##" + id).c_str());
AlienImGui::Tooltip("Revert changes");
return result;
}

namespace
{
ImVec2 operator-(const ImVec2& l, const ImVec2& r)
Expand Down
2 changes: 2 additions & 0 deletions source/Gui/AlienImGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ class AlienImGui

static ImVec2 RotationCenter(ImDrawList* drawList);

static bool revertButton(std::string const& id);

static std::unordered_set<unsigned int> _basicSilderExpanded;
static int _rotationStartIndex;
static std::unordered_map<unsigned int, int> _neuronSelectedInput;
Expand Down
3 changes: 1 addition & 2 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ _MainWindow::_MainWindow(SimulationController const& simController, GuiLogger co
std::make_shared<_EditorController>(_simController);
_simulationView = std::make_shared<_SimulationView>(_simController);
_simInteractionController = std::make_shared<_SimulationInteractionController>(_simController, _editorController, _simulationView);
simulationViewPtr = _simulationView.get();
_statisticsWindow = std::make_shared<_StatisticsWindow>(_simController);
_temporalControlWindow = std::make_shared<_TemporalControlWindow>(_simController, _statisticsWindow);
_spatialControlWindow = std::make_shared<_SpatialControlWindow>(_simController, _temporalControlWindow);
_radiationSourcesWindow = std::make_shared<_RadiationSourcesWindow>(_simController);
_radiationSourcesWindow = std::make_shared<_RadiationSourcesWindow>(_simController, _simInteractionController);
_simulationParametersWindow = std::make_shared<_SimulationParametersWindow>(_simController, _radiationSourcesWindow, _simInteractionController);
_gpuSettingsDialog = std::make_shared<_GpuSettingsDialog>(_simController);
_startupController = std::make_shared<_StartupController>(_simController, _temporalControlWindow);
Expand Down
62 changes: 27 additions & 35 deletions source/Gui/RadiationSourcesWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

#include "RadiationSourcesWindow.h"
#include "StyleRepository.h"
#include "SimulationInteractionController.h"

namespace
{
auto const RightColumnWidth = 120.0f;
}

_RadiationSourcesWindow::_RadiationSourcesWindow(SimulationController const& simController)
_RadiationSourcesWindow::_RadiationSourcesWindow(SimulationController const& simController, SimulationInteractionController const& simInteractionController)
: _AlienWindow("Radiation sources", "windows.radiation sources", false)
, _simController(simController)
, _simInteractionController(simInteractionController)
{}

void _RadiationSourcesWindow::processIntern()
Expand Down Expand Up @@ -80,42 +82,32 @@ bool _RadiationSourcesWindow::processTab(int index)
}
}

AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Position X")
.textWidth(RightColumnWidth)
.min(0)
.max(toFloat(worldSize.x))
.format("%.0f")
.defaultValue(&origSource.posX),
&source.posX);
AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Position Y")
auto getMousePickerEnabledFunc = [&]() { return _simInteractionController->isPositionSelectionMode(); };
auto setMousePickerEnabledFunc = [&](bool value) { _simInteractionController->setPositionSelectionMode(value); };
auto getMousePickerPositionFunc = [&]() { return _simInteractionController->getPositionSelectionData(); };
AlienImGui::SliderFloat2(
AlienImGui::SliderFloat2Parameters()
.name("Position")
.textWidth(RightColumnWidth)
.min(0)
.max(toFloat(worldSize.y))
.format("%.0f")
.defaultValue(&origSource.posY),
&source.posY);
AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Velocity X")
.textWidth(RightColumnWidth)
.min(-4.0f)
.max(4.0f)
.format("%.3f")
.defaultValue(&origSource.velX),
&source.velX);
AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Velocity Y")
.min({0, 0})
.max(toRealVector2D(worldSize))
.defaultValue(RealVector2D{origSource.posX, origSource.posY})
.format("%.2f")
.getMousePickerEnabledFunc(getMousePickerEnabledFunc)
.setMousePickerEnabledFunc(setMousePickerEnabledFunc)
.getMousePickerPositionFunc(getMousePickerPositionFunc),
source.posX,
source.posY);
AlienImGui::SliderFloat2(
AlienImGui::SliderFloat2Parameters()
.name("Velocity")
.textWidth(RightColumnWidth)
.min(-4.0f)
.max(4.0f)
.format("%.3f")
.defaultValue(&origSource.velY),
&source.velY);
.min({-4.0f, -4.0f})
.max({4.0f, 4.0f})
.defaultValue(RealVector2D{origSource.velX, origSource.velY})
.format("%.2f"),
source.velX,
source.velY);
AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Angle")
Expand Down
3 changes: 2 additions & 1 deletion source/Gui/RadiationSourcesWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class _RadiationSourcesWindow : public _AlienWindow
{
public:
_RadiationSourcesWindow(SimulationController const& simController);
_RadiationSourcesWindow(SimulationController const& simController, SimulationInteractionController const& simInteractionController);

private:
void processIntern() override;
Expand All @@ -21,4 +21,5 @@ class _RadiationSourcesWindow : public _AlienWindow
void validationAndCorrection(RadiationSource& source) const;

SimulationController _simController;
SimulationInteractionController _simInteractionController;
};
59 changes: 49 additions & 10 deletions source/Gui/SimulationInteractionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,56 @@ void _SimulationInteractionController::drawCursor()
ImGui::SetMouseCursor(ImGuiMouseCursor_None);
}

if (_modes.positionSelectionMode || _modes.editMode) {
// position selection cursor
if (_modes.positionSelectionMode) {
auto cursorSize = scale(CursorRadius);

// shadow
drawList->AddRectFilled(
{mousePos.x - scale(2.0f), mousePos.y - cursorSize}, {mousePos.x + scale(2.0f), mousePos.y - cursorSize / 2}, Const::CursorShadowColor);
drawList->AddRectFilled(
{mousePos.x - scale(2.0f), mousePos.y + cursorSize / 2}, {mousePos.x + scale(2.0f), mousePos.y + cursorSize}, Const::CursorShadowColor);
drawList->AddRectFilled(
{mousePos.x - cursorSize, mousePos.y - scale(2.0f)}, {mousePos.x - cursorSize / 2, mousePos.y + scale(2.0f)}, Const::CursorShadowColor);
drawList->AddRectFilled(
{mousePos.x + cursorSize / 2, mousePos.y - scale(2.0f)}, {mousePos.x + cursorSize, mousePos.y + scale(2.0f)}, Const::CursorShadowColor);

// foreground
drawList->AddRectFilled(
{mousePos.x - scale(1.0f), mousePos.y - cursorSize}, {mousePos.x + scale(1.0f), mousePos.y - cursorSize / 2}, Const::CursorColor);
drawList->AddRectFilled(
{mousePos.x - scale(1.0f), mousePos.y + cursorSize / 2}, {mousePos.x + scale(1.0f), mousePos.y + cursorSize}, Const::CursorColor);
drawList->AddRectFilled(
{mousePos.x - cursorSize, mousePos.y - scale(1.0f)}, {mousePos.x - cursorSize / 2, mousePos.y + scale(1.0f)}, Const::CursorColor);
drawList->AddRectFilled(
{mousePos.x + cursorSize / 2, mousePos.y - scale(1.0f)}, {mousePos.x + cursorSize, mousePos.y + scale(1.0f)}, Const::CursorColor);
return;
}

// editing cursors
if (_modes.editMode) {
if (!_modes.drawMode || _simController->isSimulationRunning()) {
auto cursorSize = scale(CursorRadius);

//shadow
// shadow
drawList->AddRectFilled(
{mousePos.x - scale(2.0f), mousePos.y - cursorSize}, {mousePos.x + scale(2.0f), mousePos.y - cursorSize / 2}, Const::CursorShadowColor);
drawList->AddRectFilled(
{mousePos.x - scale(2.0f), mousePos.y - cursorSize}, {mousePos.x + scale(2.0f), mousePos.y + cursorSize}, Const::CursorShadowColor);
{mousePos.x - scale(2.0f), mousePos.y + cursorSize / 2}, {mousePos.x + scale(2.0f), mousePos.y + cursorSize}, Const::CursorShadowColor);
drawList->AddRectFilled(
{mousePos.x - cursorSize, mousePos.y - scale(2.0f)}, {mousePos.x + cursorSize, mousePos.y + scale(2.0f)}, Const::CursorShadowColor);
{mousePos.x - cursorSize, mousePos.y - scale(2.0f)}, {mousePos.x - cursorSize / 2, mousePos.y + scale(2.0f)}, Const::CursorShadowColor);
drawList->AddRectFilled(
{mousePos.x + cursorSize / 2, mousePos.y - scale(2.0f)}, {mousePos.x + cursorSize, mousePos.y + scale(2.0f)}, Const::CursorShadowColor);

//foreground
// foreground
drawList->AddRectFilled(
{mousePos.x - scale(1.0f), mousePos.y - cursorSize}, {mousePos.x + scale(1.0f), mousePos.y - cursorSize / 2}, Const::CursorColor);
drawList->AddRectFilled(
{mousePos.x - scale(1.0f), mousePos.y - cursorSize}, {mousePos.x + scale(1.0f), mousePos.y + cursorSize}, Const::CursorColor);
{mousePos.x - scale(1.0f), mousePos.y + cursorSize / 2}, {mousePos.x + scale(1.0f), mousePos.y + cursorSize}, Const::CursorColor);
drawList->AddRectFilled(
{mousePos.x - cursorSize, mousePos.y - scale(1.0f)}, {mousePos.x + cursorSize, mousePos.y + scale(1.0f)}, Const::CursorColor);
{mousePos.x - cursorSize, mousePos.y - scale(1.0f)}, {mousePos.x - cursorSize / 2, mousePos.y + scale(1.0f)}, Const::CursorColor);
drawList->AddRectFilled(
{mousePos.x + cursorSize / 2, mousePos.y - scale(1.0f)}, {mousePos.x + cursorSize, mousePos.y + scale(1.0f)}, Const::CursorColor);
} else {
auto zoom = Viewport::getZoomFactor();
auto radius = editorModel->getPencilWidth() * zoom;
Expand All @@ -367,18 +402,22 @@ void _SimulationInteractionController::drawCursor()
AlienImGui::ConvertRGBtoHSV(color, h, s, v);
drawList->AddCircleFilled(mousePos, radius, ImColor::HSV(h, s, v, 0.6f));
}
} else {
return;
}

// navigation cursor
if (!_modes.editMode) {
auto cursorSize = scale(CursorRadius);

//shadow
// shadow
drawList->AddCircle(mousePos, cursorSize / 2, Const::CursorShadowColor, 0, scale(4.0f));
drawList->AddLine(
{mousePos.x + sqrtf(2.0f) / 2.0f * cursorSize / 2, mousePos.y + sqrtf(2.0f) / 2.0f * cursorSize / 2},
{mousePos.x + cursorSize, mousePos.y + cursorSize},
Const::CursorShadowColor,
scale(4.0f));

//foreground
// foreground
drawList->AddCircle(mousePos, cursorSize / 2, Const::CursorColor, 0, scale(2.0f));
drawList->AddLine(
{mousePos.x + sqrtf(2.0f) / 2.0f * cursorSize / 2, mousePos.y + sqrtf(2.0f) / 2.0f * cursorSize / 2},
Expand Down
14 changes: 8 additions & 6 deletions source/Gui/SimulationParametersWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ _SimulationParametersWindow::_SimulationParametersWindow(
_cellFunctionStrings.emplace_back(Const::CellFunctionToStringMap.at(i));
}

_getMousePickerEnabledFunc = [&]() { return _simInteractionController->isPositionSelectionMode(); };
_setMousePickerEnabledFunc = [&](bool value) { _simInteractionController->setPositionSelectionMode(value); };
_getMousePickerPositionFunc = [&]() { return _simInteractionController->getPositionSelectionData(); };
}

_SimulationParametersWindow::~_SimulationParametersWindow()
Expand Down Expand Up @@ -1662,6 +1659,11 @@ bool _SimulationParametersWindow::processSpot(int index)
spot.shapeType)) {
createDefaultSpotData(spot);
}

auto getMousePickerEnabledFunc = [&]() { return _simInteractionController->isPositionSelectionMode(); };
auto setMousePickerEnabledFunc = [&](bool value) { _simInteractionController->setPositionSelectionMode(value); };
auto getMousePickerPositionFunc = [&]() { return _simInteractionController->getPositionSelectionData(); };

AlienImGui::SliderFloat2(
AlienImGui::SliderFloat2Parameters()
.name("Position")
Expand All @@ -1670,9 +1672,9 @@ bool _SimulationParametersWindow::processSpot(int index)
.max(toRealVector2D(worldSize))
.defaultValue(RealVector2D{origSpot.posX, origSpot.posY})
.format("%.2f")
.getMousePickerEnabledFunc(_getMousePickerEnabledFunc)
.setMousePickerEnabledFunc(_setMousePickerEnabledFunc)
.getMousePickerPositionFunc(_getMousePickerPositionFunc),
.getMousePickerEnabledFunc(getMousePickerEnabledFunc)
.setMousePickerEnabledFunc(setMousePickerEnabledFunc)
.getMousePickerPositionFunc(getMousePickerPositionFunc),
spot.posX,
spot.posY);
AlienImGui::SliderFloat2(
Expand Down
4 changes: 0 additions & 4 deletions source/Gui/SimulationParametersWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,4 @@ class _SimulationParametersWindow : public _AlienWindow

bool _featureListOpen = false;
float _featureListHeight = 200.0f;

std::function<bool(void)> _getMousePickerEnabledFunc;
std::function<void(bool)> _setMousePickerEnabledFunc;
std::function<std::optional<RealVector2D>(void)> _getMousePickerPositionFunc;
};
2 changes: 1 addition & 1 deletion source/Gui/StatisticsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void _StatisticsWindow::processTimelineStatistics()
ImGui::TableSetColumnIndex(1);
AlienImGui::Text("Diversity");
ImGui::SameLine();
AlienImGui::HelpMarker("The number of colonies is displayed. A colony is a set of at least 40 same mutants.");
AlienImGui::HelpMarker("The number of colonies is displayed. A colony is a set of at least 20 same mutants.");

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
Expand Down

0 comments on commit be4d5a7

Please sign in to comment.