From 97de3de68fd49566215e23694abf902d2a7468ce Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sat, 15 Feb 2025 22:50:38 +0100 Subject: [PATCH] Base: Add Color parameter Type This adds Color parameter type to the ParameterGroup. Internally colors are stored as unsigned longs so it only is convienance layer. --- src/Base/Parameter.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ src/Base/Parameter.h | 18 ++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 3e02aae6e6..197858030b 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -1252,6 +1252,55 @@ void ParameterGrp::RemoveUnsigned(const char* Name) Notify(Name); } +Base::Color ParameterGrp::GetColor(const char* Name, Base::Color lPreset) const +{ + auto packed = GetUnsigned(Name, lPreset.getPackedValue()); + + return Color(static_cast(packed)); +} + +void ParameterGrp::SetColor(const char* Name, Base::Color lValue) +{ + SetUnsigned(Name, lValue.getPackedValue()); +} + +std::vector ParameterGrp::GetColors(const char* sFilter) const +{ + auto packed = GetUnsigneds(sFilter); + std::vector result; + + std::transform(packed.begin(), + packed.end(), + std::back_inserter(result), + [](const unsigned long lValue) { + return Color(static_cast(lValue)); + }); + + return result; +} + +std::vector> +ParameterGrp::GetColorMap(const char* sFilter) const +{ + auto packed = GetUnsignedMap(sFilter); + std::vector> result; + + std::transform(packed.begin(), + packed.end(), + std::back_inserter(result), + [](const std::pair& lValue) { + return std::make_pair(lValue.first, + Color(static_cast(lValue.second))); + }); + + return result; +} + +void ParameterGrp::RemoveColor(const char* Name) +{ + RemoveUnsigned(Name); +} + void ParameterGrp::RemoveGrp(const char* Name) { if (!_pGroupNode) { diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index 78bbc1c8e4..db04cae617 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -31,7 +31,6 @@ #ifndef BASE_PARAMETER_H #define BASE_PARAMETER_H -#include // Python stuff using PyObject = struct _object; @@ -57,6 +56,7 @@ using PyObject = struct _object; #include "Handle.h" #include "Observer.h" +#include "Color.h" #ifdef _MSC_VER #pragma warning(disable : 4251) @@ -89,7 +89,6 @@ XERCES_CPP_NAMESPACE_END class ParameterManager; - /** The parameter container class * This is the base class of all classes handle parameter. * The class contains a map of key-value pairs in a grouping @@ -308,6 +307,21 @@ public: void RemoveUnsigned(const char* Name); //@} + /** @name methods for Colors handling, colors are persisted as packed uints */ + //@{ + /// read color value or give default + Base::Color GetColor(const char* Name, Base::Color lPreset = Base::Color(1.0, 1.0, 1.0)) const; + /// set a color value + void SetColor(const char* Name, Base::Color lValue); + /// get a vector of all color values in this group + std::vector GetColors(const char* sFilter = nullptr) const; + /// get a map with all color values and the keys of this group + std::vector> + GetColorMap(const char* sFilter = nullptr) const; + /// remove a color value from this group + void RemoveColor(const char* Name); + //@} + /** @name methods for Float handling */ //@{