graphics: More exact scaling

This is related to #622
This commit is contained in:
Hajime Hoshi 2018-06-08 00:06:57 +09:00
parent e6d0943366
commit 3136ef5fbd

View File

@ -33,6 +33,7 @@ type graphicsContext struct {
f func(*Image) error
offscreen *Image
screen *Image
screenScale float64
initialized bool
invalidated bool // browser only
offsetX float64
@ -48,6 +49,8 @@ func (c *graphicsContext) Invalidate() {
}
func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale float64) {
c.screenScale = screenScale
if c.screen != nil {
_ = c.screen.Dispose()
}
@ -109,14 +112,12 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
c.screen.DrawImage(emptyImage, op)
}
dw, dh := c.screen.Size()
sw, _ := c.offscreen.Size()
scale := float64(dw) / float64(sw)
_, dh := c.screen.Size()
op := &DrawImageOptions{}
// c.screen is special: its Y axis is down to up,
// and the origin point is lower left.
op.GeoM.Scale(scale, -scale)
op.GeoM.Scale(c.screenScale, -c.screenScale)
op.GeoM.Translate(0, float64(dh))
op.GeoM.Translate(c.offsetX, c.offsetY)