UI: Add icon color saturation preference

Toolbar icon saturation can now be set from the preferences,
(use 0.4 by default).
This commit is contained in:
2018-04-28 13:34:52 +02:00
parent 69ca12c45c
commit a74097dc19
8 changed files with 31 additions and 10 deletions

View File

@@ -898,6 +898,7 @@ class USERPREF_PT_theme(Panel):
colsub = padding.column()
colsub.row().prop(ui, "menu_shadow_fac")
colsub.row().prop(ui, "icon_alpha")
colsub.row().prop(ui, "icon_saturation")
colsub.row().prop(ui, "editor_outline")
subsplit = row.split(percentage=0.85)

View File

@@ -76,7 +76,7 @@ void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspec
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha);
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3]);
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha);
void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha);
void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha, float desaturate);
void UI_icons_free(void);
void UI_icons_free_drawinfo(void *drawinfo);

View File

@@ -977,7 +977,7 @@ PreviewImage *UI_icon_to_preview(int icon_id)
}
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh,
unsigned int *rect, float alpha, const float rgb[3], const bool desaturate)
unsigned int *rect, float alpha, const float rgb[3], const float desaturate)
{
ImBuf *ima = NULL;
int draw_w = w;
@@ -1026,8 +1026,19 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
UI_widgetbase_draw_cache_flush();
/* draw */
GPUBuiltinShader shader = (desaturate) ? GPU_SHADER_2D_IMAGE_DESATURATE_COLOR : GPU_SHADER_2D_IMAGE_COLOR;
GPUBuiltinShader shader;
if (desaturate != 0.0f) {
shader = GPU_SHADER_2D_IMAGE_DESATURATE_COLOR;
}
else {
shader = GPU_SHADER_2D_IMAGE_COLOR;
}
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(shader);
if (shader == GPU_SHADER_2D_IMAGE_DESATURATE_COLOR) {
immUniform1f("factor", desaturate);
}
immDrawPixelsTex(&state, draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
1.0f, 1.0f, col);
@@ -1193,7 +1204,7 @@ static int get_draw_size(enum eIconSizes size)
static void icon_draw_size(
float x, float y, int icon_id, float aspect, float alpha, const float rgb[3],
enum eIconSizes size, int draw_size, const bool desaturate)
enum eIconSizes size, int draw_size, const float desaturate)
{
bTheme *btheme = UI_GetTheme();
Icon *icon = NULL;
@@ -1529,7 +1540,7 @@ int UI_idcode_icon_get(const int idcode)
static void icon_draw_at_size(
float x, float y, int icon_id, float aspect, float alpha,
enum eIconSizes size, const bool desaturate)
enum eIconSizes size, const float desaturate)
{
int draw_size = get_draw_size(size);
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, desaturate);
@@ -1537,7 +1548,7 @@ static void icon_draw_at_size(
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha)
{
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, false);
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0.0f);
}
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3])
@@ -1546,9 +1557,9 @@ void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, cons
icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false);
}
void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha)
void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha, float desaturate)
{
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, true);
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, desaturate);
}
/* draws icon with dpi scale factor */

View File

@@ -1327,7 +1327,8 @@ static void widget_draw_icon_ex(
UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
}
else {
UI_icon_draw_desaturate(xs, ys, icon, aspect, alpha);
const bTheme *btheme = UI_GetTheme();
UI_icon_draw_desaturate(xs, ys, icon, aspect, alpha, 1.0 - btheme->tui.icon_saturation);
}
}

View File

@@ -2999,6 +2999,7 @@ void init_userdef_do_versions(void)
};
for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) {
btheme->tui.wcol_toolbar_item = wcol_toolbar_item;
btheme->tui.icon_saturation = 0.4f;
}
}

View File

@@ -1,4 +1,5 @@
uniform float factor;
in vec2 texCoord_interp;
out vec4 fragColor;
@@ -8,6 +9,6 @@ uniform sampler2D image;
void main()
{
vec4 tex = texture(image, texCoord_interp);
tex.rgb = 0.3333333 * vec3(tex.r + tex.g + tex.b);
tex.rgb = ((0.3333333 * factor) * vec3(tex.r + tex.g + tex.b)) + (tex.rgb * (1.0 - factor));
fragColor = tex * color;
}

View File

@@ -185,6 +185,8 @@ typedef struct ThemeUI {
char iconfile[256]; // FILE_MAXFILE length
float icon_alpha;
float icon_saturation;
char _pad[4];
/* Axis Colors */
char xaxis[4], yaxis[4], zaxis[4];

View File

@@ -1076,6 +1076,10 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
prop = RNA_def_property(srna, "icon_alpha", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_ui_text(prop, "Icon Alpha", "Transparency of icons in the interface, to reduce contrast");
RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "icon_saturation", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_ui_text(prop, "Icon Saturation", "Saturation of icons in the interface");
RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "widget_emboss", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "widget_emboss");