[Bf-blender-cvs] [cf97bd606ea] soc-2020-outliner: Collection Colors: Add icons

Nathan Craddock noreply at git.blender.org
Fri Jul 3 05:42:16 CEST 2020


Commit: cf97bd606ea8b29ed5044e54fa41de7c2302e5a8
Author: Nathan Craddock
Date:   Thu Jul 2 20:05:08 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rBcf97bd606ea8b29ed5044e54fa41de7c2302e5a8

Collection Colors: Add icons

Add square icons for collection color tags. These are still using
hard-coded colors but it would be easy to add them to the themes now.

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

M	release/scripts/startup/bl_ui/space_outliner.py
M	source/blender/editors/include/UI_icons.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/makesrna/intern/rna_collection.c

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

diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index e01c470f74c..5d33c17bd42 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -159,13 +159,13 @@ class OUTLINER_MT_collection_color_tag(Menu):
     def draw(self, context):
         layout = self.layout
 
-        layout.operator("outliner.collection_color_tag_set", text="None").color = 'NONE'
-        layout.operator("outliner.collection_color_tag_set", text="Red").color = 'RED'
-        layout.operator("outliner.collection_color_tag_set", text="Orange").color = 'ORANGE'
-        layout.operator("outliner.collection_color_tag_set", text="Yellow").color = 'YELLOW'
-        layout.operator("outliner.collection_color_tag_set", text="Green").color = 'GREEN'
-        layout.operator("outliner.collection_color_tag_set", text="Blue").color = 'BLUE'
-        layout.operator("outliner.collection_color_tag_set", text="Purple").color = 'PURPLE'
+        layout.operator("outliner.collection_color_tag_set", text="None", icon="NONE").color = 'NONE'
+        layout.operator("outliner.collection_color_tag_set", text="Red", icon="COLLECTION_COLOR_RED").color = 'RED'
+        layout.operator("outliner.collection_color_tag_set", text="Orange", icon="COLLECTION_COLOR_ORANGE").color = 'ORANGE'
+        layout.operator("outliner.collection_color_tag_set", text="Yellow", icon="COLLECTION_COLOR_YELLOW").color = 'YELLOW'
+        layout.operator("outliner.collection_color_tag_set", text="Green", icon="COLLECTION_COLOR_GREEN").color = 'GREEN'
+        layout.operator("outliner.collection_color_tag_set", text="Blue", icon="COLLECTION_COLOR_BLUE").color = 'BLUE'
+        layout.operator("outliner.collection_color_tag_set", text="Purple", icon="COLLECTION_COLOR_PURPLE").color = 'PURPLE'
 
 
 class OUTLINER_MT_collection_view_layer(Menu):
diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h
index 452a1fca111..e5a78407ab8 100644
--- a/source/blender/editors/include/UI_icons.h
+++ b/source/blender/editors/include/UI_icons.h
@@ -980,6 +980,13 @@ DEF_ICON_VECTOR(COLORSET_18_VEC)
 DEF_ICON_VECTOR(COLORSET_19_VEC)
 DEF_ICON_VECTOR(COLORSET_20_VEC)
 
+DEF_ICON_VECTOR(COLLECTION_COLOR_RED)
+DEF_ICON_VECTOR(COLLECTION_COLOR_ORANGE)
+DEF_ICON_VECTOR(COLLECTION_COLOR_YELLOW)
+DEF_ICON_VECTOR(COLLECTION_COLOR_GREEN)
+DEF_ICON_VECTOR(COLLECTION_COLOR_BLUE)
+DEF_ICON_VECTOR(COLLECTION_COLOR_PURPLE)
+
 /* Events  */
 DEF_ICON_COLOR(EVENT_A)
 DEF_ICON_COLOR(EVENT_B)
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 7411639a99f..c7e75913cff 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -39,6 +39,7 @@
 #include "BLI_utildefines.h"
 
 #include "DNA_brush_types.h"
+#include "DNA_collection_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_dynamicpaint_types.h"
 #include "DNA_gpencil_types.h"
@@ -459,6 +460,83 @@ DEF_ICON_VECTOR_COLORSET_DRAW_NTH(20, 19)
 
 #  undef DEF_ICON_VECTOR_COLORSET_DRAW_NTH
 
