mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
ui: Refactoring
This commit is contained in:
parent
db782ff0d9
commit
ec70ea3be5
@ -142,7 +142,7 @@ func ScreenScale() float64 {
|
||||
return s
|
||||
}
|
||||
|
||||
func Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
||||
func Run(width, height int, scale float64, title string, g GraphicsContext, glContext opengl.Context) error {
|
||||
u := currentUI
|
||||
// GLContext must be created before setting the screen size, which requires
|
||||
// swapping buffers.
|
||||
|
@ -57,7 +57,7 @@ func ScreenScale() float64 {
|
||||
return currentUI.scale
|
||||
}
|
||||
|
||||
func (u *userInterface) ActualScreenScale() float64 {
|
||||
func (u *userInterface) actualScreenScale() float64 {
|
||||
return u.scale * u.deviceScale
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
||||
if u.sizeChanged {
|
||||
u.sizeChanged = false
|
||||
w, h := u.size()
|
||||
if err := g.SetSize(w, h, u.ActualScreenScale()); err != nil {
|
||||
if err := g.SetSize(w, h, u.actualScreenScale()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -98,10 +98,6 @@ func (u *userInterface) loop(g GraphicsContext) error {
|
||||
return <-ch
|
||||
}
|
||||
|
||||
func (u *userInterface) FinishRendering() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func touchEventToTouches(e *js.Object) []touch {
|
||||
scale := currentUI.scale
|
||||
j := e.Get("targetTouches")
|
||||
@ -273,7 +269,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro
|
||||
}
|
||||
|
||||
func (u *userInterface) size() (width, height int) {
|
||||
a := u.ActualScreenScale()
|
||||
a := u.actualScreenScale()
|
||||
if a == 0 {
|
||||
// a == 0 only on the initial state.
|
||||
return
|
||||
@ -291,8 +287,8 @@ func (u *userInterface) setScreenSize(width, height int, scale float64) bool {
|
||||
}
|
||||
u.scale = scale
|
||||
u.deviceScale = devicePixelRatio()
|
||||
canvas.Set("width", int(float64(width)*u.ActualScreenScale()))
|
||||
canvas.Set("height", int(float64(height)*u.ActualScreenScale()))
|
||||
canvas.Set("width", int(float64(width)*u.actualScreenScale()))
|
||||
canvas.Set("height", int(float64(height)*u.actualScreenScale()))
|
||||
canvasStyle := canvas.Get("style")
|
||||
|
||||
cssWidth := int(float64(width) * scale)
|
||||
|
Loading…
Reference in New Issue
Block a user