go.mobile/geom: rename Scale to PixelsPerPt.
LGTM=crawshaw R=crawshaw CC=golang-codereviews https://golang.org/cl/160160043
This commit is contained in:
parent
32b64a7e1e
commit
fab1e51609
|
@ -66,7 +66,7 @@ func onCreate(activity *C.ANativeActivity) {
|
|||
dpi = int(density) // This is a guess.
|
||||
}
|
||||
|
||||
geom.Scale = float32(dpi) / 72
|
||||
geom.PixelsPerPt = float32(dpi) / 72
|
||||
}
|
||||
|
||||
//export onStart
|
||||
|
|
|
@ -44,9 +44,9 @@ func run(callbacks Callbacks) {
|
|||
}
|
||||
|
||||
//export setGeom
|
||||
func setGeom(scale, width, height float64) {
|
||||
func setGeom(pixelsPerPt, width, height float64) {
|
||||
// Macs default to 72 DPI, so scales are equivalent.
|
||||
geom.Scale = float32(scale)
|
||||
geom.PixelsPerPt = float32(pixelsPerPt)
|
||||
geom.Width = geom.Pt(width)
|
||||
geom.Height = geom.Pt(height)
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func fpsInit() {
|
|||
fps.Image = glutil.NewImage(geom.Point{50, 12})
|
||||
monofont.SetDst(fps.Image.RGBA)
|
||||
monofont.SetClip(fps.Bounds())
|
||||
monofont.SetDPI(72 * float64(geom.Scale))
|
||||
monofont.SetDPI(72 * float64(geom.PixelsPerPt))
|
||||
monofont.SetFontSize(12)
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ func DrawFPS() {
|
|||
str := fmt.Sprintf("%.0f FPS", float32(time.Second)/float32(diff))
|
||||
draw.Draw(fps.Image, fps.Image.Rect, image.White, image.Point{}, draw.Src)
|
||||
|
||||
ftpt12 := freetype.Pt(0, int(12*geom.Scale))
|
||||
ftpt12 := freetype.Pt(0, int(12*geom.PixelsPerPt))
|
||||
if _, err := monofont.DrawString(str, ftpt12); err != nil {
|
||||
log.Printf("DrawFPS: %v", err)
|
||||
return
|
||||
|
|
|
@ -99,8 +99,8 @@ func windowDrawLoop(cb Callbacks, w *C.ANativeWindow, queue *C.AInputQueue) {
|
|||
log.Printf("GL initialization error: %s", errv)
|
||||
}
|
||||
|
||||
geom.Width = geom.Pt(float32(C.windowWidth) / geom.Scale)
|
||||
geom.Height = geom.Pt(float32(C.windowHeight) / geom.Scale)
|
||||
geom.Width = geom.Pt(float32(C.windowWidth) / geom.PixelsPerPt)
|
||||
geom.Height = geom.Pt(float32(C.windowHeight) / geom.PixelsPerPt)
|
||||
|
||||
for {
|
||||
processEvents(cb, queue)
|
||||
|
@ -150,8 +150,8 @@ func processEvent(cb Callbacks, e *C.AInputEvent) {
|
|||
cb.Touch(event.Touch{
|
||||
Type: ty,
|
||||
Loc: geom.Point{
|
||||
X: geom.Pt(float32(x) / geom.Scale),
|
||||
Y: geom.Pt(float32(y) / geom.Scale),
|
||||
X: geom.Pt(float32(x) / geom.PixelsPerPt),
|
||||
Y: geom.Pt(float32(y) / geom.PixelsPerPt),
|
||||
},
|
||||
})
|
||||
default:
|
||||
|
|
|
@ -36,7 +36,7 @@ func run(callbacks Callbacks) {
|
|||
func onResize(w, h int) {
|
||||
// TODO(nigeltao): don't assume 72 DPI. DisplayWidth / DisplayWidthMM
|
||||
// is probably the best place to start looking.
|
||||
geom.Scale = 1
|
||||
geom.PixelsPerPt = 1
|
||||
geom.Width = geom.Pt(w)
|
||||
geom.Height = geom.Pt(h)
|
||||
}
|
||||
|
|
10
geom/geom.go
10
geom/geom.go
|
@ -11,11 +11,11 @@ import "fmt"
|
|||
// The unit Pt is a typographical point, 1/72 of an inch (0.3527 mm).
|
||||
//
|
||||
// It can be be converted to a length in current device pixels by
|
||||
// multiplying with Scale after app initialization is complete.
|
||||
// multiplying with PixelsPerPt after app initialization is complete.
|
||||
type Pt float32
|
||||
|
||||
// Px converts the length to current device pixels.
|
||||
func (p Pt) Px() float32 { return float32(p) * Scale }
|
||||
func (p Pt) Px() float32 { return float32(p) * PixelsPerPt }
|
||||
|
||||
// String returns a string representation of p like "3.2pt".
|
||||
func (p Pt) String() string { return fmt.Sprintf("%.2fpt", p) }
|
||||
|
@ -37,14 +37,14 @@ type Rectangle struct {
|
|||
// String returns a string representation of r like "(3,4)-(6,5)".
|
||||
func (r Rectangle) String() string { return r.Min.String() + "-" + r.Max.String() }
|
||||
|
||||
// Scale is the number of pixels in a single Pt on the current device.
|
||||
// PixelsPerPt is the number of pixels in a single Pt on the current device.
|
||||
//
|
||||
// There are a wide variety of pixel densities in existing phones and
|
||||
// tablets, so apps should be written to expect various non-integer
|
||||
// Scale values. In general, work in Pt.
|
||||
// PixelsPerPt values. In general, work in Pt.
|
||||
//
|
||||
// Not valid until app initialization has completed.
|
||||
var Scale float32
|
||||
var PixelsPerPt float32
|
||||
|
||||
// Width is the width of the device screen.
|
||||
// Not valid until app initialization has completed.
|
||||
|
|
|
@ -47,7 +47,7 @@ func TestImage(t *testing.T) {
|
|||
ptW = geom.Pt(150)
|
||||
ptH = geom.Pt(100)
|
||||
)
|
||||
geom.Scale = float32(pixW) / float32(ptW)
|
||||
geom.PixelsPerPt = float32(pixW) / float32(ptW)
|
||||
geom.Width = ptW
|
||||
geom.Height = ptH
|
||||
|
||||
|
|
|
@ -98,8 +98,8 @@ func (e *engine) Render(scene *sprite.Node, t clock.Time) {
|
|||
// the geom.Pt onto an image.Image we need to convert to system
|
||||
// pixels. We scale by geom.Scale to do this.
|
||||
e.absTransforms = append(e.absTransforms[:0], f32.Affine{
|
||||
{geom.Scale, 0, 0},
|
||||
{0, geom.Scale, 0},
|
||||
{geom.PixelsPerPt, 0, 0},
|
||||
{0, geom.PixelsPerPt, 0},
|
||||
})
|
||||
e.render(scene, t)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue