2023-01-12 10:51:42 -07:00
|
|
|
package testing
|
2023-01-08 23:03:19 -07:00
|
|
|
|
|
|
|
import "image"
|
|
|
|
import "image/color"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
2023-01-11 13:46:48 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
2023-01-08 23:03:19 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
2023-01-09 19:25:11 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
2023-01-08 23:03:19 -07:00
|
|
|
|
2023-01-12 10:51:42 -07:00
|
|
|
// Mouse is an element capable of testing mouse input. When the mouse is clicked
|
|
|
|
// and dragged on it, it draws a trail.
|
|
|
|
type Mouse struct {
|
2023-01-09 19:25:11 -07:00
|
|
|
*core.Core
|
|
|
|
core core.CoreControl
|
2023-01-10 15:34:40 -07:00
|
|
|
drawing bool
|
2023-01-13 23:54:57 -07:00
|
|
|
color artist.Pattern
|
2023-01-10 15:34:40 -07:00
|
|
|
lastMousePos image.Point
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-01-12 10:51:42 -07:00
|
|
|
// NewMouse creates a new mouse test element.
|
|
|
|
func NewMouse () (element *Mouse) {
|
|
|
|
element = &Mouse { }
|
2023-01-31 12:57:02 -07:00
|
|
|
element.Core, element.core = core.NewCore(element.draw)
|
2023-01-08 23:03:19 -07:00
|
|
|
element.core.SetMinimumSize(32, 32)
|
2023-01-10 15:34:40 -07:00
|
|
|
element.color = artist.NewUniform(color.Black)
|
2023-01-08 23:03:19 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:57:02 -07:00
|
|
|
func (element *Mouse) draw () {
|
2023-01-24 14:41:12 -07:00
|
|
|
bounds := element.Bounds()
|
2023-01-28 23:49:01 -07:00
|
|
|
pattern, _ := theme.AccentPattern(theme.PatternState { })
|
2023-01-31 14:18:10 -07:00
|
|
|
artist.FillRectangle(element, pattern, bounds)
|
2023-01-15 22:35:05 -07:00
|
|
|
artist.StrokeRectangle (
|
2023-01-31 14:18:10 -07:00
|
|
|
element,
|
2023-01-15 22:35:05 -07:00
|
|
|
artist.NewUniform(color.Black), 1,
|
2023-01-24 14:41:12 -07:00
|
|
|
bounds)
|
2023-01-15 22:35:05 -07:00
|
|
|
artist.Line (
|
2023-01-31 14:18:10 -07:00
|
|
|
element, artist.NewUniform(color.White), 1,
|
2023-01-31 16:39:17 -07:00
|
|
|
bounds.Min.Add(image.Pt(1, 1)),
|
|
|
|
bounds.Min.Add(image.Pt(bounds.Dx() - 2, bounds.Dy() - 2)))
|
2023-01-15 22:35:05 -07:00
|
|
|
artist.Line (
|
2023-01-31 14:18:10 -07:00
|
|
|
element, artist.NewUniform(color.White), 1,
|
2023-01-31 16:39:17 -07:00
|
|
|
bounds.Min.Add(image.Pt(1, bounds.Dy() - 2)),
|
|
|
|
bounds.Min.Add(image.Pt(bounds.Dx() - 2, 1)))
|
2023-01-15 22:35:05 -07:00
|
|
|
}
|
2023-01-10 15:34:40 -07:00
|
|
|
|
2023-01-15 22:35:05 -07:00
|
|
|
func (element *Mouse) HandleMouseDown (x, y int, button tomo.Button) {
|
|
|
|
element.drawing = true
|
|
|
|
element.lastMousePos = image.Pt(x, y)
|
|
|
|
}
|
2023-01-10 15:34:40 -07:00
|
|
|
|
2023-01-15 22:35:05 -07:00
|
|
|
func (element *Mouse) HandleMouseUp (x, y int, button tomo.Button) {
|
|
|
|
element.drawing = false
|
|
|
|
mousePos := image.Pt(x, y)
|
2023-01-19 13:05:13 -07:00
|
|
|
element.core.DamageRegion (artist.Line (
|
2023-01-31 14:18:10 -07:00
|
|
|
element, element.color, 1,
|
2023-01-15 22:35:05 -07:00
|
|
|
element.lastMousePos, mousePos))
|
|
|
|
element.lastMousePos = mousePos
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
2023-01-15 22:35:05 -07:00
|
|
|
|
|
|
|
func (element *Mouse) HandleMouseMove (x, y int) {
|
|
|
|
if !element.drawing { return }
|
|
|
|
mousePos := image.Pt(x, y)
|
2023-01-19 13:05:13 -07:00
|
|
|
element.core.DamageRegion (artist.Line (
|
2023-01-31 14:18:10 -07:00
|
|
|
element, element.color, 1,
|
2023-01-15 22:35:05 -07:00
|
|
|
element.lastMousePos, mousePos))
|
|
|
|
element.lastMousePos = mousePos
|
|
|
|
}
|
|
|
|
|
2023-01-19 13:05:13 -07:00
|
|
|
func (element *Mouse) HandleMouseScroll (x, y int, deltaX, deltaY float64) { }
|