diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-30 23:02:02 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-30 23:02:02 -0400 |
| commit | 77bf566ebbcb62acd4d08d905d9542d6ff9b6b80 (patch) | |
| tree | eeb8e72bc3bf57f5be7f0c0af4319189ac6de838 /yz_repaint_test.go | |
| parent | 155899c65ed32245e2ccad4197a10c77017d835b (diff) | |
...in with the new.
Diffstat (limited to 'yz_repaint_test.go')
| -rw-r--r-- | yz_repaint_test.go | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/yz_repaint_test.go b/yz_repaint_test.go new file mode 100644 index 0000000..1c8eb55 --- /dev/null +++ b/yz_repaint_test.go @@ -0,0 +1,125 @@ +// 21 august 2014 + +package ui + +import ( + "image" + "image/color" + "image/draw" + "strconv" +) + +type repainter struct { + img *image.RGBA + area Area + x TextField + y TextField + width TextField + height TextField + repaint Button + all Button + stack Stack + + xv int + yv int + wv int + hv int +} + +func newRepainter(times int) *repainter { + r := new(repainter) + r.img = tileImage(times) + r.area = NewArea(r.img.Rect.Dx(), r.img.Rect.Dy(), r) + r.area.OnTextFieldDismissed(r.tfdone) + r.x = NewTextField() + r.x.OnChanged(r.setx) + r.y = NewTextField() + r.y.OnChanged(r.sety) + r.width = NewTextField() + r.width.OnChanged(r.setwidth) + r.height = NewTextField() + r.height.OnChanged(r.setheight) + r.repaint = NewButton("Rect") + r.repaint.OnClicked(r.dorect) + r.all = NewButton("All") + r.all.OnClicked(r.doall) + 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) +} + +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()) +} + +func (r *repainter) Key(ke KeyEvent) bool { return false } + +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() +} |
