diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-10 06:43:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-10 06:48:25 +0300 |
commit | 6b082278d19599100cc0b50cc96e4fa00865d093 (patch) | |
tree | d5f7341c5f53d1282d71383218f2a9f8d46c1caa /source/blender | |
parent | a287153ee49741e23dbee273a6ad7425dab94de4 (diff) |
UI: expose tool settings in the 3D view side-bar
Internally tool settings have been moved to the 3D view.
Added the ability for to draw panels from another space/region
so they can be mirrored in the properties editor.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_screen.h | 5 | ||||
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_panel.c | 6 | ||||
-rw-r--r-- | source/blender/editors/screen/area.c | 86 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/space_buttons.c | 103 | ||||
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 104 |
7 files changed, 168 insertions, 143 deletions
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 9759be73270..a7a95a4a659 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -87,9 +87,12 @@ void ED_region_panels_ex(const struct bContext *C, void ED_region_panels(const struct bContext *C, struct ARegion *ar); void ED_region_panels_layout_ex(const struct bContext *C, struct ARegion *ar, + struct ListBase *paneltypes, const char *contexts[], int contextnr, - const bool vertical); + const bool vertical, + const char *category_override); + void ED_region_panels_layout(const struct bContext *C, struct ARegion *ar); void ED_region_panels_draw(const struct bContext *C, struct ARegion *ar); diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index fd51419a3ee..3503d38ad92 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -730,4 +730,9 @@ void ED_view3d_gizmo_mesh_preselect_get_active(struct bContext *C, struct Base **r_base, struct BMElem **r_ele); +/* space_view3d.c */ +void ED_view3d_buttons_region_layout_ex(const struct bContext *C, + struct ARegion *ar, + const char *category_override); + #endif /* __ED_VIEW3D_H__ */ diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index cb2c55a26df..be43df76813 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -2069,7 +2069,11 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active) ui_fontscale(&fstyle_points, aspect / (U.pixelsize * 1.1f)); BLF_size(fontid, fstyle_points, U.dpi); - BLI_assert(UI_panel_category_is_visible(ar)); + /* Check the region type supports categories to avoid an assert + * for showing 3D view panels in the properties space. */ + if ((1 << ar->regiontype) & RGN_TYPE_HAS_CATEGORY_MASK) { + BLI_assert(UI_panel_category_is_visible(ar)); + } /* calculate tab rect's and check if we need to scale down */ for (pc_dyn = ar->panels_category.first; pc_dyn; pc_dyn = pc_dyn->next) { diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index b359a4c4440..d74d4a0d798 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -2300,14 +2300,48 @@ static void ed_panel_draw(const bContext *C, * Matching against any of these strings will draw the panel. * Can be NULL to skip context checks. */ -void ED_region_panels_layout_ex( - const bContext *C, ARegion *ar, const char *contexts[], int contextnr, const bool vertical) +void ED_region_panels_layout_ex(const bContext *C, + ARegion *ar, + ListBase *paneltypes, + const char *contexts[], + int contextnr, + const bool vertical, + const char *category_override) { + /* collect panels to draw */ + LinkNode *panel_types_stack = NULL; + for (PanelType *pt = paneltypes->last; pt; pt = pt->prev) { + WorkSpace *workspace = CTX_wm_workspace(C); + /* Only draw top level panels. */ + if (pt->parent) { + continue; + } + + if (category_override) { + if (!STREQ(pt->category, category_override)) { + continue; + } + } + + /* verify context */ + if (contexts && pt->context[0] && !streq_array_any(pt->context, contexts)) { + continue; + } + + /* If we're tagged, only use compatible. */ + if (pt->owner_id[0] && BKE_workspace_owner_id_check(workspace, pt->owner_id) == false) { + continue; + } + + /* draw panel */ + if (pt->draw && (!pt->poll || pt->poll(C, pt))) { + BLI_linklist_prepend_alloca(&panel_types_stack, pt); + } + } + ar->runtime.category = NULL; - const WorkSpace *workspace = CTX_wm_workspace(C); ScrArea *sa = CTX_wm_area(C); - PanelType *pt; View2D *v2d = &ar->v2d; int x, y, w, em; bool is_context_new = 0; @@ -2315,16 +2349,15 @@ void ED_region_panels_layout_ex( /* XXX, should use some better check? */ /* For now also has hardcoded check for clip editor until it supports actual toolbar. */ - bool use_category_tabs = ((1 << ar->regiontype) & RGN_TYPE_HAS_CATEGORY_MASK) || - (ar->regiontype == RGN_TYPE_TOOLS && sa->spacetype == SPACE_CLIP); + bool use_category_tabs = (category_override == NULL) && + ((((1 << ar->regiontype) & RGN_TYPE_HAS_CATEGORY_MASK) || + (ar->regiontype == RGN_TYPE_TOOLS && sa->spacetype == SPACE_CLIP))); /* offset panels for small vertical tab area */ const char *category = NULL; const int category_tabs_width = UI_PANEL_CATEGORY_MARGIN_WIDTH; int margin_x = 0; const bool region_layout_based = ar->flag & RGN_FLAG_DYNAMIC_SIZE; - BLI_SMALLSTACK_DECLARE(pt_stack, PanelType *); - if (contextnr != -1) { is_context_new = UI_view2d_tab_set(v2d, contextnr); } @@ -2348,42 +2381,19 @@ void ED_region_panels_layout_ex( scroll = v2d->scroll; - /* collect panels to draw */ - for (pt = ar->type->paneltypes.last; pt; pt = pt->prev) { - /* Only draw top level panels. */ - if (pt->parent) { - continue; - } - - /* verify context */ - if (contexts && pt->context[0] && !streq_array_any(pt->context, contexts)) { - continue; - } - - /* If we're tagged, only use compatible. */ - if (pt->owner_id[0] && BKE_workspace_owner_id_check(workspace, pt->owner_id) == false) { - continue; - } - - /* draw panel */ - if (pt->draw && (!pt->poll || pt->poll(C, pt))) { - BLI_SMALLSTACK_PUSH(pt_stack, pt); - } - } - /* collect categories */ if (use_category_tabs) { UI_panel_category_clear_all(ar); /* gather unique categories */ - BLI_SMALLSTACK_ITER_BEGIN (pt_stack, pt) { + for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) { + PanelType *pt = pt_link->link; if (pt->category[0]) { if (!UI_panel_category_find(ar, pt->category)) { UI_panel_category_add(ar, pt->category); } } } - BLI_SMALLSTACK_ITER_END; if (!UI_panel_category_is_visible(ar)) { use_category_tabs = false; @@ -2411,7 +2421,8 @@ void ED_region_panels_layout_ex( /* set view2d view matrix - UI_block_begin() stores it */ UI_view2d_view_ortho(v2d); - BLI_SMALLSTACK_ITER_BEGIN (pt_stack, pt) { + for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) { + PanelType *pt = pt_link->link; Panel *panel = UI_panel_find_by_type(&ar->panels, pt); if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) { @@ -2422,7 +2433,6 @@ void ED_region_panels_layout_ex( ed_panel_draw(C, sa, ar, &ar->panels, pt, panel, w, em, vertical); } - BLI_SMALLSTACK_ITER_END; /* align panels and return size */ UI_panels_end(C, ar, &x, &y); @@ -2493,9 +2503,11 @@ void ED_region_panels_layout_ex( ar->runtime.category = category; } } + void ED_region_panels_layout(const bContext *C, ARegion *ar) { - ED_region_panels_layout_ex(C, ar, NULL, -1, true); + bool vertical = true; + ED_region_panels_layout_ex(C, ar, &ar->type->paneltypes, NULL, -1, vertical, NULL); } void ED_region_panels_draw(const bContext *C, ARegion *ar) @@ -2544,7 +2556,7 @@ void ED_region_panels_ex( const bContext *C, ARegion *ar, const char *contexts[], int contextnr, const bool vertical) { /* TODO: remove? */ - ED_region_panels_layout_ex(C, ar, contexts, contextnr, vertical); + ED_region_panels_layout_ex(C, ar, &ar->type->paneltypes, contexts, contextnr, vertical, NULL); ED_region_panels_draw(C, ar); } diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 12d82bef118..9b0150d731d 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -34,6 +34,7 @@ #include "ED_space_api.h" #include "ED_screen.h" +#include "ED_view3d.h" /* To draw toolbar UI. */ #include "WM_api.h" #include "WM_types.h" @@ -198,105 +199,7 @@ static void buttons_main_region_layout_properties(const bContext *C, } const bool vertical = true; - ED_region_panels_layout_ex(C, ar, contexts, sbuts->mainb, vertical); -} - -static void buttons_main_region_layout_tool(const bContext *C, ARegion *ar) -{ - const enum eContextObjectMode mode = CTX_data_mode_enum(C); - - const char *contexts_base[5] = {NULL}; - contexts_base[0] = ".active_tool"; - const char **contexts = &contexts_base[1]; - - /* Hard coded to 3D view. */ - { - switch (mode) { - case CTX_MODE_EDIT_MESH: - ARRAY_SET_ITEMS(contexts, ".mesh_edit"); - break; - case CTX_MODE_EDIT_CURVE: - ARRAY_SET_ITEMS(contexts, ".curve_edit"); - break; - case CTX_MODE_EDIT_SURFACE: - ARRAY_SET_ITEMS(contexts, ".curve_edit"); - break; - case CTX_MODE_EDIT_TEXT: - ARRAY_SET_ITEMS(contexts, ".text_edit"); - break; - case CTX_MODE_EDIT_ARMATURE: - ARRAY_SET_ITEMS(contexts, ".armature_edit"); - break; - case CTX_MODE_EDIT_METABALL: - ARRAY_SET_ITEMS(contexts, ".mball_edit"); - break; - case CTX_MODE_EDIT_LATTICE: - ARRAY_SET_ITEMS(contexts, ".lattice_edit"); - break; - case CTX_MODE_POSE: - ARRAY_SET_ITEMS(contexts, ".posemode"); - break; - case CTX_MODE_SCULPT: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".sculpt_mode"); - break; - case CTX_MODE_PAINT_WEIGHT: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".weightpaint"); - break; - case CTX_MODE_PAINT_VERTEX: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".vertexpaint"); - break; - case CTX_MODE_PAINT_TEXTURE: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".imagepaint"); - break; - case CTX_MODE_PARTICLE: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".particlemode"); - break; - case CTX_MODE_OBJECT: - ARRAY_SET_ITEMS(contexts, ".objectmode"); - break; - case CTX_MODE_PAINT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); - break; - case CTX_MODE_SCULPT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); - break; - case CTX_MODE_WEIGHT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); - break; - default: - break; - } - } - - /* for grease pencil we don't use tool system yet, so we need check outside - * workspace->tools_space_type because this value is not available - */ - switch (mode) { - case CTX_MODE_PAINT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); - break; - case CTX_MODE_SCULPT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); - break; - case CTX_MODE_WEIGHT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); - break; - case CTX_MODE_EDIT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_edit"); - break; - default: - break; - } - - int i = 0; - while (contexts_base[i]) { - i++; - } - BLI_assert(i < ARRAY_SIZE(contexts_base)); - contexts_base[i] = ".workspace"; - - const bool vertical = true; - ED_region_panels_layout_ex(C, ar, contexts_base, -1, vertical); + ED_region_panels_layout_ex(C, ar, &ar->type->paneltypes, contexts, sbuts->mainb, vertical, NULL); } static void buttons_main_region_layout(const bContext *C, ARegion *ar) @@ -305,7 +208,7 @@ static void buttons_main_region_layout(const bContext *C, ARegion *ar) SpaceProperties *sbuts = CTX_wm_space_properties(C); if (sbuts->mainb == BCONTEXT_TOOL) { - buttons_main_region_layout_tool(C, ar); + ED_view3d_buttons_region_layout_ex(C, ar, "Tool"); } else { buttons_main_region_layout_properties(C, sbuts, ar); diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 5a3564249ac..00f07583bd6 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -762,7 +762,7 @@ static void image_buttons_region_layout(const bContext *C, ARegion *ar) } const bool vertical = true; - ED_region_panels_layout_ex(C, ar, contexts_base, -1, vertical); + ED_region_panels_layout_ex(C, ar, &ar->type->paneltypes, contexts_base, -1, vertical, NULL); } static void image_buttons_region_draw(const bContext *C, ARegion *ar) diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 3bc8a64dd20..0217d6655d7 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -1200,9 +1200,106 @@ static void view3d_buttons_region_init(wmWindowManager *wm, ARegion *ar) WM_event_add_keymap_handler(&ar->handlers, keymap); } -static void view3d_buttons_region_draw(const bContext *C, ARegion *ar) +void ED_view3d_buttons_region_layout_ex(const bContext *C, + ARegion *ar, + const char *category_override) { - ED_region_panels_ex(C, ar, (const char *[]){CTX_data_mode_string(C), NULL}, -1, true); + const enum eContextObjectMode mode = CTX_data_mode_enum(C); + + const char *contexts_base[4] = {NULL}; + contexts_base[0] = CTX_data_mode_string(C); + + const char **contexts = &contexts_base[1]; + + switch (mode) { + case CTX_MODE_EDIT_MESH: + ARRAY_SET_ITEMS(contexts, ".mesh_edit"); + break; + case CTX_MODE_EDIT_CURVE: + ARRAY_SET_ITEMS(contexts, ".curve_edit"); + break; + case CTX_MODE_EDIT_SURFACE: + ARRAY_SET_ITEMS(contexts, ".curve_edit"); + break; + case CTX_MODE_EDIT_TEXT: + ARRAY_SET_ITEMS(contexts, ".text_edit"); + break; + case CTX_MODE_EDIT_ARMATURE: + ARRAY_SET_ITEMS(contexts, ".armature_edit"); + break; + case CTX_MODE_EDIT_METABALL: + ARRAY_SET_ITEMS(contexts, ".mball_edit"); + break; + case CTX_MODE_EDIT_LATTICE: + ARRAY_SET_ITEMS(contexts, ".lattice_edit"); + break; + case CTX_MODE_POSE: + ARRAY_SET_ITEMS(contexts, ".posemode"); + break; + case CTX_MODE_SCULPT: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".sculpt_mode"); + break; + case CTX_MODE_PAINT_WEIGHT: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".weightpaint"); + break; + case CTX_MODE_PAINT_VERTEX: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".vertexpaint"); + break; + case CTX_MODE_PAINT_TEXTURE: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".imagepaint"); + break; + case CTX_MODE_PARTICLE: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".particlemode"); + break; + case CTX_MODE_OBJECT: + ARRAY_SET_ITEMS(contexts, ".objectmode"); + break; + case CTX_MODE_PAINT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); + break; + case CTX_MODE_SCULPT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); + break; + case CTX_MODE_WEIGHT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); + break; + default: + break; + } + + switch (mode) { + case CTX_MODE_PAINT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); + break; + case CTX_MODE_SCULPT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); + break; + case CTX_MODE_WEIGHT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); + break; + case CTX_MODE_EDIT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_edit"); + break; + default: + break; + } + + ListBase *paneltypes = &ar->type->paneltypes; + + /* Allow drawing 3D view toolbar from non 3D view space type. */ + if (category_override != NULL) { + SpaceType *st = BKE_spacetype_from_id(SPACE_VIEW3D); + ARegionType *art = BKE_regiontype_from_id(st, RGN_TYPE_UI); + paneltypes = &art->paneltypes; + } + + const bool vertical = true; + ED_region_panels_layout_ex(C, ar, paneltypes, contexts_base, -1, vertical, category_override); +} + +static void view3d_buttons_region_layout(const bContext *C, ARegion *ar) +{ + ED_view3d_buttons_region_layout_ex(C, ar, NULL); } static void view3d_buttons_region_listener(wmWindow *UNUSED(win), @@ -1512,7 +1609,8 @@ void ED_spacetype_view3d(void) art->listener = view3d_buttons_region_listener; art->message_subscribe = ED_area_do_mgs_subscribe_for_tool_ui; art->init = view3d_buttons_region_init; - art->draw = view3d_buttons_region_draw; + art->layout = view3d_buttons_region_layout; + art->draw = ED_region_panels_draw; BLI_addhead(&st->regiontypes, art); view3d_buttons_register(art); |