| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Go Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style | |
| 3 // license that can be found in the LICENSE file. | |
| 4 | |
| 5 // +build linux,!android | |
| 6 | |
| 7 package app | |
| 8 | |
| 9 /* | |
| 10 Simple on-screen app debugging for X11. Not an officially supported | |
| 11 development target for apps, as screens with mice are very different | |
| 12 than screens with touch panels. | |
| 13 | |
| 14 On Ubuntu 14.04 'Trusty', you may have to install these libraries: | |
| 15 sudo apt-get install libegl1-mesa-dev libgles2-mesa-dev libx11-dev | |
| 16 */ | |
| 17 | |
| 18 /* | |
| 19 #cgo LDFLAGS: -lEGL -lGLESv2 -lX11 | |
| 20 | |
| 21 void runApp(void); | |
| 22 */ | |
| 23 import "C" | |
| 24 import ( | |
| 25 "runtime" | |
| 26 "sync" | |
| 27 | |
| 28 "golang.org/x/mobile/event" | |
| 29 "golang.org/x/mobile/geom" | |
| 30 ) | |
| 31 | |
| 32 var cb Callbacks | |
| 33 | |
| 34 func run(callbacks Callbacks) { | |
| 35 runtime.LockOSThread() | |
| 36 cb = callbacks | |
| 37 C.runApp() | |
| 38 } | |
| 39 | |
| 40 //export onResize | |
| 41 func onResize(w, h int) { | |
| 42 // TODO(nigeltao): don't assume 72 DPI. DisplayWidth / DisplayWidthMM | |
| 43 // is probably the best place to start looking. | |
| 44 geom.PixelsPerPt = 1 | |
| 45 geom.Width = geom.Pt(w) | |
| 46 geom.Height = geom.Pt(h) | |
| 47 } | |
| 48 | |
| 49 var events struct { | |
| 50 sync.Mutex | |
| 51 pending []event.Touch | |
| 52 } | |
| 53 | |
| 54 func sendTouch(ty event.TouchType, x, y float32) { | |
| 55 events.Lock() | |
| 56 events.pending = append(events.pending, event.Touch{ | |
| 57 Type: ty, | |
| 58 Loc: geom.Point{ | |
| 59 X: geom.Pt(x), | |
| 60 Y: geom.Pt(y), | |
| 61 }, | |
| 62 }) | |
| 63 events.Unlock() | |
| 64 } | |
| 65 | |
| 66 //export onTouchStart | |
| 67 func onTouchStart(x, y float32) { sendTouch(event.TouchStart, x, y) } | |
| 68 | |
| 69 //export onTouchMove | |
| 70 func onTouchMove(x, y float32) { sendTouch(event.TouchMove, x, y) } | |
| 71 | |
| 72 //export onTouchEnd | |
| 73 func onTouchEnd(x, y float32) { sendTouch(event.TouchEnd, x, y) } | |
| 74 | |
| 75 //export onDraw | |
| 76 func onDraw() { | |
| 77 events.Lock() | |
| 78 pending := events.pending | |
| 79 events.pending = nil | |
| 80 events.Unlock() | |
| 81 | |
| 82 for _, e := range pending { | |
| 83 if cb.Touch != nil { | |
| 84 cb.Touch(e) | |
| 85 } | |
| 86 } | |
| 87 if cb.Draw != nil { | |
| 88 cb.Draw() | |
| 89 } | |
| 90 } | |
| OLD | NEW |