Skip to content

Commit

Permalink
+ GCC compile errors fixed
Browse files Browse the repository at this point in the history
+ load/save zoom sensitivity
  • Loading branch information
chrxh committed Aug 31, 2024
1 parent 1730394 commit f641a1a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 35 deletions.
2 changes: 1 addition & 1 deletion source/EngineInterface/AuxiliaryDataParserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ namespace
}
PropertyParser::encodeDecode(tree, spot.fadeoutRadius, defaultSpot.fadeoutRadius, base + "fadeout radius", parserTask);

PropertyParser::PropertyParser::encodeDecodeWithEnabled(tree, spot.values.friction, spot.activatedValues.friction, defaultSpot.values.friction, base + "friction", parserTask);
PropertyParser::encodeDecodeWithEnabled(tree, spot.values.friction, spot.activatedValues.friction, defaultSpot.values.friction, base + "friction", parserTask);
PropertyParser::encodeDecodeWithEnabled(tree, spot.values.rigidity, spot.activatedValues.rigidity, defaultSpot.values.rigidity, base + "rigidity", parserTask);
PropertyParser::encodeDecodeWithEnabled(
tree,
Expand Down
88 changes: 59 additions & 29 deletions source/EngineInterface/PropertyParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@ class PropertyParser

//return true if value does not exist in tree
template <typename T>
static bool encodeDecode(boost::property_tree::ptree& tree, T& parameter, T const& defaultValue, std::string const& node, ParserTask task)
static bool encodeDecode(boost::property_tree::ptree& tree, T& parameter, T const& defaultValue, std::string const& node, ParserTask task);

template <typename T>
static bool encodeDecodeWithEnabled(
boost::property_tree::ptree& tree,
T& parameter,
bool& isActivated,
T const& defaultValue,
std::string const& node,
ParserTask task);
};

