[Bf-blender-cvs] [60ca2fe3385] master: UI: dim icons in inactive tabs, similar to text

Brecht Van Lommel noreply at git.blender.org
Thu May 9 19:55:52 CEST 2019


Commit: 60ca2fe3385d4c8b51d54ca05012d5741b5c1c79
Author: Brecht Van Lommel
Date:   Thu May 9 17:37:26 2019 +0200
Branches: master
https://developer.blender.org/rB60ca2fe3385d4c8b51d54ca05012d5741b5c1c79

UI: dim icons in inactive tabs, similar to text

This makes the properties editor navigation bar less saturated. Internally
the icon theme coloring was refactored a bit to move more towards the button
drawing code.

===================================================================

M	source/blender/editors/include/UI_interface_icons.h
M	source/blender/editors/include/UI_resources.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/interface/resources.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/windowmanager/intern/wm_dragdrop.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index 53bd0f01d34..1f15fa3bd4d 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -56,6 +56,7 @@ void UI_icons_reload_internal_textures(void);
 
 int UI_icon_get_width(int icon_id);
 int UI_icon_get_height(int icon_id);
+bool UI_icon_get_theme_color(int icon_id, unsigned char color[4]);
 
 void UI_id_icon_render(const struct bContext *C,
                        struct Scene *scene,
@@ -74,7 +75,8 @@ void UI_icon_draw_ex(float x,
                      float aspect,
                      float alpha,
                      float desaturate,
-                     const char mono_color[4]);
+                     const char mono_color[4],
+                     const bool mono_border);
 
 void UI_icon_draw_desaturate(float x,
                              float y,
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index 404dfe3c177..7abc27c5b37 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -384,7 +384,7 @@ void UI_GetThemeColorType3ubv(int colorid, int spacetype, unsigned char col[3]);
 void UI_GetThemeColorType4ubv(int colorid, int spacetype, unsigned char col[4]);
 
 // get theme color for coloring monochrome icons
-bool UI_GetIconThemeColor4fv(int colorid, float col[4]);
+bool UI_GetIconThemeColor4ubv(int colorid, unsigned char col[4]);
 
 // shade a 3 byte color (same as UI_GetColorPtrBlendShade3ubv with 0.0 factor)
 void UI_GetColorPtrShade3ubv(const unsigned char cp1[3], unsigned char col[3], int offset);
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 3b941969fd5..baa782dcb35 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1222,6 +1222,17 @@ int UI_icon_get_height(int icon_id)
   return 0;
 }
 
+bool UI_icon_get_theme_color(int icon_id, uchar color[4])
+{
+  Icon *icon = BKE_icon_get(icon_id);
+  if (icon == NULL) {
+    return false;
+  }
+
+  DrawInfo *di = icon_ensure_drawinfo(icon);
+  return UI_GetIconThemeColor4ubv(di->data.texture.theme_color, color);
+}
+
 void UI_icons_init()
 {
 #ifndef WITH_HEADLESS
@@ -1762,7 +1773,8 @@ static void icon_draw_size(float x,
                            enum eIconSizes size,
                            int draw_size,
                            const float desaturate,
-                           const char mono_rgba[4])
+                           const char mono_rgba[4],
+                           const bool mono_border)
 {
   bTheme *btheme = UI_GetTheme();
   Icon *icon = NULL;
@@ -1843,19 +1855,14 @@ static void icon_draw_size(float x,
                       false);
   }
   else if (di->type == ICON_TYPE_MONO_TEXTURE) {
-    /* icon that matches text color, assumed to be white */
-    bool with_border = false;
+    /* Monochrome icon that uses text or theme color. */
+    bool with_border = mono_border && (btheme->tui.icon_border_intensity > 0.0f);
     float color[4];
-    if (!UI_GetIconThemeColor4fv(di->data.texture.theme_color, color)) {
-      if (mono_rgba) {
-        rgba_uchar_to_float(color, (const uchar *)mono_rgba);
-      }
-      else {
-        UI_GetThemeColor4fv(TH_TEXT, color);
-      }
+    if (mono_rgba) {
+      rgba_uchar_to_float(color, (const uchar *)mono_rgba);
     }
     else {
-      with_border = (btheme->tui.icon_border_intensity > 0.0f);
+      UI_GetThemeColor4fv(TH_TEXT, color);
     }
 
     mul_v4_fl(color, alpha);
@@ -2233,17 +2240,17 @@ int UI_idcode_icon_get(const int idcode)
 /* draws icon with dpi scale factor */
 void UI_icon_draw(float x, float y, int icon_id)
 {
-  UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, 0.0f, NULL);
+  UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, 0.0f, NULL, false);
 }
 
 void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
 {
-  UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, 0.0f, NULL);
+  UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, 0.0f, NULL, false);
 }
 
 void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)
 {
-  icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, false, NULL);
+  icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, false, NULL, false);
 }
 
 void UI_icon_draw_ex(float x,
@@ -2252,8 +2259,18 @@ void UI_icon_draw_ex(float x,
                      float aspect,
                      float alpha,
                      float desaturate,
-                     const char mono_color[4])
+                     const char mono_color[4],
+                     const bool mono_border)
 {
   int draw_size = get_draw_size(ICON_SIZE_ICON);
-  icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, draw_size, desaturate, mono_color);
+  icon_draw_size(x,
+                 y,
+                 icon_id,
+                 aspect,
+                 alpha,
+                 ICON_SIZE_ICON,
+                 draw_size,
+                 desaturate,
+                 mono_color,
+                 mono_border);
 }
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 66fb609335d..724d5aa8cd2 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -771,7 +771,8 @@ void ui_draw_aligned_panel(uiStyle *style,
                     (block->aspect / UI_DPI_FAC),
                     1.0f,
                     0.0f,
-                    (const char *)col_title);
+                    (const char *)col_title,
+                    false);
     GPU_blend(false);
   }
 
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 62fc785a432..43efa758492 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1506,20 +1506,27 @@ static void widget_draw_icon(
       ys = (int)(ys + 0.1f);
     }
 
