diff --git a/include/ReWindow/types/Window.h b/include/ReWindow/types/Window.h index 13b9756..6481089 100644 --- a/include/ReWindow/types/Window.h +++ b/include/ReWindow/types/Window.h @@ -23,12 +23,6 @@ namespace ReWindow { class VulkanWindow; } -enum class WindowFlag: uint8_t { - IN_FOCUS, FULLSCREEN, RESIZABLE, - VSYNC, QUIT, MAX_FLAG -}; -std::string WindowFlagToStr(WindowFlag flag); - class ReWindow::MouseState { public: struct @@ -77,8 +71,6 @@ protected: std::string title = "Redacted Window"; IPair lastKnownWindowSize {0, 0}; - // TODO remove the flags. - bool flags[5]; std::vector eventLog; // history of all logged window events. std::queue eventQueue; // MouseState currentMouse; // purrent frame mouse state. @@ -108,9 +100,6 @@ protected: public: KeyboardState currentKeyboard; // current frame keyboard state. KeyboardState previousKeyboard; // previous frame keyboard state. - // TODO: Josh hates parameter-flags, it's not 1995 :/ - [[nodiscard]] bool GetFlag(WindowFlag flag) const; - void SetFlag(WindowFlag flag, bool state); /// The default constructor does not set any members, and are left uninitialized. RWindow(); diff --git a/main.cpp b/main.cpp index 3d69427..9bb9b15 100644 --- a/main.cpp +++ b/main.cpp @@ -87,9 +87,8 @@ int main() { window->OnMouseButtonDownEvent += [&] (MouseButtonDownEvent e) { jlog::Debug(e.Button.Mnemonic + std::to_string(e.Button.ButtonIndex)); }; window->OnMouseWheelEvent += [&, window] (MouseWheelEvent e) { std::cout << window->GetMouseWheelPersistent() << std::endl; }; - while (!window->IsClosing()) { + while (!window->IsClosing()) window->ManagedRefresh(); - //window->Flash(); - } + delete window; } \ No newline at end of file diff --git a/src/platform/linux/Window.cpp b/src/platform/linux/Window.cpp index cbfe781..c067b50 100644 --- a/src/platform/linux/Window.cpp +++ b/src/platform/linux/Window.cpp @@ -45,11 +45,8 @@ extant = this; IPair position; RWindow::RWindow(const std::string& wTitle, int wWidth, int wHeight, bool wFullscreen, bool wResizable, bool wVsync) - : title(wTitle), width(wWidth), height(wHeight), fullscreen_mode(wFullscreen), resizable(wResizable), vsync(wVsync), - flags{false,wFullscreen,wResizable,wVsync} { - platform = new Platform(); - extant = this; -} + : title(wTitle), width(wWidth), height(wHeight), fullscreen_mode(wFullscreen), resizable(wResizable), vsync(wVsync) + { platform = new Platform(); extant = this; } void RWindow::Raise() { Logger::Debug(std::format("Raising window '{}'", this->title)); @@ -168,20 +165,6 @@ void RWindow::SetResizable(bool sizable) { } } -void RWindow::SetFlag(WindowFlag flag, bool state) { - XGetWindowAttributes(platform->display, platform->window, &platform->windowAttributes); - flags[(int) flag] = state; - //Once you've done this you cannot make it resizable again. - if (flag == WindowFlag::RESIZABLE && !state) { - Logger::Debug("Once you've done this you cannot make it resizable again."); - platform->hints.flags = PMinSize | PMaxSize; - platform->hints.min_width = platform->hints.max_width = platform->windowAttributes.width; - platform->hints.min_height = platform->hints.max_height = platform->windowAttributes.height; - XSetWMNormalHints(platform->display, platform->window, &platform->hints); - } - Logger::Debug(std::format("Set flag '{}' to state '{}' for window '{}'", WindowFlagToStr(flag), state, this->title)); -} - void RWindow::PollEvents() { while(XPending(platform->display)) { XNextEvent(platform->display, &platform->xev); diff --git a/src/platform/shared/Window.cpp b/src/platform/shared/Window.cpp index 89d1754..b615c50 100644 --- a/src/platform/shared/Window.cpp +++ b/src/platform/shared/Window.cpp @@ -1,21 +1,8 @@ #include #include #include -std::string WindowFlagToStr(WindowFlag flag) { - switch (flag) { - case WindowFlag::IN_FOCUS: return "IN_FOCUS"; - case WindowFlag::FULLSCREEN: return "FULLSCREEN"; - case WindowFlag::RESIZABLE: return "RESIZEABLE"; - case WindowFlag::VSYNC: return "VSYNC"; - case WindowFlag::QUIT: return "QUIT"; - case WindowFlag::MAX_FLAG: return "MAX_FLAG"; - default: - return "unimplemented flag"; - } -}; using namespace ReWindow; - RWindow::~RWindow() { if (open) DestroyOSWindowHandle(); @@ -27,10 +14,6 @@ IPair RWindow::GetMouseCoordinates() const { return currentMouse.Position; } -bool RWindow::GetFlag(WindowFlag flag) const { - return flags[(int) flag]; -} - bool RWindow::IsAlive() const { return (!closing) && open; } diff --git a/src/platform/windows/Window.cpp b/src/platform/windows/Window.cpp index e896aa7..d13f2c3 100644 --- a/src/platform/windows/Window.cpp +++ b/src/platform/windows/Window.cpp @@ -12,9 +12,22 @@ public: }; using namespace ReWindow; + +//bool local_fullscreen_mode = false; +bool local_focused = true; +//bool local_vsync = false; +//bool local_cursor_visible = true; +//bool local_closing = false; +void RWindow::PollEvents() { + MSG msg; + while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) + TranslateMessage(&msg), + DispatchMessage(&msg); + focused = local_focused; +} + LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { auto* window = reinterpret_cast( GetWindowLongPtr(hwnd, GWLP_USERDATA) ); - switch (uMsg) { case WM_CLOSE: { DestroyWindow(hwnd); @@ -38,7 +51,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_SETFOCUS: { window->processFocusIn(); - window->SetFlag(WindowFlag::IN_FOCUS, true); + local_focused = true; // TODO actually check if it's flashing. FLASHWINFO fi; @@ -53,7 +66,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_KILLFOCUS: { window->processFocusOut(); - window->SetFlag(WindowFlag::IN_FOCUS, false); + local_focused = false; } case WM_SETCURSOR: { @@ -157,7 +170,7 @@ bool RWindow::IsVisible() const { } void RWindow::Flash() { - if (!GetFlag(WindowFlag::IN_FOCUS)) { + if (!focused) { FLASHWINFO fi; fi.cbSize = sizeof(FLASHWINFO); fi.hwnd = platform->hwnd; @@ -172,28 +185,15 @@ void RWindow::DestroyOSWindowHandle() { DestroyWindow(platform->hwnd); } -void RWindow::SetFlag(WindowFlag flag, bool state) { - flags[(int) flag] = state; - if (flag == WindowFlag::RESIZABLE && !state) { +void RWindow::SetResizable(bool resizable) { + if (!resizable) { RECT rect; GetWindowRect(platform->hwnd, &rect); LONG style = GetWindowLong(platform->hwnd, GWL_STYLE); style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); SetWindowLong(platform->hwnd, GWL_STYLE, style); - SetWindowPos(platform->hwnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER); - } -} - -void RWindow::SetResizable(bool resizable) { - SetFlag(WindowFlag::RESIZABLE, resizable);; -} - - -void RWindow::PollEvents() { - MSG msg; - while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); + SetWindowPos(platform->hwnd, nullptr, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER); } } @@ -257,7 +257,7 @@ RWindow::RWindow() { RWindow::RWindow(const std::string& wTitle, int wWidth, int wHeight, bool wFullscreen, bool wResizable, bool wVsync) : title(wTitle), width(wWidth), height(wHeight), fullscreen_mode(wFullscreen), resizable(wResizable), -vsync(wVsync), flags{false,wFullscreen,wResizable,wVsync} { +vsync(wVsync) { extant = this; platform = new Platform(); }