diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-19 17:40:57 +0100 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-19 17:40:57 +0100 | 
| commit | 2d5848de7180257c1a55764d019f2edf7ddbd4be (patch) | |
| tree | d2a91e15ac2c66e67197b164f8c83fbc671d2d70 /plugingui | |
| parent | 67ee3d654e5e70f1209bbd319f921cf4cdbfcd71 (diff) | |
Use event queue.
Diffstat (limited to 'plugingui')
| -rw-r--r-- | plugingui/nativewindow_win32.cc | 50 | ||||
| -rw-r--r-- | plugingui/nativewindow_win32.h | 4 | 
2 files changed, 21 insertions, 33 deletions
| diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index 99c0c3e..edccb01 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -55,7 +55,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,  				ResizeEvent* resizeEvent = new ResizeEvent();  				resizeEvent->width = LOWORD(lp);  				resizeEvent->height = HIWORD(lp); -				native->event = resizeEvent; +				native->event_queue.push(resizeEvent);  				first = false;  			}  		} @@ -66,14 +66,14 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,  //      MoveEvent* moveEvent = new MoveEvent();  //      moveEvent->x = (short)LOWORD(lp);  //      moveEvent->y = (short)HIWORD(lp); -//      native->event = moveEvent; +//      native->event_queue.push(moveEvent);  		}  		break;  	case WM_CLOSE:  		{  			CloseEvent* closeEvent = new CloseEvent(); -			native->event = closeEvent; +			native->event_queue.push(closeEvent);  		}  		break;  //		HWND child, old; @@ -94,7 +94,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,  			MouseMoveEvent* mouseMoveEvent = new MouseMoveEvent();  			mouseMoveEvent->x = (short)LOWORD(lp);  			mouseMoveEvent->y = (short)HIWORD(lp); -			native->event = mouseMoveEvent; +			native->event_queue.push(mouseMoveEvent);  		}  		break; @@ -111,7 +111,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 = scrollEvent; +			native->event_queue.push(scrollEvent);  		}  		break; @@ -171,7 +171,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,  			                            msg == WM_RBUTTONDBLCLK ||  			                            msg == WM_MBUTTONDBLCLK); -			native->event = buttonEvent; +			native->event_queue.push(buttonEvent);  		}  		break; @@ -199,7 +199,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,  			keyEvent->direction =  				(msg == WM_KEYDOWN) ? Direction::down : Direction::up; -			native->event = keyEvent; +			native->event_queue.push(keyEvent);  		}  		break; @@ -211,7 +211,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,  				keyEvent->keycode = Key::character;  				keyEvent->text += (char)wp;  				keyEvent->direction = Direction::up; -				native->event = keyEvent; +				native->event_queue.push(keyEvent);  			}  		}  		break; @@ -223,7 +223,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,  			repaintEvent->y = 0;  			repaintEvent->width = 100;  			repaintEvent->height = 100; -			native->event = repaintEvent; +			native->event_queue.push(repaintEvent);  			// Move to window.h (in class)  			HDC pDC; @@ -315,14 +315,12 @@ NativeWindowWin32::NativeWindowWin32(void* native_window, Window& window)  	RegisterClassEx(&wcex); -	parent_window = (HWND)native_window; -  	m_hwnd = CreateWindowEx(0/*ex_style*/, m_className,  	                        "DGBasisWidget",  	                        (native_window?WS_CHILD:WS_OVERLAPPEDWINDOW) | WS_VISIBLE,  	                        window.x(), window.y(),  	                        window.width(), window.height(), -	                        parent_window, nullptr, +	                        (HWND)native_window, nullptr,  	                        GetModuleHandle(nullptr), nullptr);  	SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); @@ -397,41 +395,29 @@ void NativeWindowWin32::grabMouse(bool grab)  bool NativeWindowWin32::hasEvent()  { -	MSG msg; -	return PeekMessage(&msg, parent_window, 0, 0, PM_NOREMOVE) != 0; +	return !event_queue.empty();  }  Event* NativeWindowWin32::getNextEvent()  { -	Event* event = nullptr; - -	MSG msg; -	if(GetMessage(&msg, parent_window, 0, 0)) +	if(event_queue.empty())  	{ -		TranslateMessage(&msg); -		DispatchMessage(&msg); +		return nullptr;  	} -	event = this->event; -	this->event = nullptr; - +	auto event = event_queue.front(); +	event_queue.pop();  	return event;  }  Event* NativeWindowWin32::peekNextEvent()  { -	Event* event = nullptr; - -	MSG msg; -	if(PeekMessage(&msg, parent_window, 0, 0, PM_NOREMOVE)) +	if(event_queue.empty())  	{ -		TranslateMessage(&msg); -		DispatchMessage(&msg); +		return nullptr;  	} -	event = this->event; -	this->event = nullptr; - +	auto event = event_queue.front();  	return event;  } diff --git a/plugingui/nativewindow_win32.h b/plugingui/nativewindow_win32.h index e6db787..b30101a 100644 --- a/plugingui/nativewindow_win32.h +++ b/plugingui/nativewindow_win32.h @@ -26,6 +26,8 @@   */  #pragma once +#include <queue> +  #include "nativewindow.h"  #define WIN32_LEAN_AND_MEAN @@ -63,7 +65,7 @@ private:  	Window& window;  	WNDID m_hwnd = 0;  	char* m_className = nullptr; -	Event* event = nullptr; +	std::queue<Event*> event_queue;  };  } // GUI:: | 
