1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package layout
import (
"image"
"github.com/faiface/gui/event"
)
func Sub(eif EventImageFlusher, r image.Rectangle) EventImageFlusher {
s := &sub{
eif: eif,
}
s.Event("resize", func(evt string) bool {
var x1, y1, x2, y2 int
event.Sscan(evt, &x1, &y1, &x2, &y2)
r := image.Rect(x1, y1, x2, y2)
s.sub = eif.Image().SubImage(r).(*image.RGBA)
return false
})
s.Happen(event.Sprint("resize", r.Min.X, r.Min.Y, r.Max.X, r.Max.Y))
return s
}
type sub struct {
event.Dispatch
eif EventImageFlusher
sub *image.RGBA
}
func (s *sub) Image() *image.RGBA {
return s.sub
}
func (s *sub) Flush(r image.Rectangle) {
r = s.sub.Bounds().Intersect(r)
s.eif.Flush(r)
}
|