mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
ui: Get correct device scale for iOS
This commit is contained in:
parent
858b391592
commit
6f50ef3604
@ -44,8 +44,6 @@ type context struct {
|
|||||||
gl mgl.Context
|
gl mgl.Context
|
||||||
worker mgl.Worker
|
worker mgl.Worker
|
||||||
initialized chan struct{}
|
initialized chan struct{}
|
||||||
screenFramebufferWidth int
|
|
||||||
screenFramebufferHeight int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext() (*Context, error) {
|
func NewContext() (*Context, error) {
|
||||||
@ -81,22 +79,11 @@ func NewContext() (*Context, error) {
|
|||||||
c.BlendFunc(CompositeModeSourceOver)
|
c.BlendFunc(CompositeModeSourceOver)
|
||||||
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
||||||
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
|
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
|
||||||
// It is invalid to get the size of the deafult framebuffer.
|
|
||||||
if c.screenFramebuffer.Value != 0 {
|
|
||||||
width := c.gl.GetRenderbufferParameteri(mgl.RENDERBUFFER, mgl.RENDERBUFFER_WIDTH)
|
|
||||||
height := c.gl.GetRenderbufferParameteri(mgl.RENDERBUFFER, mgl.RENDERBUFFER_HEIGHT)
|
|
||||||
c.screenFramebufferWidth = width
|
|
||||||
c.screenFramebufferHeight = height
|
|
||||||
}
|
|
||||||
close(c.initialized)
|
close(c.initialized)
|
||||||
}()
|
}()
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) ScreenFramebufferSize() (int, int) {
|
|
||||||
return c.screenFramebufferWidth, c.screenFramebufferHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) Resume() error {
|
func (c *Context) Resume() error {
|
||||||
c.locationCache = newLocationCache()
|
c.locationCache = newLocationCache()
|
||||||
c.lastFramebuffer = invalidFramebuffer
|
c.lastFramebuffer = invalidFramebuffer
|
||||||
|
19
internal/ui/ui_android.go
Normal file
19
internal/ui/ui_android.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2016 Hajime Hoshi
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
func deviceScale() int {
|
||||||
|
return 1
|
||||||
|
}
|
31
internal/ui/ui_ios.go
Normal file
31
internal/ui/ui_ios.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2016 Hajime Hoshi
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build ios darwin,arm darwin,arm64
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
// #cgo CFLAGS: -x objective-c
|
||||||
|
// #cgo LDFLAGS: -framework Foundation -framework UIKit
|
||||||
|
//
|
||||||
|
// #import <UIKit/UIKit.h>
|
||||||
|
//
|
||||||
|
// static int devicePixelRatio() {
|
||||||
|
// return [[UIScreen mainScreen] scale];
|
||||||
|
// }
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
func deviceScale() int {
|
||||||
|
return int(C.devicePixelRatio())
|
||||||
|
}
|
@ -77,7 +77,6 @@ type userInterface struct {
|
|||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
scale int
|
scale int
|
||||||
framebufferScale int
|
|
||||||
sizeChanged bool
|
sizeChanged bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,17 +146,7 @@ func (u *userInterface) ScreenScale() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) actualScreenScale() int {
|
func (u *userInterface) actualScreenScale() int {
|
||||||
if u.framebufferScale == 0 {
|
return u.scale * deviceScale()
|
||||||
width, _ := glContext.ScreenFramebufferSize()
|
|
||||||
if width == 0 {
|
|
||||||
// Android
|
|
||||||
u.framebufferScale = 1
|
|
||||||
} else {
|
|
||||||
// iOS
|
|
||||||
u.framebufferScale = width / u.width
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return u.scale * u.framebufferScale
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateTouches(touches []Touch) {
|
func UpdateTouches(touches []Touch) {
|
||||||
|
Loading…
Reference in New Issue
Block a user