namespace detail
{
template <typename T>
static bool encodeDecodeImpl(boost::property_tree::ptree& tree, T& parameter, T const& defaultValue, std::string const& node, ParserTask task)
{
return JsonParser::encodeDecode(tree, parameter, defaultValue, node, task);
}

template <>
static bool encodeDecode(
inline bool encodeDecodeImpl(
boost::property_tree::ptree& tree,
ColorVector<float>& parameter,
ColorVector<float> const& defaultValue,
Expand All @@ -26,13 +41,13 @@ class PropertyParser
{
auto result = false;
for (int i = 0; i < MAX_COLORS; ++i) {
result |= encodeDecode(tree, parameter[i], defaultValue[i], node + "[" + std::to_string(i) + "]", task);
result |= encodeDecodeImpl(tree, parameter[i], defaultValue[i], node + "[" + std::to_string(i) + "]", task);
}
return result;
}

template <>
static bool encodeDecode(
inline bool encodeDecodeImpl(
boost::property_tree::ptree& tree,
ColorVector<int>& parameter,
ColorVector<int> const& defaultValue,
Expand All @@ -41,13 +56,13 @@ class PropertyParser
{
auto result = false;
for (int i = 0; i < MAX_COLORS; ++i) {
result |= encodeDecode(tree, parameter[i], defaultValue[i], node + "[" + std::to_string(i) + "]", task);
result |= encodeDecodeImpl(tree, parameter[i], defaultValue[i], node + "[" + std::to_string(i) + "]", task);
}
return result;
}

template <>
static bool encodeDecode<ColorMatrix<float>>(
inline bool encodeDecodeImpl<ColorMatrix<float>>(
boost::property_tree::ptree& tree,
ColorMatrix<float>& parameter,
ColorMatrix<float> const& defaultValue,
Expand All @@ -57,15 +72,14 @@ class PropertyParser
auto result = false;
for (int i = 0; i < MAX_COLORS; ++i) {
for (int j = 0; j < MAX_COLORS; ++j) {
result |=
encodeDecode(tree, parameter[i][j], defaultValue[i][j], node + "[" + std::to_string(i) + ", " + std::to_string(j) + "]", task);
result |= encodeDecodeImpl(tree, parameter[i][j], defaultValue[i][j], node + "[" + std::to_string(i) + ", " + std::to_string(j) + "]", task);
}
}
return result;
}

template <>
static bool encodeDecode<ColorMatrix<int>>(
inline bool encodeDecodeImpl<ColorMatrix<int>>(
boost::property_tree::ptree& tree,
ColorMatrix<int>& parameter,
ColorMatrix<int> const& defaultValue,
Expand All @@ -75,15 +89,14 @@ class PropertyParser
auto result = false;
for (int i = 0; i < MAX_COLORS; ++i) {
for (int j = 0; j < MAX_COLORS; ++j) {
result |=
encodeDecode(tree, parameter[i][j], defaultValue[i][j], node + "[" + std::to_string(i) + ", " + std::to_string(j) + "]", task);
result |= encodeDecodeImpl(tree, parameter[i][j], defaultValue[i][j], node + "[" + std::to_string(i) + ", " + std::to_string(j) + "]", task);
}
}
return result;
}

template <>
static bool encodeDecode<ColorMatrix<bool>>(
inline bool encodeDecodeImpl<ColorMatrix<bool>>(
boost::property_tree::ptree& tree,
ColorMatrix<bool>& parameter,
ColorMatrix<bool> const& defaultValue,
Expand All @@ -93,15 +106,14 @@ class PropertyParser
auto result = false;
for (int i = 0; i < MAX_COLORS; ++i) {
for (int j = 0; j < MAX_COLORS; ++j) {
result |=
encodeDecode(tree, parameter[i][j], defaultValue[i][j], node + "[" + std::to_string(i) + ", " + std::to_string(j) + "]", task);
result |= encodeDecodeImpl(tree, parameter[i][j], defaultValue[i][j], node + "[" + std::to_string(i) + ", " + std::to_string(j) + "]", task);
}
}
return result;
}

template <>
static bool encodeDecode(
inline bool encodeDecodeImpl(
boost::property_tree::ptree& tree,
std::chrono::milliseconds& parameter,
std::chrono::milliseconds const& defaultValue,
Expand All @@ -110,69 +122,87 @@ class PropertyParser
{
if (ParserTask::Encode == task) {
auto parameterAsString = std::to_string(parameter.count());
return encodeDecode(tree, parameterAsString, std::string(), node, task);
return encodeDecodeImpl(tree, parameterAsString, std::string(), node, task);
} else {
std::string parameterAsString;
auto defaultAsString = std::to_string(defaultValue.count());
auto result = encodeDecode(tree, parameterAsString, defaultAsString, node, task);
auto result = encodeDecodeImpl(tree, parameterAsString, defaultAsString, node, task);
parameter = std::chrono::milliseconds(std::stoi(parameterAsString));
return result;
}
}

template <typename T>
static bool encodeDecodeWithEnabled(
inline bool encodeDecodeWithEnabledImpl(
boost::property_tree::ptree& tree,
T& parameter,
bool& isActivated,
T const& defaultValue,
std::string const& node,
ParserTask task)
{
auto result = encodeDecode(tree, isActivated, false, node + ".activated", task);
result |= encodeDecode(tree, parameter, defaultValue, node + ".value", task);
auto result = encodeDecodeImpl(tree, isActivated, false, node + ".activated", task);
result |= encodeDecodeImpl(tree, parameter, defaultValue, node + ".value", task);
return result;
}

template <>
static bool encodeDecodeWithEnabled(
inline bool encodeDecodeWithEnabledImpl(
boost::property_tree::ptree& tree,
ColorVector<float>& parameter,
bool& isActivated,
ColorVector<float> const& defaultValue,
std::string const& node,
ParserTask task)
{
auto result = encodeDecode(tree, isActivated, false, node + ".activated", task);
result |= encodeDecode(tree, parameter, defaultValue, node, task);
auto result = encodeDecodeImpl(tree, isActivated, false, node + ".activated", task);
result |= encodeDecodeImpl(tree, parameter, defaultValue, node, task);
return result;
}

template <>
static bool encodeDecodeWithEnabled(
inline bool encodeDecodeWithEnabledImpl(
boost::property_tree::ptree& tree,
ColorVector<int>& parameter,
bool& isActivated,
ColorVector<int> const& defaultValue,
std::string const& node,
ParserTask task)
{
auto result = encodeDecode(tree, isActivated, false, node + ".activated", task);
result |= encodeDecode(tree, parameter, defaultValue, node, task);
auto result = encodeDecodeImpl(tree, isActivated, false, node + ".activated", task);
result |= encodeDecodeImpl(tree, parameter, defaultValue, node, task);
return result;
}

template <typename T>
static bool encodeDecodeWithEnabled(
inline bool encodeDecodeWithEnabledImpl(
boost::property_tree::ptree& tree,
ColorMatrix<T>& parameter,
bool& isActivated,
ColorMatrix<bool> const& defaultValue,
std::string const& node,
ParserTask task)
{
auto result = encodeDecode(tree, isActivated, false, node + ".activated", task);
result |= encodeDecode(tree, parameter, defaultValue, node, task);
auto result = encodeDecodeImpl(tree, isActivated, false, node + ".activated", task);
result |= encodeDecodeImpl(tree, parameter, defaultValue, node, task);
return result;
}
};

template <typename T>
bool PropertyParser::encodeDecode(boost::property_tree::ptree& tree, T& parameter, T const& defaultValue, std::string const& node, ParserTask task)
{
return detail::encodeDecodeImpl(tree, parameter, defaultValue, node, task);
}

template <typename T>
bool PropertyParser::encodeDecodeWithEnabled(
boost::property_tree::ptree& tree,
T& parameter,
bool& isActivated,
T const& defaultValue,
std::string const& node,
ParserTask task)
{
return detail::encodeDecodeWithEnabledImpl(tree, parameter, isActivated, defaultValue, node, task);
}
15 changes: 11 additions & 4 deletions source/Gui/SpatialControlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
#include "AlienImGui.h"
#include "ResizeWorldDialog.h"

_SpatialControlWindow::_SpatialControlWindow(
SimulationController const& simController,
TemporalControlWindow const& temporalControlWindow)
_SpatialControlWindow::_SpatialControlWindow(SimulationController const& simController, TemporalControlWindow const& temporalControlWindow)
: _AlienWindow("Spatial control", "windows.spatial control", true)
, _simController(simController)
{
_resizeWorldDialog = std::make_shared<_ResizeWorldDialog>(simController, temporalControlWindow);

auto& settings = GlobalSettings::getInstance();
Viewport::setZoomSensitivity(settings.getFloat("windows.spatial control.zoom sensitivity", Viewport::getZoomSensitivity()));
}

_SpatialControlWindow::~_SpatialControlWindow()
{
auto& settings = GlobalSettings::getInstance();
settings.setFloat("windows.spatial control.zoom sensitivity", Viewport::getZoomSensitivity());
}

void _SpatialControlWindow::processIntern()
Expand Down Expand Up @@ -72,7 +79,7 @@ void _SpatialControlWindow::processIntern()
ImGui::Spacing();
ImGui::Spacing();
float sensitivity = Viewport::getZoomSensitivity();
if (AlienImGui::SliderFloat(AlienImGui::SliderFloatParameters().name("Zoom sensitivity").min(1.0f).max(1.05f).textWidth(130).format(""), &sensitivity)) {
if (AlienImGui::SliderFloat(AlienImGui::SliderFloatParameters().name("Zoom sensitivity").min(1.0f).max(1.07f).textWidth(130).format(""), &sensitivity)) {
Viewport::setZoomSensitivity(sensitivity);
}
}
Expand Down
1 change: 1 addition & 0 deletions source/Gui/SpatialControlWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class _SpatialControlWindow : public _AlienWindow
{
public:
_SpatialControlWindow(SimulationController const& simController, TemporalControlWindow const& temporalControlWindow);
~_SpatialControlWindow();

private:
void processIntern() override;
Expand Down
2 changes: 1 addition & 1 deletion source/Gui/Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ float Viewport::getZoomSensitivity()

void Viewport::setZoomSensitivity(float value)
{
_zoomSensitivity = value;
_zoomSensitivity = std::min(10.0f, std::max(1.0f, value));
}

void Viewport::centerTo(RealVector2D const& worldPosition, IntVector2D const& viewPos)
Expand Down

0 comments on commit f641a1a

Please sign in to comment.