From 8a21065fe8021443263ce6fc663a9e854e0c9c68 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Thu, 26 Mar 2020 14:37:08 -0700 Subject: [PATCH] ui: Start logo animation on appearing --- ui/xemu-custom-widgets.c | 3 ++- ui/xemu-custom-widgets.h | 2 +- ui/xemu-hud.cc | 19 +++++++++++++++++-- ui/xemu-shaders.c | 3 ++- ui/xemu-shaders.h | 1 + 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ui/xemu-custom-widgets.c b/ui/xemu-custom-widgets.c index 555a7f90c1..a640d76f1b 100644 --- a/ui/xemu-custom-widgets.c +++ b/ui/xemu-custom-widgets.c @@ -287,8 +287,9 @@ void render_controller_port(float frame_x, float frame_y, int i, uint32_t port_c glUseProgram(0); } -void render_logo(uint32_t primary_color, uint32_t secondary_color, uint32_t fill_color) +void render_logo(uint32_t time, uint32_t primary_color, uint32_t secondary_color, uint32_t fill_color) { + s_logo->time = time; glUseProgram(s_logo->prog); glBindVertexArray(s->vao); glBlendFunc(GL_ONE, GL_ZERO); diff --git a/ui/xemu-custom-widgets.h b/ui/xemu-custom-widgets.h index 4dbd7a0fb3..398608ad66 100644 --- a/ui/xemu-custom-widgets.h +++ b/ui/xemu-custom-widgets.h @@ -36,7 +36,7 @@ void initialize_custom_ui_rendering(void); void render_meter(struct decal_shader *s, float x, float y, float width, float height, float p, uint32_t color_bg, uint32_t color_fg); void render_controller(float frame_x, float frame_y, uint32_t primary_color, uint32_t secondary_color, struct controller_state *state); void render_controller_port(float frame_x, float frame_y, int i, uint32_t port_color); -void render_logo(uint32_t primary_color, uint32_t secondary_color, uint32_t fill_color); +void render_logo(uint32_t time, uint32_t primary_color, uint32_t secondary_color, uint32_t fill_color); #ifdef __cplusplus } diff --git a/ui/xemu-hud.cc b/ui/xemu-hud.cc index a9e32648e9..03f0ab9268 100644 --- a/ui/xemu-hud.cc +++ b/ui/xemu-hud.cc @@ -1112,6 +1112,12 @@ struct AboutWindow return; } + static uint32_t time_start = 0; + if (ImGui::IsWindowAppearing()) { + time_start = SDL_GetTicks(); + } + uint32_t now = SDL_GetTicks() - time_start; + ImGui::SetCursorPosY(ImGui::GetCursorPosY()-50); ImGui::SetCursorPosX((ImGui::GetWindowWidth()-256)/2); @@ -1123,7 +1129,10 @@ struct AboutWindow ImVec2(t_w-x_off, t_h), ImVec2(x_off/t_w, t_h/t_h), ImVec2(t_w/t_w, 0)); - render_logo(0x42e335ff, 0x42e335ff, 0x00000000); + if (ImGui::IsItemClicked()) { + time_start = SDL_GetTicks(); + } + render_logo(now, 0x42e335ff, 0x42e335ff, 0x00000000); render_to_default_fb(); ImGui::SetCursorPosX(10); @@ -1186,6 +1195,12 @@ struct FirstBootWindow return; } + static uint32_t time_start = 0; + if (ImGui::IsWindowAppearing()) { + time_start = SDL_GetTicks(); + } + uint32_t now = SDL_GetTicks() - time_start; + ImGui::SetCursorPosY(ImGui::GetCursorPosY()-50); ImGui::SetCursorPosX((ImGui::GetWindowWidth()-256)/2); @@ -1197,7 +1212,7 @@ struct FirstBootWindow ImVec2(t_w-x_off, t_h), ImVec2(x_off/t_w, t_h/t_h), ImVec2(t_w/t_w, 0)); - render_logo(0x42e335ff, 0x42e335ff, 0x00000000); + render_logo(now, 0x42e335ff, 0x42e335ff, 0x00000000); render_to_default_fb(); ImGui::SetCursorPosX(10); diff --git a/ui/xemu-shaders.c b/ui/xemu-shaders.c index 1f37547394..8857ce428f 100644 --- a/ui/xemu-shaders.c +++ b/ui/xemu-shaders.c @@ -61,6 +61,7 @@ struct decal_shader *create_decal_shader(enum SHADER_TYPE type) s->scale = 1.4; s->smoothing = 1.0; s->outline_dist = 1.0; + s->time = 0; const char *vert_src = "#version 150 core\n" @@ -244,7 +245,7 @@ void render_decal( glUniform4f(s->ColorPrimary_loc, COL(primary, 3), COL(primary, 2), COL(primary, 1), COL(primary, 0)); glUniform4f(s->ColorSecondary_loc, COL(secondary, 3), COL(secondary, 2), COL(secondary, 1), COL(secondary, 0)); glUniform4f(s->ColorFill_loc, COL(fill, 3), COL(fill, 2), COL(fill, 1), COL(fill, 0)); - if (s->time_loc >= 0) glUniform1f(s->time_loc, SDL_GetTicks()/1000.0f); + if (s->time_loc >= 0) glUniform1f(s->time_loc, s->time/1000.0f); if (s->scale_loc >= 0) glUniform1f(s->scale_loc, s->scale); #undef COL glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); diff --git a/ui/xemu-shaders.h b/ui/xemu-shaders.h index 5c58824f8e..cd6fef2af1 100644 --- a/ui/xemu-shaders.h +++ b/ui/xemu-shaders.h @@ -37,6 +37,7 @@ struct decal_shader float scale; float smoothing; float outline_dist; + uint32_t time; // GL object handles GLuint prog, vao, vbo, ebo;