From 8560204c3975795e5aa44096adb390b69a2bdaa9 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 17 May 2020 15:30:52 +0200 Subject: [PATCH] Added display move event. - The Allegro (alui) implementation only provides emulation of the event (comparing the position every time other events are handled). --- allg5ui/renderer.go | 15 ++++++++++++++- sdlui/renderer.go | 2 ++ ui/event.go | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/allg5ui/renderer.go b/allg5ui/renderer.go index 92b08b3..0c2e71f 100644 --- a/allg5ui/renderer.go +++ b/allg5ui/renderer.go @@ -47,7 +47,7 @@ func NewRenderer(w, h int, opts allg5.NewDisplayOptions) (*Renderer, error) { }) clean = nil - return &Renderer{disp, eq, nil, user, &ui.OSResources{}, ui.KeyState{}, ui.KeyModifierNone, ui.MouseCursorDefault}, nil + return &Renderer{disp, eq, nil, user, &ui.OSResources{}, dispPos(disp), ui.KeyState{}, ui.KeyModifierNone, ui.MouseCursorDefault}, nil } // Renderer implements ui.Renderer using Allegro 5. @@ -58,6 +58,7 @@ type Renderer struct { user *allg5.UserEventSource res ui.Resources + dispPos geom.Point keys ui.KeyState modifiers ui.KeyModifier cursor ui.MouseCursor @@ -118,6 +119,13 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { } ev = r.eq.Get() } + dispPos := dispPos(r.disp) + if dispPos != r.dispPos { + r.dispPos = dispPos + w := r.disp.Width() + h := r.disp.Height() + t.Handle(&ui.DisplayMoveEvent{Bounds: r.dispPos.RectRel2D(w, h).ToF32()}) + } if !unhandled && cursor != r.cursor { switch r.cursor { @@ -381,3 +389,8 @@ func newColor(c color.Color) allg5.Color { func snap(p geom.PointF32) (float32, float32) { return float32(math.Round(float64(p.X))), float32(math.Round(float64(p.Y))) } + +func dispPos(disp *allg5.Display) geom.Point { + x, y := disp.Position() + return geom.Pt(x, y) +} diff --git a/sdlui/renderer.go b/sdlui/renderer.go index 9dafdbb..45c385f 100644 --- a/sdlui/renderer.go +++ b/sdlui/renderer.go @@ -120,6 +120,8 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { switch e.Event { case sdl.WINDOWEVENT_CLOSE: t.Handle(&ui.DisplayCloseEvent{EventBase: eventBase(e)}) + case sdl.WINDOWEVENT_MOVED: + t.Handle(&ui.DisplayMoveEvent{EventBase: eventBase(e), Bounds: r.WindowBounds()}) case sdl.WINDOWEVENT_RESIZED: t.Handle(&ui.DisplayResizeEvent{EventBase: eventBase(e), Bounds: r.WindowBounds()}) case sdl.WINDOWEVENT_ENTER: diff --git a/ui/event.go b/ui/event.go index 40af5e6..55f38c1 100644 --- a/ui/event.go +++ b/ui/event.go @@ -6,6 +6,11 @@ type DisplayCloseEvent struct { EventBase } +type DisplayMoveEvent struct { + EventBase + Bounds geom.RectangleF32 +} + type DisplayResizeEvent struct { EventBase Bounds geom.RectangleF32