|
| 1 | +#define _POSIX_C_SOURCE 199309L |
| 2 | +#include "stlxdm_splash.h" |
| 3 | +#include <stdio.h> |
| 4 | +#include <stdlib.h> |
| 5 | +#include <string.h> |
| 6 | +#include <unistd.h> |
| 7 | +#include <math.h> |
| 8 | +#include <time.h> |
| 9 | +#include <stlxgfx/internal/stlxgfx_dm.h> |
| 10 | +#include <stlxgfx/surface.h> |
| 11 | +#include <stlibc/stlibc.h> |
| 12 | + |
| 13 | +// Splash screen configuration |
| 14 | +#define SPLASH_FRAME_RATE 60 // Target 60 FPS |
| 15 | +#define SPLASH_FRAME_DELAY_MS (1000 / SPLASH_FRAME_RATE) |
| 16 | + |
| 17 | +// Color definitions |
| 18 | +#define SPLASH_BG_DARK 0xFF0A0A0A |
| 19 | +#define SPLASH_CYAN_BORDER 0xFF00FFFF |
| 20 | +#define SPLASH_WHITE_BRIGHT 0xFFFFFFFF |
| 21 | +#define SPLASH_WHITE_MIN 0xFF808080 |
| 22 | + |
| 23 | +// Logo dimensions |
| 24 | +#define LOGO_WIDTH 600 |
| 25 | +#define LOGO_HEIGHT 80 |
| 26 | +#define LOGO_BORDER_WIDTH 10 |
| 27 | +#define LOGO_BORDER_RADIUS 15 |
| 28 | + |
| 29 | +static void create_dark_background(stlxgfx_surface_t* surface) { |
| 30 | + if (!surface) return; |
| 31 | + stlxgfx_clear_surface(surface, SPLASH_BG_DARK); |
| 32 | +} |
| 33 | + |
| 34 | +static void draw_animated_gradient_logo(stlxgfx_surface_t* surface, uint32_t frame) { |
| 35 | + if (!surface) return; |
| 36 | + |
| 37 | + uint32_t center_x = surface->width / 2; |
| 38 | + uint32_t logo_y = surface->height / 3; |
| 39 | + uint32_t logo_x = center_x - LOGO_WIDTH / 2; |
| 40 | + |
| 41 | + // Create flowing gradient animation |
| 42 | + for (uint32_t y = logo_y; y < logo_y + LOGO_HEIGHT; y++) { |
| 43 | + for (uint32_t x = logo_x; x < logo_x + LOGO_WIDTH; x++) { |
| 44 | + float progress_x = (float)(x - logo_x) / LOGO_WIDTH; |
| 45 | + float progress_y = (float)(y - logo_y) / LOGO_HEIGHT; |
| 46 | + |
| 47 | + // Add flowing animation to the gradient |
| 48 | + float flow_offset = sinf((float)frame * 0.02f + progress_x * 3.14159f) * 0.1f; |
| 49 | + progress_x += flow_offset; |
| 50 | + |
| 51 | + if (progress_x < 0.0f) progress_x = 0.0f; |
| 52 | + if (progress_x > 1.0f) progress_x = 1.0f; |
| 53 | + |
| 54 | + // Deep purple to magenta gradient with vertical variation |
| 55 | + uint32_t red = (uint32_t)(40 + progress_x * 140 + progress_y * 15); |
| 56 | + uint32_t green = (uint32_t)(0 + progress_y * 20); |
| 57 | + uint32_t blue = (uint32_t)(80 + progress_x * 120 + progress_y * 10); |
| 58 | + |
| 59 | + if (red > 255) red = 255; |
| 60 | + if (green > 255) green = 255; |
| 61 | + if (blue > 255) blue = 255; |
| 62 | + |
| 63 | + uint32_t color = 0xFF000000 | (red << 16) | (green << 8) | blue; |
| 64 | + stlxgfx_draw_pixel(surface, x, y, color); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +static void draw_cyan_border(stlxgfx_surface_t* surface) { |
| 70 | + if (!surface) return; |
| 71 | + |
| 72 | + uint32_t center_x = surface->width / 2; |
| 73 | + uint32_t logo_y = surface->height / 3; |
| 74 | + uint32_t logo_x = center_x - LOGO_WIDTH / 2; |
| 75 | + |
| 76 | + stlxgfx_draw_rounded_rect(surface, |
| 77 | + logo_x - LOGO_BORDER_WIDTH, |
| 78 | + logo_y - LOGO_BORDER_WIDTH, |
| 79 | + LOGO_WIDTH + (2 * LOGO_BORDER_WIDTH), |
| 80 | + LOGO_HEIGHT + (2 * LOGO_BORDER_WIDTH), |
| 81 | + LOGO_BORDER_RADIUS, |
| 82 | + SPLASH_CYAN_BORDER); |
| 83 | +} |
| 84 | + |
| 85 | +static void draw_static_title(stlxgfx_surface_t* surface, stlxgfx_context_t* gfx_ctx) { |
| 86 | + if (!surface || !gfx_ctx) return; |
| 87 | + |
| 88 | + const char* title = "Display Manager v0.1.0"; |
| 89 | + uint32_t center_x = surface->width / 2; |
| 90 | + uint32_t logo_y = surface->height / 3; |
| 91 | + uint32_t title_y = logo_y + LOGO_HEIGHT + 30; |
| 92 | + |
| 93 | + uint32_t text_width = strlen(title) * 28 * 0.6f; |
| 94 | + uint32_t title_x = center_x - text_width / 2; |
| 95 | + |
| 96 | + stlxgfx_render_text(gfx_ctx, surface, title, title_x, title_y, 28, SPLASH_WHITE_BRIGHT); |
| 97 | +} |
| 98 | + |
| 99 | +static void draw_breathing_text(stlxgfx_surface_t* surface, stlxgfx_context_t* gfx_ctx, |
| 100 | + uint32_t frame) { |
| 101 | + if (!surface || !gfx_ctx) return; |
| 102 | + |
| 103 | + const char* text = "Press Enter to continue..."; |
| 104 | + uint32_t center_x = surface->width / 2; |
| 105 | + uint32_t logo_y = surface->height / 3; |
| 106 | + uint32_t text_y = logo_y + LOGO_HEIGHT + 130; |
| 107 | + |
| 108 | + // Slower breathing effect |
| 109 | + float breath = 0.5f + 0.5f * sinf((float)frame * 0.15f); |
| 110 | + |
| 111 | + // Interpolate between minimum brightness and full brightness |
| 112 | + uint8_t min_intensity = 0x80; |
| 113 | + uint8_t max_intensity = 0xFF; |
| 114 | + uint8_t intensity = (uint8_t)(min_intensity + (max_intensity - min_intensity) * breath); |
| 115 | + |
| 116 | + uint32_t text_color = 0xFF000000 | (intensity << 16) | (intensity << 8) | intensity; |
| 117 | + |
| 118 | + uint32_t text_width = strlen(text) * 16 * 0.6f; |
| 119 | + uint32_t text_x = center_x - text_width / 2; |
| 120 | + |
| 121 | + stlxgfx_render_text(gfx_ctx, surface, text, text_x, text_y, 16, text_color); |
| 122 | +} |
| 123 | + |
| 124 | +static void add_modern_decorative_elements(stlxgfx_surface_t* surface, uint32_t frame) { |
| 125 | + if (!surface) return; |
| 126 | + |
| 127 | + uint32_t center_x = surface->width / 2; |
| 128 | + uint32_t logo_y = surface->height / 3; |
| 129 | + uint32_t logo_x = center_x - LOGO_WIDTH / 2; |
| 130 | + |
| 131 | + // Add breathing corner accents |
| 132 | + float breath = 0.5f + 0.5f * sinf((float)frame * 0.15f); |
| 133 | + uint8_t min_intensity = 0x40; |
| 134 | + uint8_t max_intensity = 0xFF; |
| 135 | + uint8_t corner_intensity = (uint8_t)(min_intensity + (max_intensity - min_intensity) * breath); |
| 136 | + uint32_t corner_color = 0xFF000000 | (corner_intensity << 16) | (corner_intensity << 8) | corner_intensity; |
| 137 | + |
| 138 | + uint32_t corner_size = 8; |
| 139 | + |
| 140 | + // Top-left corner |
| 141 | + stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size, |
| 142 | + logo_y - LOGO_BORDER_WIDTH - corner_size, corner_size, 2, corner_color); |
| 143 | + stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size, |
| 144 | + logo_y - LOGO_BORDER_WIDTH - corner_size, 2, corner_size, corner_color); |
| 145 | + |
| 146 | + // Top-right corner |
| 147 | + stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH, |
| 148 | + logo_y - LOGO_BORDER_WIDTH - corner_size, corner_size, 2, corner_color); |
| 149 | + stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH + corner_size - 2, |
| 150 | + logo_y - LOGO_BORDER_WIDTH - corner_size, 2, corner_size, corner_color); |
| 151 | + |
| 152 | + // Bottom-left corner (rotated 90 degrees clockwise from top-left) |
| 153 | + stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size, |
| 154 | + logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH, 2, corner_size, corner_color); |
| 155 | + stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size, |
| 156 | + logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH + corner_size - 2, corner_size, 2, corner_color); |
| 157 | + |
| 158 | + // Bottom-right corner (rotated 90 degrees clockwise from top-right) |
| 159 | + stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH + corner_size - 2, |
| 160 | + logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH, 2, corner_size, corner_color); |
| 161 | + stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH, |
| 162 | + logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH + corner_size - 2, corner_size, 2, corner_color); |
| 163 | +} |
| 164 | + |
| 165 | +static int check_for_enter_key() { |
| 166 | + input_event_t events[16]; |
| 167 | + int n = stlx_read_input_events(STLXGFX_INPUT_QUEUE_ID_SYSTEM, 0, events, 16); |
| 168 | + |
| 169 | + if (n > 0) { |
| 170 | + for (int i = 0; i < n; i++) { |
| 171 | + if (events[i].type == STLXGFX_KBD_EVT_KEY_PRESSED) { |
| 172 | + if (events[i].udata1 == 40) { |
| 173 | + return 1; // Enter pressed |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + return 0; // No Enter key |
| 180 | +} |
| 181 | + |
| 182 | +int stlxdm_show_splash_screen(stlxdm_compositor_t* compositor) { |
| 183 | + if (!compositor || !compositor->initialized) { |
| 184 | + printf("[STLXDM_SPLASH] ERROR: Invalid compositor for splash screen\n"); |
| 185 | + return -1; |
| 186 | + } |
| 187 | + |
| 188 | + printf("[STLXDM_SPLASH] Starting splash screen...\n"); |
| 189 | + |
| 190 | + const struct gfx_framebuffer_info* fb_info = stlxdm_compositor_get_fb_info(compositor); |
| 191 | + if (!fb_info) { |
| 192 | + printf("[STLXDM_SPLASH] ERROR: No framebuffer info available\n"); |
| 193 | + return -1; |
| 194 | + } |
| 195 | + |
| 196 | + stlxgfx_surface_t* splash_surface = stlxgfx_dm_create_surface( |
| 197 | + compositor->gfx_ctx, |
| 198 | + fb_info->width, |
| 199 | + fb_info->height, |
| 200 | + compositor->gop_format |
| 201 | + ); |
| 202 | + |
| 203 | + if (!splash_surface) { |
| 204 | + printf("[STLXDM_SPLASH] ERROR: Failed to create splash surface\n"); |
| 205 | + return -1; |
| 206 | + } |
| 207 | + |
| 208 | + uint32_t frame = 0; |
| 209 | + printf("[STLXDM_SPLASH] Displaying splash screen (press Enter to continue)\n"); |
| 210 | + |
| 211 | + while (1) { |
| 212 | + create_dark_background(splash_surface); |
| 213 | + draw_animated_gradient_logo(splash_surface, frame); |
| 214 | + draw_cyan_border(splash_surface); |
| 215 | + draw_static_title(splash_surface, compositor->gfx_ctx); |
| 216 | + draw_breathing_text(splash_surface, compositor->gfx_ctx, frame); |
| 217 | + add_modern_decorative_elements(splash_surface, frame); |
| 218 | + |
| 219 | + stlxdm_begin_frame(); |
| 220 | + int present_result = stlxgfx_blit_surface_to_buffer( |
| 221 | + splash_surface, |
| 222 | + compositor->framebuffer, |
| 223 | + fb_info->pitch |
| 224 | + ); |
| 225 | + stlxdm_end_frame(); |
| 226 | + |
| 227 | + if (present_result != 0) { |
| 228 | + printf("[STLXDM_SPLASH] Warning: Failed to present splash frame\n"); |
| 229 | + } |
| 230 | + |
| 231 | + if (check_for_enter_key()) { |
| 232 | + printf("[STLXDM_SPLASH] Enter key pressed, continuing to display manager\n"); |
| 233 | + break; |
| 234 | + } |
| 235 | + |
| 236 | + struct timespec delay = { |
| 237 | + .tv_sec = 0, |
| 238 | + .tv_nsec = SPLASH_FRAME_DELAY_MS * 1000000 |
| 239 | + }; |
| 240 | + nanosleep(&delay, NULL); |
| 241 | + |
| 242 | + frame++; |
| 243 | + } |
| 244 | + |
| 245 | + stlxgfx_dm_destroy_surface(compositor->gfx_ctx, splash_surface); |
| 246 | + printf("[STLXDM_SPLASH] Splash screen completed\n"); |
| 247 | + return 0; |
| 248 | +} |
0 commit comments