Skip to content

Commit fef6fc9

Browse files
committed
Adding UIPreviewColors to the settings for each ColorPalette
1 parent 5b2c0bf commit fef6fc9

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

Src/DasherCore/ColorIO.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ bool CColorIO::Parse(pugi::xml_document& document, const std::string, bool bUser
7777

7878
std::unordered_map<NamedColor::knownColorName, ColorPalette::Color> NamedColors;
7979
std::unordered_map<std::string, ColorPalette::GroupColorInfo> GroupColors;
80+
std::vector<ColorPalette::Color> UIPreviewColors;
8081
std::string parentName = outer.attribute("parentName").as_string(HardcodedDefaultPalette->PaletteName.c_str());
8182
std::string colorSchemeName = outer.attribute("name").as_string(); // definitely exists, we checked above
8283

8384
for(pugi::xml_attribute attribute : outer.attributes())
8485
{
8586
if(strcmp(attribute.name(),"parentName") == 0 || strcmp(attribute.name(),"name") == 0) continue;
8687

88+
if(strcmp(attribute.name(),"uiPreviewColors") == 0){
89+
UIPreviewColors = GetAttributeAsColorList(attribute);
90+
continue;
91+
}
92+
8793
NamedColors[attribute.name()] = ColorPalette::Color(attribute.as_string());
8894
}
8995

@@ -106,8 +112,24 @@ bool CColorIO::Parse(pugi::xml_document& document, const std::string, bool bUser
106112
GroupColors[groupInfo.attribute("name").as_string()] = group;
107113
}
108114

115+
//could not be loaded, determine default colors by search first group >=4 and sample four equally spaced colors
116+
if(UIPreviewColors.size() != 4){
117+
UIPreviewColors.clear();
118+
for(auto& [name, group] : GroupColors){
119+
if(group.nodeColorSequence.size() >= 4){
120+
UIPreviewColors.push_back(group.nodeColorSequence.front());
121+
UIPreviewColors.push_back(group.nodeColorSequence[group.nodeColorSequence.size() / 3]);
122+
UIPreviewColors.push_back(group.nodeColorSequence[group.nodeColorSequence.size() / 3 * 2]);
123+
UIPreviewColors.push_back(group.nodeColorSequence.back());
124+
break;
125+
}
126+
}
127+
}
128+
std::array<ColorPalette::Color, 4> uiColorsArray;
129+
std::copy_n(std::make_move_iterator(UIPreviewColors.begin()), uiColorsArray.size(), uiColorsArray.begin());
130+
109131
//"HardcodedDefault" is the parent for now, later on the parents get relinked by looking up the parentNames
110-
KnownPalettes[colorSchemeName] = new ColorPalette(HardcodedDefaultPalette, parentName, NamedColors, GroupColors, colorSchemeName);
132+
KnownPalettes[colorSchemeName] = new ColorPalette(HardcodedDefaultPalette, parentName, NamedColors, GroupColors, uiColorsArray, colorSchemeName);
111133

112134
return true;
113135
}
@@ -170,5 +192,12 @@ void CColorIO::CreateDefault() {
170192
{NamedColor::gameGuide, ColorPalette::Color(255, 100, 204, 255)}
171193
};
172194

173-
HardcodedDefaultPalette = new ColorPalette(nullptr, "NonExistentRootRootPalette", NamedColors, {}, "HardcodedDefault"); //TODO: No groups for now, but will later be added
195+
std::array<ColorPalette::Color, 4> uiColorsArray = {
196+
ColorPalette::Color(0, 0, 0, 255),
197+
ColorPalette::Color(255, 0, 255, 255),
198+
ColorPalette::Color(0, 0, 0, 255),
199+
ColorPalette::Color(255, 0, 255, 255)
200+
};
201+
202+
HardcodedDefaultPalette = new ColorPalette(nullptr, "NonExistentRootRootPalette", NamedColors, {}, uiColorsArray, "HardcodedDefault"); //TODO: No groups for now, but will later be added
174203
}