+static void get_collection_color(float col[4], short color)
+{
+  switch (color) {
+    case COLLECTION_COLOR_RED:
+      col[0] = 0.945f;
+      col[1] = 0.568f;
+      col[2] = 0.560f;
+      col[3] = 1.0f;
+      break;
+    case COLLECTION_COLOR_ORANGE:
+      col[0] = 0.945f;
+      col[1] = 0.580f;
+      col[2] = 0.384f;
+      col[3] = 1.0f;
+      break;
+    case COLLECTION_COLOR_YELLOW:
+      col[0] = 0.752f;
+      col[1] = 0.674f;
+      col[2] = 0.309f;
+      col[3] = 1.0f;
+      break;
+    case COLLECTION_COLOR_GREEN:
+      col[0] = 0.576f;
+      col[1] = 0.717f;
+      col[2] = 0.305f;
+      col[3] = 1.0f;
+      break;
+    case COLLECTION_COLOR_BLUE:
+      col[0] = 0.329f;
+      col[1] = 0.733f;
+      col[2] = 0.705f;
+      col[3] = 1.0f;
+      break;
+    case COLLECTION_COLOR_PURPLE:
+      col[0] = 0.721f;
+      col[1] = 0.619f;
+      col[2] = 0.929f;
+      col[3] = 1.0f;
+      break;
+  }
+}
+
+static void vicon_collection_color_draw(
+    short color, int x, int y, int w, int h, float UNUSED(alpha))
+{
+  bTheme *btheme = UI_GetTheme();
+  float col[4];
+  get_collection_color(col, color);
+  const int c = x + w;
+
+  uint pos = GPU_vertformat_attr_add(
+      immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
+  immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+  /* XXX: Include alpha into this... */
+  /* normal */
+  immUniformColor3fv(col);
+  immRecti(pos, x, y, c, y + h);
+
+  immUnbindProgram();
+}
+
+#  define DEF_ICON_COLLECTION_COLOR_DRAW(name, color) \
+    static void vicon_collection_color_draw_##name(int x, int y, int w, int h, float alpha) \
+    { \
+      vicon_collection_color_draw(color, x, y, w, h, alpha); \
+    }
+
+DEF_ICON_COLLECTION_COLOR_DRAW(red, COLLECTION_COLOR_RED);
+DEF_ICON_COLLECTION_COLOR_DRAW(orange, COLLECTION_COLOR_ORANGE);
+DEF_ICON_COLLECTION_COLOR_DRAW(yellow, COLLECTION_COLOR_YELLOW);
+DEF_ICON_COLLECTION_COLOR_DRAW(green, COLLECTION_COLOR_GREEN);
+DEF_ICON_COLLECTION_COLOR_DRAW(blue, COLLECTION_COLOR_BLUE);
+DEF_ICON_COLLECTION_COLOR_DRAW(purple, COLLECTION_COLOR_PURPLE);
+
+#  undef DEF_ICON_COLLECTION_COLOR_DRAW
+
 /* Dynamically render icon instead of rendering a plain color to a texture/buffer
  * This is not strictly a "vicon", as it needs access to icon->obj to get the color info,
  * but it works in a very similar way.
@@ -1010,6 +1088,13 @@ static void init_internal_icons(void)
   def_internal_vicon(ICON_COLORSET_18_VEC, vicon_colorset_draw_18);
   def_internal_vicon(ICON_COLORSET_19_VEC, vicon_colorset_draw_19);
   def_internal_vicon(ICON_COLORSET_20_VEC, vicon_colorset_draw_20);
+
+  def_internal_vicon(ICON_COLLECTION_COLOR_RED, vicon_collection_color_draw_red);
+  def_internal_vicon(ICON_COLLECTION_COLOR_ORANGE, vicon_collection_color_draw_orange);
+  def_internal_vicon(ICON_COLLECTION_COLOR_YELLOW, vicon_collection_color_draw_yellow);
+  def_internal_vicon(ICON_COLLECTION_COLOR_GREEN, vicon_collection_color_draw_green);
+  def_internal_vicon(ICON_COLLECTION_COLOR_BLUE, vicon_collection_color_draw_blue);
+  def_internal_vicon(ICON_COLLECTION_COLOR_PURPLE, vicon_collection_color_draw_purple);
 }
 #  endif /* WITH_HEADLESS */
 
diff --git a/source/blender/makesrna/intern/rna_collection.c b/source/blender/makesrna/intern/rna_collection.c
index 04d94e87f32..8d2869c5a19 100644
--- a/source/blender/makesrna/intern/rna_collection.c
+++ b/source/blender/makesrna/intern/rna_collection.c
@@ -31,23 +31,35 @@
 #include "WM_types.h"
 
 const EnumPropertyItem rna_enum_collection_color_items[] = {
-    {COLLECTION_COLOR_NONE, "NONE", 0, "None", "Assign no color tag to the collection"},
-    {COLLECTION_COLOR_RED, "RED", 0, "Red", "Assign a red color tag to the collection"},
+    {COLLECTION_COLOR_NONE, "NONE", ICON_NONE, "None", "Assign no color tag to the collection"},
+    {COLLECTION_COLOR_RED,
+     "RED",
+     ICON_COLLECTION_COLOR_RED,
+     "Red",
+     "Assign a red color tag to the collection"},
     {COLLECTION_COLOR_ORANGE,
      "ORANGE",
-     0,
+     ICON_COLLECTION_COLOR_ORANGE,
      "Orange",
      "Assign an orange color tag to the collection"},
     {COLLECTION_COLOR_YELLOW,
      "YELLOW",
-     0,
+     ICON_COLLECTION_COLOR_YELLOW,
      "Yellow",
      "Assign a yellow color tag to the collection"},
-    {COLLECTION_COLOR_GREEN, "GREEN", 0, "Green", "Assign a green color tag to the collection"},
-    {COLLECTION_COLOR_BLUE, "BLUE", 0, "Blue", "Assign a blue color tag to the collection"},
+    {COLLECTION_COLOR_GREEN,
+     "GREEN",
+     ICON_COLLECTION_COLOR_GREEN,
+     "Green",
+     "Assign a green color tag to the collection"},
+    {COLLECTION_COLOR_BLUE,
+     "BLUE",
+     ICON_COLLECTION_COLOR_GREEN,
+     "Blue",
+     "Assign a blue color tag to the collection"},
     {COLLECTION_COLOR_PURPLE,
      "PURPLE",
-     0,
+     ICON_COLLECTION_COLOR_PURPLE,
      "Purple",
      "Assign a purple color tag to the collection"},
     {0, NULL, 0, NULL, NULL},



More information about the Bf-blender-cvs mailing list