ui: extended color scheme and added new color scheme bad_rainbow
* added color scheme template * define fill, border, text, icon and hatching colors for each node with states normal and focus * define colors for each edge with states normal and focus * use default node and edge colors when no type specific ones are defined * use normal colors for nodes and edges when no focused are defined * allow nodes and edges to imitate look of others with "like" tag * added style for bundle * added style for count circle
This commit is contained in:
@@ -6,6 +6,21 @@
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
int GraphViewStyle::s_gridCellSize = 5;
|
||||
int GraphViewStyle::s_gridCellPadding = 10;
|
||||
|
||||
std::map<Node::NodeType, float> GraphViewStyle::s_charWidths;
|
||||
std::map<Node::NodeType, float> GraphViewStyle::s_charHeights;
|
||||
|
||||
std::shared_ptr<GraphViewStyleImpl> GraphViewStyle::s_impl;
|
||||
|
||||
int GraphViewStyle::s_fontSize;
|
||||
std::string GraphViewStyle::s_fontName;
|
||||
float GraphViewStyle::s_zoomFactor;
|
||||
|
||||
std::map<std::string, GraphViewStyle::NodeColor> GraphViewStyle::s_nodeColors;
|
||||
std::map<std::string, std::string> GraphViewStyle::s_edgeColors;
|
||||
|
||||
GraphViewStyle::NodeMargins::NodeMargins()
|
||||
: left(0)
|
||||
, right(0)
|
||||
@@ -27,6 +42,7 @@ GraphViewStyle::NodeStyle::NodeStyle()
|
||||
, fontSize(0)
|
||||
, fontBold(false)
|
||||
, iconSize(0)
|
||||
, hasHatching(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -67,6 +83,9 @@ void GraphViewStyle::loadStyleSettings()
|
||||
|
||||
s_charWidths.clear();
|
||||
s_charHeights.clear();
|
||||
|
||||
s_nodeColors.clear();
|
||||
s_edgeColors.clear();
|
||||
}
|
||||
|
||||
float GraphViewStyle::getCharWidthForNodeType(Node::NodeType type)
|
||||
@@ -169,9 +188,9 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
|
||||
margins.bottom = 15;
|
||||
break;
|
||||
|
||||
case Node::NODE_FILE:
|
||||
case Node::NODE_ENUM:
|
||||
case Node::NODE_TYPEDEF:
|
||||
case Node::NODE_FILE:
|
||||
case Node::NODE_MACRO:
|
||||
margins.iconWidth = s_fontSize + 11;
|
||||
case Node::NODE_TYPE:
|
||||
@@ -255,19 +274,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
|
||||
){
|
||||
NodeStyle style;
|
||||
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
|
||||
if (isActive || isFocused)
|
||||
{
|
||||
style.color = scheme->getNodeTypeColor(type, "hover");
|
||||
}
|
||||
else
|
||||
{
|
||||
style.color = scheme->getNodeTypeColor(type);
|
||||
}
|
||||
|
||||
style.textColor = scheme->getColor("graph/text");
|
||||
style.borderColor = scheme->getColor("graph/border");
|
||||
style.color = getNodeColor(Node::getTypeString(type), isActive || isFocused);
|
||||
|
||||
style.fontName = getFontNameForNodeType(type);
|
||||
style.fontSize = getFontSizeForNodeType(type);
|
||||
@@ -278,10 +285,6 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
|
||||
style.borderDashed = true;
|
||||
|
||||
case Node::NODE_NAMESPACE:
|
||||
style.borderColor = style.color;
|
||||
style.color = "#00000000";
|
||||
style.borderWidth = 1;
|
||||
|
||||
style.cornerRadius = 20;
|
||||
|
||||
style.textOffset.x = 15;
|
||||
@@ -294,6 +297,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
|
||||
case Node::NODE_ENUM:
|
||||
case Node::NODE_TYPEDEF:
|
||||
case Node::NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
case Node::NODE_FILE:
|
||||
case Node::NODE_MACRO:
|
||||
if (hasChildren)
|
||||
{
|
||||
@@ -307,26 +311,6 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
|
||||
style.textOffset.x = 8;
|
||||
style.textOffset.y = 8;
|
||||
}
|
||||
|
||||
if (isActive)
|
||||
{
|
||||
style.borderWidth = 2;
|
||||
}
|
||||
else if (isFocused)
|
||||
{
|
||||
style.borderWidth = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
style.borderWidth = 1;
|
||||
style.borderColor = style.borderColor.replace(0, 1, "#20");
|
||||
}
|
||||
break;
|
||||
|
||||
case Node::NODE_FILE:
|
||||
style.cornerRadius = 10;
|
||||
style.textOffset.x = 6;
|
||||
style.textOffset.y = 9;
|
||||
break;
|
||||
|
||||
case Node::NODE_FUNCTION:
|
||||
@@ -337,23 +321,24 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
|
||||
style.cornerRadius = 8;
|
||||
style.textOffset.x = 5;
|
||||
style.textOffset.y = 3;
|
||||
|
||||
if (isActive)
|
||||
{
|
||||
style.borderWidth = 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (isActive)
|
||||
{
|
||||
style.borderWidth = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
style.borderWidth = 1;
|
||||
}
|
||||
|
||||
if (isActive || isFocused)
|
||||
{
|
||||
style.fontBold = true;
|
||||
}
|
||||
|
||||
if (!defined)
|
||||
{
|
||||
style.hatchingColor = scheme->getColor("graph/hatching");
|
||||
}
|
||||
style.hasHatching = !defined;
|
||||
|
||||
addIcon(type, hasChildren, &style);
|
||||
|
||||
@@ -364,12 +349,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfAccessNode()
|
||||
{
|
||||
NodeStyle style;
|
||||
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
|
||||
style.color = scheme->getColor("graph/background");
|
||||
style.textColor = scheme->getColor("graph/text");
|
||||
style.iconColor = scheme->getColor("graph/icon");
|
||||
style.borderColor = "#00000000";
|
||||
style.color = getNodeColor("access", false);
|
||||
|
||||
style.cornerRadius = 12;
|
||||
|
||||
@@ -387,12 +367,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode()
|
||||
{
|
||||
NodeStyle style;
|
||||
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
|
||||
style.color = scheme->getColor("graph/background");
|
||||
style.textColor = scheme->getColor("graph/text");
|
||||
style.iconColor = scheme->getColor("graph/icon");
|
||||
style.borderColor = "#00000000";
|
||||
style.color = getNodeColor("access", false);
|
||||
|
||||
style.cornerRadius = 100;
|
||||
|
||||
@@ -402,10 +377,24 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode()
|
||||
return style;
|
||||
}
|
||||
|
||||
GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfCountCircle()
|
||||
{
|
||||
NodeStyle style;
|
||||
|
||||
style.color = getNodeColor("count_number", false);
|
||||
|
||||
style.fontName = getFontNameOfExpandToggleNode();
|
||||
style.fontSize = getFontSizeOfCountCircle();
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfBundleNode(bool isFocused)
|
||||
{
|
||||
NodeStyle style = getStyleForNodeType(Node::NODE_CLASS, true, false, isFocused, false);
|
||||
|
||||
style.color = getNodeColor("bundle", isFocused);
|
||||
|
||||
addIcon(Node::NODE_ENUM, false, &style);
|
||||
style.iconPath = "data/gui/graph_view/images/bundle.png";
|
||||
|
||||
@@ -431,14 +420,7 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType typ
|
||||
style.originOffset.y = -1;
|
||||
style.targetOffset.y = 1;
|
||||
|
||||
if (isActive)
|
||||
{
|
||||
style.color = ColorScheme::getInstance()->getEdgeTypeColor(type, "hover");
|
||||
}
|
||||
else
|
||||
{
|
||||
style.color = ColorScheme::getInstance()->getEdgeTypeColor(type);
|
||||
}
|
||||
style.color = getEdgeColor(Edge::getTypeString(type), isActive || isFocused);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@@ -512,6 +494,50 @@ float GraphViewStyle::getZoomFactor()
|
||||
return s_zoomFactor;
|
||||
}
|
||||
|
||||
const GraphViewStyle::NodeColor& GraphViewStyle::getNodeColor(const std::string& typeStr, bool focus)
|
||||
{
|
||||
std::string type = focus ? typeStr + "focus" : typeStr;
|
||||
std::map<std::string, NodeColor>::const_iterator it = s_nodeColors.find(type);
|
||||
|
||||
if (it != s_nodeColors.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
NodeColor color;
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
ColorScheme::ColorState state = focus ? ColorScheme::FOCUS : ColorScheme::NORMAL;
|
||||
|
||||
color.fill = scheme->getNodeTypeColor(typeStr, "fill", state);
|
||||
color.border = scheme->getNodeTypeColor(typeStr, "border", state);
|
||||
color.text = scheme->getNodeTypeColor(typeStr, "text", state);
|
||||
color.icon = scheme->getNodeTypeColor(typeStr, "icon", state);
|
||||
color.hatching = scheme->getNodeTypeColor(typeStr, "hatching", state);
|
||||
|
||||
s_nodeColors.emplace(type, color);
|
||||
|
||||
return s_nodeColors.find(type)->second;
|
||||
}
|
||||
|
||||
const std::string& GraphViewStyle::getEdgeColor(const std::string& typeStr, bool focus)
|
||||
{
|
||||
std::string type = focus ? typeStr + "focus" : typeStr;
|
||||
std::map<std::string, std::string>::const_iterator it = s_edgeColors.find(type);
|
||||
|
||||
if (it != s_edgeColors.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
ColorScheme::ColorState state = focus ? ColorScheme::FOCUS : ColorScheme::NORMAL;
|
||||
std::string color = scheme->getEdgeTypeColor(typeStr, state);
|
||||
|
||||
s_edgeColors.emplace(type, color);
|
||||
|
||||
return s_edgeColors.find(type)->second;
|
||||
}
|
||||
|
||||
void GraphViewStyle::addIcon(Node::NodeType type, bool hasChildren, NodeStyle* style)
|
||||
{
|
||||
switch (type)
|
||||
@@ -545,17 +571,4 @@ void GraphViewStyle::addIcon(Node::NodeType type, bool hasChildren, NodeStyle* s
|
||||
}
|
||||
|
||||
style->iconOffset.y = 9;
|
||||
style->iconColor = ColorScheme::getInstance()->getColor("graph/icon");
|
||||
}
|
||||
|
||||
int GraphViewStyle::s_gridCellSize = 5;
|
||||
int GraphViewStyle::s_gridCellPadding = 10;
|
||||
|
||||
std::map<Node::NodeType, float> GraphViewStyle::s_charWidths;
|
||||
std::map<Node::NodeType, float> GraphViewStyle::s_charHeights;
|
||||
|
||||
std::shared_ptr<GraphViewStyleImpl> GraphViewStyle::s_impl;
|
||||
|
||||
int GraphViewStyle::s_fontSize;
|
||||
std::string GraphViewStyle::s_fontName;
|
||||
float GraphViewStyle::s_zoomFactor;
|
||||
|
||||
@@ -35,19 +35,24 @@ public:
|
||||
int iconWidth;
|
||||
};
|
||||
|
||||
struct NodeColor
|
||||
{
|
||||
std::string fill;
|
||||
std::string border;
|
||||
std::string text;
|
||||
std::string icon;
|
||||
std::string hatching;
|
||||
};
|
||||
|
||||
struct NodeStyle
|
||||
{
|
||||
NodeStyle();
|
||||
|
||||
std::string color;
|
||||
std::string textColor;
|
||||
std::string iconColor;
|
||||
std::string hatchingColor;
|
||||
NodeColor color;
|
||||
|
||||
int cornerRadius;
|
||||
|
||||
int borderWidth;
|
||||
std::string borderColor;
|
||||
bool borderDashed;
|
||||
|
||||
std::string fontName;
|
||||
@@ -59,6 +64,8 @@ public:
|
||||
std::string iconPath;
|
||||
Vec2i iconOffset;
|
||||
size_t iconSize;
|
||||
|
||||
bool hasHatching;
|
||||
};
|
||||
|
||||
struct EdgeStyle
|
||||
@@ -108,6 +115,7 @@ public:
|
||||
static NodeStyle getStyleForNodeType(Node::NodeType type, bool defined, bool isActive, bool isFocused, bool hasChildren);
|
||||
static NodeStyle getStyleOfAccessNode();
|
||||
static NodeStyle getStyleOfExpandToggleNode();
|
||||
static NodeStyle getStyleOfCountCircle();
|
||||
static NodeStyle getStyleOfBundleNode(bool isFocused);
|
||||
|
||||
static EdgeStyle getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused);
|
||||
@@ -118,6 +126,9 @@ public:
|
||||
|
||||
static float getZoomFactor();
|
||||
|
||||
static const NodeColor& getNodeColor(const std::string& typeStr, bool focus);
|
||||
static const std::string& getEdgeColor(const std::string& typeStr, bool focus);
|
||||
|
||||
static int s_gridCellSize;
|
||||
static int s_gridCellPadding;
|
||||
|
||||
@@ -132,6 +143,9 @@ private:
|
||||
static int s_fontSize;
|
||||
static std::string s_fontName;
|
||||
static float s_zoomFactor;
|
||||
|
||||
static std::map<std::string, NodeColor> s_nodeColors;
|
||||
static std::map<std::string, std::string> s_edgeColors;
|
||||
};
|
||||
|
||||
#endif // GRAPH_VIEW_STYLE_H
|
||||
|
||||
@@ -18,19 +18,63 @@ ColorScheme::~ColorScheme()
|
||||
|
||||
std::string ColorScheme::getColor(const std::string& key) const
|
||||
{
|
||||
return getValue<std::string>(key, "#FFFFFF");
|
||||
return getValue<std::string>(key, "");
|
||||
}
|
||||
|
||||
std::string ColorScheme::getNodeTypeColor(Node::NodeType type, const std::string& state) const
|
||||
std::string ColorScheme::getNodeTypeColor(Node::NodeType type, const std::string& key, ColorState state) const
|
||||
{
|
||||
std::string path = "graph/node/" + Node::getTypeString(type) + "/" + state;
|
||||
return getValue<std::string>(path, "#FFFFFF");
|
||||
return getNodeTypeColor(Node::getTypeString(type), key, state);
|
||||
}
|
||||
|
||||
std::string ColorScheme::getEdgeTypeColor(Edge::EdgeType type, const std::string& state) const
|
||||
std::string ColorScheme::getNodeTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const
|
||||
{
|
||||
std::string path = "graph/edge/" + Edge::getTypeString(type) + "/" + state;
|
||||
return getValue<std::string>(path, "#FFFFFF");
|
||||
std::string type = getValue<std::string>("graph/node/" + typeStr + "/like", typeStr);
|
||||
std::string color = getValue<std::string>("graph/node/" + type + "/" + key + "/" + stateToString(state), "");
|
||||
|
||||
if (!color.size() && state != NORMAL)
|
||||
{
|
||||
color = getValue<std::string>("graph/node/" + type + "/" + key + "/" + stateToString(NORMAL), "");
|
||||
}
|
||||
|
||||
if (!color.size())
|
||||
{
|
||||
color = getValue<std::string>("graph/node/default/" + key + "/" + stateToString(state), "");
|
||||
}
|
||||
|
||||
if (!color.size() && state != NORMAL)
|
||||
{
|
||||
color = getValue<std::string>("graph/node/default/" + key + "/" + stateToString(NORMAL), "#FFFFFF");
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
std::string ColorScheme::getEdgeTypeColor(Edge::EdgeType type, ColorState state) const
|
||||
{
|
||||
return getEdgeTypeColor(Edge::getTypeString(type), state);
|
||||
}
|
||||
|
||||
std::string ColorScheme::getEdgeTypeColor(const std::string& typeStr, ColorState state) const
|
||||
{
|
||||
std::string type = getValue<std::string>("graph/edge/" + typeStr + "/like", typeStr);
|
||||
std::string color = getValue<std::string>("graph/edge/" + type + "/" + stateToString(state), "");
|
||||
|
||||
if (!color.size() && state != NORMAL)
|
||||
{
|
||||
color = getValue<std::string>("graph/edge/" + type + "/" + stateToString(NORMAL), "");
|
||||
}
|
||||
|
||||
if (!color.size())
|
||||
{
|
||||
color = getValue<std::string>("graph/edge/default/" + stateToString(state), "");
|
||||
}
|
||||
|
||||
if (!color.size() && state != NORMAL)
|
||||
{
|
||||
color = getValue<std::string>("graph/edge/default/" + stateToString(NORMAL), "#FFFFFF");
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
std::string ColorScheme::getSearchTypeColor(const std::string& searchTypeName, const std::string& state) const
|
||||
@@ -47,3 +91,14 @@ std::string ColorScheme::getSyntaxColor(const std::string& key) const
|
||||
ColorScheme::ColorScheme()
|
||||
{
|
||||
}
|
||||
|
||||
std::string ColorScheme::stateToString(ColorState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case NORMAL: return "normal";
|
||||
case FOCUS: return "focus";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
#ifndef COLOR_SCHEME_H
|
||||
#define COLOR_SCHEME_H
|
||||
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/graph/Edge.h"
|
||||
#include "data/graph/Node.h"
|
||||
#include "settings/Settings.h"
|
||||
|
||||
class ColorScheme
|
||||
: public Settings
|
||||
{
|
||||
public:
|
||||
enum ColorState
|
||||
{
|
||||
NORMAL,
|
||||
FOCUS
|
||||
};
|
||||
|
||||
static std::shared_ptr<ColorScheme> getInstance();
|
||||
virtual ~ColorScheme();
|
||||
|
||||
std::string getColor(const std::string& key) const;
|
||||
|
||||
std::string getNodeTypeColor(Node::NodeType type, const std::string& state = "normal") const;
|
||||
std::string getEdgeTypeColor(Edge::EdgeType type, const std::string& state = "normal") const;
|
||||
std::string getNodeTypeColor(Node::NodeType type, const std::string& key, ColorState state) const;
|
||||
std::string getNodeTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const;
|
||||
|
||||
std::string getEdgeTypeColor(Edge::EdgeType type, ColorState state) const;
|
||||
std::string getEdgeTypeColor(const std::string& typeStr, ColorState state) const;
|
||||
|
||||
std::string getSearchTypeColor(const std::string& searchTypeName, const std::string& state = "normal") const;
|
||||
std::string getSyntaxColor(const std::string& key) const;
|
||||
|
||||
@@ -25,6 +35,8 @@ protected:
|
||||
void operator=(const ColorScheme&);
|
||||
|
||||
static std::shared_ptr<ColorScheme> s_instance;
|
||||
|
||||
static std::string stateToString(ColorState state);
|
||||
};
|
||||
|
||||
#endif // COLOR_SCHEME_H
|
||||
|
||||
Reference in New Issue
Block a user