Add logo to footer in guide mode

This commit is contained in:
markmental 2026-03-29 14:43:18 -04:00
commit 7bbcf2e5f3
3 changed files with 53 additions and 5 deletions

View file

@ -2,15 +2,15 @@ CC ?= cc
CSTD ?= -std=c11
CFLAGS ?= -O2 -Wall -Wextra -Wpedantic $(CSTD)
SDL_CFLAGS := $(shell pkg-config --cflags SDL2 SDL2_ttf 2>/dev/null)
SDL_LIBS := $(shell pkg-config --libs SDL2 SDL2_ttf 2>/dev/null)
SDL_CFLAGS := $(shell pkg-config --cflags SDL2 SDL2_ttf SDL2_image 2>/dev/null)
SDL_LIBS := $(shell pkg-config --libs SDL2 SDL2_ttf SDL2_image 2>/dev/null)
FFMPEG_CFLAGS := $(shell pkg-config --cflags libavformat libavcodec libswscale libswresample libavutil 2>/dev/null)
FFMPEG_LIBS := $(shell pkg-config --libs libavformat libavcodec libswscale libswresample libavutil 2>/dev/null)
MULTIARCH_CFLAGS := $(if $(wildcard /usr/include/i386-linux-gnu/SDL2/_real_SDL_config.h),-I/usr/include/i386-linux-gnu,)
ifeq ($(strip $(SDL_CFLAGS)),)
SDL_CFLAGS := $(shell sdl2-config --cflags 2>/dev/null) $(MULTIARCH_CFLAGS)
SDL_LIBS := $(shell sdl2-config --libs 2>/dev/null) -lSDL2_ttf
SDL_LIBS := $(shell sdl2-config --libs 2>/dev/null) -lSDL2_ttf -lSDL2_image
endif
ifeq ($(strip $(FFMPEG_LIBS)),)

View file

@ -1,5 +1,6 @@
#include "ui.h"
#include <SDL2/SDL_image.h>
#include <stdio.h>
#include <string.h>
@ -103,6 +104,34 @@ static SDL_Texture *text_to_texture(SDL_Renderer *renderer, TTF_Font *font, cons
return texture;
}
static SDL_Texture *load_png_texture(SDL_Renderer *renderer, const char *path, int *width, int *height) {
SDL_Surface *surface;
SDL_Texture *texture;
surface = IMG_Load(path);
if (!surface) {
fprintf(stderr, "Failed to load image %s: %s\n", path, IMG_GetError());
return NULL;
}
texture = SDL_CreateTextureFromSurface(renderer, surface);
if (!texture) {
SDL_FreeSurface(surface);
fprintf(stderr, "Failed to create texture from %s: %s\n", path, SDL_GetError());
return NULL;
}
if (width) {
*width = surface->w;
}
if (height) {
*height = surface->h;
}
SDL_FreeSurface(surface);
return texture;
}
static void draw_cached_text(SDL_Renderer *renderer, const UiTextTexture *text_texture, int x, int y) {
SDL_Rect dst;
@ -591,7 +620,8 @@ static void draw_footer_legend(SDL_Renderer *renderer,
const UiFonts *fonts,
const GuideTheme *theme,
int window_width,
int window_height) {
int window_height,
SDL_Texture *logo_texture) {
SDL_Rect footer = {0, window_height - 54, window_width, 54};
SDL_Rect chip = {window_width / 2 - 220, window_height - 38, 34, 20};
SDL_Color footer_text = readable_text_color(theme->footer_mid);
@ -617,6 +647,17 @@ static void draw_footer_legend(SDL_Renderer *renderer,
draw_pill_button(renderer, theme, &chip, theme->row_mid, theme->panel_border);
draw_text_clipped(renderer, fonts->small, "<>", &footer, chip.x + 5, chip.y + 2, footer_text);
draw_text_clipped(renderer, fonts->small, "TIME", &footer, chip.x + 42, chip.y - 1, footer_text);
if (logo_texture) {
int logo_size = 32;
SDL_Rect logo_dst = {
10,
footer.y + (footer.h - logo_size) / 2,
logo_size,
logo_size
};
SDL_RenderCopy(renderer, logo_texture, NULL, &logo_dst);
}
}
static void draw_scanline_overlay(SDL_Renderer *renderer, int width, int height, const GuideTheme *theme) {
@ -1102,7 +1143,7 @@ void ui_render_guide(SDL_Renderer *renderer,
draw_selection_glow(renderer, &(SDL_Rect){guide_x_start, highlight.y + (int) (6 * scale_y), timeline_w, row_height - (int) (12 * scale_y)}, theme->selection_edge);
}
draw_footer_legend(renderer, fonts, theme, window_width, window_height);
draw_footer_legend(renderer, fonts, theme, window_width, window_height, cache->logo_texture);
draw_scanline_overlay(renderer, window_width, window_height, theme);
}
@ -1186,6 +1227,8 @@ 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);
if (channels && channels->count > 0) {
cache->channels = calloc((size_t) channels->count, sizeof(UiChannelCache));
if (!cache->channels) {
@ -1223,6 +1266,10 @@ void ui_cache_destroy(UiCache *cache) {
return;
}
if (cache->logo_texture) {
SDL_DestroyTexture(cache->logo_texture);
}
text_texture_destroy(&cache->no_media_title);
text_texture_destroy(&cache->no_media_body);
text_texture_destroy(&cache->no_media_hint);

View file

@ -45,6 +45,7 @@ typedef struct UiCache {
const GuideTheme *timeline_theme;
UiChannelCache *channels;
int channel_count;
SDL_Texture *logo_texture;
} UiCache;
void ui_render_fullscreen(SDL_Renderer *renderer,