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-09 19:25:11 -07:00
|
|
|
element.Core, element.core = core.NewCore(element)
|
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-15 22:35:05 -07:00
|
|
|
func (element *Mouse) Resize (width, height int) {
|
|
|
|
element.core.AllocateCanvas(width, height)
|
|
|
|
artist.FillRectangle (
|
|
|
|
element.core,
|
|
|
|
theme.AccentPattern(),
|
|
|
|
element.Bounds())
|
|
|
|
artist.StrokeRectangle (
|
|
|
|
element.core,
|
|
|
|
artist.NewUniform(color.Black), 1,
|
|
|
|
element.Bounds())
|
|
|
|
artist.Line (
|
|
|
|
element.core, artist.NewUniform(color.White), 3,
|
|
|
|
image.Pt(1, 1),
|
|
|
|
image.Pt(width - 2, height - 2))
|
|
|
|
artist.Line (
|
|
|
|
element.core, artist.NewUniform(color.White), 1,
|
|
|
|
image.Pt(1, height - 2),
|
|
|
|
image.Pt(width - 2, 1))
|
|
|
|
}
|
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-15 22:35:05 -07:00
|
|
|
element.core, element.color, 1,
|
|
|
|
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-15 22:35:05 -07:00
|
|
|
element.core, element.color, 1,
|
|
|
|
element.lastMousePos, mousePos))
|
|
|
|
element.lastMousePos = mousePos
|
|
|
|
}
|
|
|
|
|
2023-01-19 13:05:13 -07:00
|
|
|
func (element *Mouse) HandleMouseScroll (x, y int, deltaX, deltaY float64) { }
|