Added display move event.

- The Allegro (alui) implementation only provides emulation of the event (comparing the position every time other events are handled).
This commit is contained in:
Sander Schobers 2020-05-17 15:30:52 +02:00
parent 22cc3ce444
commit 8560204c39
3 changed files with 21 additions and 1 deletions

View File

@ -47,7 +47,7 @@ func NewRenderer(w, h int, opts allg5.NewDisplayOptions) (*Renderer, error) {
}) })
clean = nil 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. // Renderer implements ui.Renderer using Allegro 5.
@ -58,6 +58,7 @@ type Renderer struct {
user *allg5.UserEventSource user *allg5.UserEventSource
res ui.Resources res ui.Resources
dispPos geom.Point
keys ui.KeyState keys ui.KeyState
modifiers ui.KeyModifier modifiers ui.KeyModifier
cursor ui.MouseCursor cursor ui.MouseCursor
@ -118,6 +119,13 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
} }
ev = r.eq.Get() 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 { if !unhandled && cursor != r.cursor {
switch r.cursor { switch r.cursor {
@ -381,3 +389,8 @@ func newColor(c color.Color) allg5.Color {
func snap(p geom.PointF32) (float32, float32) { func snap(p geom.PointF32) (float32, float32) {
return float32(math.Round(float64(p.X))), float32(math.Round(float64(p.Y))) 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)
}

View File

@ -120,6 +120,8 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
switch e.Event { switch e.Event {
case sdl.WINDOWEVENT_CLOSE: case sdl.WINDOWEVENT_CLOSE:
t.Handle(&ui.DisplayCloseEvent{EventBase: eventBase(e)}) 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: case sdl.WINDOWEVENT_RESIZED:
t.Handle(&ui.DisplayResizeEvent{EventBase: eventBase(e), Bounds: r.WindowBounds()}) t.Handle(&ui.DisplayResizeEvent{EventBase: eventBase(e), Bounds: r.WindowBounds()})
case sdl.WINDOWEVENT_ENTER: case sdl.WINDOWEVENT_ENTER:

View File

@ -6,6 +6,11 @@ type DisplayCloseEvent struct {
EventBase EventBase
} }
type DisplayMoveEvent struct {
EventBase
Bounds geom.RectangleF32
}
type DisplayResizeEvent struct { type DisplayResizeEvent struct {
EventBase EventBase
Bounds geom.RectangleF32 Bounds geom.RectangleF32