2023-01-12 17:51:42 +00:00
|
|
|
package testing
|
2023-01-09 06:03:19 +00:00
|
|
|
|
|
|
|
import "image"
|
2023-03-31 05:06:29 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
2023-02-02 06:48:16 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/input"
|
2023-01-09 06:03:19 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
2023-02-26 19:27:38 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
|
2023-01-10 02:25:11 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
2023-03-31 05:06:29 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
2023-01-09 06:03:19 +00:00
|
|
|
|
2023-01-12 17:51:42 +00: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-10 02:25:11 +00:00
|
|
|
*core.Core
|
|
|
|
core core.CoreControl
|
2023-01-10 22:34:40 +00:00
|
|
|
drawing bool
|
|
|
|
lastMousePos image.Point
|
2023-02-08 19:36:14 +00:00
|
|
|
|
2023-03-31 05:06:29 +00:00
|
|
|
config config.Wrapped
|
|
|
|
theme theme.Wrapped
|
2023-01-09 06:03:19 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 17:51:42 +00:00
|
|
|
// NewMouse creates a new mouse test element.
|
|
|
|
func NewMouse () (element *Mouse) {
|
2023-03-31 05:06:29 +00:00
|
|
|
element = &Mouse { }
|
|
|
|
element.theme.Case = tomo.C("tomo", "piano")
|
2023-03-14 23:41:36 +00:00
|
|
|
element.Core, element.core = core.NewCore(element, element.draw)
|
2023-01-09 06:03:19 +00:00
|
|
|
element.core.SetMinimumSize(32, 32)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-08 19:36:14 +00:00
|
|
|
// SetTheme sets the element's theme.
|
2023-03-31 05:06:29 +00:00
|
|
|
func (element *Mouse) SetTheme (new tomo.Theme) {
|
|
|
|
element.theme.Theme = new
|
2023-02-08 19:36:14 +00:00
|
|
|
element.redo()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConfig sets the element's configuration.
|
2023-03-31 05:06:29 +00:00
|
|
|
func (element *Mouse) SetConfig (new tomo.Config) {
|
|
|
|
element.config.Config = new
|
2023-02-08 19:36:14 +00:00
|
|
|
element.redo()
|
|
|
|
}
|
|
|
|
|
2023-02-03 23:32:22 +00:00
|
|
|
func (element *Mouse) redo () {
|
|
|
|
if !element.core.HasImage() { return }
|
|
|
|
element.draw()
|
|
|
|
element.core.DamageAll()
|
|
|
|
}
|
|
|
|
|
2023-01-31 19:57:02 +00:00
|
|
|
func (element *Mouse) draw () {
|
2023-01-24 21:41:12 +00:00
|
|
|
bounds := element.Bounds()
|
2023-02-27 03:20:17 +00:00
|
|
|
accent := element.theme.Color (
|
2023-03-31 05:06:29 +00:00
|
|
|
tomo.ColorAccent,
|
|
|
|
tomo.State { })
|
2023-02-27 03:20:17 +00:00
|
|
|
shapes.FillColorRectangle(element.core, accent, bounds)
|
2023-02-26 19:27:38 +00:00
|
|
|
shapes.StrokeColorRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-02-26 19:27:38 +00:00
|
|
|
artist.Hex(0x000000FF),
|
|
|
|
bounds, 1)
|
|
|
|
shapes.ColorLine (
|
|
|
|
element.core, artist.Hex(0xFFFFFFFF), 1,
|
2023-01-31 23:39:17 +00:00
|
|
|
bounds.Min.Add(image.Pt(1, 1)),
|
|
|
|
bounds.Min.Add(image.Pt(bounds.Dx() - 2, bounds.Dy() - 2)))
|
2023-02-26 19:27:38 +00:00
|
|
|
shapes.ColorLine (
|
|
|
|
element.core, artist.Hex(0xFFFFFFFF), 1,
|
2023-01-31 23:39:17 +00:00
|
|
|
bounds.Min.Add(image.Pt(1, bounds.Dy() - 2)),
|
|
|
|
bounds.Min.Add(image.Pt(bounds.Dx() - 2, 1)))
|
2023-01-16 05:35:05 +00:00
|
|
|
}
|
2023-01-10 22:34:40 +00:00
|
|
|
|
2023-02-02 06:48:16 +00:00
|
|
|
func (element *Mouse) HandleMouseDown (x, y int, button input.Button) {
|
2023-01-16 05:35:05 +00:00
|
|
|
element.drawing = true
|
|
|
|
element.lastMousePos = image.Pt(x, y)
|
|
|
|
}
|
2023-01-10 22:34:40 +00:00
|
|
|
|
2023-02-02 06:48:16 +00:00
|
|
|
func (element *Mouse) HandleMouseUp (x, y int, button input.Button) {
|
2023-01-16 05:35:05 +00:00
|
|
|
element.drawing = false
|
|
|
|
mousePos := image.Pt(x, y)
|
2023-02-26 19:27:38 +00:00
|
|
|
element.core.DamageRegion (shapes.ColorLine (
|
|
|
|
element.core, artist.Hex(0x000000FF), 1,
|
2023-01-16 05:35:05 +00:00
|
|
|
element.lastMousePos, mousePos))
|
|
|
|
element.lastMousePos = mousePos
|
2023-01-09 06:03:19 +00:00
|
|
|
}
|
2023-01-16 05:35:05 +00:00
|
|
|
|
2023-03-14 23:41:36 +00:00
|
|
|
func (element *Mouse) HandleMotion (x, y int) {
|
2023-01-16 05:35:05 +00:00
|
|
|
if !element.drawing { return }
|
|
|
|
mousePos := image.Pt(x, y)
|
2023-02-26 19:27:38 +00:00
|
|
|
element.core.DamageRegion (shapes.ColorLine (
|
|
|
|
element.core, artist.Hex(0x000000FF), 1,
|
2023-01-16 05:35:05 +00:00
|
|
|
element.lastMousePos, mousePos))
|
|
|
|
element.lastMousePos = mousePos
|
|
|
|
}
|