From 23e6b498454d27f53b2dc173e58a890e2f1294a3 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 19 Mar 2020 15:55:57 +0900 Subject: [PATCH] [qwaq] Implement mouse enter/leave events --- ruamoko/qwaq/qwaq-group.h | 2 ++ ruamoko/qwaq/qwaq-group.r | 30 ++++++++++++++++++++++++++++++ ruamoko/qwaq/qwaq-view.h | 7 ++++++- ruamoko/qwaq/qwaq-view.r | 18 ++++++++++++++++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/ruamoko/qwaq/qwaq-group.h b/ruamoko/qwaq/qwaq-group.h index 956e43d1a..c1edd01b3 100644 --- a/ruamoko/qwaq/qwaq-group.h +++ b/ruamoko/qwaq/qwaq-group.h @@ -11,6 +11,8 @@ @interface Group : Object { Array *views; + View *mouse_grabbed; + View *mouse_within; int focused; id context; } diff --git a/ruamoko/qwaq/qwaq-group.r b/ruamoko/qwaq/qwaq-group.r index 0480fbf05..75c5c2a90 100644 --- a/ruamoko/qwaq/qwaq-group.r +++ b/ruamoko/qwaq/qwaq-group.r @@ -65,6 +65,18 @@ not_dont_draw (id aView, void *aGroup) return self; } +static View * +find_mouse_view(Group *group, Point pos) +{ + for (int i = [group.views count]; i--; ) { + View *v = [group.views objectAtIndex: i]; + if ([v containsPoint: pos]) { + return v; + } + } + return nil; +} + -handleEvent: (qwaq_event_t *) event { if (event.what & qe_focused) { @@ -72,6 +84,24 @@ not_dont_draw (id aView, void *aGroup) [[views objectAtIndex:focused] handleEvent: event]; } } else if (event.what & qe_positional) { + Point pos = {event.mouse.x, event.mouse.y}; + if (mouse_grabbed) { + [mouse_grabbed handleEvent: event]; + } else { + if (mouse_within && ![mouse_within containsPoint: pos]) { + [mouse_within onMouseLeave: pos]; + mouse_within = nil; + } + if (!mouse_within) { + mouse_within = find_mouse_view (self, pos); + if (mouse_within) { + [mouse_within onMouseEnter: pos]; + } + } + if (mouse_within) { + [mouse_within handleEvent: event]; + } + } } else { // broadcast [views makeObjectsPerformSelector: @selector(draw) withObject: event]; diff --git a/ruamoko/qwaq/qwaq-view.h b/ruamoko/qwaq/qwaq-view.h index 920fa793e..a7314f7e0 100644 --- a/ruamoko/qwaq/qwaq-view.h +++ b/ruamoko/qwaq/qwaq-view.h @@ -60,7 +60,9 @@ enum { -setOwner: (Group *) owner; --(struct Rect_s *)rect; +-(Rect)rect; + +-(int) containsPoint: (Point) point; -(int) options; @@ -69,6 +71,9 @@ enum { -redraw; -handleEvent: (qwaq_event_t *) event; +- (void) onMouseEnter: (Point) pos; +- (void) onMouseLeave: (Point) pos; + - (void) refresh; - (void) mvprintf: (Point) pos, string fmt, ...; diff --git a/ruamoko/qwaq/qwaq-view.r b/ruamoko/qwaq/qwaq-view.r index 5217504fd..b46004755 100644 --- a/ruamoko/qwaq/qwaq-view.r +++ b/ruamoko/qwaq/qwaq-view.r @@ -95,9 +95,14 @@ updateScreenCursor (View *view) return self; } -- (Rect *) rect +- (Rect) rect { - return ▭ + return rect; +} + +-(int) containsPoint: (Point) point +{ + return rectContainsPoint (rect, point); } - (void) forward: (SEL) sel : (@va_list) args @@ -144,4 +149,13 @@ updateScreenCursor (View *view) return self; } +- (void) onMouseEnter: (Point) pos +{ +} + +- (void) onMouseLeave: (Point) pos +{ +} + + @end