summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/yz_icons_test.go20
-rw-r--r--redo/yz_repaint_test.go46
-rw-r--r--redo/zz_test.go5
3 files changed, 70 insertions, 1 deletions
diff --git a/redo/yz_icons_test.go b/redo/yz_icons_test.go
index 591807d..a85f58e 100644
--- a/redo/yz_icons_test.go
+++ b/redo/yz_icons_test.go
@@ -16,6 +16,8 @@ type icon struct {
Name string
}
+var firstimg *image.RGBA
+
func readIcons() ([]icon, ImageList) {
out := make([]icon, len(icons))
outil := NewImageList()
@@ -27,6 +29,9 @@ func readIcons() ([]icon, ImageList) {
}
img := image.NewRGBA(png.Bounds())
draw.Draw(img, img.Rect, png, image.ZP, draw.Src)
+ if firstimg == nil {
+ firstimg = img
+ }
out[i].Icon = ImageIndex(i)
out[i].Name = icons[i].name
outil.Append(img)
@@ -34,6 +39,21 @@ func readIcons() ([]icon, ImageList) {
return out, outil
}
+func tileImage(times int) *image.RGBA {
+ dx := firstimg.Rect.Dx()
+ dy := firstimg.Rect.Dy()
+ res := image.NewRGBA(image.Rect(0, 0, times * dx, times * dy))
+ r := image.Rect(0, 0, dx, dy)
+ for y := 0; y < times; y++ {
+ rr := r.Add(image.Pt(0, y * dy))
+ for x := 0; x < times; x++ {
+ draw.Draw(res, rr, firstimg, image.ZP, draw.Src)
+ rr = rr.Add(image.Pt(dx, 0))
+ }
+ }
+ return res
+}
+
var icons = []struct {
data []byte
name string
diff --git a/redo/yz_repaint_test.go b/redo/yz_repaint_test.go
new file mode 100644
index 0000000..99cc515
--- /dev/null
+++ b/redo/yz_repaint_test.go
@@ -0,0 +1,46 @@
+// 21 august 2014
+
+package ui
+
+import (
+ "image"
+)
+
+type repainter struct {
+ img *image.RGBA
+ area Area
+ x TextField
+ y TextField
+ width TextField
+ height TextField
+ repaint Button
+ all Button
+ stack Stack
+}
+
+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.x = NewTextField()
+ r.y = NewTextField()
+ r.width = NewTextField()
+ r.height = NewTextField()
+ r.repaint = NewButton("Rect")
+ r.all = NewButton("All")
+ 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) {}
+func (r *repainter) Key(ke KeyEvent) bool { return false }
diff --git a/redo/zz_test.go b/redo/zz_test.go
index e8ccead..ab6591e 100644
--- a/redo/zz_test.go
+++ b/redo/zz_test.go
@@ -34,6 +34,7 @@ var ddata = []dtype{
type testwin struct {
t Tab
w Window
+ repainter *repainter
fe *ForeignEvent
festack Stack
festart Button
@@ -134,8 +135,10 @@ func (tw *testwin) make(done chan struct{}) {
done <- struct{}{}
return true
})
+ tw.icons, tw.il = readIcons() // repainter uses these
+ tw.repainter = newRepainter(15)
+ tw.t.Append("Repaint", tw.repainter.stack)
tw.addfe()
- tw.icons, tw.il = readIcons()
tw.icontbl = NewTable(reflect.TypeOf(icon{}))
tw.icontbl.Lock()
idq := tw.icontbl.Data().(*[]icon)