diff options
Diffstat (limited to 'plugingui')
-rw-r--r-- | plugingui/eventhandler.cc | 11 | ||||
-rw-r--r-- | plugingui/guievent.h | 11 | ||||
-rw-r--r-- | plugingui/nativewindow_win32.cc | 26 | ||||
-rw-r--r-- | plugingui/nativewindow_x11.cc | 26 | ||||
-rw-r--r-- | plugingui/widget.cc | 2 | ||||
-rw-r--r-- | plugingui/window.cc | 34 | ||||
-rw-r--r-- | plugingui/window.h | 1 |
7 files changed, 69 insertions, 42 deletions
diff --git a/plugingui/eventhandler.cc b/plugingui/eventhandler.cc index 083efae..a5249a6 100644 --- a/plugingui/eventhandler.cc +++ b/plugingui/eventhandler.cc @@ -55,10 +55,10 @@ std::shared_ptr<Event> EventHandler::peekNextEvent() void EventHandler::processEvents() { + Painter p(window); // Make sure we only redraw buffer one time. + while(hasEvent()) { - Painter p(window); // Make sure we only redraw buffer one time. - auto event = getNextEvent(); if(event == nullptr) @@ -71,6 +71,13 @@ void EventHandler::processEvents() window.redraw(); break; + case EventType::move: + { + auto moveEvent = static_cast<MoveEvent*>(event.get()); + window.moved(moveEvent->x, moveEvent->y); + } + break; + case EventType::resize: { while(true) diff --git a/plugingui/guievent.h b/plugingui/guievent.h index 133b630..78fe0f8 100644 --- a/plugingui/guievent.h +++ b/plugingui/guievent.h @@ -44,7 +44,8 @@ enum class EventType { scroll, key, close, - resize + resize, + move }; class Event { @@ -150,4 +151,12 @@ public: size_t height; }; +class MoveEvent : public Event { +public: + EventType type() { return EventType::move; } + + int x; + int y; +}; + } // GUI:: diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index 9e80be0..172850d 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -26,10 +26,10 @@ */ #include "nativewindow_win32.h" -#include "window.h" - #include <cstring> +#include "window.h" + namespace GUI { LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, @@ -49,24 +49,20 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, switch(msg) { case WM_SIZE: { - static bool first = true; - if(!first) - { - auto resizeEvent = std::make_shared<ResizeEvent>(); - resizeEvent->width = LOWORD(lp); - resizeEvent->height = HIWORD(lp); - native->event_queue.push(resizeEvent); - first = false; - } + auto resizeEvent = std::make_shared<ResizeEvent>(); + resizeEvent->width = LOWORD(lp); + resizeEvent->height = HIWORD(lp); + //native->event_queue.push(resizeEvent); + native->window.resized(resizeEvent->width, resizeEvent->height); } break; case WM_MOVE: { -// auto moveEvent = std::make_shared<MoveEvent>(); -// moveEvent->x = (short)LOWORD(lp); -// moveEvent->y = (short)HIWORD(lp); -// native->event_queue.push(moveEvent); + auto moveEvent = std::make_shared<MoveEvent>(); + moveEvent->x = (short)LOWORD(lp); + moveEvent->y = (short)HIWORD(lp); + native->event_queue.push(moveEvent); } break; diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index 8a86c80..1ca7d00 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -414,13 +414,25 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent, case ConfigureNotify: { - auto resizeEvent = std::make_shared<ResizeEvent>(); - resizeEvent->window_id = xevent.xconfigure.window; - //resizeEvent->x = xevent.xconfigure.x; - //resizeEvent->y = xevent.xconfigure.y; - resizeEvent->width = xevent.xconfigure.width; - resizeEvent->height = xevent.xconfigure.height; - event = resizeEvent; + if((window.width() != (std::size_t)xevent.xconfigure.width) || + (window.height() != (std::size_t)xevent.xconfigure.height)) + { + auto resizeEvent = std::make_shared<ResizeEvent>(); + resizeEvent->window_id = xevent.xconfigure.window; + resizeEvent->width = xevent.xconfigure.width; + resizeEvent->height = xevent.xconfigure.height; + event = 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->x = xevent.xconfigure.x; + moveEvent->y = xevent.xconfigure.y; + event = moveEvent; + } } break; diff --git a/plugingui/widget.cc b/plugingui/widget.cc index 4b1d1f7..476746e 100644 --- a/plugingui/widget.cc +++ b/plugingui/widget.cc @@ -123,7 +123,7 @@ void Widget::resize(int width, int height) _width = width; _height = height; pixbuf.realloc(width, height); - + repaintEvent(nullptr); sizeChangeNotifier(width, height); } diff --git a/plugingui/window.cc b/plugingui/window.cc index 7449607..f8232ad 100644 --- a/plugingui/window.cc +++ b/plugingui/window.cc @@ -26,7 +26,6 @@ */ #include "window.h" -#include <hugin.hpp> #include "painter.h" #ifndef PUGL @@ -73,7 +72,6 @@ Window::~Window() void Window::setFixedSize(int w, int h) { native->setFixedSize(w, h); - resize(w,h); } void Window::setCaption(const std::string& caption) @@ -81,6 +79,9 @@ void Window::setCaption(const std::string& caption) native->setCaption(caption); } +//! This overload the resize method on Widget and simply requests a window resize +//! on the windowmanager/OS. The resized() method is called by the event handler +//! once the window has been resized. void Window::resize(int width, int height) { if((width < 1) || (height < 1)) @@ -88,17 +89,15 @@ void Window::resize(int width, int height) return; } - resized(width, height); - Widget::resize(width, height); native->resize(width, height); } +//! This overload the move method on Widget and simply requests a window move +//! on the windowmanager/OS. The moved() method is called by the event handler +//! once the window has been moved. void Window::move(size_t x, size_t y) { native->move(x, y); - - // Make sure widget corrdinates are updated. - Widget::move(x, y); } size_t Window::windowX() @@ -113,6 +112,7 @@ size_t Window::windowY() void Window::show() { + Widget::show(); repaintChildren(nullptr); native->show(); } @@ -120,6 +120,7 @@ void Window::show() void Window::hide() { native->hide(); + Widget::hide(); } Window* Window::window() @@ -185,6 +186,8 @@ void Window::redraw() native->redraw(); } +//! Called by event handler when an windowmanager/OS window resize event has +//! been received. Do not call this directly. void Window::resized(size_t width, size_t height) { if((_width == width) && (_height == height)) @@ -192,22 +195,21 @@ void Window::resized(size_t width, size_t height) return; } - _width = width; - _height = height; - wpixbuf.realloc(width, height); + Widget::resize(width, height); updateBuffer(); +} - pixbuf.realloc(width, height); - repaintEvent(nullptr); - - // Notify Widget - sizeChangeNotifier(width, height); +//! Called by event handler when an windowmanager/OS window move event has +//! been received. Do not call this directly. +void Window::moved(int x, int y) +{ + // Make sure widget corrdinates are updated. + Widget::move(x, y); } void Window::updateBuffer() { - //DEBUG(window, "Updating buffer\n"); for(auto pixelBuffer : getPixelBuffers()) { size_t updateWidth = pixelBuffer->width; diff --git a/plugingui/window.h b/plugingui/window.h index 1fea9c0..705742f 100644 --- a/plugingui/window.h +++ b/plugingui/window.h @@ -74,6 +74,7 @@ protected: friend class EventHandler; void redraw(); void resized(size_t w, size_t h); + void moved(int x, int y); void updateBuffer(); // For the Painter |