summaryrefslogtreecommitdiff
path: root/plugingui/eventhandler.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-11-29 09:32:52 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2015-11-29 09:32:52 +0100
commitf59d2329c904e8cb5f6509050444bf2aee4b8f65 (patch)
treec1e2ed264664c030d96399016221072e9dabfc8e /plugingui/eventhandler.cc
parent77cd0b84e1cef83a4fa9b77663cea65b42355f7a (diff)
Move event skip optimization fromNativeWindowXYZ to EventHandler
Diffstat (limited to 'plugingui/eventhandler.cc')
-rw-r--r--plugingui/eventhandler.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/plugingui/eventhandler.cc b/plugingui/eventhandler.cc
index 98e4cef..68f7f46 100644
--- a/plugingui/eventhandler.cc
+++ b/plugingui/eventhandler.cc
@@ -48,6 +48,11 @@ Event *EventHandler::getNextEvent()
return nativeWindow.getNextEvent();
}
+Event *EventHandler::peekNextEvent()
+{
+ return nativeWindow.peekNextEvent();
+}
+
void EventHandler::processEvents()
{
while(hasEvent())
@@ -68,6 +73,22 @@ void EventHandler::processEvents()
case EventType::resize:
{
+ while(true)
+ {
+ if(!hasEvent())
+ {
+ break;
+ }
+
+ auto peekEvent = peekNextEvent();
+ if(!peekEvent || (peekEvent->type() != EventType::resize))
+ {
+ break;
+ }
+
+ event = getNextEvent();
+ }
+
auto resizeEvent = static_cast<ResizeEvent*>(event);
if((resizeEvent->width != window.width()) ||
(resizeEvent->height != window.height()))
@@ -79,6 +100,22 @@ void EventHandler::processEvents()
case EventType::mouseMove:
{
+ while(true)
+ {
+ if(!hasEvent())
+ {
+ break;
+ }
+
+ auto peekEvent = peekNextEvent();
+ if(!peekEvent || (peekEvent->type() != EventType::mouseMove))
+ {
+ break;
+ }
+
+ event = getNextEvent();
+ }
+
auto moveEvent = static_cast<MouseMoveEvent*>(event);
auto widget = window.find(moveEvent->x, moveEvent->y);
@@ -173,7 +210,27 @@ void EventHandler::processEvents()
case EventType::scroll:
{
+ int delta = 0;
+ while(true)
+ {
+ if(!hasEvent())
+ {
+ break;
+ }
+
+ auto peekEvent = peekNextEvent();
+ if(!peekEvent || (peekEvent->type() != EventType::scroll))
+ {
+ break;
+ }
+
+ auto scrollEvent = static_cast<ScrollEvent*>(event);
+ delta += scrollEvent->delta;
+ event = getNextEvent();
+ }
+
auto scrollEvent = static_cast<ScrollEvent*>(event);
+ scrollEvent->delta += delta;
auto widget = window.find(scrollEvent->x, scrollEvent->y);
if(widget)
@@ -188,6 +245,9 @@ void EventHandler::processEvents()
case EventType::key:
{
+
+ // TODO: Filter out multiple arrow events.
+
auto keyEvent = static_cast<KeyEvent*>(event);
if(window.keyboardFocus())
{