2014-08-21 14:32:36 -05:00
|
|
|
// 21 august 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2014-08-21 17:23:51 -05:00
|
|
|
"image/color"
|
|
|
|
"image/draw"
|
|
|
|
"strconv"
|
2014-08-21 14:32:36 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type repainter struct {
|
|
|
|
img *image.RGBA
|
|
|
|
area Area
|
|
|
|
x TextField
|
|
|
|
y TextField
|
|
|
|
width TextField
|
|
|
|
height TextField
|
|
|
|
repaint Button
|
|
|
|
all Button
|
|
|
|
stack Stack
|
2014-08-21 17:23:51 -05:00
|
|
|
|
|
|
|
xv int
|
|
|
|
yv int
|
|
|
|
wv int
|
|
|
|
hv int
|
2014-08-21 14:32:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newRepainter(times int) *repainter {
|
|
|
|
r := new(repainter)
|
|
|
|
r.img = tileImage(times)
|
|
|
|
r.area = NewArea(r.img.Rect.Dx(), r.img.Rect.Dy(), r)
|
2014-08-22 10:39:45 -05:00
|
|
|
r.area.OnTextFieldDismissed(r.tfdone)
|
2014-08-21 14:32:36 -05:00
|
|
|
r.x = NewTextField()
|
2014-08-21 17:23:51 -05:00
|
|
|
r.x.OnChanged(r.setx)
|
2014-08-21 14:32:36 -05:00
|
|
|
r.y = NewTextField()
|
2014-08-21 17:23:51 -05:00
|
|
|
r.y.OnChanged(r.sety)
|
2014-08-21 14:32:36 -05:00
|
|
|
r.width = NewTextField()
|
2014-08-21 17:23:51 -05:00
|
|
|
r.width.OnChanged(r.setwidth)
|
2014-08-21 14:32:36 -05:00
|
|
|
r.height = NewTextField()
|
2014-08-21 17:23:51 -05:00
|
|
|
r.height.OnChanged(r.setheight)
|
2014-08-21 14:32:36 -05:00
|
|
|
r.repaint = NewButton("Rect")
|
2014-08-21 17:23:51 -05:00
|
|
|
r.repaint.OnClicked(r.dorect)
|
2014-08-21 14:32:36 -05:00
|
|
|
r.all = NewButton("All")
|
2014-08-21 17:23:51 -05:00
|
|
|
r.all.OnClicked(r.doall)
|
2014-08-21 14:32:36 -05:00
|
|
|
r.stack = NewHorizontalStack(r.x, r.y, r.width, r.height, r.repaint, r.all)
|
|
|
|
r.stack.SetStretchy(0)
|
|
|
|
r.stack.SetStretchy(1)
|
|
|
|
r.stack.SetStretchy(2)
|
|
|
|
r.stack.SetStretchy(3)
|
|
|
|
r.stack = NewVerticalStack(r.area, r.stack)
|
|
|
|
r.stack.SetStretchy(0)
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) Paint(rect image.Rectangle) *image.RGBA {
|
|
|
|
return r.img.SubImage(rect).(*image.RGBA)
|
|
|
|
}
|
|
|
|
|
2014-08-22 10:29:44 -05:00
|
|
|
func (r *repainter) Mouse(me MouseEvent) {
|
|
|
|
if me.Up == 1 {
|
|
|
|
r.area.OpenTextFieldAt(me.Pos.X, me.Pos.Y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) tfdone() {
|
|
|
|
println(r.area.TextFieldText())
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:32:36 -05:00
|
|
|
func (r *repainter) Key(ke KeyEvent) bool { return false }
|
2014-08-21 17:23:51 -05:00
|
|
|
|
|
|
|
func (r *repainter) setx() {
|
|
|
|
i, err := strconv.Atoi(r.x.Text())
|
|
|
|
if err != nil {
|
|
|
|
r.x.Invalid(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.x.Invalid("")
|
|
|
|
r.xv = i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) sety() {
|
|
|
|
i, err := strconv.Atoi(r.y.Text())
|
|
|
|
if err != nil {
|
|
|
|
r.y.Invalid(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.y.Invalid("")
|
|
|
|
r.yv = i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) setwidth() {
|
|
|
|
i, err := strconv.Atoi(r.width.Text())
|
|
|
|
if err != nil {
|
|
|
|
r.width.Invalid(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.width.Invalid("")
|
|
|
|
r.wv = i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) setheight() {
|
|
|
|
i, err := strconv.Atoi(r.height.Text())
|
|
|
|
if err != nil {
|
|
|
|
r.height.Invalid(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.height.Invalid("")
|
|
|
|
r.hv = i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) alter(rect image.Rectangle, c color.Color) {
|
|
|
|
draw.Draw(r.img, rect, &image.Uniform{c}, image.ZP, draw.Over)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) dorect() {
|
|
|
|
rect := image.Rect(r.xv, r.yv, r.xv + r.wv, r.yv + r.hv)
|
|
|
|
r.alter(rect, color.RGBA{255, 0, 255, 128})
|
|
|
|
r.area.Repaint(rect)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repainter) doall() {
|
|
|
|
r.alter(r.img.Rect, color.RGBA{255, 255, 0, 128})
|
|
|
|
r.area.RepaintAll()
|
|
|
|
}
|