Exposed last known key modifiers in context.

This commit is contained in:
Sander Schobers 2020-05-18 20:35:34 +02:00
parent e7ada7fea0
commit 16d4e26cd0

View File

@ -8,6 +8,7 @@ type Context interface {
Animate()
Fonts() *Fonts
HasQuit() bool
KeyModifiers() KeyModifier
MousePosition() geom.PointF32
Overlays() *Overlays
Quit()
@ -22,16 +23,17 @@ var _ Context = &context{}
var _ EventTarget = &context{}
type context struct {
animate bool
quit chan struct{}
renderer Renderer
view Control
mouse geom.PointF32
tooltip *Tooltip
overlays *Overlays
fonts *Fonts
textures *Textures
style *Style
animate bool
quit chan struct{}
renderer Renderer
view Control
modifiers KeyModifier
mouse geom.PointF32
tooltip *Tooltip
overlays *Overlays
fonts *Fonts
textures *Textures
style *Style
}
func newContext(r Renderer, s *Style, view Control) *context {
@ -66,6 +68,8 @@ func (c *context) HasQuit() bool {
}
}
func (c *context) KeyModifiers() KeyModifier { return c.modifiers }
func (c *context) MousePosition() geom.PointF32 { return c.mouse }
func (c *context) Overlays() *Overlays { return c.overlays }
@ -97,6 +101,10 @@ func (c *context) Handle(e Event) {
return
case *MouseMoveEvent:
c.mouse = e.Pos()
case *KeyDownEvent:
c.modifiers = e.Modifiers
case *KeyUpEvent:
c.modifiers = e.Modifiers
}
c.overlays.Handle(c, e)
}