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 {
|
2014-10-02 09:05:53 -05:00
|
|
|
img *image.RGBA
|
|
|
|
area Area
|
|
|
|
x TextField
|
|
|
|
y TextField
|
|
|
|
width TextField
|
|
|
|
height TextField
|
|
|
|
repaint Button
|
|
|
|
all Button
|
|
|
|
grid Grid
|
|
|
|
|
|
|
|
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-31 17:59:55 -05:00
|
|
|
grid := NewGrid()
|
2014-09-03 17:36:33 -05:00
|
|
|
grid.Add(r.area, nil, South, true, Fill, true, Fill, 3, 6)
|
|
|
|
grid.Add(r.x, nil, East, true, Fill, false, LeftTop, 1, 1)
|
|
|
|
grid.Add(r.y, nil, South, true, Fill, false, LeftTop, 1, 1)
|
|
|
|
grid.Add(r.width, nil, South, true, Fill, false, LeftTop, 1, 1)
|
|
|
|
grid.Add(r.height, nil, South, true, Fill, false, LeftTop, 1, 1)
|
|
|
|
grid.Add(r.repaint, nil, South, true, Fill, true, Fill, 1, 1)
|
|
|
|
grid.Add(r.all, nil, South, true, Center, false, LeftTop, 1, 1)
|
|
|
|
r.grid = grid
|
2014-08-21 14:32:36 -05:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2014-10-02 09:05:53 -05:00
|
|
|
func (r *repainter) Paint(rect image.Rectangle) *image.RGBA {
|
2014-08-21 14:32:36 -05:00
|
|
|
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() {
|
2014-10-02 09:05:53 -05:00
|
|
|
rect := image.Rect(r.xv, r.yv, r.xv+r.wv, r.yv+r.hv)
|
2014-08-21 17:23:51 -05:00
|
|
|
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()
|
|
|
|
}
|