New directory based system for channels

This commit is contained in:
markmental 2026-03-28 00:25:06 -04:00
commit b84a3060c1
8 changed files with 466 additions and 241 deletions

View file

@ -389,7 +389,8 @@ static void draw_info_panel(SDL_Renderer *renderer,
char description[384];
time_t start_time;
time_t end_time;
double live_position;
double program_seek;
const ProgramEntry *program;
if (!rect || !selected_channel) {
return;
@ -402,23 +403,24 @@ static void draw_info_panel(SDL_Renderer *renderer,
draw_panel_bevel(renderer, rect);
stroke_rect(renderer, rect, COLOR_BORDER_DARK);
live_position = channel_live_position_precise(selected_channel, app_start_ticks, now_ticks);
start_time = now_wall - (time_t) live_position;
end_time = start_time + (time_t) selected_channel->duration_seconds;
program = channel_resolve_program(selected_channel, app_start_ticks, now_ticks, &program_seek, NULL);
if (!program) {
return;
}
start_time = now_wall - (time_t) program_seek;
end_time = start_time + (time_t) program->duration_seconds;
format_time_compact(time_range, sizeof(time_range), start_time);
format_time_compact(end_text, sizeof(end_text), end_time);
strncat(time_range, " - ", sizeof(time_range) - strlen(time_range) - 1);
strncat(time_range, end_text, sizeof(time_range) - strlen(time_range) - 1);
snprintf(description,
sizeof(description),
"Channel %d presents %s. Source: %s.",
selected_channel->number,
selected_channel->program_title,
selected_channel->file_name);
"%s",
selected_channel->description[0] != '\0' ? selected_channel->description : "Local programming lineup.");
clip_rect = (SDL_Rect){rect->x + 16, rect->y + 12, rect->w - 32, rect->h - 24};
draw_text_clipped(renderer, fonts->large, selected_channel->name, &clip_rect, rect->x + 18, rect->y + 44, COLOR_PANEL_TEXT);
draw_text_clipped(renderer, fonts->medium, selected_channel->program_title, &clip_rect, rect->x + 18, rect->y + 88, COLOR_PANEL_TEXT);
draw_text_clipped(renderer, fonts->medium, program->program_title, &clip_rect, rect->x + 18, rect->y + 88, COLOR_PANEL_TEXT);
draw_text_clipped(renderer, fonts->small, time_range, &clip_rect, rect->x + 18, rect->y + 124, COLOR_PANEL_TEXT);
draw_text_clipped(renderer, fonts->small, description, &clip_rect, rect->x + 18, rect->y + 148, COLOR_PANEL_TEXT);
}
@ -581,15 +583,27 @@ void ui_render_guide(SDL_Renderer *renderer,
{
const Channel *channel = &channels->items[channel_index];
double live_position = channel_live_position_precise(channel, app_start_ticks, now_ticks);
double live_position = 0.0;
double program_seek = 0.0;
const ProgramEntry *program = channel_resolve_program(channel, app_start_ticks, now_ticks, &program_seek, NULL);
time_t guide_view_start_time = now_wall - (30 * 60);
time_t program_start_time = now_wall - (time_t) live_position;
int block_x = GUIDE_X_START + (int) (((double) (program_start_time - guide_view_start_time)) / 60.0 * pixels_per_minute);
int block_w = (int) ((channel->duration_seconds / 60.0) * pixels_per_minute);
SDL_Rect block = {block_x, timeline_rect.y + 4, SDL_max(block_w, 48), timeline_rect.h - 8};
int block_x = GUIDE_X_START;
int block_w = 48;
SDL_Rect block = {GUIDE_X_START, timeline_rect.y + 4, 48, timeline_rect.h - 8};
SDL_Rect title_rect = {block.x + 8, block.y + 8, block.w - 16, block.h - 16};
char title[128];
if (!program) {
continue;
}
live_position = channel_live_position_precise(channel, app_start_ticks, now_ticks);
program_start_time = now_wall - (time_t) program_seek;
block_x = GUIDE_X_START + (int) (((double) (program_start_time - guide_view_start_time)) / 60.0 * pixels_per_minute);
block_w = (int) ((program->duration_seconds / 60.0) * pixels_per_minute);
block = (SDL_Rect){block_x, timeline_rect.y + 4, SDL_max(block_w, 48), timeline_rect.h - 8};
title_rect = (SDL_Rect){block.x + 8, block.y + 8, block.w - 16, block.h - 16};
if (is_selected) {
draw_text_clipped(renderer, fonts->medium, channel->name, &sidebar, 20, row_rect.y + 12, COLOR_ACTIVE_TEXT);
{
@ -601,7 +615,7 @@ void ui_render_guide(SDL_Renderer *renderer,
draw_cached_text(renderer, &cache->channels[channel_index].name_medium, 20, row_rect.y + 12);
draw_cached_text(renderer, &cache->channels[channel_index].number_medium, 176, row_rect.y + 12);
}
draw_cached_text(renderer, &cache->channels[channel_index].file_small, 20, row_rect.y + 38);
draw_text_clipped(renderer, fonts->small, program->file_name, &sidebar, 20, row_rect.y + 38, COLOR_PALE_BLUE);
SDL_RenderSetClipRect(renderer, &clip);
draw_beveled_bar(renderer,
@ -612,7 +626,7 @@ void ui_render_guide(SDL_Renderer *renderer,
is_selected ? COLOR_SELECTION_EDGE : COLOR_GLOSS,
COLOR_BORDER_DARK);
fit_text_with_ellipsis(is_selected ? fonts->medium : fonts->small,
channel->program_title,
program->program_title,
title_rect.w,
title,
sizeof(title));
@ -676,17 +690,18 @@ int ui_cache_init(UiCache *cache, SDL_Renderer *renderer, const UiFonts *fonts,
for (int i = 0; i < channels->count; ++i) {
const Channel *channel = &channels->items[i];
const ProgramEntry *program = channel->program_count > 0 ? &channel->programs[0] : NULL;
snprintf(buffer, sizeof(buffer), "%d", channel->number);
if (text_texture_init(&cache->channels[i].name_medium, renderer, fonts->medium, channel->name, COLOR_TEXT_LIGHT) != 0 ||
text_texture_init(&cache->channels[i].number_medium, renderer, fonts->medium, buffer, COLOR_TEXT_LIGHT) != 0 ||
text_texture_init(&cache->channels[i].file_small, renderer, fonts->small, channel->file_name, COLOR_PALE_BLUE) != 0 ||
text_texture_init(&cache->channels[i].program_small_light, renderer, fonts->small, channel->program_title, COLOR_TEXT_LIGHT) != 0 ||
text_texture_init(&cache->channels[i].program_medium_dark, renderer, fonts->medium, channel->program_title, COLOR_TEXT_DARK) != 0) {
text_texture_init(&cache->channels[i].file_small, renderer, fonts->small, program ? program->file_name : "", COLOR_PALE_BLUE) != 0 ||
text_texture_init(&cache->channels[i].program_small_light, renderer, fonts->small, program ? program->program_title : "", COLOR_TEXT_LIGHT) != 0 ||
text_texture_init(&cache->channels[i].program_medium_dark, renderer, fonts->medium, program ? program->program_title : "", COLOR_TEXT_DARK) != 0) {
ui_cache_destroy(cache);
return -1;
}
snprintf(buffer, sizeof(buffer), "%.0f min - %s", channel->duration_seconds / 60.0, channel->file_name);
snprintf(buffer, sizeof(buffer), "%.0f min - %s", program ? program->duration_seconds / 60.0 : 0.0, program ? program->file_name : "");
if (text_texture_init(&cache->channels[i].detail_small_dark, renderer, fonts->small, buffer, COLOR_TEXT_DARK) != 0) {
ui_cache_destroy(cache);
return -1;