diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 26968d7867..435fb4475f 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -37,6 +37,7 @@ #endif #include "../../frontend/frontend_driver.h" +#include "../../ui/ui_companion_driver.h" #include "../menu_driver.h" #include "../menu_screensaver.h" @@ -175,7 +176,8 @@ enum materialui_node_icon_type MUI_ICON_TYPE_MENU_EXPLORE, MUI_ICON_TYPE_PLAYLIST, MUI_ICON_TYPE_MENU_CONTENTLESS_CORE, - MUI_ICON_TYPE_ACHIEVEMENT + MUI_ICON_TYPE_ACHIEVEMENT, + MUI_ICON_TYPE_APPICON }; /* Defines all standard menu textures */ @@ -4011,6 +4013,14 @@ static void materialui_render_menu_entry_default( uintptr_t icon_texture = 0; bool draw_text_outside = (x_offset != 0); gfx_display_t *p_disp = disp_get_ptr(); + uico_driver_state_t *uico_st = uico_state_get_ptr(); + + static float color_white[16] = { + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + }; if (!p_disp->dispctx->handles_transform) { @@ -4076,12 +4086,6 @@ static void materialui_render_menu_entry_default( if (icon_texture) { /* draw the icon ourselves - the draw_icon below tints it to match the theme */ - static float color_white[16] = { - 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, - }; materialui_draw_icon( userdata, p_disp, video_width, @@ -4116,6 +4120,33 @@ static void materialui_render_menu_entry_default( } break; #endif + case MUI_ICON_TYPE_APPICON: + if (uico_st->drv && uico_st->drv->get_app_icon_texture) + { + icon_texture = uico_st->drv->get_app_icon_texture(entry_label); + if (icon_texture) + { + /* draw the icon ourselves - the draw_icon below tints it to match the theme */ + materialui_draw_icon( + userdata, p_disp, + video_width, + video_height, + mui->icon_size, + (uintptr_t)icon_texture, + entry_x + (int)mui->landscape_optimization.entry_margin, + entry_y + (node->entry_height / 2.0f) - (mui->icon_size / 2.0f), + 0, + 1, + color_white, + &mymat); + + entry_margin += mui->icon_size; + usable_width -= mui->icon_size; + + icon_texture = 0; /* prevent drawing tinted icon */ + } + } + break; default: switch (entry_file_type) { @@ -10481,6 +10512,13 @@ static void materialui_list_insert( case MENU_SETTING_ACTION_CONTENTLESS_CORE_RUN: node->icon_type = MUI_ICON_TYPE_MENU_CONTENTLESS_CORE; break; + case MENU_SETTING_DROPDOWN_SETTING_STRING_OPTIONS_ITEM: + if (atoi(fullpath) == MENU_ENUM_LABEL_APPICON_SETTINGS) + { + node->icon_type = MUI_ICON_TYPE_APPICON; + } + /* for other types we don't have an icon */ + break; case FILE_TYPE_RPL_ENTRY: case MENU_SETTING_DROPDOWN_ITEM: case MENU_SETTING_DROPDOWN_ITEM_RESOLUTION: @@ -10498,7 +10536,6 @@ static void materialui_list_insert( case MENU_SETTING_DROPDOWN_ITEM_INPUT_DESCRIPTION: case MENU_SETTING_DROPDOWN_ITEM_INPUT_DESCRIPTION_KBD: case MENU_SETTING_DROPDOWN_SETTING_CORE_OPTIONS_ITEM: - case MENU_SETTING_DROPDOWN_SETTING_STRING_OPTIONS_ITEM: case MENU_SETTING_DROPDOWN_SETTING_FLOAT_ITEM: case MENU_SETTING_DROPDOWN_SETTING_INT_ITEM: case MENU_SETTING_DROPDOWN_SETTING_UINT_ITEM: diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index 54652d18d6..75819a2bb5 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -1117,6 +1117,7 @@ ui_companion_driver_t ui_companion_cocoa = { NULL, /* is_active */ NULL, /* get_app_icons */ NULL, /* set_app_icon */ + NULL, /* get_app_icon_texture */ &ui_browser_window_cocoa, &ui_msg_window_cocoa, &ui_window_cocoa, diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 00ab52e8ce..722384ebf0 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -105,6 +105,40 @@ static void ui_companion_cocoatouch_set_app_icon(const char *iconName) [[UIApplication sharedApplication] setAlternateIconName:str completionHandler:nil]; } +static uintptr_t ui_companion_cocoatouch_get_app_icon_texture(const char *icon) +{ + static NSMutableDictionary *textures = nil; + static dispatch_once_t once; + dispatch_once(&once, ^{ + textures = [NSMutableDictionary dictionaryWithCapacity:6]; + }); + + NSString *iconName = [NSString stringWithUTF8String:icon]; + if (!textures[iconName]) + { + UIImage *img = [UIImage imageNamed:iconName]; + if (!img) + { + RARCH_LOG("could not load %s\n", icon); + return NULL; + } + NSData *png = UIImagePNGRepresentation(img); + if (!png) + { + RARCH_LOG("could not get png for %s\n", icon); + return NULL; + } + + uintptr_t item; + gfx_display_reset_textures_list_buffer(&item, TEXTURE_FILTER_MIPMAP_LINEAR, + (void*)[png bytes], (unsigned int)[png length], IMAGE_TYPE_PNG, + NULL, NULL); + textures[iconName] = [NSNumber numberWithUnsignedLong:item]; + } + + return [textures[iconName] unsignedLongValue]; +} + static void rarch_draw_observer(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) { @@ -506,22 +540,6 @@ enum } } -- (NSData *)pngForIcon:(NSString *)iconName -{ - UIImage *img; - NSData *png; - img = [UIImage imageNamed:iconName]; - if (!img) - NSLog(@"could not load %@\n", iconName); - else - { - png = UIImagePNGRepresentation(img); - if (!png) - NSLog(@"could not get png for %@\n", iconName); - } - return png; -} - - (void)applicationDidFinishLaunching:(UIApplication *)application { char arguments[] = "retroarch"; @@ -763,6 +781,7 @@ ui_companion_driver_t ui_companion_cocoatouch = { NULL, /* is_active */ ui_companion_cocoatouch_get_app_icons, ui_companion_cocoatouch_set_app_icon, + ui_companion_cocoatouch_get_app_icon_texture, NULL, /* browser_window */ NULL, /* msg_window */ NULL, /* window */ diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index 1f5a6ff733..e89b0ac98f 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -4992,6 +4992,7 @@ ui_companion_driver_t ui_companion_qt = { ui_companion_qt_is_active, NULL, /* get_app_icons */ NULL, /* set_app_icon */ + NULL, /* get_app_icon_texture */ &ui_browser_window_qt, &ui_msg_window_qt, &ui_window_qt, diff --git a/ui/drivers/ui_win32.c b/ui/drivers/ui_win32.c index fd4520270c..54803c6296 100644 --- a/ui/drivers/ui_win32.c +++ b/ui/drivers/ui_win32.c @@ -338,6 +338,7 @@ ui_companion_driver_t ui_companion_win32 = { NULL, /* is_active */ NULL, /* get_app_icons */ NULL, /* set_app_icon */ + NULL, /* get_app_icon_texture */ &ui_browser_window_win32, &ui_msg_window_win32, &ui_window_win32, diff --git a/ui/ui_companion_driver.c b/ui/ui_companion_driver.c index 92408eaf2b..649891188b 100644 --- a/ui/ui_companion_driver.c +++ b/ui/ui_companion_driver.c @@ -40,6 +40,7 @@ static ui_companion_driver_t ui_companion_null = { NULL, /* is_active */ NULL, /* get_app_icons */ NULL, /* set_app_icon */ + NULL, /* get_app_icon_texture */ NULL, /* browser_window */ NULL, /* msg_window */ NULL, /* window */ diff --git a/ui/ui_companion_driver.h b/ui/ui_companion_driver.h index 0e5f8c21e3..5c3520fc45 100644 --- a/ui/ui_companion_driver.h +++ b/ui/ui_companion_driver.h @@ -133,6 +133,7 @@ typedef struct ui_companion_driver bool (*is_active)(void *data); struct string_list *(*get_app_icons)(void); void (*set_app_icon)(const char *icon); + uintptr_t (*get_app_icon_texture)(const char *icon); ui_browser_window_t *browser_window; ui_msg_window_t *msg_window; ui_window_t *window;