Src/DasherCore/ColorPalette.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ ColorPalette::Color ColorPalette::Color::lerp(const Color& ColorA, const Color&
6565

6666
ColorPalette::ColorPalette(ColorPalette* ParentPalette, std::string ParentPaletteName,
6767
const std::unordered_map<NamedColor::knownColorName, Color>& NamedColors,
68-
const std::unordered_map<std::string, GroupColorInfo>& GroupColors, std::string PaletteName) : ParentPalette(ParentPalette), ParentPaletteName(
69-
std::move(ParentPaletteName)), NamedColors(NamedColors), GroupColors(GroupColors), PaletteName(PaletteName)
68+
const std::unordered_map<std::string, GroupColorInfo>& GroupColors, std::array<Color,4> UIPreviewColors, std::string PaletteName) : ParentPalette(ParentPalette), ParentPaletteName(
69+
std::move(ParentPaletteName)), NamedColors(NamedColors), GroupColors(GroupColors), UIPreviewColors(UIPreviewColors), PaletteName(PaletteName)
7070
{
7171
}
7272

@@ -93,6 +93,11 @@ const ColorPalette::Color& ColorPalette::GetNamedColor(const NamedColor::knownCo
9393
return (ParentPalette && AskParent) ? ParentPalette->GetNamedColor(NamedColor) : undefinedColor;
9494
}
9595

96+
const std::array<ColorPalette::Color,4>& ColorPalette::GetUIPreviewColors() const
97+
{
98+
return UIPreviewColors;
99+
}
100+
96101
const ColorPalette::Color& ColorPalette::GetGroupColor(const std::string& GroupName, const bool& UseAltColor) const
97102
{
98103
if(GroupName.empty()) return undefinedColor;

Src/DasherCore/ColorPalette.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <unordered_map>
1212
#include <vector>
13+
#include <array>
1314
#include <string>
1415

1516
namespace Dasher {
@@ -93,7 +94,7 @@ namespace Dasher {
9394
std::pair<Color,Color> groupLabelColor = {undefinedColor, undefinedColor};
9495
} GroupColorInfo;
9596

96-
ColorPalette(ColorPalette* ParentPalette, std::string ParentPaletteName, const std::unordered_map<NamedColor::knownColorName, Color>& NamedColors, const std::unordered_map<std::string, GroupColorInfo>& GroupColors, std::string PaletteName);
97+
ColorPalette(ColorPalette* ParentPalette, std::string ParentPaletteName, const std::unordered_map<NamedColor::knownColorName, Color>& NamedColors, const std::unordered_map<std::string, GroupColorInfo>& GroupColors, std::array<Color,4> UIPreviewColors, std::string PaletteName);
9798
const Color& GetAltColor(const std::vector<Color>& NormalColors, const std::vector<Color>& AltColors, bool useAlt, int Index) const;
9899
const Color& GetAltColor(const Color& NormalColor, const Color& AltColor, bool useAlt) const;
99100

@@ -104,6 +105,8 @@ namespace Dasher {
104105

105106
const Color& GetNamedColor(const NamedColor::knownColorName& NamedColor, bool AskParent = true) const;
106107

108+
const std::array<Color,4>& GetUIPreviewColors() const;
109+
107110
const Color& GetGroupColor(const std::string& GroupName, const bool& UseAltColor) const;
108111
const Color& GetGroupOutlineColor(const std::string& GroupName, const bool& UseAltColor, bool UseDefaultColor = true) const;
109112
const Color& GetGroupLabelColor(const std::string& GroupName, const bool& UseAltColor, bool UseDefaultColor = true) const;
@@ -114,6 +117,7 @@ namespace Dasher {
114117
private:
115118
std::unordered_map<NamedColor::knownColorName, Color> NamedColors;
116119
std::unordered_map<std::string, GroupColorInfo> GroupColors;
120+
std::array<Color,4> UIPreviewColors;
117121
};
118122

119123

0 commit comments

Comments
 (0)