[Bf-blender-cvs] [1a67617631d] geometry-nodes: Geometry Nodes: Expose the active modifier to the UI

Hans Goudey noreply at git.blender.org
Fri Nov 20 20:29:58 CET 2020


Commit: 1a67617631da87637e73037b122002c8b9dbdfa1
Author: Hans Goudey
Date:   Fri Nov 20 14:22:08 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rB1a67617631da87637e73037b122002c8b9dbdfa1

Geometry Nodes: Expose the active modifier to the UI

This exposes the operator to set the active modifier as the type icon
in the header of the modifier panels. Tweaks to the widget drawing
code were necessary to use the red alert for non-emboss operator
buttons. Then, the panel for the active modifier gets a border around it
(which currently uses the property search theme color), requiring
an "active property" field in the PanelType struct.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/modifiers/intern/MOD_ui_common.c

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 68c341692c2..dea9884f508 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -251,6 +251,11 @@ typedef struct PanelType {
   /* draw entirely, view changes should be handled here */
   void (*draw)(const struct bContext *C, struct Panel *panel);
 
+  /**
+   * Identifier of a boolean property of the panel custom data. Used to draw a highlighted border.
+   */
+  const char *active_property;
+
   /* For instanced panels corresponding to a list: */
 
   /** Reorder function, called when drag and drop finishes. */
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 839363c9599..5fbc4818e8b 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -45,6 +45,8 @@
 #include "BKE_context.h"
 #include "BKE_screen.h"
 
+#include "RNA_access.h"
+
 #include "BLF_api.h"
 
 #include "WM_api.h"
@@ -90,6 +92,8 @@ typedef enum uiPanelRuntimeFlag {
    * position. Unlike #PANEL_STATE_ANIMATION, this is applied to sub-panels as well.
    */
   PANEL_IS_DRAG_DROP = (1 << 10),
+  /** Draw a border with the active color around the panel. */
+  PANEL_ACTIVE_BORDER = (1 << 11),
 } uiPanelRuntimeFlag;
 
 /* The state of the mouse position relative to the panel. */
@@ -579,6 +583,22 @@ static void set_panels_list_data_expand_flag(const bContext *C, const ARegion *r
 /** \name Panels
  * \{ */
 
+static bool panel_use_active_highlight(const Panel *panel)
+{
+  /* The caller should make sure the panel is active and has a type. */
+  BLI_assert(UI_panel_is_active(panel));
+  BLI_assert(panel->type != NULL);
+
+  if (panel->type->active_property) {
+    PointerRNA *ptr = UI_panel_custom_data_get(panel);
+    if (ptr != NULL && !RNA_pointer_is_null(ptr)) {
+      return RNA_boolean_get(ptr, panel->type->active_property);
+    }
+  }
+
+  return false;
+}
+
 /**
  * Set flag state for a panel and its sub-panels.
  */
@@ -1062,6 +1082,40 @@ static void panel_title_color_get(const Panel *panel,
   }
 }
 
+static void panel_draw_highlight_border(const Panel *panel,
+                                        const rcti *rect,
+                                        const rcti *header_rect)
+{
+  const bool draw_box_style = panel->type->flag & PANEL_TYPE_DRAW_BOX;
+  const bool is_subpanel = panel->type->parent != NULL;
+  if (is_subpanel) {
+    return;
+  }
+
+  float radius;
+  if (draw_box_style) {
+    /* Use the theme for box widgets. */
+    const uiWidgetColors *box_wcol = &UI_GetTheme()->tui.wcol_box;
+    UI_draw_roundbox_corner_set(UI_CNR_ALL);
+    radius = box_wcol->roundness * U.widget_unit;
+  }
+  else {
+    UI_draw_roundbox_corner_set(UI_CNR_NONE);
+    radius = 0.0f;
+  }
+
+  /* Abuse the property search theme color for now. */
+  float color[4];
+  UI_GetThemeColor4fv(TH_MATCH, color);
+  UI_draw_roundbox_aa(false,
+                      rect->xmin,
+                      UI_panel_is_closed(panel) ? header_rect->ymin : rect->ymin,
+                      rect->xmax,
+                      header_rect->ymax,
+                      radius,
+                      color);
+}
+
 static void panel_draw_aligned_widgets(const uiStyle *style,
                                        const Panel *panel,
                                        const rcti *header_rect,
@@ -1287,6 +1341,10 @@ void ui_draw_aligned_panel(const uiStyle *style,
                                show_background,
                                region_search_filter_active);
   }
+
+  if (panel_use_active_highlight(panel)) {
+    panel_draw_highlight_border(panel, rect, &header_rect);
+  }
 }
 
 /** \} */
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index e2c835ac461..5c1eb4224a7 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -264,7 +264,7 @@ typedef struct uiWidgetType {
   /* converted colors for state */
   uiWidgetColors wcol;
 
-  void (*state)(struct uiWidgetType *, int state, int drawflag);
+  void (*state)(struct uiWidgetType *, int state, int drawflag, char emboss);
   void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign);
   void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign);
   void (*text)(const uiFontStyle *, const uiWidgetColors *, uiBut *, rcti *);
@@ -2561,7 +2561,7 @@ static const uchar *widget_color_blend_from_flags(const uiWidgetStateColors *wco
 }
 
 /* copy colors from theme, and set changes in it based on state */
