Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2020-11-19 23:21:18 +0300
committerHans Goudey <h.goudey@me.com>2020-11-19 23:21:18 +0300
commit6d77e2bb1767828c887604040f7c718cb7e47da3 (patch)
treecf2a61a0fef0af760fb243b3a7fcc1f64c270e89
parentb7d7051dc390e1dcc8e05a4a0db7ab59a5cf7d7f (diff)
Geometry Nodes: Expose the active modifier to the UIgeometry-nodes-active-modifier-drawing
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.
-rw-r--r--source/blender/blenkernel/BKE_screen.h5
-rw-r--r--source/blender/editors/interface/interface_panel.c58
-rw-r--r--source/blender/editors/interface/interface_widgets.c61
-rw-r--r--source/blender/modifiers/intern/MOD_ui_common.c12
4 files changed, 111 insertions, 25 deletions
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 the region's background color to force an opaque background. */
uiWidgetColors *wcol = &wt->wcol;
- wt->state(wt, 0, 0);
+ wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
float background[4];
UI_GetThemeColor4fv(TH_BACK, background);
float new_inner[4];
@@ -5025,7 +5038,7 @@ void ui_draw_popover_back(struct ARegion *region,
wt->wcol_theme, rect, block->direction, U.widget_unit / block->aspect, mval_origin);
}
else {
- wt->state(wt, 0, 0);
+ wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, 0, 0);
}
@@ -5215,7 +5228,7 @@ static void ui_draw_widget_back_color(uiWidgetTypeEnum type,
}
rcti rect_copy = *rect;
- wt->state(wt, 0, 0);
+ wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
if (color) {
rgba_float_to_uchar(wt->wcol.inner, color);
}
@@ -5234,7 +5247,7 @@ void ui_draw_widget_menu_back(const rcti *rect, bool use_shadow)
void ui_draw_tooltip_background(const uiStyle *UNUSED(style), uiBlock *UNUSED(block), rcti *rect)
{
uiWidgetType *wt = widget_type(UI_WTYPE_TOOLTIP);
- wt->state(wt, 0, 0);
+ wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
/* wt->draw ends up using same function to draw the tooltip as menu_back */
wt->draw(&wt->wcol, rect, 0, 0);
}
@@ -5261,7 +5274,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
const rcti _rect = *rect;
char *cpoin = NULL;
- wt->state(wt, state, 0);
+ wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, 0, 0);
UI_fontstyle_set(fstyle);
@@ -5344,7 +5357,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
if (use_sep) {
if (cpoin) {
/* Set inactive state for grayed out text. */
- wt->state(wt, state | UI_BUT_INACTIVE, 0);
+ wt->state(wt, state | UI_BUT_INACTIVE, 0, UI_EMBOSS_UNDEFINED);
rect->xmax = _rect.xmax - 5;
UI_fontstyle_draw(fstyle,
@@ -5368,7 +5381,7 @@ void ui_draw_preview_item(
uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM);
/* drawing button background */
- wt->state(wt, state, 0);
+ wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, 0, 0);
/* draw icon in rect above the space reserved for the label */
diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c
index 6c92ceb6fc0..6c348474390 100644
--- a/source/blender/modifiers/intern/MOD_ui_common.c
+++ b/source/blender/modifiers/intern/MOD_ui_common.c
@@ -306,11 +306,20 @@ static void modifier_panel_header(const bContext *C, Panel *panel)
int index = BLI_findindex(&ob->modifiers, md);
/* Modifier Icon. */
+ uiItemS_ex(layout, 0.1f);
sub = uiLayoutRow(layout, true);
if (mti->isDisabled && mti->isDisabled(scene, md, 0)) {
uiLayoutSetRedAlert(sub, true);
}
- uiItemL(sub, "", RNA_struct_ui_icon(ptr->type));
+ uiLayoutSetEmboss(sub, UI_EMBOSS_NONE);
+ uiItemFullO(sub,
+ "OBJECT_OT_modifier_set_active",
+ "",
+ RNA_struct_ui_icon(ptr->type),
+ NULL,
+ WM_OP_INVOKE_DEFAULT,
+ 0,
+ NULL);
row = uiLayoutRow(layout, true);
@@ -417,6 +426,7 @@ PanelType *modifier_panel_register(ARegionType *region_type, ModifierType type,
/* Give the panel the special flag that says it was built here and corresponds to a
* modifier rather than a #PanelType. */
panel_type->flag = PANEL_TYPE_HEADER_EXPAND | PANEL_TYPE_DRAW_BOX | PANEL_TYPE_INSTANCED;
+ panel_type->active_property = "is_active";
panel_type->reorder = modifier_reorder;
panel_type->get_list_data_expand_flag = get_modifier_expand_flag;
panel_type->set_list_data_expand_flag = set_modifier_expand_flag;