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