From 09db3d0b721685fda1cee71833ec4dd0fe1b4c9a Mon Sep 17 00:00:00 2001 From: faiface Date: Tue, 29 Aug 2017 00:35:28 +0200 Subject: start over, concurrency full on --- layout/interface.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 layout/interface.go (limited to 'layout/interface.go') 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 +} -- cgit v1.2.3