-static void widget_state(uiWidgetType *wt, int state, int drawflag)
+static void widget_state(uiWidgetType *wt, int state, int drawflag, char emboss)
 {
   uiWidgetStateColors *wcol_state = wt->wcol_state;
 
@@ -2611,7 +2611,7 @@ static void widget_state(uiWidgetType *wt, int state, int drawflag)
 
   if (state & UI_BUT_REDALERT) {
     const uchar red[4] = {255, 0, 0};
-    if (wt->draw) {
+    if (wt->draw && emboss != UI_EMBOSS_NONE) {
       color_blend_v3_v3(wt->wcol.inner, red, 0.4f);
     }
     else {
@@ -2639,12 +2639,12 @@ static void widget_state(uiWidgetType *wt, int state, int drawflag)
  * \{ */
 
 /* sliders use special hack which sets 'item' as inner when drawing filling */
-static void widget_state_numslider(uiWidgetType *wt, int state, int drawflag)
+static void widget_state_numslider(uiWidgetType *wt, int state, int drawflag, char emboss)
 {
   uiWidgetStateColors *wcol_state = wt->wcol_state;
 
   /* call this for option button */
-  widget_state(wt, state, drawflag);
+  widget_state(wt, state, drawflag, emboss);
 
   const uchar *color_blend = widget_color_blend_from_flags(wcol_state, state, drawflag);
   if (color_blend != NULL) {
@@ -2662,7 +2662,7 @@ static void widget_state_numslider(uiWidgetType *wt, int state, int drawflag)
 }
 
 /* labels use theme colors for text */
-static void widget_state_option_menu(uiWidgetType *wt, int state, int drawflag)
+static void widget_state_option_menu(uiWidgetType *wt, int state, int drawflag, char emboss)
 {
   const bTheme *btheme = UI_GetTheme();
 
@@ -2674,24 +2674,33 @@ static void widget_state_option_menu(uiWidgetType *wt, int state, int drawflag)
   copy_v3_v3_uchar(wcol_menu_option.text_sel, btheme->tui.wcol_menu_back.text_sel);
   wt->wcol_theme = &wcol_menu_option;
 
-  widget_state(wt, state, drawflag);
+  widget_state(wt, state, drawflag, emboss);
 
   wt->wcol_theme = old_wcol;
 }
 
-static void widget_state_nothing(uiWidgetType *wt, int UNUSED(state), int UNUSED(drawflag))
+static void widget_state_nothing(uiWidgetType *wt,
+                                 int UNUSED(state),
+                                 int UNUSED(drawflag),
+                                 char UNUSED(emboss))
 {
   wt->wcol = *(wt->wcol_theme);
 }
 
 /* special case, button that calls pulldown */
-static void widget_state_pulldown(uiWidgetType *wt, int UNUSED(state), int UNUSED(drawflag))
+static void widget_state_pulldown(uiWidgetType *wt,
+                                  int UNUSED(state),
+                                  int UNUSED(drawflag),
+                                  char UNUSED(emboss))
 {
   wt->wcol = *(wt->wcol_theme);
 }
 
 /* special case, pie menu items */
-static void widget_state_pie_menu_item(uiWidgetType *wt, int state, int UNUSED(drawflag))
+static void widget_state_pie_menu_item(uiWidgetType *wt,
+                                       int state,
+                                       int UNUSED(drawflag),
+                                       char UNUSED(emboss))
 {
   wt->wcol = *(wt->wcol_theme);
 
@@ -2723,7 +2732,10 @@ static void widget_state_pie_menu_item(uiWidgetType *wt, int state, int UNUSED(d
 }
 
 /* special case, menu items */
-static void widget_state_menu_item(uiWidgetType *wt, int state, int UNUSED(drawflag))
+static void widget_state_menu_item(uiWidgetType *wt,
+                                   int state,
+                                   int UNUSED(drawflag),
+                                   char UNUSED(emboss))
 {
   wt->wcol = *(wt->wcol_theme);
 
@@ -3911,7 +3923,8 @@ static void widget_unitvec(
 static void widget_icon_has_anim(
     uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
 {
-  if (state & (UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN | UI_BUT_REDALERT)) {
+  if (state & (UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN | UI_BUT_REDALERT) &&
+      but->emboss != UI_EMBOSS_NONE) {
     uiWidgetBase wtb;
     float rad;
 
@@ -4102,18 +4115,18 @@ static void widget_optionbut(uiWidgetColors *wcol,
 }
 
 /* labels use Editor theme colors for text */
-static void widget_state_label(uiWidgetType *wt, int state, int drawflag)
+static void widget_state_label(uiWidgetType *wt, int state, int drawflag, char emboss)
 {
   if (state & UI_BUT_LIST_ITEM) {
     /* Override default label theme's colors. */
     bTheme *btheme = UI_GetTheme();
     wt->wcol_theme = &btheme->tui.wcol_list_item;
     /* call this for option button */
-    widget_state(wt, state, drawflag);
+    widget_state(wt, state, drawflag, emboss);
   }
   else {
     /* call this for option button */
-    widget_state(wt, state, drawflag);
+    widget_state(wt, state, drawflag, emboss);
     if (state & UI_SELECT) {
       UI_GetThemeColor3ubv(TH_TEXT_HI, wt->wcol.text);
     }
@@ -4857,7 +4870,7 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu
     }
 #endif
 
-    wt->state(wt, state, drawflag);
+    wt->state(wt, state, drawflag, but->emboss);
     if (wt->custom) {
       wt->custom(but, &wt->wcol, rect, state, roundboxalign);
     }
@@ -4902,7 +4915,7 @@ void ui_draw_menu_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
 {
   uiWidgetType *wt = widget_type(UI_WTYPE_MENU_BACK);
 
-  wt->state(wt, 0, 0);
+  wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
   if (block) {
     wt->draw(&wt->wcol, rect, block->flag, block->direction);
   }
@@ -4923,7 +4936,7 @@ void ui_draw_box_opaque(rcti *rect, int roundboxalign)
 
   /* Alpha blend with t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list