mirror of
https://github.com/go-i2p/gomobile-java.git
synced 2025-07-13 11:54:44 -04:00
event/config: rename to event/size.
Change-Id: I908b5f0818da32b2b040f430ebcc3762eb6f7570 Reviewed-on: https://go-review.googlesource.com/13601 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
@ -53,9 +53,9 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/mobile/app/internal/callfn"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/event/touch"
|
||||
"golang.org/x/mobile/geom"
|
||||
"golang.org/x/mobile/gl"
|
||||
@ -166,7 +166,7 @@ func onContentRectChanged(activity *C.ANativeActivity, rect *C.ARect) {
|
||||
}
|
||||
|
||||
type windowConfig struct {
|
||||
orientation config.Orientation
|
||||
orientation size.Orientation
|
||||
pixelsPerPt float32
|
||||
}
|
||||
|
||||
@ -202,12 +202,12 @@ func windowConfigRead(activity *C.ANativeActivity) windowConfig {
|
||||
}
|
||||
}
|
||||
|
||||
o := config.OrientationUnknown
|
||||
o := size.OrientationUnknown
|
||||
switch orient {
|
||||
case C.ACONFIGURATION_ORIENTATION_PORT:
|
||||
o = config.OrientationPortrait
|
||||
o = size.OrientationPortrait
|
||||
case C.ACONFIGURATION_ORIENTATION_LAND:
|
||||
o = config.OrientationLandscape
|
||||
o = size.OrientationLandscape
|
||||
}
|
||||
|
||||
return windowConfig{
|
||||
@ -253,7 +253,7 @@ func main(f func(App)) {
|
||||
|
||||
var q *C.AInputQueue
|
||||
var pixelsPerPt float32
|
||||
var orientation config.Orientation
|
||||
var orientation size.Orientation
|
||||
|
||||
// Android can send a windowRedrawNeeded event any time, including
|
||||
// in the middle of a paint cycle. The redraw event may have changed
|
||||
@ -290,7 +290,7 @@ func main(f func(App)) {
|
||||
sendLifecycle(lifecycle.StageFocused)
|
||||
widthPx := int(C.ANativeWindow_getWidth(w))
|
||||
heightPx := int(C.ANativeWindow_getHeight(w))
|
||||
eventsIn <- config.Event{
|
||||
eventsIn <- size.Event{
|
||||
WidthPx: widthPx,
|
||||
HeightPx: heightPx,
|
||||
WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt),
|
||||
|
@ -7,9 +7,9 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/gl"
|
||||
_ "golang.org/x/mobile/internal/mobileinit"
|
||||
)
|
||||
@ -26,10 +26,10 @@ func Main(f func(App)) {
|
||||
type App interface {
|
||||
// Events returns the events channel. It carries events from the system to
|
||||
// the app. The type of such events include:
|
||||
// - config.Event
|
||||
// - lifecycle.Event
|
||||
// - mouse.Event
|
||||
// - paint.Event
|
||||
// - size.Event
|
||||
// - touch.Event
|
||||
// from the golang.org/x/mobile/event/etc packages. Other packages may
|
||||
// define other event types that are carried on this channel.
|
||||
@ -175,7 +175,7 @@ func pump(dst chan interface{}) (src chan interface{}) {
|
||||
// KitKat). If only x11 needs this, should we move this to x11.go??
|
||||
func registerGLViewportFilter() {
|
||||
RegisterFilter(func(e interface{}) interface{} {
|
||||
if e, ok := e.(config.Event); ok {
|
||||
if e, ok := e.(size.Event); ok {
|
||||
gl.Viewport(0, 0, e.WidthPx, e.HeightPx)
|
||||
}
|
||||
return e
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/mobile/app/internal/apptest"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/size"
|
||||
)
|
||||
|
||||
// TestAndroidApp tests the lifecycle, event, and window semantics of a
|
||||
@ -110,12 +110,12 @@ func TestAndroidApp(t *testing.T) {
|
||||
}
|
||||
|
||||
var pixelsPerPt float32
|
||||
var orientation config.Orientation
|
||||
var orientation size.Orientation
|
||||
|
||||
comm.Recv("hello_from_testapp")
|
||||
comm.Send("hello_from_host")
|
||||
comm.Recv("lifecycle_visible")
|
||||
comm.Recv("config", &pixelsPerPt, &orientation)
|
||||
comm.Recv("size", &pixelsPerPt, &orientation)
|
||||
if pixelsPerPt < 0.1 {
|
||||
t.Fatalf("bad pixelsPerPt: %f", pixelsPerPt)
|
||||
}
|
||||
@ -135,13 +135,13 @@ func TestAndroidApp(t *testing.T) {
|
||||
}
|
||||
|
||||
rotate(rotationLandscape)
|
||||
comm.Recv("config", &pixelsPerPt, &orientation)
|
||||
if want := config.OrientationLandscape; orientation != want {
|
||||
comm.Recv("size", &pixelsPerPt, &orientation)
|
||||
if want := size.OrientationLandscape; orientation != want {
|
||||
t.Errorf("want orientation %d, got %d", want, orientation)
|
||||
}
|
||||
rotate(rotationPortrait)
|
||||
comm.Recv("config", &pixelsPerPt, &orientation)
|
||||
if want := config.OrientationPortrait; orientation != want {
|
||||
comm.Recv("size", &pixelsPerPt, &orientation)
|
||||
if want := size.OrientationPortrait; orientation != want {
|
||||
t.Errorf("want orientation %d, got %d", want, orientation)
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,10 @@ import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/key"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/event/touch"
|
||||
"golang.org/x/mobile/geom"
|
||||
"golang.org/x/mobile/gl"
|
||||
@ -116,7 +116,7 @@ var windowHeightPx float32
|
||||
//export setGeom
|
||||
func setGeom(pixelsPerPt float32, widthPx, heightPx int) {
|
||||
windowHeightPx = float32(heightPx)
|
||||
eventsIn <- config.Event{
|
||||
eventsIn <- size.Event{
|
||||
WidthPx: widthPx,
|
||||
HeightPx: heightPx,
|
||||
WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt),
|
||||
|
@ -29,9 +29,9 @@ import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/event/touch"
|
||||
"golang.org/x/mobile/geom"
|
||||
"golang.org/x/mobile/gl"
|
||||
@ -100,16 +100,16 @@ func setScreen(scale int) {
|
||||
|
||||
//export updateConfig
|
||||
func updateConfig(width, height, orientation int32) {
|
||||
o := config.OrientationUnknown
|
||||
o := size.OrientationUnknown
|
||||
switch orientation {
|
||||
case C.UIDeviceOrientationPortrait, C.UIDeviceOrientationPortraitUpsideDown:
|
||||
o = config.OrientationPortrait
|
||||
o = size.OrientationPortrait
|
||||
case C.UIDeviceOrientationLandscapeLeft, C.UIDeviceOrientationLandscapeRight:
|
||||
o = config.OrientationLandscape
|
||||
o = size.OrientationLandscape
|
||||
}
|
||||
widthPx := screenScale * int(width)
|
||||
heightPx := screenScale * int(height)
|
||||
eventsIn <- config.Event{
|
||||
eventsIn <- size.Event{
|
||||
WidthPx: widthPx,
|
||||
HeightPx: heightPx,
|
||||
WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt),
|
||||
|
@ -69,10 +69,10 @@ goroutine as other code that calls OpenGL.
|
||||
An event is represented by the empty interface type interface{}. Any value can
|
||||
be an event. Commonly used types include Event types defined by the following
|
||||
packages:
|
||||
- golang.org/x/mobile/event/config
|
||||
- golang.org/x/mobile/event/lifecycle
|
||||
- golang.org/x/mobile/event/mouse
|
||||
- golang.org/x/mobile/event/paint
|
||||
- golang.org/x/mobile/event/size
|
||||
- golang.org/x/mobile/event/touch
|
||||
For example, touch.Event is the type that represents touch events. Other
|
||||
packages may define their own events, and send them on an app's event channel.
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/app/internal/apptest"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/event/touch"
|
||||
)
|
||||
|
||||
@ -40,7 +40,6 @@ func main() {
|
||||
comm.Recv("hello_from_host")
|
||||
|
||||
sendPainting := false
|
||||
var c config.Event
|
||||
for e := range a.Events() {
|
||||
switch e := app.Filter(e).(type) {
|
||||
case lifecycle.Event:
|
||||
@ -51,9 +50,8 @@ func main() {
|
||||
case lifecycle.CrossOff:
|
||||
comm.Send("lifecycle_not_visible")
|
||||
}
|
||||
case config.Event:
|
||||
c = e
|
||||
comm.Send("config", c.PixelsPerPt, c.Orientation)
|
||||
case size.Event:
|
||||
comm.Send("size", e.PixelsPerPt, e.Orientation)
|
||||
case paint.Event:
|
||||
if sendPainting {
|
||||
comm.Send("paint")
|
||||
|
@ -27,9 +27,9 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/event/touch"
|
||||
"golang.org/x/mobile/geom"
|
||||
"golang.org/x/mobile/gl"
|
||||
@ -79,7 +79,7 @@ func onResize(w, h int) {
|
||||
// TODO(nigeltao): don't assume 72 DPI. DisplayWidth and DisplayWidthMM
|
||||
// is probably the best place to start looking.
|
||||
pixelsPerPt := float32(1)
|
||||
eventsIn <- config.Event{
|
||||
eventsIn <- size.Event{
|
||||
WidthPx: w,
|
||||
HeightPx: h,
|
||||
WidthPt: geom.Pt(w),
|
||||
|
@ -2,11 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package config defines an event for the dimensions and physical resolution
|
||||
// of the app's window.
|
||||
// Package size defines an event for the dimensions, physical resolution and
|
||||
// orientation of the app's window.
|
||||
//
|
||||
// See the golang.org/x/mobile/app package for details on the event model.
|
||||
package config // import "golang.org/x/mobile/event/config"
|
||||
package size // import "golang.org/x/mobile/event/size"
|
||||
|
||||
import (
|
||||
"image"
|
||||
@ -14,7 +14,8 @@ import (
|
||||
"golang.org/x/mobile/geom"
|
||||
)
|
||||
|
||||
// Event holds the dimensions and physical resolution of the app's window.
|
||||
// Event holds the dimensions, physical resolution and orientation of the app's
|
||||
// window.
|
||||
type Event struct {
|
||||
// WidthPx and HeightPx are the window's dimensions in pixels.
|
||||
WidthPx, HeightPx int
|
||||
@ -35,8 +36,8 @@ type Event struct {
|
||||
Orientation Orientation
|
||||
}
|
||||
|
||||
// Bounds returns the window's bounds in pixels, at the time this configuration
|
||||
// event was sent.
|
||||
// Bounds returns the window's bounds in pixels, at the time this size event
|
||||
// was sent.
|
||||
//
|
||||
// The top-left pixel is always (0, 0). The bottom-right pixel is given by the
|
||||
// width and height.
|
@ -41,9 +41,9 @@ import (
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/asset"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/app/debug"
|
||||
"golang.org/x/mobile/exp/audio"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
@ -66,7 +66,7 @@ var (
|
||||
|
||||
player *audio.Player
|
||||
|
||||
cfg config.Event
|
||||
sz size.Event
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -80,8 +80,8 @@ func main() {
|
||||
case lifecycle.CrossOff:
|
||||
onStop()
|
||||
}
|
||||
case config.Event:
|
||||
cfg = e
|
||||
case size.Event:
|
||||
sz = e
|
||||
case paint.Event:
|
||||
onPaint()
|
||||
a.EndPaint(e)
|
||||
@ -112,8 +112,8 @@ func onPaint() {
|
||||
gl.ClearColor(1, 1, 1, 1)
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
now := clock.Time(time.Since(startTime) * 60 / time.Second)
|
||||
eng.Render(scene, now, cfg)
|
||||
debug.DrawFPS(cfg)
|
||||
eng.Render(scene, now, sz)
|
||||
debug.DrawFPS(sz)
|
||||
}
|
||||
|
||||
func newNode() *sprite.Node {
|
||||
@ -136,7 +136,7 @@ func loadScene() {
|
||||
dx, dy := float32(1), float32(1)
|
||||
|
||||
n := newNode()
|
||||
// TODO: Shouldn't arranger pass the config.Event?
|
||||
// TODO: Shouldn't arranger pass the size.Event?
|
||||
n.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
|
||||
eng.SetSubTex(n, gopher)
|
||||
|
||||
@ -148,11 +148,11 @@ func loadScene() {
|
||||
dy = 1
|
||||
boing()
|
||||
}
|
||||
if x+width > float32(cfg.WidthPt) {
|
||||
if x+width > float32(sz.WidthPt) {
|
||||
dx = -1
|
||||
boing()
|
||||
}
|
||||
if y+height > float32(cfg.HeightPt) {
|
||||
if y+height > float32(sz.HeightPt) {
|
||||
dy = -1
|
||||
boing()
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/event/touch"
|
||||
"golang.org/x/mobile/exp/app/debug"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
@ -57,7 +57,7 @@ var (
|
||||
|
||||
func main() {
|
||||
app.Main(func(a app.App) {
|
||||
var c config.Event
|
||||
var sz size.Event
|
||||
for e := range a.Events() {
|
||||
switch e := app.Filter(e).(type) {
|
||||
case lifecycle.Event:
|
||||
@ -67,12 +67,12 @@ func main() {
|
||||
case lifecycle.CrossOff:
|
||||
onStop()
|
||||
}
|
||||
case config.Event:
|
||||
c = e
|
||||
touchX = float32(c.WidthPx / 2)
|
||||
touchY = float32(c.HeightPx / 2)
|
||||
case size.Event:
|
||||
sz = e
|
||||
touchX = float32(sz.WidthPx / 2)
|
||||
touchY = float32(sz.HeightPx / 2)
|
||||
case paint.Event:
|
||||
onPaint(c)
|
||||
onPaint(sz)
|
||||
a.EndPaint(e)
|
||||
case touch.Event:
|
||||
touchX = e.X
|
||||
@ -107,7 +107,7 @@ func onStop() {
|
||||
gl.DeleteBuffer(buf)
|
||||
}
|
||||
|
||||
func onPaint(c config.Event) {
|
||||
func onPaint(sz size.Event) {
|
||||
gl.ClearColor(1, 0, 0, 1)
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
|
||||
@ -119,7 +119,7 @@ func onPaint(c config.Event) {
|
||||
}
|
||||
gl.Uniform4f(color, 0, green, 0, 1)
|
||||
|
||||
gl.Uniform2f(offset, touchX/float32(c.WidthPx), touchY/float32(c.HeightPx))
|
||||
gl.Uniform2f(offset, touchX/float32(sz.WidthPx), touchY/float32(sz.HeightPx))
|
||||
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, buf)
|
||||
gl.EnableVertexAttribArray(position)
|
||||
@ -127,7 +127,7 @@ func onPaint(c config.Event) {
|
||||
gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)
|
||||
gl.DisableVertexAttribArray(position)
|
||||
|
||||
debug.DrawFPS(c)
|
||||
debug.DrawFPS(sz)
|
||||
}
|
||||
|
||||
var triangleData = f32.Bytes(binary.LittleEndian,
|
||||
|
@ -43,8 +43,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/app/debug"
|
||||
"golang.org/x/mobile/gl"
|
||||
)
|
||||
@ -54,13 +54,13 @@ func main() {
|
||||
go checkNetwork()
|
||||
|
||||
app.Main(func(a app.App) {
|
||||
var c config.Event
|
||||
var sz size.Event
|
||||
for e := range a.Events() {
|
||||
switch e := app.Filter(e).(type) {
|
||||
case config.Event:
|
||||
c = e
|
||||
case size.Event:
|
||||
sz = e
|
||||
case paint.Event:
|
||||
onDraw(c)
|
||||
onDraw(sz)
|
||||
a.EndPaint(e)
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ func checkNetwork() {
|
||||
ok = true
|
||||
}
|
||||
|
||||
func onDraw(c config.Event) {
|
||||
func onDraw(sz size.Event) {
|
||||
select {
|
||||
case <-determined:
|
||||
if ok {
|
||||
@ -95,5 +95,5 @@ func onDraw(c config.Event) {
|
||||
}
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
|
||||
debug.DrawFPS(c)
|
||||
debug.DrawFPS(sz)
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ import (
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/asset"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/paint"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/app/debug"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
"golang.org/x/mobile/exp/sprite"
|
||||
@ -56,28 +56,28 @@ var (
|
||||
|
||||
func main() {
|
||||
app.Main(func(a app.App) {
|
||||
var c config.Event
|
||||
var sz size.Event
|
||||
for e := range a.Events() {
|
||||
switch e := app.Filter(e).(type) {
|
||||
case config.Event:
|
||||
c = e
|
||||
case size.Event:
|
||||
sz = e
|
||||
case paint.Event:
|
||||
onPaint(c)
|
||||
onPaint(sz)
|
||||
a.EndPaint(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func onPaint(c config.Event) {
|
||||
func onPaint(sz size.Event) {
|
||||
if scene == nil {
|
||||
loadScene()
|
||||
}
|
||||
gl.ClearColor(1, 1, 1, 1)
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
now := clock.Time(time.Since(startTime) * 60 / time.Second)
|
||||
eng.Render(scene, now, c)
|
||||
debug.DrawFPS(c)
|
||||
eng.Render(scene, now, sz)
|
||||
debug.DrawFPS(sz)
|
||||
}
|
||||
|
||||
func newNode() *sprite.Node {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/gl/glutil"
|
||||
"golang.org/x/mobile/geom"
|
||||
)
|
||||
@ -21,17 +21,17 @@ var lastDraw = time.Now()
|
||||
|
||||
var fps struct {
|
||||
mu sync.Mutex
|
||||
c config.Event
|
||||
sz size.Event
|
||||
m *glutil.Image
|
||||
}
|
||||
|
||||
// DrawFPS draws the per second framerate in the bottom-left of the screen.
|
||||
func DrawFPS(c config.Event) {
|
||||
func DrawFPS(sz size.Event) {
|
||||
const imgW, imgH = 7*(fontWidth+1) + 1, fontHeight + 2
|
||||
|
||||
fps.mu.Lock()
|
||||
if fps.c != c || fps.m == nil {
|
||||
fps.c = c
|
||||
if fps.sz != sz || fps.m == nil {
|
||||
fps.sz = sz
|
||||
fps.m = glutil.NewImage(imgW, imgH)
|
||||
}
|
||||
fps.mu.Unlock()
|
||||
@ -67,10 +67,10 @@ func DrawFPS(c config.Event) {
|
||||
|
||||
fps.m.Upload()
|
||||
fps.m.Draw(
|
||||
c,
|
||||
geom.Point{0, c.HeightPt - imgH},
|
||||
geom.Point{imgW, c.HeightPt - imgH},
|
||||
geom.Point{0, c.HeightPt},
|
||||
sz,
|
||||
geom.Point{0, sz.HeightPt - imgH},
|
||||
geom.Point{imgW, sz.HeightPt - imgH},
|
||||
geom.Point{0, sz.HeightPt},
|
||||
fps.m.RGBA.Bounds(),
|
||||
)
|
||||
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
"sync"
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/lifecycle"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
"golang.org/x/mobile/geom"
|
||||
"golang.org/x/mobile/gl"
|
||||
@ -225,7 +225,7 @@ func (img *Image) Delete() {
|
||||
|
||||
// Draw draws the srcBounds part of the image onto a parallelogram, defined by
|
||||
// three of its corners, in the current GL framebuffer.
|
||||
func (img *Image) Draw(c config.Event, topLeft, topRight, bottomLeft geom.Point, srcBounds image.Rectangle) {
|
||||
func (img *Image) Draw(sz size.Event, topLeft, topRight, bottomLeft geom.Point, srcBounds image.Rectangle) {
|
||||
// TODO(crawshaw): Adjust viewport for the top bar on android?
|
||||
gl.UseProgram(glimage.program)
|
||||
tex := texmap.get(*img.key)
|
||||
@ -265,12 +265,12 @@ func (img *Image) Draw(c config.Event, topLeft, topRight, bottomLeft geom.Point,
|
||||
// First of all, convert from geom space to framebuffer space. For
|
||||
// later convenience, we divide everything by 2 here: px2 is half of
|
||||
// the P.X co-ordinate (in framebuffer space).
|
||||
px2 := -0.5 + float32(topLeft.X/c.WidthPt)
|
||||
py2 := +0.5 - float32(topLeft.Y/c.HeightPt)
|
||||
qx2 := -0.5 + float32(topRight.X/c.WidthPt)
|
||||
qy2 := +0.5 - float32(topRight.Y/c.HeightPt)
|
||||
sx2 := -0.5 + float32(bottomLeft.X/c.WidthPt)
|
||||
sy2 := +0.5 - float32(bottomLeft.Y/c.HeightPt)
|
||||
px2 := -0.5 + float32(topLeft.X/sz.WidthPt)
|
||||
py2 := +0.5 - float32(topLeft.Y/sz.HeightPt)
|
||||
qx2 := -0.5 + float32(topRight.X/sz.WidthPt)
|
||||
qy2 := +0.5 - float32(topRight.Y/sz.HeightPt)
|
||||
sx2 := -0.5 + float32(bottomLeft.X/sz.WidthPt)
|
||||
sy2 := +0.5 - float32(bottomLeft.Y/sz.HeightPt)
|
||||
// Next, solve for the affine transformation matrix
|
||||
// [ a00 a01 a02 ]
|
||||
// a = [ a10 a11 a12 ]
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/geom"
|
||||
"golang.org/x/mobile/gl"
|
||||
)
|
||||
@ -65,7 +65,7 @@ func TestImage(t *testing.T) {
|
||||
ptW = geom.Pt(50)
|
||||
ptH = geom.Pt(50)
|
||||
)
|
||||
cfg := config.Event{
|
||||
sz := size.Event{
|
||||
WidthPx: pixW,
|
||||
HeightPx: pixH,
|
||||
WidthPt: ptW,
|
||||
@ -109,7 +109,7 @@ func TestImage(t *testing.T) {
|
||||
ptTopRight := geom.Point{32, 0}
|
||||
ptBottomLeft := geom.Point{12, 24 + 16}
|
||||
ptBottomRight := geom.Point{12 + 32, 16}
|
||||
m.Draw(cfg, ptTopLeft, ptTopRight, ptBottomLeft, b)
|
||||
m.Draw(sz, ptTopLeft, ptTopRight, ptBottomLeft, b)
|
||||
|
||||
// For unknown reasons, a windowless OpenGL context renders upside-
|
||||
// down. That is, a quad covering the initial viewport spans:
|
||||
@ -131,8 +131,8 @@ func TestImage(t *testing.T) {
|
||||
}
|
||||
|
||||
drawCross(got, 0, 0)
|
||||
drawCross(got, int(ptTopLeft.X.Px(cfg.PixelsPerPt)), int(ptTopLeft.Y.Px(cfg.PixelsPerPt)))
|
||||
drawCross(got, int(ptBottomRight.X.Px(cfg.PixelsPerPt)), int(ptBottomRight.Y.Px(cfg.PixelsPerPt)))
|
||||
drawCross(got, int(ptTopLeft.X.Px(sz.PixelsPerPt)), int(ptTopLeft.Y.Px(sz.PixelsPerPt)))
|
||||
drawCross(got, int(ptBottomRight.X.Px(sz.PixelsPerPt)), int(ptBottomRight.Y.Px(sz.PixelsPerPt)))
|
||||
drawCross(got, pixW-1, pixH-1)
|
||||
|
||||
const wantPath = "../../../testdata/testpattern-window.png"
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"image"
|
||||
"image/draw"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
"golang.org/x/mobile/exp/gl/glutil"
|
||||
"golang.org/x/mobile/exp/sprite"
|
||||
@ -91,15 +91,15 @@ func (e *engine) SetTransform(n *sprite.Node, m f32.Affine) {
|
||||
e.nodes[n.EngineFields.Index].relTransform = m
|
||||
}
|
||||
|
||||
func (e *engine) Render(scene *sprite.Node, t clock.Time, cfg config.Event) {
|
||||
func (e *engine) Render(scene *sprite.Node, t clock.Time, sz size.Event) {
|
||||
e.absTransforms = append(e.absTransforms[:0], f32.Affine{
|
||||
{1, 0, 0},
|
||||
{0, 1, 0},
|
||||
})
|
||||
e.render(scene, t, cfg)
|
||||
e.render(scene, t, sz)
|
||||
}
|
||||
|
||||
func (e *engine) render(n *sprite.Node, t clock.Time, cfg config.Event) {
|
||||
func (e *engine) render(n *sprite.Node, t clock.Time, sz size.Event) {
|
||||
if n.EngineFields.Index == 0 {
|
||||
panic("glsprite: sprite.Node not registered")
|
||||
}
|
||||
@ -116,7 +116,7 @@ func (e *engine) render(n *sprite.Node, t clock.Time, cfg config.Event) {
|
||||
|
||||
if x := n.EngineFields.SubTex; x.T != nil {
|
||||
x.T.(*texture).glImage.Draw(
|
||||
cfg,
|
||||
sz,
|
||||
geom.Point{
|
||||
geom.Pt(m[0][2]),
|
||||
geom.Pt(m[1][2]),
|
||||
@ -134,7 +134,7 @@ func (e *engine) render(n *sprite.Node, t clock.Time, cfg config.Event) {
|
||||
}
|
||||
|
||||
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||
e.render(c, t, cfg)
|
||||
e.render(c, t, sz)
|
||||
}
|
||||
|
||||
// Pop absTransforms.
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
"golang.org/x/mobile/geom"
|
||||
)
|
||||
@ -38,7 +38,7 @@ func TestAffine(t *testing.T) {
|
||||
ptW = geom.Pt(50)
|
||||
ptH = geom.Pt(50)
|
||||
)
|
||||
cfg := config.Event{
|
||||
sz := size.Event{
|
||||
WidthPx: pixW,
|
||||
HeightPx: pixH,
|
||||
WidthPt: ptW,
|
||||
@ -56,7 +56,7 @@ func TestAffine(t *testing.T) {
|
||||
|
||||
var a f32.Affine
|
||||
a.Identity()
|
||||
a.Scale(&a, cfg.PixelsPerPt, cfg.PixelsPerPt)
|
||||
a.Scale(&a, sz.PixelsPerPt, sz.PixelsPerPt)
|
||||
a.Translate(&a, 0, 24)
|
||||
a.Rotate(&a, float32(math.Asin(12./20)))
|
||||
// See commentary in the render method defined in portable.go.
|
||||
@ -69,8 +69,8 @@ func TestAffine(t *testing.T) {
|
||||
ptBottomRight := geom.Point{12 + 32, 16}
|
||||
|
||||
drawCross(got, 0, 0)
|
||||
drawCross(got, int(ptTopLeft.X.Px(cfg.PixelsPerPt)), int(ptTopLeft.Y.Px(cfg.PixelsPerPt)))
|
||||
drawCross(got, int(ptBottomRight.X.Px(cfg.PixelsPerPt)), int(ptBottomRight.Y.Px(cfg.PixelsPerPt)))
|
||||
drawCross(got, int(ptTopLeft.X.Px(sz.PixelsPerPt)), int(ptTopLeft.Y.Px(sz.PixelsPerPt)))
|
||||
drawCross(got, int(ptBottomRight.X.Px(sz.PixelsPerPt)), int(ptBottomRight.Y.Px(sz.PixelsPerPt)))
|
||||
drawCross(got, pixW-1, pixH-1)
|
||||
|
||||
const wantPath = "../../../testdata/testpattern-window.png"
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
|
||||
xdraw "golang.org/x/image/draw"
|
||||
"golang.org/x/image/math/f64"
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
"golang.org/x/mobile/exp/sprite"
|
||||
"golang.org/x/mobile/exp/sprite/clock"
|
||||
@ -94,13 +94,13 @@ func (e *engine) SetTransform(n *sprite.Node, m f32.Affine) {
|
||||
e.nodes[n.EngineFields.Index].relTransform = m
|
||||
}
|
||||
|
||||
func (e *engine) Render(scene *sprite.Node, t clock.Time, cfg config.Event) {
|
||||
func (e *engine) Render(scene *sprite.Node, t clock.Time, sz size.Event) {
|
||||
// Affine transforms are done in geom.Pt. When finally drawing
|
||||
// the geom.Pt onto an image.Image we need to convert to system
|
||||
// pixels. We scale by cfg.PixelsPerPt to do this.
|
||||
// pixels. We scale by sz.PixelsPerPt to do this.
|
||||
e.absTransforms = append(e.absTransforms[:0], f32.Affine{
|
||||
{cfg.PixelsPerPt, 0, 0},
|
||||
{0, cfg.PixelsPerPt, 0},
|
||||
{sz.PixelsPerPt, 0, 0},
|
||||
{0, sz.PixelsPerPt, 0},
|
||||
})
|
||||
e.render(scene, t)
|
||||
}
|
||||
@ -130,7 +130,7 @@ func (e *engine) render(n *sprite.Node, t clock.Time) {
|
||||
// should have the dimensions (1pt, 1pt). To do this we divide
|
||||
// by the pixel width and height, reducing the texture to
|
||||
// (1px, 1px) of the destination image. Multiplying by
|
||||
// cfg.PixelsPerPt, done in Render above, makes it (1pt, 1pt).
|
||||
// sz.PixelsPerPt, done in Render above, makes it (1pt, 1pt).
|
||||
dx, dy := x.R.Dx(), x.R.Dy()
|
||||
if dx > 0 && dy > 0 {
|
||||
m.Scale(&m, 1/float32(dx), 1/float32(dy))
|
||||
|
@ -20,7 +20,7 @@
|
||||
// quantize time.Now() to a clock.Time
|
||||
// process UI events
|
||||
// modify the scene's nodes and animations (Arranger values)
|
||||
// e.Render(scene, t, c)
|
||||
// e.Render(scene, t, sz)
|
||||
// }
|
||||
package sprite // import "golang.org/x/mobile/exp/sprite"
|
||||
|
||||
@ -28,7 +28,7 @@ import (
|
||||
"image"
|
||||
"image/draw"
|
||||
|
||||
"golang.org/x/mobile/event/config"
|
||||
"golang.org/x/mobile/event/size"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
"golang.org/x/mobile/exp/sprite/clock"
|
||||
)
|
||||
@ -60,7 +60,7 @@ type Engine interface {
|
||||
|
||||
// Render renders the scene arranged at the given time, for the given
|
||||
// window configuration (dimensions and resolution).
|
||||
Render(scene *Node, t clock.Time, c config.Event)
|
||||
Render(scene *Node, t clock.Time, sz size.Event)
|
||||
}
|
||||
|
||||
// A Node is a renderable element and forms a tree of Nodes.
|
||||
|
Reference in New Issue
Block a user