diff --git a/src/gui/CoreComponents.hpp b/src/gui/CoreComponents.hpp index b991597..ab545da 100644 --- a/src/gui/CoreComponents.hpp +++ b/src/gui/CoreComponents.hpp @@ -6,163 +6,154 @@ 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; + } }; + +/**************************************************** + * A "Are you sure you want to exit?" Window. + * + * Yes is default + * TODO: Make the Yes-Button standout as the default +****************************************************/ class SafeClosePopup final : public GuiMovableWindow { - Vector2 anchor03 = { 0,0 }; + Vector2 anchor03 = { 0,0 }; - bool m_CQB_YesButton = false; - bool m_CQB_NoButton = false; -public: - void onAttach() override - { - m_WindowOpen = false; - } + bool m_CQB_YesButton = false; + bool m_CQB_NoButton = false; + + public: - int draw() override - { - if (WindowShouldClose()) - { - m_WindowOpen = !m_WindowOpen; - onResize(); - } + ~SafeClosePopup() { + CloseWindow(); + } - if (m_WindowOpen) - { - anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 }; + void onAttach() override + { + m_WindowOpen = false; + } - 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) m_WindowOpen = false; + int draw() override + { + if (WindowShouldClose()) + { + if (m_WindowOpen) { + CloseWindow(); + } + else { + OpenWindow(); + } + onResize(); + } - } - return 0; - } + if (m_WindowOpen) + { + GuiUnlock(); + anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 }; - int rinput(Vector2& mouse_position) override - { - if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !CheckCollisionPointRec(mouse_position, m_WndRect)) - { - SetMousePosition(anchor03.x, anchor03.y); - } - return 0; - } + 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; + } + + 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; + } + + void CloseWindow() { + m_WindowOpen = false; + GuiUnlock(); + } }; -class SettingsComponent final : public sva::GuiComponent -{ - Vector2 anchor01 = { 0,0 }; - int ActiveMonitorID = 0; +class SettingsComponent final : public sva::GuiComponent { + public: + struct { + bool borderlessFullscreen; + uint32_t state; + } values; - std::string m_ScreenListString; + void onAttach() override { + values.borderlessFullscreen = false; + values.state = 0; + } -public: - void onAttach() override - { - for (int i = 0; i < GetMonitorCount(); ++i) - { - m_ScreenListString += GetMonitorName(i); - m_ScreenListString += ";"; - } - m_ScreenListString.pop_back(); - - fitWindowToMonitor(); - } - - void onResize() override - { - anchor01 = { static_cast(m_WndWidth) / 4, static_cast(m_WndHeight) / 4 }; - } - - int draw() override - { - if (GetCurrentMonitor() != ActiveMonitorID) - { - fitWindowToMonitor(ActiveMonitorID); - m_ScreenListString.clear(); - for (int i = 0; i < GetMonitorCount(); ++i) - { - m_ScreenListString += GetMonitorName(i); - m_ScreenListString += ";"; - } - m_ScreenListString.pop_back(); - } - - GuiGroupBox({ anchor01.x + 0, anchor01.y + 0, 264, 104 }, "Settings"); - GuiLabel({ anchor01.x + 16, anchor01.y + 24, 72, 24 }, "#181#Screen:"); - GuiComboBox({ anchor01.x + 88, anchor01.y + 24, 160, 24 }, m_ScreenListString.c_str(), &ActiveMonitorID); - return 0; - } - -private: - static void fitWindowToMonitor(int monitor = 0) - { - if (GetMonitorCount() < monitor) return; - int width = GetMonitorHeight(monitor); - int height = GetMonitorHeight(monitor); - SetWindowMonitor(monitor); - SetWindowSize(width, height); - - int refresh_rate = GetMonitorRefreshRate(monitor); - SetTargetFPS(refresh_rate); - ToggleBorderlessWindowed(); - } + 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 cc98140..fef3d9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,7 @@ enum class logerr_level }; -int main(void) +int main(int argc, char** argv) { #ifdef _DEBUG spdlog::set_level(spdlog::level::debug); @@ -57,8 +57,9 @@ int main(void) return 0; } - ClearWindowState(ConfigFlags::FLAG_WINDOW_RESIZABLE | ConfigFlags::FLAG_WINDOW_TRANSPARENT); + ClearWindowState(ConfigFlags::FLAG_WINDOW_TRANSPARENT); SetWindowState(ConfigFlags::FLAG_WINDOW_ALWAYS_RUN); + SetWindowState(ConfigFlags::FLAG_WINDOW_RESIZABLE); SetWindowFocused(); @@ -73,9 +74,10 @@ int main(void) 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); @@ -121,4 +123,4 @@ int main(void) } return 0; -} \ No newline at end of file +}