From a74097dc19d1b1d43797fe7dfbc4a2137ad21c22 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 28 Apr 2018 13:34:52 +0200 Subject: UI: Add icon color saturation preference Toolbar icon saturation can now be set from the preferences, (use 0.4 by default). --- .../blender/editors/include/UI_interface_icons.h | 2 +- source/blender/editors/interface/interface_icons.c | 25 ++++++++++++++++------ .../blender/editors/interface/interface_widgets.c | 3 ++- source/blender/editors/interface/resources.c | 1 + .../shaders/gpu_shader_image_desaturate_frag.glsl | 3 ++- source/blender/makesdna/DNA_userdef_types.h | 2 ++ source/blender/makesrna/intern/rna_userdef.c | 4 ++++ 7 files changed, 30 insertions(+), 10 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h index a17eb6be618..a3be887bf5b 100644 --- a/source/blender/editors/include/UI_interface_icons.h +++ b/source/blender/editors/include/UI_interface_icons.h @@ -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); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index c78e49517c3..2fca0bbbf79 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -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 */ diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 339bedc1c06..bd9b22c9a2f 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -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); } } diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index d284bde6ce6..96ba722289d 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -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; } } diff --git a/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl index 5b2ccb8ff3a..1ac0d68b35f 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl @@ -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; } diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 3973006283d..7b2ad060e61 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -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]; diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index f99b4b59f1a..03034522d30 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -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"); -- cgit v1.2.3