UI: Improved Area Icon Using a SpaceType Callback #124556

Merged
Harley Acheson merged 5 commits from Harley/blender:AreaIcons into main 2024-07-12 00:08:35 +02:00
8 changed files with 58 additions and 0 deletions
Showing only changes of commit 90ca0541a9 - Show all commits

View File

@ -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)(ScrArea *area);
/**
* Update pointers for all structs directly owned by this space.

View File

@ -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(ScrArea *area);
Harley marked this conversation as resolved Outdated

Just realized these should have const arguments

Just realized these should have const arguments

Will change the argument of the "name" one to const after this merge.

Will change the argument of the "name" one to const after this merge.
int ED_screen_area_active(const bContext *C);
void ED_screen_global_areas_refresh(wmWindow *win);
void ED_screen_global_areas_sync(wmWindow *win);

View File

@ -916,6 +916,17 @@ blender::StringRefNull ED_area_name(ScrArea *area)
return item.name;
}
int ED_area_icon(ScrArea *area)
{
if (area->type->space_name_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 */

View File

@ -874,6 +874,14 @@ static blender::StringRefNull action_space_name_get(ScrArea *area)
return item.name;
}
static int action_space_icon_get(ScrArea *area)
{
SpaceAction *sact = static_cast<SpaceAction *>(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;

View File

@ -839,6 +839,14 @@ static blender::StringRefNull file_space_name_get(ScrArea *area)
return item.name;
}
static int file_space_icon_get(ScrArea *area)
{
SpaceFile *sfile = static_cast<SpaceFile *>(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;

View File

@ -876,6 +876,14 @@ static blender::StringRefNull graph_space_name_get(ScrArea *area)
return item.name;
}
static int graph_space_icon_get(ScrArea *area)
{
SpaceGraph *sgraph = static_cast<SpaceGraph *>(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;

View File

@ -1085,6 +1085,14 @@ static blender::StringRefNull image_space_name_get(ScrArea *area)
return item.name;
}
static int image_space_icon_get(ScrArea *area)
{
SpaceImage *sima = static_cast<SpaceImage *>(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;

View File

@ -1341,6 +1341,13 @@ static blender::StringRefNull node_space_name_get(ScrArea *area)
return tree_type->ui_name;
}
static int node_space_icon_get(ScrArea *area)
{
SpaceNode *snode = (SpaceNode *)area->spacedata.first;
Harley marked this conversation as resolved Outdated

static_cast

`static_cast`

Will post a separate PR changing to static_cast for node_space_name_get and other places in the same file.

Will post a separate PR changing to static_cast for node_space_name_get and other places in the same file.
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;