Fixed mouse test

This commit is contained in:
Sasha Koshka 2023-04-21 21:48:38 -04:00
parent cd7a683af9
commit 61d3c14519
1 changed files with 23 additions and 11 deletions

View File

@ -52,9 +52,10 @@ func (element *Mouse) Draw (destination canvas.Canvas) {
bounds.Min.Add(image.Pt(1, bounds.Dy() - 2)), bounds.Min.Add(image.Pt(1, bounds.Dy() - 2)),
bounds.Min.Add(image.Pt(bounds.Dx() - 2, 1))) bounds.Min.Add(image.Pt(bounds.Dx() - 2, 1)))
if element.pressed { if element.pressed {
midpoint := bounds.Min.Add(bounds.Max.Sub(bounds.Min).Div(2))
shapes.ColorLine ( shapes.ColorLine (
destination, artist.Hex(0x000000FF), 1, destination, artist.Hex(0x000000FF), 1,
bounds.Min, element.lastMousePos) midpoint, element.lastMousePos)
} }
} }
@ -70,16 +71,27 @@ func (element *Mouse) SetConfig (new tomo.Config) {
element.entity.Invalidate() element.entity.Invalidate()
} }
func (element *Mouse) HandleMouseDown (x, y int, button input.Button) { func (element *Mouse) HandleMouseDown (
position image.Point,
button input.Button,
modifiers input.Modifiers,
) {
element.pressed = true element.pressed = true
} element.lastMousePos = position
element.entity.Invalidate()
func (element *Mouse) HandleMouseUp (x, y int, button input.Button) { }
element.pressed = false
} func (element *Mouse) HandleMouseUp (
position image.Point,
func (element *Mouse) HandleMotion (x, y int) { button input.Button,
if !element.pressed { return } modifiers input.Modifiers,
element.lastMousePos = image.Pt(x, y) ) {
element.pressed = false
element.entity.Invalidate()
}
func (element *Mouse) HandleMotion (position image.Point) {
if !element.pressed { return }
element.lastMousePos = position
element.entity.Invalidate() element.entity.Invalidate()
} }