diff options
| author | faiface <faiface@ksp.sk> | 2017-08-29 00:35:28 +0200 |
|---|---|---|
| committer | faiface <faiface@ksp.sk> | 2017-08-29 00:35:28 +0200 |
| commit | 09db3d0b721685fda1cee71833ec4dd0fe1b4c9a (patch) | |
| tree | 7473dfeb9d1b4664c25be1e7cc939a804855c650 /layout/interface.go | |
| parent | 0c433c89a218c428cbc6dc093d4b4d6dd8174114 (diff) | |
| download | gui-09db3d0b721685fda1cee71833ec4dd0fe1b4c9a.zip | |
start over, concurrency full on
Diffstat (limited to 'layout/interface.go')
| -rw-r--r-- | layout/interface.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/layout/interface.go b/layout/interface.go new file mode 100644 index 0000000..1dcf34a --- /dev/null +++ b/layout/interface.go @@ -0,0 +1,40 @@ +package layout + +import ( + "fmt" + "image" + "image/draw" +) + +type EventDrawer interface { + Event() <-chan EventConsume + Draw() chan<- ImageFlush +} + +type EventConsume struct { + Event string + Consume chan<- bool +} + +func SendEvent(ch chan<- EventConsume, format string, a ...interface{}) (consume <-chan bool) { + cons := make(chan bool) + ch <- EventConsume{fmt.Sprintf(format, a...), cons} + return cons +} + +func (ec EventConsume) Matches(format string, a ...interface{}) bool { + _, err := fmt.Sscanf(ec.Event, format, a...) + return err == nil +} + +type ImageFlush struct { + Image chan<- draw.Image + Flush <-chan image.Rectangle +} + +func SendDraw(ch chan<- ImageFlush) (img <-chan draw.Image, flush chan<- image.Rectangle) { + imgC := make(chan draw.Image) + flushC := make(chan image.Rectangle) + ch <- ImageFlush{imgC, flushC} + return imgC, flushC +} |