From 61d3c14519648517688d11635c52f34e25bde49a Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 21 Apr 2023 21:48:38 -0400 Subject: [PATCH] Fixed mouse test --- elements/testing/mouse.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/elements/testing/mouse.go b/elements/testing/mouse.go index fa22b9a..5f4a401 100644 --- a/elements/testing/mouse.go +++ b/elements/testing/mouse.go @@ -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(bounds.Dx() - 2, 1))) if element.pressed { + midpoint := bounds.Min.Add(bounds.Max.Sub(bounds.Min).Div(2)) shapes.ColorLine ( 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() } -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 -} - -func (element *Mouse) HandleMouseUp (x, y int, button input.Button) { - element.pressed = false -} - -func (element *Mouse) HandleMotion (x, y int) { - if !element.pressed { return } - element.lastMousePos = image.Pt(x, y) + element.lastMousePos = position + element.entity.Invalidate() +} + +func (element *Mouse) HandleMouseUp ( + position image.Point, + button input.Button, + modifiers input.Modifiers, +) { + element.pressed = false + element.entity.Invalidate() +} + +func (element *Mouse) HandleMotion (position image.Point) { + if !element.pressed { return } + element.lastMousePos = position element.entity.Invalidate() }