+    /* Get theme color. */
+    char color[4] = {mono_color[0], mono_color[1], mono_color[2], mono_color[3]};
+    bool has_theme = UI_icon_get_theme_color(icon, (uchar *)color);
+
     /* to indicate draggable */
     if (but->dragpoin && (but->flag & UI_ACTIVE)) {
-      UI_icon_draw_ex(xs, ys, icon, aspect, 1.25f, 0.0f, mono_color);
+      UI_icon_draw_ex(xs, ys, icon, aspect, 1.25f, 0.0f, color, has_theme);
     }
     else if ((but->flag & (UI_ACTIVE | UI_SELECT | UI_SELECT_DRAW))) {
-      UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, mono_color);
+      UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, color, has_theme);
     }
     else if (!UI_but_is_tool(but)) {
-      UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, mono_color);
+      if (has_theme) {
+        alpha *= 0.8f;
+      }
+      UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, color, has_theme);
     }
     else {
       const bTheme *btheme = UI_GetTheme();
       const float desaturate = 1.0 - btheme->tui.icon_saturation;
-      UI_icon_draw_ex(xs, ys, icon, aspect, alpha, desaturate, mono_color);
+      UI_icon_draw_ex(xs, ys, icon, aspect, alpha, desaturate, color, has_theme);
     }
   }
 
@@ -1586,7 +1593,8 @@ static void ui_text_clip_right_ex(const uiFontStyle *fstyle,
   BLI_assert(str[0]);
 
   /* If the trailing ellipsis takes more than 20% of all available width, just cut the string
-   * (as using the ellipsis would remove even more useful chars, and we cannot show much already!).
+   * (as using the ellipsis would remove even more useful chars, and we cannot show much
+   * already!).
    */
   if (sep_strwidth / okwidth > 0.2f) {
     l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, &tmp);
@@ -1701,7 +1709,8 @@ float UI_text_clip_middle_ex(const uiFontStyle *fstyle,
         /* Corner case, the str already takes all available mem,
          * and the ellipsis chars would actually add more chars.
          * Better to just trim one or two letters to the right in this case...
-         * Note: with a single-char ellipsis, this should never happen! But better be safe here...
+         * Note: with a single-char ellipsis, this should never happen! But better be safe
+         * here...
          */
         ui_text_clip_right_ex(
             fstyle, str, max_len, okwidth, sep, sep_len, sep_strwidth, &final_lpart_len);
@@ -5203,7 +5212,7 @@ void ui_draw_menu_item(
 
     GPU_blend(true);
     /* XXX scale weak get from fstyle? */
-    UI_icon_draw_ex(xs, ys, iconid, aspect, 1.0f, 0.0f, wt->wcol.text);
+    UI_icon_draw_ex(xs, ys, iconid, aspect, 1.0f, 0.0f, wt->wcol.text, false);
     GPU_blend(false);
   }
 }
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 86806946db0..14fad2f3072 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -1357,7 +1357,7 @@ void UI_GetThemeColorType4ubv(int colorid, int spacetype, uchar col[4])
   col[3] = cp[3];
 }
 
-bool UI_GetIconThemeColor4fv(int colorid, float col[4])
+bool UI_GetIconThemeColor4ubv(int colorid, uchar col[4])
 {
   if (colorid == 0) {
     return false;
@@ -1371,12 +1371,11 @@ bool UI_GetIconThemeColor4fv(int colorid, float col[4])
     return false;
   }
 
-  const uchar *cp;
-  cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
-  col[0] = ((float)cp[0]) / 255.0f;
-  col[1] = ((float)cp[1]) / 255.0f;
-  col[2] = ((float)cp[2]) / 255.0f;
-  col[3] = ((float)cp[3]) / 255.0f;
+  const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
+  col[0] = cp[0];
+  col[1] = cp[1];
+  col[2] = cp[2];
+  col[3] = cp[3];
 
   return true;
 }
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 765dfc9dd88..322b798057e 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -203,7 +203,7 @@ static voi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list