diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-18 13:16:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-18 13:44:17 +0300 |
commit | 6aef124e7d2869a692dd564a4515f2304924da33 (patch) | |
tree | 9ed5d09fd9a94761ce08db54abe2b5082a00029f /source/blender/makesrna | |
parent | d55a9cac2c0aa6a7d130a256cac7c04e52cdee4a (diff) |
UI: move region toggling to properties
Each space had separate operators, duplicating logic.
Use RNA properties instead so adding the ability to toggle other
region types (floating redo region for eg) doesn't need to have an
extra operator per space type.
It's also nicer to show a check-box for something which can be toggled.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 132 |
1 files changed, 131 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index d5b12ed5d5b..f6ce958752d 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -550,6 +550,91 @@ static void rna_area_region_from_regiondata(PointerRNA *ptr, ScrArea **r_sa, ARe area_region_from_regiondata(sc, regiondata, r_sa, r_ar); } +/* -------------------------------------------------------------------- */ +/** \name Generic Region Flag Access + * \{ */ + +static bool rna_Space_bool_from_region_flag_get_by_type(PointerRNA *ptr, + const int region_type, + const int region_flag) +{ + ScrArea *sa = rna_area_from_space(ptr); + ARegion *ar = BKE_area_find_region_type(sa, region_type); + if (ar) { + return (ar->flag & region_flag); + } + return false; +} + +static void rna_Space_bool_from_region_flag_set_by_type(PointerRNA *ptr, + const int region_type, + const int region_flag, + bool value) +{ + ScrArea *sa = rna_area_from_space(ptr); + ARegion *ar = BKE_area_find_region_type(sa, region_type); + if (ar) { + SET_FLAG_FROM_TEST(ar->flag, value, region_flag); + } + ED_region_tag_redraw(ar); +} + +static void rna_Space_bool_from_region_flag_update_by_type(bContext *C, + PointerRNA *ptr, + const int region_type, + const int region_flag) +{ + ScrArea *sa = rna_area_from_space(ptr); + ARegion *ar = BKE_area_find_region_type(sa, region_type); + if (ar) { + if (region_flag == RGN_FLAG_HIDDEN) { + /* Only support animation when the area is in the current context. */ + if (ar->overlap && (sa == CTX_wm_area(C))) { + ED_region_visibility_change_update_animated(C, sa, ar); + } + else { + ED_region_visibility_change_update(C, sa, ar); + } + } + } +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Region Flag Access (Typed Callbacks) + * \{ */ + +/* Tools Region. */ +static bool rna_Space_show_region_toolbar_get(PointerRNA *ptr) +{ + return !rna_Space_bool_from_region_flag_get_by_type(ptr, RGN_TYPE_TOOLS, RGN_FLAG_HIDDEN); +} +static void rna_Space_show_region_toolbar_set(PointerRNA *ptr, bool value) +{ + rna_Space_bool_from_region_flag_set_by_type(ptr, RGN_TYPE_TOOLS, RGN_FLAG_HIDDEN, !value); +} +static void rna_Space_show_region_toolbar_update(bContext *C, PointerRNA *ptr) +{ + rna_Space_bool_from_region_flag_update_by_type(C, ptr, RGN_TYPE_TOOLS, RGN_FLAG_HIDDEN); +} + +/* UI Region */ +static bool rna_Space_show_region_ui_get(PointerRNA *ptr) +{ + return !rna_Space_bool_from_region_flag_get_by_type(ptr, RGN_TYPE_UI, RGN_FLAG_HIDDEN); +} +static void rna_Space_show_region_ui_set(PointerRNA *ptr, bool value) +{ + rna_Space_bool_from_region_flag_set_by_type(ptr, RGN_TYPE_UI, RGN_FLAG_HIDDEN, !value); +} +static void rna_Space_show_region_ui_update(bContext *C, PointerRNA *ptr) +{ + rna_Space_bool_from_region_flag_update_by_type(C, ptr, RGN_TYPE_UI, RGN_FLAG_HIDDEN); +} + +/** \} */ + static bool rna_Space_view2d_sync_get(PointerRNA *ptr) { ScrArea *sa; @@ -1731,7 +1816,7 @@ static void rna_SpaceDopeSheetEditor_mode_update(bContext *C, PointerRNA *ptr) else { channels_region->flag &= ~RGN_FLAG_HIDDEN; } - ED_region_visibility_change_update(C, channels_region); + ED_region_visibility_change_update(C, sa, channels_region); } } @@ -2308,6 +2393,33 @@ static void rna_def_space(BlenderRNA *brna) RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Space_view2d_sync_update"); } +static void rna_def_space_generic_show_region_toggles(StructRNA *srna, int region_type_mask) +{ + PropertyRNA *prop; + +# define DEF_SHOW_REGION_PROPERTY(identifier, label, description) \ + { \ + prop = RNA_def_property(srna, STRINGIFY(identifier), PROP_BOOLEAN, PROP_NONE); \ + RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); \ + RNA_def_property_boolean_funcs(prop, \ + STRINGIFY(rna_Space_##identifier##_get), \ + STRINGIFY(rna_Space_##identifier##_set)); \ + RNA_def_property_ui_text(prop, label, description); \ + RNA_def_property_update(prop, 0, STRINGIFY(rna_Space_##identifier##_update)); \ + } \ + ((void)0) + + if (region_type_mask & (1 << RGN_TYPE_TOOLS)) { + region_type_mask &= ~(1 << RGN_TYPE_TOOLS); + DEF_SHOW_REGION_PROPERTY(show_region_toolbar, "Toolbar", ""); + } + if (region_type_mask & (1 << RGN_TYPE_UI)) { + region_type_mask &= ~(1 << RGN_TYPE_UI); + DEF_SHOW_REGION_PROPERTY(show_region_ui, "Sidebar", ""); + } + BLI_assert(region_type_mask == 0); +} + /* for all spaces that use a mask */ static void rna_def_space_mask_info(StructRNA *srna, int noteflag, const char *mask_set_func) { @@ -3387,6 +3499,8 @@ static void rna_def_space_view3d(BlenderRNA *brna) RNA_def_struct_sdna(srna, "View3D"); RNA_def_struct_ui_text(srna, "3D View Space", "3D View space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_TOOLS) | (1 << RGN_TYPE_UI)); + prop = RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_pointer_sdna(prop, NULL, "camera"); @@ -3891,6 +4005,8 @@ static void rna_def_space_image(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceImage"); RNA_def_struct_ui_text(srna, "Space Image Editor", "Image and UV editor space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_TOOLS) | (1 << RGN_TYPE_UI)); + /* image */ prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceImageEditor_image_set", NULL, NULL); @@ -4119,6 +4235,8 @@ static void rna_def_space_sequencer(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceSeq"); RNA_def_struct_ui_text(srna, "Space Sequence Editor", "Sequence editor space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_UI)); + /* view type, fairly important */ prop = RNA_def_property(srna, "view_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "view"); @@ -4261,6 +4379,8 @@ static void rna_def_space_text(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceText"); RNA_def_struct_ui_text(srna, "Space Text Editor", "Text editor space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_UI)); + /* text */ prop = RNA_def_property(srna, "text", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); @@ -4383,6 +4503,8 @@ static void rna_def_space_dopesheet(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceAction"); RNA_def_struct_ui_text(srna, "Space Dope Sheet Editor", "Dope Sheet space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_UI)); + /* data */ prop = RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); @@ -4561,6 +4683,8 @@ static void rna_def_space_graph(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceGraph"); RNA_def_struct_ui_text(srna, "Space Graph Editor", "Graph Editor space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_UI)); + /* mode */ prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "mode"); @@ -4712,6 +4836,8 @@ static void rna_def_space_nla(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceNla"); RNA_def_struct_ui_text(srna, "Space Nla Editor", "NLA editor space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_UI)); + /* display */ prop = RNA_def_property(srna, "show_seconds", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SNLA_DRAWTIME); @@ -5503,6 +5629,8 @@ static void rna_def_space_node(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceNode"); RNA_def_struct_ui_text(srna, "Space Node Editor", "Node editor space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_TOOLS) | (1 << RGN_TYPE_UI)); + prop = RNA_def_property(srna, "tree_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, dummy_items); RNA_def_property_enum_funcs(prop, @@ -5679,6 +5807,8 @@ static void rna_def_space_clip(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SpaceClip"); RNA_def_struct_ui_text(srna, "Space Clip Editor", "Clip editor space data"); + rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_UI)); + /* movieclip */ prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); |