From d375f9ca7d49d21918cf22537f0f708471bf792e Mon Sep 17 00:00:00 2001 From: noffie Date: Sun, 22 Dec 2024 21:30:08 +0100 Subject: [PATCH] Making the default button stand out --- src/gui/CoreComponents.hpp | 234 +++++++++++++++++++------------------ src/main.cpp | 11 +- 2 files changed, 126 insertions(+), 119 deletions(-) diff --git a/src/gui/CoreComponents.hpp b/src/gui/CoreComponents.hpp index ab545da..9e2bdba 100644 --- a/src/gui/CoreComponents.hpp +++ b/src/gui/CoreComponents.hpp @@ -6,47 +6,47 @@ class GuiMovableWindow : public sva::GuiComponent { - private: - bool m_DragWindow = false; - Vector2 m_PanOffset = { 0,0 }; - protected: - Rectangle m_WndRect = { 20,20, 200, 100 }; - bool m_WindowOpen = true; - public: +private: + bool m_DragWindow = false; + Vector2 m_PanOffset = { 0,0 }; +protected: + Rectangle m_WndRect = { 20,20, 200, 100 }; + bool m_WindowOpen = true; +public: - virtual int input() override - { - if (!m_WindowOpen) return 0; - Vector2 mouse_pos = GetMousePosition(); + virtual int input() override + { + if (!m_WindowOpen) return 0; + Vector2 mouse_pos = GetMousePosition(); - if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !m_DragWindow) - { - if (CheckCollisionPointRec(mouse_pos, { m_WndRect.x, m_WndRect.y, m_WndRect.width - 24, 20 })) - { - m_DragWindow = true; - m_PanOffset = { mouse_pos.x - m_WndRect.x, mouse_pos.y - m_WndRect.y }; - } - } + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !m_DragWindow) + { + if (CheckCollisionPointRec(mouse_pos, { m_WndRect.x, m_WndRect.y, m_WndRect.width - 24, 20 })) + { + m_DragWindow = true; + m_PanOffset = { mouse_pos.x - m_WndRect.x, mouse_pos.y - m_WndRect.y }; + } + } - if (m_DragWindow) - { - m_WndRect.x = (mouse_pos.x - m_PanOffset.x); - m_WndRect.y = (mouse_pos.y - m_PanOffset.y); - if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) m_DragWindow = false; - } - return rinput(mouse_pos); - } + if (m_DragWindow) + { + m_WndRect.x = (mouse_pos.x - m_PanOffset.x); + m_WndRect.y = (mouse_pos.y - m_PanOffset.y); + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) m_DragWindow = false; + } + return rinput(mouse_pos); + } - virtual int rinput(Vector2& mouse_position) { return 0; }; + virtual int rinput(Vector2& mouse_position) { return 0; }; - virtual int draw() override - { - if (!m_WindowOpen) return 0; + virtual int draw() override + { + if (!m_WindowOpen) return 0; - m_WindowOpen = !GuiWindowBox(m_WndRect, "Example Movable Window"); + m_WindowOpen = !GuiWindowBox(m_WndRect, "Example Movable Window"); - return 0; - } + return 0; + } }; @@ -58,102 +58,108 @@ class GuiMovableWindow : public sva::GuiComponent ****************************************************/ class SafeClosePopup final : public GuiMovableWindow { - Vector2 anchor03 = { 0,0 }; + Vector2 anchor03 = { 0,0 }; - bool m_CQB_YesButton = false; - bool m_CQB_NoButton = false; - - public: + bool m_CQB_YesButton = false; + bool m_CQB_NoButton = false; - ~SafeClosePopup() { - CloseWindow(); - } +public: - void onAttach() override - { - m_WindowOpen = false; - } + ~SafeClosePopup() { + CloseWindow(); + } - int draw() override - { - if (WindowShouldClose()) - { - if (m_WindowOpen) { - CloseWindow(); - } - else { - OpenWindow(); - } - onResize(); - } + void onAttach() override + { + m_WindowOpen = false; + } - if (m_WindowOpen) - { - GuiUnlock(); - anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 }; + int draw() override + { + if (WindowShouldClose()) + { + if (m_WindowOpen) { + CloseWindow(); + } + else { + OpenWindow(); + } + onResize(); + } - m_WindowOpen = !GuiWindowBox(m_WndRect, "#191# Are you sure you want to close this program?"); - m_CQB_YesButton = GuiButton({ anchor03.x + -152, anchor03.y + 32, 120, 24 }, "#112#Yes"); - m_CQB_NoButton = GuiButton({ anchor03.x + 24, anchor03.y + 32, 120, 24 }, "#113#No"); - GuiLabel({ anchor03.x + -104, anchor03.y + -40, 208, 24 }, "Are you sure you want to close this?"); - GuiLabel({ anchor03.x + -56, anchor03.y + -8, 120, 24 }, "Press \"Yes\" to close"); - if (m_CQB_YesButton) - { - *m_WndRunning = false; - return 1; - } - if (m_CQB_NoButton) CloseWindow(); - } - return 0; - } + if (m_WindowOpen) + { + GuiUnlock(); + anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 }; - int rinput(Vector2& mouse_position) override - { - if (IsKeyReleased(KEY_ENTER)) { - *m_WndRunning = false; - return 1; - } - GuiLock(); - return 0; - } + m_WindowOpen = !GuiWindowBox(m_WndRect, "#191# Are you sure you want to close this program?"); + int border_color = GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL); + int base_color = GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL); + GuiSetStyle(DEFAULT, BORDER_COLOR_NORMAL, 0x7192C2FF); + GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, 0xBBCDD3FF); + m_CQB_YesButton = GuiButton({ anchor03.x + -152, anchor03.y + 32, 120, 24 }, "#112#Yes"); + GuiSetStyle(DEFAULT, BORDER_COLOR_NORMAL, border_color); + GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, base_color); + m_CQB_NoButton = GuiButton({ anchor03.x + 24, anchor03.y + 32, 120, 24 }, "#113#No"); + GuiLabel({ anchor03.x + -104, anchor03.y + -40, 208, 24 }, "Are you sure you want to close this?"); + GuiLabel({ anchor03.x + -56, anchor03.y + -8, 120, 24 }, "Press \"Yes\" to close"); + if (m_CQB_YesButton) + { + *m_WndRunning = false; + return 1; + } + if (m_CQB_NoButton) CloseWindow(); + } + return 0; + } + + int rinput(Vector2& mouse_position) override + { + if (IsKeyReleased(KEY_ENTER)) { + *m_WndRunning = false; + return 1; + } + GuiLock(); + return 0; + } - void onResize() override - { - anchor03 = { static_cast(m_WndWidth) / 2 , static_cast(m_WndHeight) / 2 }; - m_WndRect = { anchor03.x + -168, anchor03.y + -88, 328, 160 }; - } + void onResize() override + { + anchor03 = { static_cast(m_WndWidth) / 2 , static_cast(m_WndHeight) / 2 }; + m_WndRect = { anchor03.x + -168, anchor03.y + -88, 328, 160 }; + } - public: - void OpenWindow() { - GuiLock(); - m_WindowOpen = true; - } +public: + void OpenWindow() { + GuiLock(); + m_WindowOpen = true; + } - void CloseWindow() { - m_WindowOpen = false; - GuiUnlock(); - } + void CloseWindow() { + m_WindowOpen = false; + GuiUnlock(); + } }; class SettingsComponent final : public sva::GuiComponent { - public: - struct { - bool borderlessFullscreen; - uint32_t state; - } values; +public: + struct { + bool borderlessFullscreen; + uint32_t state; + } values; - void onAttach() override { - values.borderlessFullscreen = false; - values.state = 0; - } + void onAttach() override { + values.borderlessFullscreen = false; + values.state = 0; + } - int draw() override { - if(GuiButton({100, 100, 300, 30}, "This should not work when the safe window is open!")) { - std::cout << "got pressed\n"; - } - return 0; - } + int draw() override { + if (GuiButton({ 100, 100, 300, 30 }, "This should not work when the safe window is open!")) { + std::cout << "got pressed\n"; + } + return 0; + } }; diff --git a/src/main.cpp b/src/main.cpp index 13a5abf..ff92ca7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,7 +59,7 @@ int main(int argc, char** argv) ClearWindowState(ConfigFlags::FLAG_WINDOW_TRANSPARENT); SetWindowState(ConfigFlags::FLAG_WINDOW_ALWAYS_RUN); - SetWindowState(ConfigFlags::FLAG_WINDOW_RESIZABLE); + SetWindowState(ConfigFlags::FLAG_WINDOW_RESIZABLE); SetWindowFocused(); @@ -74,10 +74,9 @@ int main(int argc, char** argv) int run_result = 0; - ComponentStack::push(); + ComponentStack::push(); - - // always on top... + // always on top... SafeClosePopup safe_close_popup; safe_close_popup.attach(&is_running); safe_close_popup.wndrsize(ComponentStack::s_WndWidth, ComponentStack::s_WndHeight); @@ -114,6 +113,8 @@ int main(int argc, char** argv) switch (run_result) { + case 1: + return 0; case 2: spdlog::warn("Program exiting abnormally."); break; @@ -121,5 +122,5 @@ int main(int argc, char** argv) break; } - return 0; + return run_result; }