Get rid of the need for SetFlag
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m17s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m17s
This commit is contained in:
@@ -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<RWindowEvent> eventLog; // history of all logged window events.
|
||||
std::queue<RWindowEvent> 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();
|
||||
|
5
main.cpp
5
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;
|
||||
}
|
@@ -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);
|
||||
|
@@ -1,21 +1,8 @@
|
||||
#include <ReWindow/types/Window.h>
|
||||
#include <ReWindow/InputService.h>
|
||||
#include <ReWindow/Logger.h>
|
||||
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;
|
||||
}
|
||||
|
@@ -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<RWindow*>( 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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user