Few mouse interaction extensions for sdlui.

- Added Mouse{Enter,Leave}Event support.
- Simulating MouseWheel for MouseMotionEvent.
This commit is contained in:
Sander Schobers 2020-05-15 09:59:53 +02:00
parent cdfb863ab0
commit 893bf513ad

View File

@ -24,6 +24,7 @@ type Renderer struct {
refresh uint32
fonts map[string]*Font
mouse geom.PointF32
cursor ui.MouseCursor
cursors map[sdl.SystemCursor]*sdl.Cursor
}
@ -114,7 +115,6 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
r.cursor = ui.MouseCursorDefault
var unhandled bool
// TODO: simulate ui.MouseEnter & ui.MouseLeave?
switch e := event.(type) {
case *sdl.WindowEvent:
switch e.Event {
@ -122,7 +122,12 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
t.Handle(&ui.DisplayCloseEvent{EventBase: eventBase(e)})
case sdl.WINDOWEVENT_RESIZED:
t.Handle(&ui.DisplayResizeEvent{EventBase: eventBase(e), Bounds: r.WindowBounds()})
case sdl.WINDOWEVENT_ENTER:
t.Handle(&ui.MouseEnterEvent{MouseEvent: ui.MouseEvent{EventBase: eventBase(e), X: r.mouse.X, Y: r.mouse.Y}})
case sdl.WINDOWEVENT_LEAVE:
t.Handle(&ui.MouseLeaveEvent{MouseEvent: ui.MouseEvent{EventBase: eventBase(e), X: r.mouse.X, Y: r.mouse.Y}})
default:
unhandled = true
}
case *sdl.KeyboardEvent:
@ -153,7 +158,10 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
t.Handle(&ui.MouseButtonUpEvent{MouseEvent: mouseEvent(e, e.X, e.Y), Button: mouseButton(e.Button)})
}
case *sdl.MouseMotionEvent:
t.Handle(&ui.MouseMoveEvent{MouseEvent: ui.MouseEvent{EventBase: eventBase(e), X: float32(e.X), Y: float32(e.Y)}, MouseWheel: 0})
r.mouse = geom.PtF32(float32(e.X), float32(e.Y))
t.Handle(&ui.MouseMoveEvent{MouseEvent: ui.MouseEvent{EventBase: eventBase(e), X: r.mouse.X, Y: r.mouse.Y}, MouseWheel: 0})
case *sdl.MouseWheelEvent:
t.Handle(&ui.MouseMoveEvent{MouseEvent: ui.MouseEvent{EventBase: eventBase(e), X: r.mouse.X, Y: r.mouse.Y}, MouseWheel: float32(e.Y)})
case *sdl.UserEvent:
if r.refresh == e.Type {
t.Handle(&ui.RefreshEvent{EventBase: eventBase(e)})