diff --git a/allg5/event.go b/allg5/event.go index f4505c4..97378ff 100644 --- a/allg5/event.go +++ b/allg5/event.go @@ -112,12 +112,19 @@ type MouseButtonUpEvent struct { Pressure float32 } +type MouseEnterEvent struct { + MouseEvent +} + type MouseEvent struct { EventBase X, Y int Z, W int Display *Display } +type MouseLeaveEvent struct { + MouseEvent +} type MouseMoveEvent struct { MouseEvent @@ -181,9 +188,15 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event { case C.ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e)) return &MouseButtonDownEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, MouseButton(mouse.button), float32(mouse.pressure)} + case C.ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY: + mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e)) + return &MouseEnterEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}} case C.ALLEGRO_EVENT_MOUSE_BUTTON_UP: mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e)) return &MouseButtonUpEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, MouseButton(mouse.button), float32(mouse.pressure)} + case C.ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY: + mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e)) + return &MouseLeaveEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}} case C.ALLEGRO_EVENT_KEY_DOWN: key := (*C.ALLEGRO_KEYBOARD_EVENT)(unsafe.Pointer(e)) return &KeyDownEvent{KeyEvent{eb, Key(key.keycode), nil}} diff --git a/ui/allg5ui/renderer.go b/ui/allg5ui/renderer.go index 9f19b9a..fd4fcfc 100644 --- a/ui/allg5ui/renderer.go +++ b/ui/allg5ui/renderer.go @@ -66,6 +66,10 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { t.Handle(&ui.MouseButtonDownEvent{MouseEvent: mouseEvent(e.MouseEvent), Button: ui.MouseButton(e.Button)}) case *allg5.MouseButtonUpEvent: t.Handle(&ui.MouseButtonUpEvent{MouseEvent: mouseEvent(e.MouseEvent), Button: ui.MouseButton(e.Button)}) + case *allg5.MouseEnterEvent: + t.Handle(&ui.MouseLeaveEvent{MouseEvent: mouseEvent(e.MouseEvent)}) + case *allg5.MouseLeaveEvent: + t.Handle(&ui.MouseLeaveEvent{MouseEvent: mouseEvent(e.MouseEvent)}) case *allg5.MouseMoveEvent: t.Handle(&ui.MouseMoveEvent{MouseEvent: mouseEvent(e.MouseEvent), MouseWheel: float32(e.DeltaZ)}) case *allg5.UserEvent: diff --git a/ui/controlbase.go b/ui/controlbase.go index 6f0e536..5f858e3 100644 --- a/ui/controlbase.go +++ b/ui/controlbase.go @@ -76,6 +76,8 @@ func (c *ControlBase) Handle(ctx Context, e Event) { } } } + case *MouseLeaveEvent: + c.over = false case *MouseButtonDownEvent: c.over = over(e.MouseEvent) if c.over && e.Button == MouseButtonLeft { diff --git a/ui/event.go b/ui/event.go index 1b95113..ea2780a 100644 --- a/ui/event.go +++ b/ui/event.go @@ -72,6 +72,10 @@ type MouseButtonUpEvent struct { Button MouseButton } +type MouseEnterEvent struct { + MouseEvent +} + type MouseEvent struct { EventBase X, Y float32 @@ -81,6 +85,10 @@ func (e *MouseEvent) Pos() geom.PointF32 { return geom.PtF32(e.X, e.Y) } +type MouseLeaveEvent struct { + MouseEvent +} + type MouseMoveEvent struct { MouseEvent MouseWheel float32