forked from bartvdbraak/blender
UI: Expand space sub-types into the menu
Initial support for expanding editors, see: T54744
This commit is contained in:
parent
d4ac65d003
commit
756b70c6c3
@ -48,7 +48,8 @@ class NODE_HT_header(Header):
|
|||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.template_header()
|
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)
|
NODE_MT_editor_menus.draw_collapsible(context, layout)
|
||||||
|
|
||||||
|
@ -114,6 +114,10 @@ typedef struct SpaceType {
|
|||||||
/* Used when we want to replace an ID by another (or NULL). */
|
/* Used when we want to replace an ID by another (or NULL). */
|
||||||
void (*id_remap)(struct ScrArea *, struct SpaceLink *, struct ID *, struct ID *);
|
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 */
|
/* region type definitions */
|
||||||
ListBase regiontypes;
|
ListBase regiontypes;
|
||||||
|
|
||||||
|
@ -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);
|
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,
|
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;
|
return xco + 1.7 * U.widget_unit;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@
|
|||||||
#include "UI_view2d.h"
|
#include "UI_view2d.h"
|
||||||
|
|
||||||
#include "RNA_access.h"
|
#include "RNA_access.h"
|
||||||
|
#include "RNA_define.h"
|
||||||
|
#include "RNA_enum_types.h"
|
||||||
|
|
||||||
#include "WM_api.h"
|
#include "WM_api.h"
|
||||||
#include "WM_types.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 */
|
/* only called once, from space/spacetypes.c */
|
||||||
void ED_spacetype_node(void)
|
void ED_spacetype_node(void)
|
||||||
{
|
{
|
||||||
@ -964,6 +992,10 @@ void ED_spacetype_node(void)
|
|||||||
st->manipulators = node_widgets;
|
st->manipulators = node_widgets;
|
||||||
st->id_remap = node_id_remap;
|
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 */
|
/* regions: main window */
|
||||||
art = MEM_callocN(sizeof(ARegionType), "spacetype node region");
|
art = MEM_callocN(sizeof(ARegionType), "spacetype node region");
|
||||||
art->regionid = RGN_TYPE_WINDOW;
|
art->regionid = RGN_TYPE_WINDOW;
|
||||||
|
@ -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_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);
|
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__ */
|
#endif /* __RNA_ENUM_TYPES_H__ */
|
||||||
|
@ -58,6 +58,7 @@ const EnumPropertyItem rna_enum_region_type_items[] = {
|
|||||||
|
|
||||||
#include "BKE_global.h"
|
#include "BKE_global.h"
|
||||||
#include "BKE_workspace.h"
|
#include "BKE_workspace.h"
|
||||||
|
#include "BKE_screen.h"
|
||||||
|
|
||||||
#include "DEG_depsgraph.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])
|
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]);
|
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_clear_flag(prop, PROP_ANIMATABLE);
|
||||||
RNA_def_property_update(prop, 0, "rna_Area_type_update");
|
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);
|
prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
|
||||||
RNA_def_property_int_sdna(prop, NULL, "totrct.xmin");
|
RNA_def_property_int_sdna(prop, NULL, "totrct.xmin");
|
||||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||||
|
@ -1494,11 +1494,17 @@ static int rna_SpaceNodeEditor_tree_type_poll(void *Cv, bNodeTreeType *type)
|
|||||||
else
|
else
|
||||||
return true;
|
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(
|
static const EnumPropertyItem *rna_SpaceNodeEditor_tree_type_itemf(
|
||||||
bContext *C, PointerRNA *UNUSED(ptr),
|
bContext *C, PointerRNA *UNUSED(ptr),
|
||||||
PropertyRNA *UNUSED(prop), bool *r_free)
|
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)
|
static void rna_SpaceNodeEditor_path_get(PointerRNA *ptr, char *value)
|
||||||
|
@ -178,7 +178,7 @@ void register_node_tree_type_sh(void)
|
|||||||
|
|
||||||
tt->type = NTREE_SHADER;
|
tt->type = NTREE_SHADER;
|
||||||
strcpy(tt->idname, "ShaderNodeTree");
|
strcpy(tt->idname, "ShaderNodeTree");
|
||||||
strcpy(tt->ui_name, "Shader");
|
strcpy(tt->ui_name, "Shader Editor");
|
||||||
tt->ui_icon = 0; /* defined in drawnode.c */
|
tt->ui_icon = 0; /* defined in drawnode.c */
|
||||||
strcpy(tt->ui_description, "Shader nodes");
|
strcpy(tt->ui_description, "Shader nodes");
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ void register_node_tree_type_tex(void)
|
|||||||
|
|
||||||
tt->type = NTREE_TEXTURE;
|
tt->type = NTREE_TEXTURE;
|
||||||
strcpy(tt->idname, "TextureNodeTree");
|
strcpy(tt->idname, "TextureNodeTree");
|
||||||
strcpy(tt->ui_name, "Texture");
|
strcpy(tt->ui_name, "Texture Editor");
|
||||||
tt->ui_icon = 0; /* defined in drawnode.c */
|
tt->ui_icon = 0; /* defined in drawnode.c */
|
||||||
strcpy(tt->ui_description, "Texture nodes");
|
strcpy(tt->ui_description, "Texture nodes");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user