Skip to content

Commit

Permalink
internal/uidriver/*: integrate the packages into internal/ui
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Feb 6, 2022
1 parent 67bb588 commit 149736c
Show file tree
Hide file tree
Showing 39 changed files with 184 additions and 308 deletions.
31 changes: 16 additions & 15 deletions genkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,13 @@ const (
)
`

const uidriverGlfwKeysTmpl = `{{.License}}
const uiGLFWKeysTmpl = `{{.License}}
{{.DoNotEdit}}
{{.BuildTag}}
package glfw
package ui
import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
Expand All @@ -594,13 +594,13 @@ var driverKeyToGLFWKey = map[driver.Key]glfw.Key{
}
`

const uidriverJsKeysTmpl = `{{.License}}
const uiJSKeysTmpl = `{{.License}}
{{.DoNotEdit}}
{{.BuildTag}}
package js
package ui
import (
"syscall/js"
Expand Down Expand Up @@ -651,13 +651,13 @@ var androidKeyToDriverKey = map[int]driver.Key{
}
`

const uidriverMobileKeysTmpl = `{{.License}}
const uiMobileKeysTmpl = `{{.License}}
{{.DoNotEdit}}
{{.BuildTag}}
package mobile
package ui
import (
"golang.org/x/mobile/event/key"
Expand Down Expand Up @@ -790,9 +790,9 @@ func main() {
for path, tmpl := range map[string]string{
filepath.Join("internal", "driver", "keys.go"): driverKeysTmpl,
filepath.Join("internal", "glfw", "keys.go"): glfwKeysTmpl,
filepath.Join("internal", "uidriver", "glfw", "keys.go"): uidriverGlfwKeysTmpl,
filepath.Join("internal", "uidriver", "mobile", "keys.go"): uidriverMobileKeysTmpl,
filepath.Join("internal", "uidriver", "js", "keys_js.go"): uidriverJsKeysTmpl,
filepath.Join("internal", "ui", "keys_glfw.go"): uiGLFWKeysTmpl,
filepath.Join("internal", "ui", "keys_mobile.go"): uiMobileKeysTmpl,
filepath.Join("internal", "ui", "keys_js.go"): uiJSKeysTmpl,
filepath.Join("keys.go"): ebitenKeysTmpl,
filepath.Join("mobile", "ebitenmobileview", "keys_android.go"): mobileAndroidKeysTmpl,
} {
Expand All @@ -817,12 +817,13 @@ func main() {
case filepath.Join("internal", "glfw", "keys.go"):
buildTag = "//go:build !js" +
"\n// +build !js"
case filepath.Join("internal", "uidriver", "mobile", "keys.go"):
buildTag = "//go:build android || ios" +
"\n// +build android ios"
case filepath.Join("internal", "uidriver", "glfw", "keys.go"):
buildTag = "//go:build !android && !js && !ios" +
"\n// +build !android,!js,!ios"
case filepath.Join("internal", "ui", "keys_mobile.go"):
buildTag = "//go:build (android || ios) && !ebitencbackend" +
"\n// +build android ios" +
"\n// +build !ebitencbackend"
case filepath.Join("internal", "ui", "keys_glfw.go"):
buildTag = "//go:build !android && !js && !ios && !ebitencbackend" +
"\n// +build !android,!js,!ios,!ebitencbackend"
}
// NOTE: According to godoc, maps are automatically sorted by key.
if err := tmpl.Execute(f, struct {
Expand Down
3 changes: 2 additions & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ package ebiten

import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/v2/internal/ui"
)

func init() {
graphicscommand.SetGraphicsDriver(uiDriver().Graphics())
graphicscommand.SetGraphicsDriver(ui.Get().Graphics())
}
15 changes: 8 additions & 7 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
"github.com/hajimehoshi/ebiten/v2/internal/gamepaddb"
"github.com/hajimehoshi/ebiten/v2/internal/ui"
)

// AppendInputChars appends "printable" runes, read from the keyboard at the time update is called, to runes,
Expand All @@ -35,7 +36,7 @@ import (
//
// Keyboards don't work on iOS yet (#1090).
func AppendInputChars(runes []rune) []rune {
return uiDriver().Input().AppendInputChars(runes)
return ui.Get().Input().AppendInputChars(runes)
}

// InputChars return "printable" runes read from the keyboard at the time update is called.
Expand Down Expand Up @@ -82,7 +83,7 @@ func IsKeyPressed(key Key) bool {
keys = []driver.Key{driver.Key(key)}
}
for _, k := range keys {
if uiDriver().Input().IsKeyPressed(k) {
if ui.Get().Input().IsKeyPressed(k) {
return true
}
}
Expand All @@ -98,15 +99,15 @@ func IsKeyPressed(key Key) bool {
//
// CursorPosition is concurrent-safe.
func CursorPosition() (x, y int) {
return uiDriver().Input().CursorPosition()
return ui.Get().Input().CursorPosition()
}

// Wheel returns x and y offsets of the mouse wheel or touchpad scroll.
// It returns 0 if the wheel isn't being rolled.
//
// Wheel is concurrent-safe.
func Wheel() (xoff, yoff float64) {
return uiDriver().Input().Wheel()
return ui.Get().Input().Wheel()
}

// IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed.
Expand All @@ -116,7 +117,7 @@ func Wheel() (xoff, yoff float64) {
//
// IsMouseButtonPressed is concurrent-safe.
func IsMouseButtonPressed(mouseButton MouseButton) bool {
return uiDriver().Input().IsMouseButtonPressed(mouseButton)
return ui.Get().Input().IsMouseButtonPressed(mouseButton)
}

// GamepadID represents a gamepad's identifier.
Expand Down Expand Up @@ -336,7 +337,7 @@ type TouchID = driver.TouchID
//
// AppendTouchIDs is concurrent-safe.
func AppendTouchIDs(touches []TouchID) []TouchID {
return uiDriver().Input().AppendTouchIDs(touches)
return ui.Get().Input().AppendTouchIDs(touches)
}

// TouchIDs returns the current touch states.
Expand All @@ -352,5 +353,5 @@ func TouchIDs() []TouchID {
//
// TouchPosition is cuncurrent-safe.
func TouchPosition(id TouchID) (int, int) {
return uiDriver().Input().TouchPosition(id)
return ui.Get().Input().TouchPosition(id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !ebitengl && !ios
// +build !ebitengl,!ios
//go:build !ios && !ebitengl && !ebitencbackend
// +build !ios,!ebitengl,!ebitencbackend

package glfw
package ui

// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build ((ios && arm) || (ios && arm64)) && !ebitengl
//go:build ((ios && arm) || (ios && arm64)) && !ebitengl && !ebitencbackend
// +build ios,arm ios,arm64
// +build !ebitengl
// +build !ebitencbackend

package mobile
package ui

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build android || (ios && 386) || (ios && amd64) || (ios && ebitengl)
// +build android ios,386 ios,amd64 ios,ebitengl
//go:build !darwin || (ios && 386) || (ios && amd64) || ebitengl
// +build !darwin ios,386 ios,amd64 ebitengl

package mobile
package ui

import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows || js
// +build !windows js
//go:build !windows || ebitencbackend
// +build !windows ebitencbackend

package glfw
package ui

// hideConsoleWindowOnWindows does nothing on non-Windows systems.
func hideConsoleWindowOnWindows() {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package glfw
//go:build !ebitencbackend
// +build !ebitencbackend

package ui

import (
"fmt"
Expand All @@ -39,9 +42,9 @@ func freeConsole() error {
r, _, e := procFreeConsoleWindow.Call()
if r == 0 {
if e != nil && e != windows.ERROR_SUCCESS {
return fmt.Errorf("glfw: FreeConsole failed: %w", e)
return fmt.Errorf("ui: FreeConsole failed: %w", e)
}
return fmt.Errorf("glfw: FreeConsole returned 0")
return fmt.Errorf("ui: FreeConsole returned 0")
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//go:build ebitencbackend
// +build ebitencbackend

package cbackend
package ui

import (
"sync"
Expand Down
6 changes: 3 additions & 3 deletions internal/uidriver/glfw/input.go → internal/ui/input_glfw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !android && !js && !ios
// +build !android,!js,!ios
//go:build !android && !js && !ios && !ebitencbackend
// +build !android,!js,!ios,!ebitencbackend

package glfw
package ui

import (
"math"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package js
package ui

import (
"syscall/js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build android || ios
//go:build (android || ios) && !ebitencbackend
// +build android ios
// +build !ebitencbackend

package mobile
package ui

import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
Expand Down
6 changes: 3 additions & 3 deletions internal/uidriver/glfw/keys.go → internal/ui/keys_glfw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/uidriver/js/keys_js.go → internal/ui/keys_js.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !ebitensinglethread && !android && !js && !ios
// +build !ebitensinglethread,!android,!js,!ios
//go:build !android && !js && !ios && !ebitencbackend && !ebitensinglethread
// +build !android,!js,!ios,!ebitencbackend,!ebitensinglethread

package glfw
package ui

import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build ebitensinglethread && !android && !js && !ios
// +build ebitensinglethread,!android,!js,!ios
//go:build !android && !js && !ios && !ebitencbackend && ebitensinglethread
// +build !android,!js,!ios,!ebitencbackend,ebitensinglethread

package glfw
package ui

import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
//go:build ebitencbackend
// +build ebitencbackend

package cbackend
package ui

import (
"runtime"
"time"

"github.com/hajimehoshi/ebiten/v2/internal/cbackend"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
)

const deviceScaleFactor = 1
Expand Down Expand Up @@ -60,7 +59,7 @@ func (u *UserInterface) Run(context driver.UIContext) error {
}

func (*UserInterface) RunWithoutMainLoop(context driver.UIContext) {
panic("cbackend: RunWithoutMainLoop is not implemented")
panic("ui: RunWithoutMainLoop is not implemented")
}

func (*UserInterface) DeviceScaleFactor() float64 {
Expand Down Expand Up @@ -136,7 +135,3 @@ func (*UserInterface) Input() driver.Input {
func (*UserInterface) Window() driver.Window {
return nil
}

func (*UserInterface) Graphics() driver.Graphics {
return opengl.Get()
}
Loading

0 comments on commit 149736c

Please sign in to comment.