Fixed input restriction bug
This commit is contained in:
parent
a8d0054c9d
commit
1db73539f6
2 changed files with 133 additions and 140 deletions
|
@ -6,163 +6,154 @@
|
||||||
|
|
||||||
class GuiMovableWindow : public sva::GuiComponent
|
class GuiMovableWindow : public sva::GuiComponent
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool m_DragWindow = false;
|
bool m_DragWindow = false;
|
||||||
Vector2 m_PanOffset = { 0,0 };
|
Vector2 m_PanOffset = { 0,0 };
|
||||||
protected:
|
protected:
|
||||||
Rectangle m_WndRect = { 20,20, 200, 100 };
|
Rectangle m_WndRect = { 20,20, 200, 100 };
|
||||||
bool m_WindowOpen = true;
|
bool m_WindowOpen = true;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual int input() override
|
virtual int input() override
|
||||||
{
|
{
|
||||||
if (!m_WindowOpen) return 0;
|
if (!m_WindowOpen) return 0;
|
||||||
Vector2 mouse_pos = GetMousePosition();
|
Vector2 mouse_pos = GetMousePosition();
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !m_DragWindow)
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !m_DragWindow)
|
||||||
{
|
{
|
||||||
if (CheckCollisionPointRec(mouse_pos, { m_WndRect.x, m_WndRect.y, m_WndRect.width - 24, 20 }))
|
if (CheckCollisionPointRec(mouse_pos, { m_WndRect.x, m_WndRect.y, m_WndRect.width - 24, 20 }))
|
||||||
{
|
{
|
||||||
m_DragWindow = true;
|
m_DragWindow = true;
|
||||||
m_PanOffset = { mouse_pos.x - m_WndRect.x, mouse_pos.y - m_WndRect.y };
|
m_PanOffset = { mouse_pos.x - m_WndRect.x, mouse_pos.y - m_WndRect.y };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_DragWindow)
|
if (m_DragWindow)
|
||||||
{
|
{
|
||||||
m_WndRect.x = (mouse_pos.x - m_PanOffset.x);
|
m_WndRect.x = (mouse_pos.x - m_PanOffset.x);
|
||||||
m_WndRect.y = (mouse_pos.y - m_PanOffset.y);
|
m_WndRect.y = (mouse_pos.y - m_PanOffset.y);
|
||||||
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) m_DragWindow = false;
|
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) m_DragWindow = false;
|
||||||
}
|
}
|
||||||
return rinput(mouse_pos);
|
return rinput(mouse_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int rinput(Vector2& mouse_position) { return 0; };
|
virtual int rinput(Vector2& mouse_position) { return 0; };
|
||||||
|
|
||||||
virtual int draw() override
|
virtual int draw() override
|
||||||
{
|
{
|
||||||
if (!m_WindowOpen) return 0;
|
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
|
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:
|
|
||||||
void onAttach() override
|
public:
|
||||||
{
|
|
||||||
m_WindowOpen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int draw() override
|
~SafeClosePopup() {
|
||||||
{
|
CloseWindow();
|
||||||
if (WindowShouldClose())
|
}
|
||||||
{
|
|
||||||
m_WindowOpen = !m_WindowOpen;
|
|
||||||
onResize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_WindowOpen)
|
void onAttach() override
|
||||||
{
|
{
|
||||||
anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 };
|
m_WindowOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
m_WindowOpen = !GuiWindowBox(m_WndRect, "#191# Are you sure you want to close this program?");
|
int draw() override
|
||||||
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");
|
if (WindowShouldClose())
|
||||||
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_WindowOpen) {
|
||||||
if (m_CQB_YesButton)
|
CloseWindow();
|
||||||
{
|
}
|
||||||
*m_WndRunning = false;
|
else {
|
||||||
return 1;
|
OpenWindow();
|
||||||
}
|
}
|
||||||
if (m_CQB_NoButton) m_WindowOpen = false;
|
onResize();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (m_WindowOpen)
|
||||||
return 0;
|
{
|
||||||
}
|
GuiUnlock();
|
||||||
|
anchor03 = { m_WndRect.x + 168, m_WndRect.y + 88 };
|
||||||
|
|
||||||
int rinput(Vector2& mouse_position) override
|
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");
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !CheckCollisionPointRec(mouse_position, m_WndRect))
|
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?");
|
||||||
SetMousePosition(anchor03.x, anchor03.y);
|
GuiLabel({ anchor03.x + -56, anchor03.y + -8, 120, 24 }, "Press \"Yes\" to close");
|
||||||
}
|
if (m_CQB_YesButton)
|
||||||
return 0;
|
{
|
||||||
}
|
*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
|
void onResize() override
|
||||||
{
|
{
|
||||||
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 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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:
|
int draw() override {
|
||||||
void onAttach() override
|
if(GuiButton({100, 100, 300, 30}, "This should not work when the safe window is open!")) {
|
||||||
{
|
std::cout << "got pressed\n";
|
||||||
for (int i = 0; i < GetMonitorCount(); ++i)
|
}
|
||||||
{
|
return 0;
|
||||||
m_ScreenListString += GetMonitorName(i);
|
}
|
||||||
m_ScreenListString += ";";
|
|
||||||
}
|
|
||||||
m_ScreenListString.pop_back();
|
|
||||||
|
|
||||||
fitWindowToMonitor();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onResize() override
|
|
||||||
{
|
|
||||||
anchor01 = { static_cast<float>(m_WndWidth) / 4, static_cast<float>(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();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -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();
|
||||||
|
|
||||||
|
@ -73,9 +74,10 @@ int main(void)
|
||||||
|
|
||||||
int run_result = 0;
|
int run_result = 0;
|
||||||
|
|
||||||
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);
|
||||||
safe_close_popup.wndrsize(ComponentStack::s_WndWidth, ComponentStack::s_WndHeight);
|
safe_close_popup.wndrsize(ComponentStack::s_WndWidth, ComponentStack::s_WndHeight);
|
||||||
|
@ -121,4 +123,4 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue