Skip to content

Commit

Permalink
Add color aliasing (#1652)
Browse files Browse the repository at this point in the history
You can refer to another color as a color value with $foo. You
can define any color you want with <color id="foo" value="#32323"/>.
Don't use circular definitinos since that will explode.

Addresses #1649
  • Loading branch information
baconpaul authored Mar 21, 2020
1 parent 98007b9 commit 4fb8e93
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/common/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,14 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
rgb = rgb >> 8;

int r = rgb % 256;
colors[id] = VSTGUI::CColor(r, g, b);
colors[id] = ColorStore( VSTGUI::CColor(r, g, b) );
}
else
else if( val[0] == '$' )
{
colors[id] = VSTGUI::CColor(255, 0, 0);
colors[id] = ColorStore( val.c_str() + 1 );
}
else {
colors[id] = ColorStore( VSTGUI::CColor(255, 0, 0) );
}
}
}
Expand All @@ -400,7 +403,16 @@ VSTGUI::CColor Skin::getColor(std::string id, const VSTGUI::CColor& def)
{
queried_colors.insert(id);
if (colors.find(id) != colors.end())
return colors[id];
{
auto c = colors[id];
switch( c.type )
{
case ColorStore::COLOR:
return c.color;
case ColorStore::ALIAS:
return getColor( c.alias, def );
}
}
return def;
}
} // namespace UI
Expand Down
16 changes: 15 additions & 1 deletion src/common/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,21 @@ class Skin
private:
std::vector<std::pair<std::string, props_t>> globals;

std::unordered_map<std::string, VSTGUI::CColor> colors;
struct ColorStore {
VSTGUI::CColor color;
std::string alias;

typedef enum {
COLOR,
ALIAS
} Type;

Type type;
ColorStore() : type( COLOR ), color( VSTGUI::kBlackCColor ) { }
ColorStore( VSTGUI::CColor c ) : type( COLOR ), color( c ) { }
ColorStore( std::string a ) : type( ALIAS ), alias( a ) { }
};
std::unordered_map<std::string, ColorStore> colors;
std::unordered_set<std::string> queried_colors;
std::unordered_map<std::string, int> imageIds;
std::vector<Control> controls;
Expand Down

0 comments on commit 4fb8e93

Please sign in to comment.