diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-05-29 10:19:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-05-29 13:15:26 +0300 |
commit | 756b70c6c34d596558f6fadf808ecb2a4bf8e3bf (patch) | |
tree | fe1c1e6ca51d4a3e5d2a3e0918d442642ad933f1 | |
parent | d4ac65d003244db4368222f52fbc8fad1cf9a788 (diff) |
UI: Expand space sub-types into the menu
Initial support for expanding editors, see: T54744
-rw-r--r-- | release/scripts/startup/bl_ui/space_node.py | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 4 | ||||
-rw-r--r-- | source/blender/editors/screen/area.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_node/space_node.c | 32 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_enum_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_screen.c | 67 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 8 | ||||
-rw-r--r-- | source/blender/nodes/shader/node_shader_tree.c | 2 | ||||
-rw-r--r-- | source/blender/nodes/texture/node_texture_tree.c | 2 |
9 files changed, 118 insertions, 5 deletions
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py index 375e101a6a5..0963613af5c 100644 --- a/release/scripts/startup/bl_ui/space_node.py +++ b/release/scripts/startup/bl_ui/space_node.py @@ -48,7 +48,8 @@ class NODE_HT_header(Header): row = layout.row(align=True) row.template_header() - layout.prop(snode, "tree_type", text="") + # Now expanded via the 'ui_type' + # layout.prop(snode, "tree_type", text="") NODE_MT_editor_menus.draw_collapsible(context, layout) diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 36708cb11a4..722a36c9f1d 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -114,6 +114,10 @@ typedef struct SpaceType { /* Used when we want to replace an ID by another (or NULL). */ void (*id_remap)(struct ScrArea *, struct SpaceLink *, struct ID *, struct ID *); + int (*space_subtype_get)(struct ScrArea *sa); + void (*space_subtype_set)(struct ScrArea *sa, int value); + void (*space_subtype_item_extend)(struct bContext *C, EnumPropertyItem **item, int *totitem); + /* region type definitions */ ListBase regiontypes; diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index e8192c4ce90..9605f1d15cc 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -1753,7 +1753,7 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco) RNA_pointer_create(&(scr->id), &RNA_Area, sa, &areaptr); uiDefButR(block, UI_BTYPE_MENU, 0, "", xco, yco, 1.6 * U.widget_unit, U.widget_unit, - &areaptr, "type", 0, 0.0f, 0.0f, 0.0f, 0.0f, ""); + &areaptr, "ui_type", 0, 0.0f, 0.0f, 0.0f, 0.0f, ""); return xco + 1.7 * U.widget_unit; } diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 28598591012..3b24500d044 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -54,6 +54,8 @@ #include "UI_view2d.h" #include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" @@ -942,6 +944,32 @@ static void node_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID } } + +static int node_space_subtype_get(ScrArea *sa) +{ + SpaceNode *snode = sa->spacedata.first; + return rna_node_tree_idname_to_enum(snode->tree_idname); +} + +static void node_space_subtype_set(ScrArea *sa, int value) +{ + SpaceNode *snode = sa->spacedata.first; + ED_node_set_tree_type(snode, rna_node_tree_type_from_enum(value)); +} + +static void node_space_subtype_item_extend( + bContext *C, EnumPropertyItem **item, int *totitem) +{ + bool free; + const EnumPropertyItem *item_src = RNA_enum_node_tree_types_itemf_impl(C, &free); + for (const EnumPropertyItem *item_iter = item_src; item_iter->identifier; item_iter++) { + RNA_enum_item_add(item, totitem, item_iter); + } + if (free) { + MEM_freeN((void *)item_src); + } +} + /* only called once, from space/spacetypes.c */ void ED_spacetype_node(void) { @@ -964,6 +992,10 @@ void ED_spacetype_node(void) st->manipulators = node_widgets; st->id_remap = node_id_remap; + st->space_subtype_item_extend = node_space_subtype_item_extend; + st->space_subtype_get = node_space_subtype_get; + st->space_subtype_set = node_space_subtype_set; + /* regions: main window */ art = MEM_callocN(sizeof(ARegionType), "spacetype node region"); art->regionid = RGN_TYPE_WINDOW; diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index bb09fe585ba..da2705d4660 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -245,4 +245,7 @@ const EnumPropertyItem *RNA_movieclip_local_itemf(struct bContext *C, struct Poi const EnumPropertyItem *RNA_mask_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free); const EnumPropertyItem *RNA_mask_local_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free); +/* Non confirming, utility function. */ +const EnumPropertyItem *RNA_enum_node_tree_types_itemf_impl(struct bContext *C, bool *r_free); + #endif /* __RNA_ENUM_TYPES_H__ */ diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index b8c7eff6241..deaf73bc9a5 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -58,6 +58,7 @@ const EnumPropertyItem rna_enum_region_type_items[] = { #include "BKE_global.h" #include "BKE_workspace.h" +#include "BKE_screen.h" #include "DEG_depsgraph.h" @@ -214,6 +215,63 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr) } } + +static const EnumPropertyItem *rna_Area_ui_type_itemf( + bContext *C, PointerRNA *UNUSED(ptr), + PropertyRNA *UNUSED(prop), bool *r_free) +{ + EnumPropertyItem *item = NULL; + int totitem = 0; + + /* +1 to skip SPACE_EMPTY */ + for (const EnumPropertyItem *item_from = rna_enum_space_type_items + 1; item_from->identifier; item_from++) { + if (ELEM(item_from->value, SPACE_TOPBAR, SPACE_STATUSBAR)) { + continue; + } + + SpaceType *st = item_from->identifier[0] ? BKE_spacetype_from_id(item_from->value) : NULL; + int totitem_prev = totitem; + if (st && st->space_subtype_item_extend != NULL) { + st->space_subtype_item_extend(C, &item, &totitem); + while (totitem_prev < totitem) { + item[totitem_prev++].value |= item_from->value << 16; + } + } + else { + RNA_enum_item_add(&item, &totitem, item_from); + item[totitem_prev++].value = item_from->value << 16; + } + } + RNA_enum_item_end(&item, &totitem); + *r_free = true; + + return item; +} + +static int rna_Area_ui_type_get(PointerRNA *ptr) +{ + int value = rna_Area_type_get(ptr) << 16; + ScrArea *sa = (ScrArea *)ptr->data; + if (sa->type->space_subtype_item_extend != NULL) { + value |= sa->type->space_subtype_get(sa); + } + return value; +} + +static void rna_Area_ui_type_set(PointerRNA *ptr, int value) +{ + rna_Area_type_set(ptr, value >> 16); + ScrArea *sa = (ScrArea *)ptr->data; + if (sa->type->space_subtype_item_extend != NULL) { + sa->type->space_subtype_set(sa, value & 0xffff); + } +} + +static void rna_Area_ui_type_update(bContext *C, PointerRNA *ptr) +{ + rna_Area_type_update(C, ptr); +} + static void rna_View2D_region_to_view(struct View2D *v2d, int x, int y, float result[2]) { UI_view2d_region_to_view(v2d, x, y, &result[0], &result[1]); @@ -284,6 +342,15 @@ static void rna_def_area(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, 0, "rna_Area_type_update"); + prop = RNA_def_property(srna, "ui_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, DummyRNA_DEFAULT_items); /* infact dummy */ + RNA_def_property_enum_default(prop, 0); + RNA_def_property_enum_funcs(prop, "rna_Area_ui_type_get", "rna_Area_ui_type_set", "rna_Area_ui_type_itemf"); + RNA_def_property_ui_text(prop, "Editor Type", "Current editor type for this area"); + RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_update(prop, 0, "rna_Area_ui_type_update"); + prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "totrct.xmin"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index e4107ee00ef..828a1c61460 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1494,11 +1494,17 @@ static int rna_SpaceNodeEditor_tree_type_poll(void *Cv, bNodeTreeType *type) else return true; } + +const EnumPropertyItem *RNA_enum_node_tree_types_itemf_impl(bContext *C, bool *r_free) +{ + return rna_node_tree_type_itemf(C, rna_SpaceNodeEditor_tree_type_poll, r_free); +} + static const EnumPropertyItem *rna_SpaceNodeEditor_tree_type_itemf( bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { - return rna_node_tree_type_itemf(C, rna_SpaceNodeEditor_tree_type_poll, r_free); + return RNA_enum_node_tree_types_itemf_impl(C, r_free); } static void rna_SpaceNodeEditor_path_get(PointerRNA *ptr, char *value) diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index bad80450f80..8f1e3fc6c5e 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -178,7 +178,7 @@ void register_node_tree_type_sh(void) tt->type = NTREE_SHADER; strcpy(tt->idname, "ShaderNodeTree"); - strcpy(tt->ui_name, "Shader"); + strcpy(tt->ui_name, "Shader Editor"); tt->ui_icon = 0; /* defined in drawnode.c */ strcpy(tt->ui_description, "Shader nodes"); diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index cd7a3f6d9c2..0d3d3f261de 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -164,7 +164,7 @@ void register_node_tree_type_tex(void) tt->type = NTREE_TEXTURE; strcpy(tt->idname, "TextureNodeTree"); - strcpy(tt->ui_name, "Texture"); + strcpy(tt->ui_name, "Texture Editor"); tt->ui_icon = 0; /* defined in drawnode.c */ strcpy(tt->ui_description, "Texture nodes"); |