Merge branch 'rework' of https://github.com/Knoficooki/sortiva into rework

This commit is contained in:
noffie 2024-12-22 20:49:51 +01:00
commit 8ccaaca579
2 changed files with 133 additions and 140 deletions

View file

@ -49,13 +49,26 @@ public:
} }
}; };
/****************************************************
* 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 class SafeClosePopup final : public GuiMovableWindow
{ {
Vector2 anchor03 = { 0,0 }; Vector2 anchor03 = { 0,0 };
bool m_CQB_YesButton = false; bool m_CQB_YesButton = false;
bool m_CQB_NoButton = false; bool m_CQB_NoButton = false;
public: public:
~SafeClosePopup() {
CloseWindow();
}
void onAttach() override void onAttach() override
{ {
m_WindowOpen = false; m_WindowOpen = false;
@ -65,12 +78,18 @@ public:
{ {
if (WindowShouldClose()) if (WindowShouldClose())
{ {
m_WindowOpen = !m_WindowOpen; if (m_WindowOpen) {
CloseWindow();
}
else {
OpenWindow();
}
onResize(); onResize();
} }
if (m_WindowOpen) if (m_WindowOpen)
{ {
GuiUnlock();
anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 }; anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 };
m_WindowOpen = !GuiWindowBox(m_WndRect, "#191# Are you sure you want to close this program?"); m_WindowOpen = !GuiWindowBox(m_WndRect, "#191# Are you sure you want to close this program?");
@ -83,18 +102,18 @@ public:
*m_WndRunning = false; *m_WndRunning = false;
return 1; return 1;
} }
if (m_CQB_NoButton) m_WindowOpen = false; if (m_CQB_NoButton) CloseWindow();
} }
return 0; return 0;
} }
int rinput(Vector2& mouse_position) override int rinput(Vector2& mouse_position) override
{ {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !CheckCollisionPointRec(mouse_position, m_WndRect)) if (IsKeyReleased(KEY_ENTER)) {
{ *m_WndRunning = false;
SetMousePosition(anchor03.x, anchor03.y); return 1;
} }
GuiLock();
return 0; return 0;
} }
@ -104,65 +123,37 @@ public:
anchor03 = { static_cast<float>(m_WndWidth) / 2 , static_cast<float>(m_WndHeight) / 2 }; anchor03 = { static_cast<float>(m_WndWidth) / 2 , static_cast<float>(m_WndHeight) / 2 };
m_WndRect = { anchor03.x + -168, anchor03.y + -88, 328, 160 }; m_WndRect = { anchor03.x + -168, anchor03.y + -88, 328, 160 };
} }
};
class SettingsComponent final : public sva::GuiComponent
{
Vector2 anchor01 = { 0,0 };
int ActiveMonitorID = 0;
std::string m_ScreenListString;
public: public:
void onAttach() override void OpenWindow() {
{ GuiLock();
for (int i = 0; i < GetMonitorCount(); ++i) m_WindowOpen = true;
{
m_ScreenListString += GetMonitorName(i);
m_ScreenListString += ";";
}
m_ScreenListString.pop_back();
fitWindowToMonitor();
} }
void onResize() override void CloseWindow() {
{ m_WindowOpen = false;
anchor01 = { static_cast<float>(m_WndWidth) / 4, static_cast<float>(m_WndHeight) / 4 }; GuiUnlock();
}
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();
} }
}; };
class SettingsComponent final : public sva::GuiComponent {
public:
struct {
bool borderlessFullscreen;
uint32_t state;
} values;
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;
}
};

View file

@ -38,7 +38,7 @@ enum class logerr_level
}; };
int main(void) int main(int argc, char** argv)
{ {
#ifdef _DEBUG #ifdef _DEBUG
spdlog::set_level(spdlog::level::debug); spdlog::set_level(spdlog::level::debug);
@ -57,8 +57,9 @@ int main(void)
return 0; 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_ALWAYS_RUN);
SetWindowState(ConfigFlags::FLAG_WINDOW_RESIZABLE);
SetWindowFocused(); SetWindowFocused();
@ -75,6 +76,7 @@ int main(void)
ComponentStack::push<SettingsComponent>(); ComponentStack::push<SettingsComponent>();
// always on top... // always on top...
SafeClosePopup safe_close_popup; SafeClosePopup safe_close_popup;
safe_close_popup.attach(&is_running); safe_close_popup.attach(&is_running);