aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfaiface <faiface@ksp.sk>2017-08-20 01:01:03 +0200
committerfaiface <faiface@ksp.sk>2017-08-20 01:01:03 +0200
commit4ae926b8859d7246ffb9b68e453668aa19f486f5 (patch)
tree03ca0118731597c3ce20d63dc98b0affb879f7ec
parentbc59c901a81aab2d24d8da3eacfe55a8669f86c6 (diff)
downloadgui-4ae926b8859d7246ffb9b68e453668aa19f486f5.zip
layout: change ImageFlusher -> EventImageFlusher and propagate events
-rw-r--r--layout/layer.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/layout/layer.go b/layout/layer.go
index 238e972..398ade9 100644
--- a/layout/layer.go
+++ b/layout/layer.go
@@ -3,31 +3,48 @@ package layout
import (
"container/list"
"errors"
+ "fmt"
"image"
"image/draw"
"github.com/faiface/gui/event"
)
-type ImageFlusher interface {
+type EventImageFlusher interface {
+ Event(pattern string, handler func(event string) bool)
Image() *image.RGBA
Flush(r image.Rectangle)
}
type LayerList struct {
event.Dispatch
- dst ImageFlusher
+ dst EventImageFlusher
layers list.List
}
-func (l *LayerList) Dst(dst ImageFlusher) {
- l.dst = dst
- for e := l.layers.Back(); e != nil; e = e.Prev() {
- layer := e.Value.(*Layer)
- rgba := image.NewRGBA(dst.Image().Bounds())
- draw.Draw(rgba, layer.rgba.Bounds(), layer.rgba, layer.rgba.Bounds().Min, draw.Src)
- layer.rgba = rgba
- }
+func NewLayerList(dst EventImageFlusher) *LayerList {
+ l := &LayerList{dst: dst}
+
+ dst.Event("", l.Happen)
+
+ l.Event("resize", func(event string) bool {
+ var x1, y1, x2, y2 int
+ fmt.Sscanf(event, "%d/%d/%d/%d", &x1, &y1, &x2, &y2)
+
+ for e := l.layers.Back(); e != nil; e = e.Prev() {
+ layer := e.Value.(*Layer)
+ rgba := image.NewRGBA(dst.Image().Bounds())
+ draw.Draw(rgba, layer.rgba.Bounds(), layer.rgba, layer.rgba.Bounds().Min, draw.Src)
+ layer.rgba = rgba
+ }
+
+ return false
+ })
+
+ r := dst.Image().Bounds()
+ l.Happen(event.Sprint("resize", r.Min.X, r.Min.Y, r.Max.X, r.Max.Y))
+
+ return l
}
func (l *LayerList) Push() *Layer {