From d6b0d6da1cf008fe1b8be48d01a96fd51600ce63 Mon Sep 17 00:00:00 2001 From: vgmoose Date: Sun, 28 Jul 2024 14:26:17 -0400 Subject: [PATCH] cursor: add idle/pulsing cursor, adjust colors to be brighter --- src/Element.cpp | 35 ++++++++++++++++++++++++++++++----- src/RootDisplay.cpp | 2 ++ src/RootDisplay.hpp | 5 +++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Element.cpp b/src/Element.cpp index 109f738..0acd8e2 100644 --- a/src/Element.cpp +++ b/src/Element.cpp @@ -49,6 +49,11 @@ bool Element::process(InputEvents* event) ret |= true; } + if (RootDisplay::idleCursorPulsing) { + // if we are using idle cursor pulsing, and this element's elastic counter is 0, force a redraw + return ret | (this->elasticCounter > 0); + } + return ret; } @@ -83,22 +88,42 @@ void Element::render(Element* parent) { CST_Rect d = { this->xAbs - 5, this->yAbs - 5, this->width + 10, this->height + 10 }; CST_SetDrawBlend(renderer, true); - CST_SetDrawColorRGBA(renderer, 0xad, 0xd8, 0xe6, 0x90); + CST_SetDrawColorRGBA(renderer, 0x10, 0xD9, 0xD9, 0x40); CST_FillRect(renderer, &d); } if (this->touchable && this->elasticCounter > NO_HIGHLIGHT) { CST_Rect d = { this->xAbs - 5, this->yAbs - 5, this->width + 10, this->height + 10 }; - CST_rectangleRGBA(renderer, d.x, d.y, d.x + d.w, d.y + d.h, 0x66, 0x7c, 0x89, 0xFF); - if (this->elasticCounter == THICK_HIGHLIGHT) { + int ticks = CST_GetTicks() / 100; + int pulseState = ticks % 20; + if (pulseState > 9) { + pulseState = 19 - pulseState; + } + + if (!RootDisplay::idleCursorPulsing) { + // if we're not using idle cursor pulsing, just draw a simple rectangle + pulseState = 0; + } + // make it a little thicker by drawing more rectangles TODO: better way to do this? - for (int x = 0; x < 5; x++) + for (int x = -2; x <= 3; x++) { - CST_rectangleRGBA(renderer, d.x + x, d.y + x, d.x + d.w - x, d.y + d.h - x, 0x66 - x * 10, 0x7c + x * 20, 0x89 + x * 10, 0xFF); + // draw a rectangle with varying brightness depending on the pulse state + int r = 0x10; //- 0x01 * pulseState; + int g = 0xD9 - 0x01 * pulseState; + int b = 0xD9 - 0x01 * pulseState; + int edgeMod = x==1 ? 0 : abs(x); // slight bias towards the inner + int a = fmax(0x0, 0xFF - 0x10 * pulseState * edgeMod); + CST_rectangleRGBA(renderer, d.x + x, d.y + x, d.x + d.w - x, d.y + d.h - x, r, g, b, a); } + } else { + // simple rectangle, not pulsing + CST_rectangleRGBA(renderer, d.x, d.y, d.x + d.w, d.y + d.h, 0x10, 0xD9, 0xD9, 0xFF); + // and one inner rectangle too + CST_rectangleRGBA(renderer, d.x + 1, d.y + 1, d.x + d.w - 1, d.y + d.h - 1, 0x10, 0xD9, 0xD9, 0xFF); } } } diff --git a/src/RootDisplay.cpp b/src/RootDisplay.cpp index b650fa3..0dcd028 100644 --- a/src/RootDisplay.cpp +++ b/src/RootDisplay.cpp @@ -34,6 +34,8 @@ int RootDisplay::screenWidth = 1280; int RootDisplay::screenHeight = 720; float RootDisplay::dpiScale = 1.0f; +bool RootDisplay::idleCursorPulsing = false; + RootDisplay::RootDisplay() { // initialize the romfs for switch/wiiu diff --git a/src/RootDisplay.hpp b/src/RootDisplay.hpp index 5a4c3ac..8db6bd5 100644 --- a/src/RootDisplay.hpp +++ b/src/RootDisplay.hpp @@ -43,6 +43,11 @@ class RootDisplay : public Element static int screenHeight; static float dpiScale; + // if enabled, the cursor will pulse when idle + // this uses more energy and forces more redraws + // TODO: enable or disable based on battery level or user preference + static bool idleCursorPulsing; + static bool isDebug; bool isRunning = true; bool exitRequested = false;