Merge branch 'main' of https://git.redacted.cc/Redacted/ReWindow
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
@@ -105,14 +105,22 @@ namespace ReWindow
|
||||
MouseButton Button;
|
||||
|
||||
MouseButtonDownEvent() = default;
|
||||
MouseButtonDownEvent(MouseButton Button) : MouseEvent() {}
|
||||
MouseButtonDownEvent(MouseButton button) : MouseEvent(), Button(button) {}
|
||||
};
|
||||
|
||||
class MouseButtonUpEvent : public MouseEvent {
|
||||
public:
|
||||
MouseButton Button;
|
||||
MouseButtonUpEvent() = default;
|
||||
MouseButtonUpEvent(MouseButton Button) : MouseEvent() {}
|
||||
MouseButtonUpEvent(MouseButton button) : MouseEvent(), Button(button) {}
|
||||
};
|
||||
|
||||
class MouseWheelEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
int Delta;
|
||||
MouseWheelEvent() = default;
|
||||
MouseWheelEvent(int delta) : MouseEvent(), Delta(delta) {}
|
||||
};
|
||||
|
||||
class WindowResizeRequestEvent : public RWindowEvent
|
||||
@@ -149,6 +157,7 @@ namespace ReWindow
|
||||
Event<MouseMoveEvent> OnMouseMoveEvent;
|
||||
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
|
||||
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
|
||||
Event<MouseWheelEvent> OnMouseWheelEvent;
|
||||
#pragma endregion
|
||||
#pragma region Overrides
|
||||
/// Intrusive virtual methods intended to be overridden in a derived class.
|
||||
@@ -168,6 +177,7 @@ namespace ReWindow
|
||||
virtual void OnMouseMove(const MouseMoveEvent&) {}
|
||||
virtual void OnMouseButtonDown(const MouseButtonDownEvent&) {}
|
||||
virtual void OnMouseButtonUp(const MouseButtonUpEvent&) {}
|
||||
virtual void OnMouseWheel(const MouseWheelEvent&) {}
|
||||
#pragma endregion
|
||||
|
||||
/// The default constructor sets a default size and window title.
|
||||
@@ -314,7 +324,7 @@ namespace ReWindow
|
||||
/// @note Call this version at most **once** per-frame. It polls the X-Window server and therefore is quite slow.
|
||||
/// @see getCursorPos();
|
||||
Vector2 GetAccurateMouseCoordinates() const;
|
||||
|
||||
public:
|
||||
/// Executes event handlers for keyboard rele;ase events.
|
||||
void processKeyRelease (Key key);
|
||||
/// Executes event handlers for keyboard press events.
|
||||
@@ -336,6 +346,8 @@ namespace ReWindow
|
||||
|
||||
void processMouseMove(Vector2 last_pos, Vector2 new_pos);
|
||||
|
||||
void processMouseWheel(int scrolls);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
@@ -165,6 +165,13 @@ void RWindow::processOnOpen()
|
||||
OnOpenEvent();
|
||||
}
|
||||
|
||||
void RWindow::processMouseWheel(int scrolls)
|
||||
{
|
||||
auto ev = MouseWheelEvent(scrolls);
|
||||
OnMouseWheel(ev);
|
||||
OnMouseWheelEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
void RWindow::Close() {
|
||||
/// TODO: Implement closing the window without destroying the handle.
|
||||
|
@@ -104,6 +104,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
switch (uMsg) {
|
||||
case WM_CLOSE: {
|
||||
DestroyWindow(hwnd);
|
||||
|
||||
eWindow->processOnClose();
|
||||
}
|
||||
|
||||
case WM_DESTROY: {
|
||||
@@ -115,26 +117,29 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
auto eventData = WindowResizeRequestEvent();
|
||||
eventData.Size = {(float) eWindow->getWidth(), (float) eWindow->getHeight()};
|
||||
eWindow->setLastKnownWindowSize({(float) eWindow->getWidth(), (float) eWindow->getHeight()});
|
||||
|
||||
// TODO: Implement eWindow->processOnResize()
|
||||
|
||||
eWindow->OnResizeRequest(eventData);
|
||||
eWindow->OnResizeRequestEvent(eventData);
|
||||
|
||||
|
||||
//Just to be absolutely sure the OpenGL viewport resizes along with the window.
|
||||
glViewport(0, 0, eWindow->getWidth(), eWindow->getHeight());
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SETFOCUS: {
|
||||
RWindowEvent event {};
|
||||
eWindow->OnFocusGain(event);
|
||||
eWindow->OnFocusGainEvent(event);
|
||||
|
||||
eWindow->processFocusIn();
|
||||
|
||||
eWindow->setFlag(RWindowFlags::IN_FOCUS, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_KILLFOCUS: {
|
||||
RWindowEvent event {};
|
||||
eWindow->OnFocusLost(event);
|
||||
eWindow->OnFocusLostEvent(event);
|
||||
|
||||
eWindow->processFocusOut();
|
||||
|
||||
eWindow->setFlag(RWindowFlags::IN_FOCUS, false);
|
||||
break;
|
||||
@@ -150,122 +155,76 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
auto key = GetKeyFromWindowsScancode((WindowsScancode) wParam);
|
||||
//Key repeat fix.
|
||||
if (!pKeyboard->PressedKeys[key]) {
|
||||
eWindow->OnKeyDownEvent(key);
|
||||
eWindow->OnKeyDown(key);
|
||||
eWindow->pressKey(key);
|
||||
eWindow->processKeyPress(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_KEYUP: {
|
||||
auto key = GetKeyFromWindowsScancode((WindowsScancode) wParam);
|
||||
eWindow->OnKeyUpEvent(key);
|
||||
eWindow->OnKeyUp(key);
|
||||
eWindow->liftKey(key);
|
||||
eWindow->processKeyRelease(key);
|
||||
break;
|
||||
}
|
||||
|
||||
//Mouse Buttons.
|
||||
case WM_MOUSEWHEEL: {
|
||||
auto eventData = MouseButtonDownEvent();
|
||||
int wheel_delta = GET_WHEEL_DELTA_WPARAM(wParam);
|
||||
|
||||
//If the wheel delta is positive it's MWheelUp, Negative is MWheelDown.
|
||||
if (wheel_delta > 0)
|
||||
eventData.Button = MouseButtons::MWheelUp,
|
||||
eWindow->OnMouseButtonDownEvent(eventData),
|
||||
eWindow->OnMouseButtonDown(eventData);
|
||||
// TODO: Determine sign of wheel_delta for each direction, (and on linux too), and document this.
|
||||
eWindow->processMouseWheel(wheel_delta);
|
||||
|
||||
else
|
||||
eventData.Button = MouseButtons::MWheelDown,
|
||||
eWindow->OnMouseButtonDownEvent(eventData),
|
||||
eWindow->OnMouseButtonDown(eventData);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONDOWN: {
|
||||
auto eventData = MouseButtonDownEvent();
|
||||
eventData.Button = MouseButtons::Left;
|
||||
|
||||
eWindow->OnMouseButtonDownEvent(eventData);
|
||||
eWindow->OnMouseButtonDown(eventData);
|
||||
eWindow->processMousePress(MouseButtons::Left);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONUP: {
|
||||
auto eventData = MouseButtonUpEvent();
|
||||
eventData.Button = MouseButtons::Left;
|
||||
|
||||
eWindow->OnMouseButtonUpEvent(eventData);
|
||||
eWindow->OnMouseButtonUp(eventData);
|
||||
eWindow->processMouseRelease(MouseButtons::Left);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_RBUTTONDOWN: {
|
||||
auto eventData = MouseButtonDownEvent();
|
||||
eventData.Button = MouseButtons::Right;
|
||||
|
||||
eWindow->OnMouseButtonDownEvent(eventData);
|
||||
eWindow->OnMouseButtonDown(eventData);
|
||||
eWindow->processMousePress(MouseButtons::Right);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_RBUTTONUP: {
|
||||
auto eventData = MouseButtonUpEvent();
|
||||
eventData.Button = MouseButtons::Right;
|
||||
|
||||
eWindow->OnMouseButtonUpEvent(eventData);
|
||||
eWindow->OnMouseButtonUp(eventData);
|
||||
eWindow->processMouseRelease(MouseButtons::Right);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MBUTTONDOWN: {
|
||||
auto eventData = MouseButtonDownEvent();
|
||||
eventData.Button = MouseButtons::Middle;
|
||||
|
||||
eWindow->OnMouseButtonDownEvent(eventData);
|
||||
eWindow->OnMouseButtonDown(eventData);
|
||||
eWindow->processMousePress(MouseButtons::Middle);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MBUTTONUP: {
|
||||
auto eventData = MouseButtonUpEvent();
|
||||
eventData.Button = MouseButtons::Middle;
|
||||
|
||||
eWindow->OnMouseButtonUpEvent(eventData);
|
||||
eWindow->OnMouseButtonUp(eventData);
|
||||
eWindow->processMouseRelease(MouseButtons::Middle);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_XBUTTONDOWN: {
|
||||
WORD button = GET_XBUTTON_WPARAM(wParam);
|
||||
auto eventData = MouseButtonDownEvent();
|
||||
|
||||
if (button == XBUTTON1)
|
||||
eventData.Button = MouseButtons::Mouse4,
|
||||
eWindow->OnMouseButtonDownEvent(eventData),
|
||||
eWindow->OnMouseButtonDown(eventData);
|
||||
eWindow->processMousePress(MouseButtons::Mouse4);
|
||||
|
||||
if (button == XBUTTON2)
|
||||
eventData.Button = MouseButtons::Mouse5,
|
||||
eWindow->OnMouseButtonDownEvent(eventData),
|
||||
eWindow->OnMouseButtonDown(eventData);
|
||||
eWindow->processMousePress(MouseButtons::Mouse5);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_XBUTTONUP: {
|
||||
WORD button = GET_XBUTTON_WPARAM(wParam);
|
||||
auto eventData = MouseButtonUpEvent();
|
||||
|
||||
if (button == XBUTTON1)
|
||||
eventData.Button = MouseButtons::Mouse4,
|
||||
eWindow->OnMouseButtonUpEvent(eventData),
|
||||
eWindow->OnMouseButtonUp(eventData);
|
||||
eWindow->processMouseRelease(MouseButtons::Mouse4);
|
||||
|
||||
if (button == XBUTTON2)
|
||||
eventData.Button = MouseButtons::Mouse5,
|
||||
eWindow->OnMouseButtonUpEvent(eventData),
|
||||
eWindow->OnMouseButtonUp(eventData);
|
||||
eWindow->processMouseRelease(MouseButtons::Mouse5);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user