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.
This commit is contained in:
Kacper Donat
2025-02-15 22:50:38 +01:00
parent a72a63232a
commit 1ce7c678bb
2 changed files with 65 additions and 2 deletions

View File

@@ -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<uint32_t>(packed));
}
void ParameterGrp::SetColor(const char* Name, Base::Color lValue)
{
SetUnsigned(Name, lValue.getPackedValue());
}
std::vector<Base::Color> ParameterGrp::GetColors(const char* sFilter) const
{
auto packed = GetUnsigneds(sFilter);
std::vector<Base::Color> result;
std::transform(packed.begin(),
packed.end(),
std::back_inserter(result),
[](const unsigned long lValue) {
return Color(static_cast<uint32_t>(lValue));
});
return result;
}
std::vector<std::pair<std::string, Base::Color>>
ParameterGrp::GetColorMap(const char* sFilter) const
{
auto packed = GetUnsignedMap(sFilter);
std::vector<std::pair<std::string, Base::Color>> result;
std::transform(packed.begin(),
packed.end(),
std::back_inserter(result),
[](const std::pair<std::string, unsigned long>& lValue) {
return std::make_pair(lValue.first,
Color(static_cast<uint32_t>(lValue.second)));
});
return result;
}
void ParameterGrp::RemoveColor(const char* Name)
{
RemoveUnsigned(Name);
}
void ParameterGrp::RemoveGrp(const char* Name)
{
if (!_pGroupNode) {

View File

@@ -31,7 +31,6 @@
#ifndef BASE_PARAMETER_H
#define BASE_PARAMETER_H
#include <Base/Color.h>
// 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<Base::Color> GetColors(const char* sFilter = nullptr) const;
/// get a map with all color values and the keys of this group
std::vector<std::pair<std::string, Base::Color>>
GetColorMap(const char* sFilter = nullptr) const;
/// remove a color value from this group
void RemoveColor(const char* Name);
//@}
/** @name methods for Float handling */
//@{