Started implementing a test of Area.RepaintAll()/Repaint().
This commit is contained in:
parent
2c305c8785
commit
4e2315e757
|
@ -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
|
||||
|
|
|
@ -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 }
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue