2023-01-08 23:03:19 -07:00
|
|
|
package basic
|
|
|
|
|
|
|
|
import "image"
|
|
|
|
import "image/color"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
|
|
|
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
|
|
|
|
|
|
|
// Test is a simple element that can be used as a placeholder.
|
|
|
|
type Test struct {
|
2023-01-09 19:25:11 -07:00
|
|
|
*core.Core
|
|
|
|
core core.CoreControl
|
2023-01-10 15:34:40 -07:00
|
|
|
drawing bool
|
|
|
|
color tomo.Image
|
|
|
|
lastMousePos image.Point
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTest creates a new test element.
|
|
|
|
func NewTest () (element *Test) {
|
|
|
|
element = &Test { }
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (element *Test) Handle (event tomo.Event) {
|
|
|
|
switch event.(type) {
|
|
|
|
case tomo.EventResize:
|
|
|
|
resizeEvent := event.(tomo.EventResize)
|
|
|
|
element.core.AllocateCanvas (
|
|
|
|
resizeEvent.Width,
|
|
|
|
resizeEvent.Height)
|
2023-01-10 18:31:18 -07:00
|
|
|
artist.Rectangle (
|
|
|
|
element.core,
|
|
|
|
artist.NewUniform (color.RGBA {
|
2023-01-08 23:03:19 -07:00
|
|
|
R: 0x40, G: 0x80, B: 0x90, A: 0xFF,
|
2023-01-10 18:31:18 -07:00
|
|
|
}),
|
|
|
|
artist.NewUniform(color.Black),
|
|
|
|
1, element.Bounds())
|
2023-01-08 23:03:19 -07:00
|
|
|
artist.Line (
|
|
|
|
element.core, artist.NewUniform(color.White), 1,
|
2023-01-10 18:31:18 -07:00
|
|
|
image.Pt(1, 1),
|
|
|
|
image.Pt(resizeEvent.Width - 2, resizeEvent.Height - 2))
|
2023-01-08 23:03:19 -07:00
|
|
|
artist.Line (
|
|
|
|
element.core, artist.NewUniform(color.White), 1,
|
2023-01-10 18:31:18 -07:00
|
|
|
image.Pt(1, resizeEvent.Height - 2),
|
|
|
|
image.Pt(resizeEvent.Width - 2, 1))
|
2023-01-10 23:56:05 -07:00
|
|
|
// println(resizeEvent.Width, resizeEvent.Height)
|
2023-01-08 23:03:19 -07:00
|
|
|
|
2023-01-10 15:34:40 -07:00
|
|
|
case tomo.EventMouseDown:
|
|
|
|
element.drawing = true
|
|
|
|
mouseDownEvent := event.(tomo.EventMouseDown)
|
|
|
|
element.lastMousePos = image.Pt (
|
|
|
|
mouseDownEvent.X,
|
|
|
|
mouseDownEvent.Y)
|
|
|
|
|
|
|
|
case tomo.EventMouseUp:
|
|
|
|
element.drawing = false
|
|
|
|
mouseUpEvent := event.(tomo.EventMouseUp)
|
|
|
|
mousePos := image.Pt (
|
|
|
|
mouseUpEvent.X,
|
|
|
|
mouseUpEvent.Y)
|
|
|
|
element.core.PushRegion (artist.Line (
|
|
|
|
element.core, element.color, 1,
|
|
|
|
element.lastMousePos, mousePos))
|
|
|
|
element.lastMousePos = mousePos
|
|
|
|
|
|
|
|
case tomo.EventMouseMove:
|
|
|
|
mouseMoveEvent := event.(tomo.EventMouseMove)
|
|
|
|
mousePos := image.Pt (
|
|
|
|
mouseMoveEvent.X,
|
|
|
|
mouseMoveEvent.Y)
|
|
|
|
element.core.PushRegion (artist.Line (
|
|
|
|
element.core, element.color, 1,
|
|
|
|
element.lastMousePos, mousePos))
|
|
|
|
element.lastMousePos = mousePos
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-09 13:14:36 -07:00
|
|
|
func (element *Test) AdvanceSelection (direction int) (ok bool) {
|
2023-01-08 23:03:19 -07:00
|
|
|
return
|
|
|
|
}
|