From a82954cb632dbfa0b3cec75b53e3e258491e028e Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 12 Jul 2024 00:08:19 +0200 Subject: [PATCH] UI: Improved Area Icon Using a SpaceType Callback Centralized method to obtain ScrArea icons. Areas can add an optional space_icon_get callback to provide an icon that differs by subtype. If not defined then ED_area_icon will return RNA UI icon, which is correct in cases without area subtypes. Pull Request: https://projects.blender.org/blender/blender/pulls/124556 --- source/blender/blenkernel/BKE_screen.hh | 2 ++ source/blender/editors/include/ED_screen.hh | 1 + source/blender/editors/screen/screen_edit.cc | 11 +++++++++++ source/blender/editors/space_action/space_action.cc | 9 +++++++++ source/blender/editors/space_file/space_file.cc | 9 +++++++++ source/blender/editors/space_graph/space_graph.cc | 9 +++++++++ source/blender/editors/space_image/space_image.cc | 9 +++++++++ source/blender/editors/space_node/space_node.cc | 8 ++++++++ 8 files changed, 58 insertions(+) diff --git a/source/blender/blenkernel/BKE_screen.hh b/source/blender/blenkernel/BKE_screen.hh index 514e201fce7..1ecde4fbd2f 100644 --- a/source/blender/blenkernel/BKE_screen.hh +++ b/source/blender/blenkernel/BKE_screen.hh @@ -128,6 +128,8 @@ struct SpaceType { /* Return a custom name, based on subtype or other reason. */ blender::StringRefNull (*space_name_get)(ScrArea *area); + /* Return a custom icon, based on subtype or other reason. */ + int (*space_icon_get)(const ScrArea *area); /** * Update pointers for all structs directly owned by this space. diff --git a/source/blender/editors/include/ED_screen.hh b/source/blender/editors/include/ED_screen.hh index f4a5b254234..c3168dcf699 100644 --- a/source/blender/editors/include/ED_screen.hh +++ b/source/blender/editors/include/ED_screen.hh @@ -211,6 +211,7 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco); void ED_area_init(wmWindowManager *wm, wmWindow *win, ScrArea *area); void ED_area_exit(bContext *C, ScrArea *area); blender::StringRefNull ED_area_name(ScrArea *area); +int ED_area_icon(const ScrArea *area); int ED_screen_area_active(const bContext *C); void ED_screen_global_areas_refresh(wmWindow *win); void ED_screen_global_areas_sync(wmWindow *win); diff --git a/source/blender/editors/screen/screen_edit.cc b/source/blender/editors/screen/screen_edit.cc index 999c13877e9..3f49d2644e7 100644 --- a/source/blender/editors/screen/screen_edit.cc +++ b/source/blender/editors/screen/screen_edit.cc @@ -916,6 +916,17 @@ blender::StringRefNull ED_area_name(ScrArea *area) return item.name; } +int ED_area_icon(const ScrArea *area) +{ + if (area->type->space_icon_get) { + return area->type->space_icon_get(area); + } + + const int index = RNA_enum_from_value(rna_enum_space_type_items, area->spacetype); + const EnumPropertyItem item = rna_enum_space_type_items[index]; + return item.icon; +} + /* *********************************** */ /* case when on area-edge or in azones, or outside window */ diff --git a/source/blender/editors/space_action/space_action.cc b/source/blender/editors/space_action/space_action.cc index 06b341c57e0..b8452d01c2a 100644 --- a/source/blender/editors/space_action/space_action.cc +++ b/source/blender/editors/space_action/space_action.cc @@ -874,6 +874,14 @@ static blender::StringRefNull action_space_name_get(ScrArea *area) return item.name; } +static int action_space_icon_get(const ScrArea *area) +{ + SpaceAction *sact = static_cast(area->spacedata.first); + const int index = RNA_enum_from_value(rna_enum_space_action_mode_items, sact->mode); + const EnumPropertyItem item = rna_enum_space_action_mode_items[index]; + return item.icon; +} + static void action_space_blend_read_data(BlendDataReader * /*reader*/, SpaceLink *sl) { SpaceAction *saction = (SpaceAction *)sl; @@ -907,6 +915,7 @@ void ED_spacetype_action() st->space_subtype_get = action_space_subtype_get; st->space_subtype_set = action_space_subtype_set; st->space_name_get = action_space_name_get; + st->space_icon_get = action_space_icon_get; st->blend_read_data = action_space_blend_read_data; st->blend_read_after_liblink = nullptr; st->blend_write = action_space_blend_write; diff --git a/source/blender/editors/space_file/space_file.cc b/source/blender/editors/space_file/space_file.cc index d53d4002ee6..a13432ddda1 100644 --- a/source/blender/editors/space_file/space_file.cc +++ b/source/blender/editors/space_file/space_file.cc @@ -839,6 +839,14 @@ static blender::StringRefNull file_space_name_get(ScrArea *area) return item.name; } +static int file_space_icon_get(const ScrArea *area) +{ + SpaceFile *sfile = static_cast(area->spacedata.first); + const int index = RNA_enum_from_value(rna_enum_space_file_browse_mode_items, sfile->browse_mode); + const EnumPropertyItem item = rna_enum_space_file_browse_mode_items[index]; + return item.icon; +} + static void file_id_remap(ScrArea *area, SpaceLink *sl, const blender::bke::id::IDRemapper & /*mappings*/) @@ -935,6 +943,7 @@ void ED_spacetype_file() st->space_subtype_get = file_space_subtype_get; st->space_subtype_set = file_space_subtype_set; st->space_name_get = file_space_name_get; + st->space_icon_get = file_space_icon_get; st->context = file_context; st->id_remap = file_id_remap; st->foreach_id = file_foreach_id; diff --git a/source/blender/editors/space_graph/space_graph.cc b/source/blender/editors/space_graph/space_graph.cc index 0dafd68d453..15b336735eb 100644 --- a/source/blender/editors/space_graph/space_graph.cc +++ b/source/blender/editors/space_graph/space_graph.cc @@ -876,6 +876,14 @@ static blender::StringRefNull graph_space_name_get(ScrArea *area) return item.name; } +static int graph_space_icon_get(const ScrArea *area) +{ + SpaceGraph *sgraph = static_cast(area->spacedata.first); + const int index = RNA_enum_from_value(rna_enum_space_graph_mode_items, sgraph->mode); + const EnumPropertyItem item = rna_enum_space_graph_mode_items[index]; + return item.icon; +} + static void graph_space_blend_read_data(BlendDataReader *reader, SpaceLink *sl) { SpaceGraph *sipo = (SpaceGraph *)sl; @@ -923,6 +931,7 @@ void ED_spacetype_ipo() st->space_subtype_get = graph_space_subtype_get; st->space_subtype_set = graph_space_subtype_set; st->space_name_get = graph_space_name_get; + st->space_icon_get = graph_space_icon_get; st->blend_read_data = graph_space_blend_read_data; st->blend_read_after_liblink = nullptr; st->blend_write = graph_space_blend_write; diff --git a/source/blender/editors/space_image/space_image.cc b/source/blender/editors/space_image/space_image.cc index 891235b56fd..adc50bb209d 100644 --- a/source/blender/editors/space_image/space_image.cc +++ b/source/blender/editors/space_image/space_image.cc @@ -1085,6 +1085,14 @@ static blender::StringRefNull image_space_name_get(ScrArea *area) return item.name; } +static int image_space_icon_get(const ScrArea *area) +{ + SpaceImage *sima = static_cast(area->spacedata.first); + const int index = RNA_enum_from_value(rna_enum_space_image_mode_items, sima->mode); + const EnumPropertyItem item = rna_enum_space_image_mode_items[index]; + return item.icon; +} + static void image_space_blend_read_data(BlendDataReader * /*reader*/, SpaceLink *sl) { SpaceImage *sima = (SpaceImage *)sl; @@ -1141,6 +1149,7 @@ void ED_spacetype_image() st->space_subtype_get = image_space_subtype_get; st->space_subtype_set = image_space_subtype_set; st->space_name_get = image_space_name_get; + st->space_icon_get = image_space_icon_get; st->blend_read_data = image_space_blend_read_data; st->blend_read_after_liblink = nullptr; st->blend_write = image_space_blend_write; diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index 49e3f3a9bcf..f66594ba53e 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -1341,6 +1341,13 @@ static blender::StringRefNull node_space_name_get(ScrArea *area) return tree_type->ui_name; } +static int node_space_icon_get(const ScrArea *area) +{ + SpaceNode *snode = static_cast(area->spacedata.first); + bke::bNodeTreeType *tree_type = bke::ntreeTypeFind(snode->tree_idname); + return tree_type->ui_icon; +} + static void node_space_blend_read_data(BlendDataReader *reader, SpaceLink *sl) { SpaceNode *snode = (SpaceNode *)sl; @@ -1395,6 +1402,7 @@ void ED_spacetype_node() st->space_subtype_get = node_space_subtype_get; st->space_subtype_set = node_space_subtype_set; st->space_name_get = node_space_name_get; + st->space_icon_get = node_space_icon_get; st->blend_read_data = node_space_blend_read_data; st->blend_read_after_liblink = nullptr; st->blend_write = node_space_blend_write;