mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
driver: Move ui.GraphicsContext to driver
This commit is contained in:
parent
b579bd7fd0
commit
1b8d4abfdb
20
internal/driver/ui.go
Normal file
20
internal/driver/ui.go
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2019 The Ebiten Authors
|
||||
//
|
||||
// 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 driver
|
||||
|
||||
type GraphicsContext interface {
|
||||
SetSize(width, height int, scale float64)
|
||||
Update(afterFrameUpdate func()) error
|
||||
}
|
@ -18,11 +18,6 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type GraphicsContext interface {
|
||||
SetSize(width, height int, scale float64)
|
||||
Update(afterFrameUpdate func()) error
|
||||
}
|
||||
|
||||
// RegularTermination represents a regular termination.
|
||||
// Run can return this error, and if this error is received,
|
||||
// the game loop should be terminated as soon as possible.
|
||||
|
@ -568,7 +568,7 @@ func DeviceScaleFactor() float64 {
|
||||
return f
|
||||
}
|
||||
|
||||
func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||
func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||
u := currentUI
|
||||
_ = mainthread.Run(func() error {
|
||||
u.graphics = graphics
|
||||
@ -714,7 +714,7 @@ func (u *userInterface) actualScreenScale() float64 {
|
||||
return u.getScale() * devicescale.GetAt(u.currentMonitor().GetPos())
|
||||
}
|
||||
|
||||
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
|
||||
func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) {
|
||||
actualScale := 0.0
|
||||
sizeChanged := false
|
||||
// TODO: Is it possible to reduce 'runOnMainThread' calls?
|
||||
@ -738,7 +738,7 @@ func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func (u *userInterface) update(g GraphicsContext) error {
|
||||
func (u *userInterface) update(g driver.GraphicsContext) error {
|
||||
shouldClose := false
|
||||
_ = mainthread.Run(func() error {
|
||||
shouldClose = u.window.ShouldClose()
|
||||
@ -802,7 +802,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *userInterface) loop(g GraphicsContext) error {
|
||||
func (u *userInterface) loop(g driver.GraphicsContext) error {
|
||||
defer func() {
|
||||
_ = mainthread.Run(func() error {
|
||||
glfw.Terminate()
|
||||
|
@ -187,7 +187,7 @@ func (u *userInterface) actualScreenScale() float64 {
|
||||
return u.getScale() * devicescale.GetAt(0, 0)
|
||||
}
|
||||
|
||||
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
|
||||
func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) {
|
||||
a := u.actualScreenScale()
|
||||
if u.lastActualScale != a {
|
||||
u.updateScreenSize()
|
||||
@ -204,7 +204,7 @@ func (u *userInterface) suspended() bool {
|
||||
return !u.runnableInBackground && (!u.windowFocus || !u.pageVisible)
|
||||
}
|
||||
|
||||
func (u *userInterface) update(g GraphicsContext) error {
|
||||
func (u *userInterface) update(g driver.GraphicsContext) error {
|
||||
if u.suspended() {
|
||||
hooks.SuspendAudio()
|
||||
return nil
|
||||
@ -221,7 +221,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *userInterface) loop(g GraphicsContext) <-chan error {
|
||||
func (u *userInterface) loop(g driver.GraphicsContext) <-chan error {
|
||||
ch := make(chan error)
|
||||
var cf js.Callback
|
||||
f := func([]js.Value) {
|
||||
@ -385,7 +385,7 @@ func Loop(ch <-chan error) error {
|
||||
return <-ch
|
||||
}
|
||||
|
||||
func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||
func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||
u := currentUI
|
||||
u.input = input.(inputDriver)
|
||||
|
||||
|
@ -148,7 +148,7 @@ func appMain(a app.App) {
|
||||
}
|
||||
}
|
||||
|
||||
func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||
func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||
if graphics != opengl.Get() {
|
||||
panic("ui: graphics driver must be OpenGL")
|
||||
}
|
||||
@ -190,7 +190,7 @@ func Loop(ch <-chan error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
|
||||
func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) {
|
||||
width, height := 0, 0
|
||||
actualScale := 0.0
|
||||
|
||||
@ -229,7 +229,7 @@ func (u *userInterface) scaleImpl() float64 {
|
||||
return scale
|
||||
}
|
||||
|
||||
func (u *userInterface) update(g GraphicsContext) error {
|
||||
func (u *userInterface) update(g driver.GraphicsContext) error {
|
||||
render:
|
||||
for {
|
||||
select {
|
||||
|
Loading…
Reference in New Issue
Block a user