mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ui: More accurate device scale factor
This commit is contained in:
parent
7528977842
commit
ea377b8e20
@ -147,16 +147,8 @@ func (u *userInterface) Start(width, height, scale int, title string) error {
|
||||
m := glfw.GetPrimaryMonitor()
|
||||
v := m.GetVideoMode()
|
||||
mw, _ := m.GetPhysicalSize()
|
||||
u.deviceScale = 1
|
||||
u.deviceScale = deviceScale()
|
||||
u.framebufferScale = 1
|
||||
// mw can be 0 on some environment like Linux VM
|
||||
if 0 < mw {
|
||||
dpi := float64(v.Width) * 25.4 / float64(mw)
|
||||
u.deviceScale = dpi / 96
|
||||
if u.deviceScale < 1 {
|
||||
u.deviceScale = 1
|
||||
}
|
||||
}
|
||||
|
||||
if !u.setScreenSize(width, height, scale) {
|
||||
err = errors.New("ui: Fail to set the screen size")
|
||||
|
22
internal/ui/ui_linux.go
Normal file
22
internal/ui/ui_linux.go
Normal file
@ -0,0 +1,22 @@
|
||||
// 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 !js
|
||||
|
||||
package ui
|
||||
|
||||
func deviceScale() float64 {
|
||||
// TODO: Implement this
|
||||
return 1
|
||||
}
|
25
internal/ui/ui_mac.go
Normal file
25
internal/ui/ui_mac.go
Normal file
@ -0,0 +1,25 @@
|
||||
// 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 darwin,!arm,!arm64
|
||||
// +build !js
|
||||
// +build !ios
|
||||
|
||||
package ui
|
||||
|
||||
func deviceScale() float64 {
|
||||
// The device scale is always 1 on Mac OS.
|
||||
// The frame buffer size is different from the window size.
|
||||
return 1
|
||||
}
|
32
internal/ui/ui_windows.go
Normal file
32
internal/ui/ui_windows.go
Normal file
@ -0,0 +1,32 @@
|
||||
// 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 !js
|
||||
|
||||
package ui
|
||||
|
||||
// #cgo LDFLAGS: -lgdi32
|
||||
//
|
||||
// #include <windows.h>
|
||||
//
|
||||
// static int getDPI() {
|
||||
// HDC dc = GetWindowDC(0);
|
||||
// return GetDeviceCaps(dc, LOGPIXELSX);
|
||||
// }
|
||||
import "C"
|
||||
|
||||
func deviceScale() float64 {
|
||||
dpi := int(C.getDPI())
|
||||
return float64(dpi) / 96
|
||||
}
|
Loading…
Reference in New Issue
Block a user