diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-11-02 10:25:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-11-02 10:25:47 +0300 |
commit | 08141260ffa619fef1871ccd446b8a59a7b111ca (patch) | |
tree | 7b226f6bf1fc81cc50339278d390b9539efc4495 | |
parent | d2e39edae8d5c6c2062b0a03f63b33e007c4d5b2 (diff) | |
parent | e32c1bd5d03148b123c8d2664b6164fe5cbd5c12 (diff) |
Merge branch 'master' into blender2.8
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 16 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 58 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 20 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 10 |
5 files changed, 51 insertions, 57 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index de6d9d78974..efa5328fc71 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -873,6 +873,10 @@ void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct Pointe void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context); const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing struct MenuType *UI_but_menutype_get(uiBut *but); +void UI_menutype_draw(struct bContext *C, struct MenuType *mt, struct uiLayout *layout); + +/* Only for convenience. */ +void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but); void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext); void uiLayoutSetActive(uiLayout *layout, bool active); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 09b79c19ae5..84252c03742 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -6787,11 +6787,8 @@ static bool ui_but_menu(bContext *C, uiBut *but) /*bool is_idprop = RNA_property_is_idprop(prop);*/ /* XXX does not work as expected, not strictly needed */ bool is_set = RNA_property_is_set(ptr, prop); - /* set the prop and pointer data for python access to the hovered ui element; TODO, index could be supported as well*/ - PointerRNA temp_ptr; - RNA_pointer_create(NULL, &RNA_Property, but->rnaprop, &temp_ptr); - uiLayoutSetContextPointer(layout, "button_prop", &temp_ptr); - uiLayoutSetContextPointer(layout, "button_pointer", ptr); + /* Set the (button_pointer, button_prop) and pointer data for Python access to the hovered ui element. */ + uiLayoutSetContextFromBut(layout, but); /* second slower test, saved people finding keyframe items in menus when its not possible */ if (is_anim) @@ -7010,9 +7007,7 @@ static bool ui_but_menu(bContext *C, uiBut *but) } /* Set the operator pointer for python access */ - if (but->opptr) { - uiLayoutSetContextPointer(layout, "button_operator", but->opptr); - } + uiLayoutSetContextFromBut(layout, but); uiItemS(layout); } @@ -7064,10 +7059,7 @@ static bool ui_but_menu(bContext *C, uiBut *but) mt = WM_menutype_find("WM_MT_button_context", true); if (mt) { - Menu menu = {NULL}; - menu.layout = uiLayoutColumn(layout, false); - menu.type = mt; - mt->draw(C, &menu); + UI_menutype_draw(C, mt, uiLayoutColumn(layout, false)); } UI_popup_menu_end(C, pup); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 212cd462aef..d5ab4fdd1ce 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -882,10 +882,8 @@ static void ui_item_hold_menu(struct bContext *C, ARegion *butregion, uiBut *but const char *menu_id = but->hold_argN; MenuType *mt = WM_menutype_find(menu_id, true); if (mt) { - Menu menu = {NULL}; - menu.layout = layout; - menu.type = mt; - mt->draw(C, &menu); + uiLayoutSetContextFromBut(layout, but); + UI_menutype_draw(C, mt, layout); } else { uiItemL(layout, "Menu Missing:", ICON_NONE); @@ -1782,22 +1780,8 @@ void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propna static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt) { MenuType *mt = (MenuType *)arg_mt; - Menu menu = {NULL}; - menu.type = mt; - menu.layout = layout; - - if (G.debug & G_DEBUG_WM) { - printf("%s: opening menu \"%s\"\n", __func__, mt->idname); - } - - if (layout->context) - CTX_store_set(C, layout->context); - - mt->draw(C, &menu); - - if (layout->context) - CTX_store_set(C, NULL); + UI_menutype_draw(C, mt, layout); /* menus are created flipped (from event handling pov) */ layout->root->block->flag ^= UI_BLOCK_IS_FLIP; @@ -3469,6 +3453,20 @@ void uiLayoutContextCopy(uiLayout *layout, bContextStore *context) layout->context = CTX_store_add_all(&block->contexts, context); } +void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but) +{ + if (but->opptr) { + uiLayoutSetContextPointer(layout, "button_operator", but->opptr); + } + + if (but->rnapoin.data && but->rnaprop) { + /* TODO: index could be supported as well */ + PointerRNA ptr_prop; + RNA_pointer_create(NULL, &RNA_Property, but->rnaprop, &ptr_prop); + uiLayoutSetContextPointer(layout, "button_prop", &ptr_prop); + uiLayoutSetContextPointer(layout, "button_pointer", &but->rnapoin); + } +} /* introspect funcs */ #include "BLI_dynstr.h" @@ -3567,3 +3565,25 @@ MenuType *UI_but_menutype_get(uiBut *but) return NULL; } } + +void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout) +{ + Menu menu = { + .layout = layout, + .type = mt, + }; + + if (G.debug & G_DEBUG_WM) { + printf("%s: opening menu \"%s\"\n", __func__, mt->idname); + } + + if (layout->context) { + CTX_store_set(C, layout->context); + } + + mt->draw(C, &menu); + + if (layout->context) { + CTX_store_set(C, NULL); + } +} diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index cd3aa2095b0..81a7640610d 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -3058,7 +3058,6 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev { uiPieMenu *pie; uiLayout *layout; - Menu menu; MenuType *mt = WM_menutype_find(idname, true); if (mt == NULL) { @@ -3073,14 +3072,7 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event); layout = UI_pie_menu_layout(pie); - menu.layout = layout; - menu.type = mt; - - if (G.debug & G_DEBUG_WM) { - printf("%s: opening menu \"%s\"\n", __func__, idname); - } - - mt->draw(C, &menu); + UI_menutype_draw(C, mt, layout); UI_pie_menu_end(C, pie); @@ -3291,7 +3283,6 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) { uiPopupMenu *pup; uiLayout *layout; - Menu menu; MenuType *mt = WM_menutype_find(idname, true); if (mt == NULL) { @@ -3306,14 +3297,7 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) pup = UI_popup_menu_begin(C, IFACE_(mt->label), ICON_NONE); layout = UI_popup_menu_layout(pup); - menu.layout = layout; - menu.type = mt; - - if (G.debug & G_DEBUG_WM) { - printf("%s: opening menu \"%s\"\n", __func__, idname); - } - - mt->draw(C, &menu); + UI_menutype_draw(C, mt, layout); UI_popup_menu_end(C, pup); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 800be7a3720..c6884f3da8b 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1989,10 +1989,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar UI_block_emboss_set(block, UI_EMBOSS); /* show the splash menu (containing interaction presets), using python */ if (mt) { - Menu menu = {NULL}; - menu.layout = layout; - menu.type = mt; - mt->draw(C, &menu); + UI_menutype_draw(C, mt, layout); // wmWindowManager *wm = CTX_wm_manager(C); // uiItemM(layout, C, "USERPREF_MT_keyconfigs", U.keyconfigstr, ICON_NONE); @@ -2049,10 +2046,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar mt = WM_menutype_find("USERPREF_MT_splash_footer", false); if (mt) { - Menu menu = {NULL}; - menu.layout = uiLayoutColumn(layout, false); - menu.type = mt; - mt->draw(C, &menu); + UI_menutype_draw(C, mt, uiLayoutColumn(layout, false)); } UI_block_bounds_set_centered(block, 0); |