2021-12-17 07:03:23 +01:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
|
|
|
//go:build ebitencbackend
|
|
|
|
// +build ebitencbackend
|
|
|
|
|
2022-02-06 08:08:22 +01:00
|
|
|
package ui
|
2021-12-17 07:03:23 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/cbackend"
|
2022-03-21 16:02:37 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
2022-03-22 15:33:21 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
2021-12-17 07:03:23 +01:00
|
|
|
)
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
type graphicsDriverCreatorImpl struct{}
|
2022-03-22 15:33:21 +01:00
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
2022-06-16 19:02:29 +02:00
|
|
|
return g.newOpenGL()
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
2022-06-16 19:02:29 +02:00
|
|
|
return opengl.NewGraphics()
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) getDirectX() graphicsdriver.Graphics {
|
2022-03-25 11:43:32 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newMetal() (graphicsdriver.Graphics, error) {
|
|
|
|
return nil, nil
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2021-12-17 07:03:23 +01:00
|
|
|
const deviceScaleFactor = 1
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
type userInterfaceImpl struct {
|
2022-03-21 16:02:37 +01:00
|
|
|
graphicsDriver graphicsdriver.Graphics
|
|
|
|
|
2022-04-01 10:59:44 +02:00
|
|
|
context *context
|
2022-02-13 08:30:33 +01:00
|
|
|
input Input
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) Run(game Game) error {
|
2022-04-01 10:59:44 +02:00
|
|
|
u.context = newContext(game)
|
2022-06-16 19:10:29 +02:00
|
|
|
g, err := chooseGraphicsDriver(&graphicsDriverCreatorImpl{})
|
2022-03-22 15:33:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
u.graphicsDriver = g
|
2021-12-17 07:03:23 +01:00
|
|
|
cbackend.InitializeGame()
|
|
|
|
for {
|
|
|
|
cbackend.BeginFrame()
|
2022-02-13 08:30:33 +01:00
|
|
|
u.input.update(u.context)
|
2021-12-17 07:03:23 +01:00
|
|
|
|
2022-02-13 18:48:28 +01:00
|
|
|
w, h := cbackend.ScreenSize()
|
2022-03-21 16:02:37 +01:00
|
|
|
if err := u.context.updateFrame(u.graphicsDriver, float64(w), float64(h), deviceScaleFactor); err != nil {
|
2021-12-17 07:03:23 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cbackend.EndFrame()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) DeviceScaleFactor() float64 {
|
2021-12-17 07:03:23 +01:00
|
|
|
return deviceScaleFactor
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) IsFocused() bool {
|
2021-12-17 07:03:23 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
2021-12-17 07:03:23 +01:00
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) resetForTick() {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) CursorMode() CursorMode {
|
2022-02-06 09:43:52 +01:00
|
|
|
return CursorModeHidden
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) CursorShape() CursorShape {
|
2022-02-06 09:43:52 +01:00
|
|
|
return CursorShapeDefault
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) SetCursorShape(shape CursorShape) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) IsFullscreen() bool {
|
2021-12-17 07:03:23 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) SetFullscreen(fullscreen bool) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) IsRunnableOnUnfocused() bool {
|
2021-12-17 07:03:23 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) SetFPSMode(mode FPSModeType) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) ScheduleFrame() {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) IsScreenTransparent() bool {
|
2021-12-17 07:03:23 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) SetScreenTransparent(transparent bool) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) SetInitFocused(focused bool) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (*userInterfaceImpl) Input() *Input {
|
2022-03-21 14:47:13 +01:00
|
|
|
return &theUI.input
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 19:09:10 +02:00
|
|
|
func (*userInterfaceImpl) Window() Window {
|
|
|
|
return &nullWindow{}
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|