Bundle assets into the appimage build
This commit is contained in:
parent
7bbcf2e5f3
commit
1217903703
2 changed files with 48 additions and 1 deletions
41
src/ui.c
41
src/ui.c
|
|
@ -1,6 +1,7 @@
|
|||
#include "ui.h"
|
||||
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_filesystem.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -1198,6 +1199,8 @@ void ui_render_theme_picker(SDL_Renderer *renderer,
|
|||
active_theme->panel_text);
|
||||
}
|
||||
|
||||
static char *get_exe_dir(void);
|
||||
|
||||
int ui_cache_init(UiCache *cache, SDL_Renderer *renderer, const UiFonts *fonts, const ChannelList *channels) {
|
||||
char buffer[256];
|
||||
|
||||
|
|
@ -1227,7 +1230,19 @@ int ui_cache_init(UiCache *cache, SDL_Renderer *renderer, const UiFonts *fonts,
|
|||
return -1;
|
||||
}
|
||||
|
||||
cache->logo_texture = load_png_texture(renderer, "logo.png", NULL, NULL);
|
||||
{
|
||||
char *exe_dir = get_exe_dir();
|
||||
if (exe_dir) {
|
||||
char logo_path[512];
|
||||
snprintf(logo_path, sizeof(logo_path), "%slogo.png", exe_dir);
|
||||
cache->logo_texture = load_png_texture(renderer, logo_path, NULL, NULL);
|
||||
SDL_free(exe_dir);
|
||||
}
|
||||
|
||||
if (!cache->logo_texture) {
|
||||
cache->logo_texture = load_png_texture(renderer, "logo.png", NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (channels && channels->count > 0) {
|
||||
cache->channels = calloc((size_t) channels->count, sizeof(UiChannelCache));
|
||||
|
|
@ -1302,12 +1317,36 @@ void ui_cache_destroy(UiCache *cache) {
|
|||
memset(cache, 0, sizeof(*cache));
|
||||
}
|
||||
|
||||
static char *get_exe_dir(void) {
|
||||
return SDL_GetBasePath();
|
||||
}
|
||||
|
||||
int ui_load_fonts(UiFonts *fonts) {
|
||||
char *exe_dir;
|
||||
|
||||
if (!fonts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(fonts, 0, sizeof(*fonts));
|
||||
|
||||
exe_dir = get_exe_dir();
|
||||
if (exe_dir) {
|
||||
char font_path[512];
|
||||
snprintf(font_path, sizeof(font_path), "%sBigBlueTermPlusNerdFontMono-Regular.ttf", exe_dir);
|
||||
|
||||
fonts->small = TTF_OpenFont(font_path, 13);
|
||||
fonts->medium = TTF_OpenFont(font_path, 17);
|
||||
fonts->large = TTF_OpenFont(font_path, 22);
|
||||
|
||||
SDL_free(exe_dir);
|
||||
|
||||
if (fonts->small && fonts->medium && fonts->large) {
|
||||
return 0;
|
||||
}
|
||||
ui_destroy_fonts(fonts);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(FONT_CANDIDATES) / sizeof(FONT_CANDIDATES[0]); ++i) {
|
||||
fonts->small = TTF_OpenFont(FONT_CANDIDATES[i], 13);
|
||||
fonts->medium = TTF_OpenFont(FONT_CANDIDATES[i], 17);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue