diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-02-10 19:52:34 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-02-10 20:11:31 +0100 |
commit | dc33f15a6b968139779c2b7d2003d3ef6e7d5748 (patch) | |
tree | 949172db6cdb9ed2b03bfe9f5051f51a683ecd19 | |
parent | f9d2d48214038689dc42085373b28b934f7fe002 (diff) |
Clean up guievent.h and use EventQueue type instead if std::queue.
-rw-r--r-- | plugingui/eventhandler.cc | 5 | ||||
-rw-r--r-- | plugingui/eventhandler.h | 8 | ||||
-rw-r--r-- | plugingui/guievent.h | 66 | ||||
-rw-r--r-- | plugingui/nativewindow.h | 18 | ||||
-rw-r--r-- | plugingui/nativewindow_win32.cc | 22 | ||||
-rw-r--r-- | plugingui/nativewindow_win32.h | 4 | ||||
-rw-r--r-- | plugingui/nativewindow_x11.cc | 34 | ||||
-rw-r--r-- | plugingui/nativewindow_x11.h | 4 | ||||
-rw-r--r-- | plugingui/testmain.cc | 1 | ||||
-rw-r--r-- | plugingui/tests/resizetest.cc | 1 | ||||
-rw-r--r-- | plugingui/tests/tabwidgettest.cc | 1 |
11 files changed, 87 insertions, 77 deletions
diff --git a/plugingui/eventhandler.cc b/plugingui/eventhandler.cc index 9643d3f..aded993 100644 --- a/plugingui/eventhandler.cc +++ b/plugingui/eventhandler.cc @@ -29,7 +29,8 @@ #include "window.h" #include "painter.h" -namespace GUI { +namespace GUI +{ EventHandler::EventHandler(NativeWindow& nativeWindow, Window& window) : window(window) @@ -51,7 +52,7 @@ std::shared_ptr<Event> EventHandler::getNextEvent() } auto event = events.front(); - events.pop(); + events.pop_front(); return event; } diff --git a/plugingui/eventhandler.h b/plugingui/eventhandler.h index 31ab3e2..2a1b657 100644 --- a/plugingui/eventhandler.h +++ b/plugingui/eventhandler.h @@ -33,11 +33,13 @@ #include "guievent.h" #include "nativewindow.h" -namespace GUI { +namespace GUI +{ class Window; -class EventHandler { +class EventHandler +{ public: EventHandler(NativeWindow& nativeWindow, Window& window); @@ -64,7 +66,7 @@ private: // Used to ignore mouse button release after a double click. bool lastWasDoubleClick; - std::queue<std::shared_ptr<Event>> events; + EventQueue events; }; } // GUI:: diff --git a/plugingui/guievent.h b/plugingui/guievent.h index 78fe0f8..2d4cc6f 100644 --- a/plugingui/guievent.h +++ b/plugingui/guievent.h @@ -26,18 +26,15 @@ */ #pragma once -#include <unistd.h> - #include <string> +#include <list> +#include <memory> -#ifdef X11 -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#endif/*X11*/ - -namespace GUI { +namespace GUI +{ -enum class EventType { +enum class EventType +{ mouseMove, repaint, button, @@ -48,18 +45,17 @@ enum class EventType { move }; -class Event { +class Event +{ public: virtual ~Event() {} virtual EventType type() = 0; - -#ifdef X11 - ::Window window_id; -#endif/*X11*/ }; -class MouseMoveEvent : public Event { +class MouseMoveEvent + : public Event +{ public: EventType type() { return EventType::mouseMove; } @@ -68,18 +64,22 @@ public: }; -enum class Direction { +enum class Direction +{ up, down, }; -enum class MouseButton { +enum class MouseButton +{ right, middle, left, }; -class ButtonEvent : public Event { +class ButtonEvent + : public Event +{ public: EventType type() { return EventType::button; } @@ -92,7 +92,9 @@ public: bool doubleClick; }; -class ScrollEvent : public Event { +class ScrollEvent + : public Event +{ public: EventType type() { return EventType::scroll; } @@ -102,7 +104,9 @@ public: int delta; }; -class RepaintEvent : public Event { +class RepaintEvent + : public Event +{ public: EventType type() { return EventType::repaint; } @@ -112,7 +116,8 @@ public: size_t height; }; -enum class Key { +enum class Key +{ unknown, left, right, @@ -128,7 +133,9 @@ enum class Key { character, //!< The actual character is stored in KeyEvent::text }; -class KeyEvent : public Event { +class KeyEvent + : public Event +{ public: EventType type() { return EventType::key; } @@ -138,12 +145,16 @@ public: std::string text; }; -class CloseEvent : public Event { +class CloseEvent + : public Event +{ public: EventType type() { return EventType::close; } }; -class ResizeEvent : public Event { +class ResizeEvent + : public Event +{ public: EventType type() { return EventType::resize; } @@ -151,7 +162,9 @@ public: size_t height; }; -class MoveEvent : public Event { +class MoveEvent + : public Event +{ public: EventType type() { return EventType::move; } @@ -159,4 +172,7 @@ public: int y; }; +using EventQueue = std::list<std::shared_ptr<Event>>; + + } // GUI:: diff --git a/plugingui/nativewindow.h b/plugingui/nativewindow.h index f5184eb..e041994 100644 --- a/plugingui/nativewindow.h +++ b/plugingui/nativewindow.h @@ -36,7 +36,8 @@ namespace GUI { //! Interface class for native window implementations. -class NativeWindow { +class NativeWindow +{ public: NativeWindow() {} virtual ~NativeWindow() {} @@ -80,20 +81,7 @@ public: //! Reads all currently enqueued events from the native window system. //! \return A queue of shared pointers to events. - virtual std::queue<std::shared_ptr<Event>> getEvents() = 0; - -/* - //! Query if the event queue contains any events. - virtual bool hasEvent() = 0; - - //! Read a single event from the event queue. - //! \return A pointer to the event or nullptr is none exists. - virtual std::shared_ptr<Event> getNextEvent() = 0; - - //! Read next event without popping it from the event queue. - //! \return A pointer to the event or nullptr is none exists. - virtual std::shared_ptr<Event> peekNextEvent() = 0; -*/ + virtual EventQueue getEvents() = 0; }; } // GUI:: diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index 3065b8c..23c9012 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -53,7 +53,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, auto resizeEvent = std::make_shared<ResizeEvent>(); resizeEvent->width = LOWORD(lp); resizeEvent->height = HIWORD(lp); - //native->event_queue.push(resizeEvent); + //native->event_queue.push_back(resizeEvent); native->window.resized(resizeEvent->width, resizeEvent->height); } break; @@ -63,14 +63,14 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, auto moveEvent = std::make_shared<MoveEvent>(); moveEvent->x = (short)LOWORD(lp); moveEvent->y = (short)HIWORD(lp); - native->event_queue.push(moveEvent); + native->event_queue.push_back(moveEvent); } break; case WM_CLOSE: { auto closeEvent = std::make_shared<CloseEvent>(); - native->event_queue.push(closeEvent); + native->event_queue.push_back(closeEvent); } break; // HWND child, old; @@ -91,7 +91,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, auto mouseMoveEvent = std::make_shared<MouseMoveEvent>(); mouseMoveEvent->x = (short)LOWORD(lp); mouseMoveEvent->y = (short)HIWORD(lp); - native->event_queue.push(mouseMoveEvent); + native->event_queue.push_back(mouseMoveEvent); } break; @@ -108,7 +108,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, scrollEvent->x = p.x; scrollEvent->y = p.y; scrollEvent->delta = -1 * (short)HIWORD(wp) / 60; - native->event_queue.push(scrollEvent); + native->event_queue.push_back(scrollEvent); } break; @@ -175,7 +175,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, msg == WM_RBUTTONDBLCLK || msg == WM_MBUTTONDBLCLK); - native->event_queue.push(buttonEvent); + native->event_queue.push_back(buttonEvent); } break; @@ -203,7 +203,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, keyEvent->direction = (msg == WM_KEYDOWN) ? Direction::down : Direction::up; - native->event_queue.push(keyEvent); + native->event_queue.push_back(keyEvent); } break; @@ -215,7 +215,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, keyEvent->keycode = Key::character; keyEvent->text += (char)wp; keyEvent->direction = Direction::up; - native->event_queue.push(keyEvent); + native->event_queue.push_back(keyEvent); } } break; @@ -227,7 +227,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, repaintEvent->y = 0; repaintEvent->width = 100; repaintEvent->height = 100; - native->event_queue.push(repaintEvent); + native->event_queue.push_back(repaintEvent); // Move to window.h (in class) HDC pDC; @@ -418,7 +418,7 @@ void NativeWindowWin32::grabMouse(bool grab) } } -std::queue<std::shared_ptr<Event>> NativeWindowWin32::getEvents() +EventQueue NativeWindowWin32::getEvents() { MSG msg; while(PeekMessage(&msg, m_hwnd, 0, 0, PM_REMOVE) != 0) @@ -427,7 +427,7 @@ std::queue<std::shared_ptr<Event>> NativeWindowWin32::getEvents() DispatchMessage(&msg); } - std::queue<std::shared_ptr<Event>> events; + EventQueue events; std::swap(events, event_queue); return events; } diff --git a/plugingui/nativewindow_win32.h b/plugingui/nativewindow_win32.h index 1ed072c..b8e1c89 100644 --- a/plugingui/nativewindow_win32.h +++ b/plugingui/nativewindow_win32.h @@ -55,7 +55,7 @@ public: void handleBuffer() override; void redraw() override; void grabMouse(bool grab) override; - std::queue<std::shared_ptr<Event>> getEvents() override; + EventQueue getEvents() override; private: static LRESULT CALLBACK dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp); @@ -64,7 +64,7 @@ private: Window& window; WNDID m_hwnd = 0; char* m_className = nullptr; - std::queue<std::shared_ptr<Event>> event_queue; + EventQueue event_queue; }; } // GUI:: diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index da6cb6d..bf18ffa 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -264,7 +264,7 @@ void NativeWindowX11::grabMouse(bool grab) // Don't need to do anything on this platform... } -std::queue<std::shared_ptr<Event>> NativeWindowX11::getEvents() +EventQueue NativeWindowX11::getEvents() { while(XPending(display)) { @@ -273,7 +273,7 @@ std::queue<std::shared_ptr<Event>> NativeWindowX11::getEvents() translateXMessage(xEvent); } - std::queue<std::shared_ptr<Event>> events; + EventQueue events; std::swap(events, event_queue); return events; } @@ -286,10 +286,10 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) //DEBUG(x11, "MotionNotify"); { auto mouseMoveEvent = std::make_shared<MouseMoveEvent>(); - mouseMoveEvent->window_id = xevent.xmotion.window; + //mouseMoveEvent->window_id = xevent.xmotion.window; mouseMoveEvent->x = xevent.xmotion.x; mouseMoveEvent->y = xevent.xmotion.y; - event_queue.push(mouseMoveEvent); + event_queue.push_back(mouseMoveEvent); } break; @@ -298,12 +298,12 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) if(xevent.xexpose.count == 0) { auto repaintEvent = std::make_shared<RepaintEvent>(); - repaintEvent->window_id = xevent.xexpose.window; + //repaintEvent->window_id = xevent.xexpose.window; repaintEvent->x = xevent.xexpose.x; repaintEvent->y = xevent.xexpose.y; repaintEvent->width = xevent.xexpose.width; repaintEvent->height = xevent.xexpose.height; - event_queue.push(repaintEvent); + event_queue.push_back(repaintEvent); } break; @@ -314,20 +314,20 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) (window.height() != (std::size_t)xevent.xconfigure.height)) { auto resizeEvent = std::make_shared<ResizeEvent>(); - resizeEvent->window_id = xevent.xconfigure.window; + //resizeEvent->window_id = xevent.xconfigure.window; resizeEvent->width = xevent.xconfigure.width; resizeEvent->height = xevent.xconfigure.height; - event_queue.push(resizeEvent); + event_queue.push_back(resizeEvent); } if((window.windowX() != (std::size_t)xevent.xconfigure.x) || (window.windowY() != (std::size_t)xevent.xconfigure.y)) { auto moveEvent = std::make_shared<MoveEvent>(); - moveEvent->window_id = xevent.xconfigure.window; + //moveEvent->window_id = xevent.xconfigure.window; moveEvent->x = xevent.xconfigure.x; moveEvent->y = xevent.xconfigure.y; - event_queue.push(moveEvent); + event_queue.push_back(moveEvent); } } break; @@ -340,16 +340,16 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) { int scroll = 1; auto scrollEvent = std::make_shared<ScrollEvent>(); - scrollEvent->window_id = xevent.xbutton.window; + //scrollEvent->window_id = xevent.xbutton.window; scrollEvent->x = xevent.xbutton.x; scrollEvent->y = xevent.xbutton.y; scrollEvent->delta = scroll * ((xevent.xbutton.button == 4) ? -1 : 1); - event_queue.push(scrollEvent); + event_queue.push_back(scrollEvent); } else { auto buttonEvent = std::make_shared<ButtonEvent>(); - buttonEvent->window_id = xevent.xbutton.window; + //buttonEvent->window_id = xevent.xbutton.window; buttonEvent->x = xevent.xbutton.x; buttonEvent->y = xevent.xbutton.y; switch(xevent.xbutton.button) { @@ -390,7 +390,7 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) { last_click = xevent.xbutton.time; } - event_queue.push(buttonEvent); + event_queue.push_back(buttonEvent); } } break; @@ -400,7 +400,7 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) //DEBUG(x11, "KeyPress"); { auto keyEvent = std::make_shared<KeyEvent>(); - keyEvent->window_id = xevent.xkey.window; + //keyEvent->window_id = xevent.xkey.window; switch(xevent.xkey.keycode) { case 113: keyEvent->keycode = Key::left; break; @@ -430,7 +430,7 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) keyEvent->direction = (xevent.type == KeyPress) ? Direction::down : Direction::up; - event_queue.push(keyEvent); + event_queue.push_back(keyEvent); } break; @@ -439,7 +439,7 @@ void NativeWindowX11::translateXMessage(XEvent& xevent) if(((unsigned int)xevent.xclient.data.l[0] == wmDeleteMessage)) { auto closeEvent = std::make_shared<CloseEvent>(); - event_queue.push(closeEvent); + event_queue.push_back(closeEvent); } break; diff --git a/plugingui/nativewindow_x11.h b/plugingui/nativewindow_x11.h index b2021c0..a026ac8 100644 --- a/plugingui/nativewindow_x11.h +++ b/plugingui/nativewindow_x11.h @@ -57,7 +57,7 @@ public: void handleBuffer() override; void redraw() override; void grabMouse(bool grab) override; - std::queue<std::shared_ptr<Event>> getEvents() override; + EventQueue getEvents() override; private: void translateXMessage(XEvent& xevent); @@ -88,7 +88,7 @@ private: Visual* visual{nullptr}; Atom wmDeleteMessage{0}; - std::queue<std::shared_ptr<Event>> event_queue; + EventQueue event_queue; }; } // GUI:: diff --git a/plugingui/testmain.cc b/plugingui/testmain.cc index d77ac8a..07bbe6c 100644 --- a/plugingui/testmain.cc +++ b/plugingui/testmain.cc @@ -28,6 +28,7 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #endif +#include <unistd.h> #include <hugin.hpp> #include <settings.h> diff --git a/plugingui/tests/resizetest.cc b/plugingui/tests/resizetest.cc index 73f8673..213cece 100644 --- a/plugingui/tests/resizetest.cc +++ b/plugingui/tests/resizetest.cc @@ -30,6 +30,7 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #endif +#include <unistd.h> #include <hugin.hpp> #include <window.h> diff --git a/plugingui/tests/tabwidgettest.cc b/plugingui/tests/tabwidgettest.cc index 9ee8eee..2ddabd3 100644 --- a/plugingui/tests/tabwidgettest.cc +++ b/plugingui/tests/tabwidgettest.cc @@ -30,6 +30,7 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #endif +#include <unistd.h> #include <hugin.hpp> #include <window.h> |