2020-05-09 13:32:43 +00:00
|
|
|
package tins2020
|
|
|
|
|
|
|
|
import "github.com/veandco/go-sdl2/sdl"
|
|
|
|
|
|
|
|
type Control interface {
|
|
|
|
Init(*Context) error
|
|
|
|
Handle(*Context, sdl.Event)
|
|
|
|
Render(*Context)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControlBase struct {
|
2020-05-10 10:21:51 +00:00
|
|
|
Bounds Rectangle
|
|
|
|
|
|
|
|
IsMouseOver bool
|
2020-05-09 13:32:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 10:21:51 +00:00
|
|
|
func (b *ControlBase) Init(*Context) error { return nil }
|
2020-05-09 13:32:43 +00:00
|
|
|
|
2020-05-10 10:21:51 +00:00
|
|
|
func (b *ControlBase) Handle(ctx *Context, event sdl.Event) {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *sdl.MouseMotionEvent:
|
|
|
|
b.IsMouseOver = b.Bounds.IsPointInside(e.X, e.Y)
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 13:32:43 +00:00
|
|
|
|
2020-05-10 10:21:51 +00:00
|
|
|
func (b *ControlBase) Render(*Context) {}
|