From 9cfb320208b655a1d7f177f038179b87d98fb066 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 27 Feb 2021 16:17:01 +1100 Subject: RNA: add Region.data member to access RegionView3D Without this, the RegionView3D could only be accessed from `context.region_data`, not the region. --- source/blender/makesrna/intern/rna_screen.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index 784172b3ac9..6cf1d7a923b 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -56,6 +56,8 @@ const EnumPropertyItem rna_enum_region_type_items[] = { #ifdef RNA_RUNTIME +# include "RNA_access.h" + # include "BKE_global.h" # include "BKE_screen.h" # include "BKE_workspace.h" @@ -274,6 +276,25 @@ static void rna_Area_ui_type_update(bContext *C, PointerRNA *ptr) ED_area_tag_refresh(area); } +static PointerRNA rna_Region_data_get(PointerRNA *ptr) +{ + bScreen *screen = (bScreen *)ptr->owner_id; + ARegion *region = ptr->data; + + if (region->regiondata != NULL) { + if (region->regiontype == RGN_TYPE_WINDOW) { + /* We could make this static, it wont change at run-time. */ + SpaceType *st = BKE_spacetype_from_id(SPACE_VIEW3D); + if (region->type == BKE_regiontype_from_id(st, region->regiontype)) { + PointerRNA newptr; + RNA_pointer_create(&screen->id, &RNA_RegionView3D, region->regiondata, &newptr); + return newptr; + } + } + } + return PointerRNA_NULL; +} + static void rna_View2D_region_to_view(struct View2D *v2d, float x, float y, float result[2]) { UI_view2d_region_to_view(v2d, x, y, &result[0], &result[1]); @@ -539,6 +560,13 @@ static void rna_def_region(BlenderRNA *brna) RNA_def_property_enum_funcs(prop, "rna_region_alignment_get", NULL, NULL); RNA_def_property_ui_text(prop, "Alignment", "Alignment of the region within the area"); + prop = RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text( + prop, "Region Data", "Region specific data (the type depends on the region type)"); + RNA_def_property_struct_type(prop, "AnyType"); + RNA_def_property_pointer_funcs(prop, "rna_Region_data_get", NULL, NULL, NULL); + RNA_def_function(srna, "tag_redraw", "ED_region_tag_redraw"); } -- cgit v1.2.3