diff options
| author | faiface <faiface2202@gmail.com> | 2019-05-09 14:28:25 +0200 |
|---|---|---|
| committer | faiface <faiface2202@gmail.com> | 2019-05-09 14:28:25 +0200 |
| commit | ba4fc4a57f9a38252f708f785f37aa24138dfe09 (patch) | |
| tree | 79bd9c19859933afe9cd792c0282dc77d292391f /examples/paint/main.go | |
| parent | de5d2f5c78da7f8a578ecc25f8e8b1fa90f20264 (diff) | |
| download | gui-ba4fc4a57f9a38252f708f785f37aa24138dfe09.zip | |
change event strings to event types
Diffstat (limited to 'examples/paint/main.go')
| -rw-r--r-- | examples/paint/main.go | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/examples/paint/main.go b/examples/paint/main.go index cd11882..fec06c3 100644 --- a/examples/paint/main.go +++ b/examples/paint/main.go @@ -18,10 +18,9 @@ func ColorPicker(env gui.Env, pick chan<- color.Color, r image.Rectangle, clr co } for event := range env.Events() { - var x, y int - switch { - case event.Matches("mo/down/%d/%d", &x, &y): - if image.Pt(x, y).In(r) { + switch event := event.(type) { + case win.MoDown: + if event.Point.In(r) { pick <- clr } } @@ -43,7 +42,7 @@ func Canvas(env gui.Env, pick <-chan color.Color, r image.Rectangle) { var ( clr = color.Color(color.Black) pressed = false - px, py = 0, 0 + prev image.Point ) for { @@ -56,21 +55,20 @@ func Canvas(env gui.Env, pick <-chan color.Color, r image.Rectangle) { return } - var x, y int - switch { - case event.Matches("mo/down/%d/%d", &x, &y): - if image.Pt(x, y).In(r) { + switch event := event.(type) { + case win.MoDown: + if event.Point.In(r) { pressed = true - px, py = x, y + prev = event.Point } - case event.Matches("mo/up/%d/%d", &x, &y): + case win.MoUp: pressed = false - case event.Matches("mo/move/%d/%d", &x, &y): + case win.MoMove: if pressed { - x0, y0, x1, y1 := px, py, x, y - px, py = x, y + x0, y0, x1, y1 := prev.X, prev.Y, event.X, event.Y + prev = event.Point env.Draw() <- func(drw draw.Image) image.Rectangle { dc.SetColor(clr) @@ -118,8 +116,8 @@ func run() { go Canvas(mux.MakeEnv(), pick, image.Rect(0, 0, 750, 600)) for event := range env.Events() { - switch { - case event.Matches("wi/close"): + switch event.(type) { + case win.WiClose: close(env.Draw()) } } |