From a6e1f7560fa4e6308a83d42d701a1b95d7db38a8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 2 Nov 2017 05:00:09 +1100 Subject: UI: Option to draw button pressed Needed to show the active tool --- source/blender/editors/include/UI_interface.h | 1 + source/blender/editors/interface/interface_layout.c | 4 ++++ source/blender/makesrna/intern/rna_ui_api.c | 15 ++++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index a609a3b51fd..a0664f020bf 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -832,6 +832,7 @@ void UI_exit(void); #define UI_ITEM_R_FULL_EVENT (1 << 6) #define UI_ITEM_R_NO_BG (1 << 7) #define UI_ITEM_R_IMMEDIATE (1 << 8) +#define UI_ITEM_O_DEPRESS (1 << 9) /* uiTemplateOperatorPropertyButs flags */ #define UI_TEMPLATE_OP_PROPS_SHOW_TITLE 1 diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 33dc74cbe23..936b4fd2bba 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -845,6 +845,10 @@ static uiBut *uiItemFullO_ptr_ex( if (flag & UI_ITEM_R_NO_BG) UI_block_emboss_set(block, UI_EMBOSS); + if (flag & UI_ITEM_O_DEPRESS) { + but->flag |= UI_SELECT; + } + if (layout->redalert) UI_but_flag_enable(but, UI_BUT_REDALERT); diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index eb95602010a..69636788493 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -175,11 +175,11 @@ static void rna_uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const c uiItemPointerR(layout, ptr, propname, searchptr, searchpropname, name, icon); } -static PointerRNA rna_uiItemO(uiLayout *layout, const char *opname, const char *name, const char *text_ctxt, - int translate, int icon, int emboss, int icon_value) +static PointerRNA rna_uiItemO( + uiLayout *layout, const char *opname, const char *name, const char *text_ctxt, + int translate, int icon, int emboss, int depress, int icon_value) { wmOperatorType *ot; - int flag; ot = WM_operatortype_find(opname, 0); /* print error next */ if (!ot || !ot->srna) { @@ -193,9 +193,8 @@ static PointerRNA rna_uiItemO(uiLayout *layout, const char *opname, const char * if (icon_value && !icon) { icon = icon_value; } - - flag = 0; - flag |= (emboss) ? 0 : UI_ITEM_R_NO_BG; + int flag = (emboss) ? 0 : UI_ITEM_R_NO_BG; + flag |= (depress) ? UI_ITEM_O_DEPRESS : 0; PointerRNA opptr; uiItemFullO_ptr(layout, ot, name, icon, NULL, uiLayoutGetOperatorContext(layout), flag, &opptr); @@ -204,7 +203,7 @@ static PointerRNA rna_uiItemO(uiLayout *layout, const char *opname, const char * static PointerRNA rna_uiItemOMenuHold( uiLayout *layout, const char *opname, const char *name, const char *text_ctxt, - int translate, int icon, int emboss, int icon_value, + int translate, int icon, int emboss, int depress, int icon_value, const char *menu) { wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */ @@ -219,6 +218,7 @@ static PointerRNA rna_uiItemOMenuHold( icon = icon_value; } int flag = (emboss) ? 0 : UI_ITEM_R_NO_BG; + flag |= (depress) ? UI_ITEM_O_DEPRESS : 0; PointerRNA opptr; uiItemFullOMenuHold_ptr(layout, ot, name, icon, NULL, uiLayoutGetOperatorContext(layout), flag, menu, &opptr); @@ -583,6 +583,7 @@ void RNA_api_ui_layout(StructRNA *srna) RNA_def_function(srna, "operator", "rna_uiItemO"); api_ui_item_op_common(func); RNA_def_boolean(func, "emboss", true, "", "Draw the button itself, just the icon/text"); + RNA_def_boolean(func, "depress", false, "", "Draw pressed in"); parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED); RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item"); if (is_menu_hold) { -- cgit v1.2.3