From 47bbcf29172f0e9232b66fe8f80f29ad0839df18 Mon Sep 17 00:00:00 2001 From: SuperSaiyajinStackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Tue, 14 Jan 2020 18:24:39 +0100 Subject: [PATCH] Animation time? :stuck_out_tongue: I just ripped the animation selector code from LeafEdit for it, because it's basically the same like LeafEdit because of Rectangles. --- include/gui.hpp | 1 + source/gui.cpp | 22 ++++++++++++++++++++++ source/screens/mainMenu.cpp | 5 ++--- source/screens/scriptBrowse.cpp | 11 ++++------- source/screens/scriptlist.cpp | 25 ++++++++++--------------- source/screens/settings.cpp | 17 +++++++---------- source/screens/unistore.cpp | 24 ++++++++++-------------- source/utils/fileBrowse.cpp | 11 ++++------- 8 files changed, 60 insertions(+), 56 deletions(-) diff --git a/include/gui.hpp b/include/gui.hpp index 7f427a5..414f79d 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -48,6 +48,7 @@ namespace Gui void sprite(int key, int x, int y, float ScaleX = 1, float ScaleY = 1); void spriteBlend(int key, int x, int y, float ScaleX = 1, float ScaleY = 1); void DrawArrow(int x, int y, float rotation = 0, int arrowSprite = 0); + void drawAnimatedSelector(float xPos, float yPos, float Width, float Height, float speed = .060, u32 colour = C2D_Color32(0, 0, 0, 0)); // Misc. bool Draw_Rect(float x, float y, float w, float h, u32 color); diff --git a/source/gui.cpp b/source/gui.cpp index 6d13c4a..b5de563 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -136,6 +136,28 @@ void Gui::DrawArrow(int x, int y, float rotation, int arrowSprite) { C2D_DrawSpriteTinted(&sprite, &tint); } +void Gui::drawAnimatedSelector(float xPos, float yPos, float Width, float Height, float speed, u32 colour) +{ + static constexpr int w = 2; + static float timer = 0.0f; + float highlight_multiplier = fmax(0.0, fabs(fmod(timer, 1.0) - 0.5) / 0.5); + u8 r = Config::SelectedColor & 0xFF; + u8 g = (Config::SelectedColor >> 8) & 0xFF; + u8 b = (Config::SelectedColor >> 16) & 0xFF; + u32 color = C2D_Color32(r + (255 - r) * highlight_multiplier, g + (255 - g) * highlight_multiplier, b + (255 - b) * highlight_multiplier, 255); + + // BG Color for the Selector. + C2D_DrawRectSolid(xPos, yPos, 0.5, Width, Height, colour); // Black. + + // Animated Selector part. + C2D_DrawRectSolid(xPos, yPos, 0.5, Width, w, color); // top + C2D_DrawRectSolid(xPos, yPos + w, 0.5, w, Height - 2 * w, color); // left + C2D_DrawRectSolid(xPos + Width - w, yPos + w, 0.5, w, Height - 2 * w, color); // right + C2D_DrawRectSolid(xPos, yPos + Height - w, 0.5, Width, w, color); // bottom + + timer += speed; // Speed of the animation. Example : .030 / .060 +} + void Gui::DisplayWarnMsg(std::string Text) { Gui::clearTextBufs(); diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index 03f68db..305524c 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -53,10 +53,9 @@ void MainMenu::Draw(void) const { Gui::DrawArrow(0, 218, 0, 1); for (int i = 0; i < 4; i++) { + Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor); if (Selection == i) { - Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor); - } else { - Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor); + Gui::drawAnimatedSelector(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, .060, Config::SelectedColor); } } diff --git a/source/screens/scriptBrowse.cpp b/source/screens/scriptBrowse.cpp index e79dc84..f04d76d 100644 --- a/source/screens/scriptBrowse.cpp +++ b/source/screens/scriptBrowse.cpp @@ -141,10 +141,9 @@ void ScriptBrowse::Draw(void) const { if (Config::viewMode == 0) { for(int i=0;i