diff --git a/example/blocks.go b/example/blocks.go index d22bbad28..ddc7d0f6e 100644 --- a/example/blocks.go +++ b/example/blocks.go @@ -18,9 +18,8 @@ package main import ( "flag" - "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/example/blocks" - "github.com/hajimehoshi/ebiten/glfw" + "github.com/hajimehoshi/ebiten/runner" "log" "os" "runtime" @@ -44,9 +43,8 @@ func main() { defer pprof.StopCPUProfile() } - ui := new(glfw.UI) game := blocks.NewGame() - if err := ebiten.Run(ui, game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)", 60); err != nil { + if err := runner.Run(game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)", 60); err != nil { log.Fatal(err) } } diff --git a/glfw/canvas.go b/internal/glfw/canvas.go similarity index 96% rename from glfw/canvas.go rename to internal/glfw/canvas.go index 73a12640c..a009d7111 100644 --- a/glfw/canvas.go +++ b/internal/glfw/canvas.go @@ -32,7 +32,7 @@ type canvas struct { funcsDone chan struct{} } -func (c *canvas) draw(d ebiten.GraphicsContextDrawer) (err error) { +func (c *canvas) draw(d GraphicsContextDrawer) (err error) { c.use(func() { c.context.PreUpdate() }) diff --git a/glfw/context.go b/internal/glfw/context.go similarity index 100% rename from glfw/context.go rename to internal/glfw/context.go diff --git a/glfw/input.go b/internal/glfw/input.go similarity index 100% rename from glfw/input.go rename to internal/glfw/input.go diff --git a/glfw/ui.go b/internal/glfw/ui.go similarity index 93% rename from glfw/ui.go rename to internal/glfw/ui.go index 9ac8f9a73..593670a6c 100644 --- a/glfw/ui.go +++ b/internal/glfw/ui.go @@ -30,6 +30,10 @@ func init() { }) } +type GraphicsContextDrawer interface { + Draw(d ebiten.GraphicsContext) error +} + type UI struct { canvas *canvas } @@ -77,7 +81,7 @@ func (u *UI) Terminate() { glfw.Terminate() } -func (u *UI) Draw(drawer ebiten.GraphicsContextDrawer) error { +func (u *UI) Draw(drawer GraphicsContextDrawer) error { return u.canvas.draw(drawer) } diff --git a/run.go b/runner/run.go similarity index 85% rename from run.go rename to runner/run.go index af2d17547..7ebf621ee 100644 --- a/run.go +++ b/runner/run.go @@ -14,9 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -package ebiten +package runner import ( + "github.com/hajimehoshi/ebiten" + "github.com/hajimehoshi/ebiten/internal/glfw" "os" "os/signal" "syscall" @@ -25,13 +27,14 @@ import ( type Game interface { Update() error - Draw(context GraphicsContext) error + Draw(context ebiten.GraphicsContext) error } // Run runs the game. Basically, this function executes ui.Start() at the start, // calls ui.DoEvent(), game.Update() and game.Draw() at a regular interval, and finally // calls ui.Terminate(). -func Run(ui UI, game Game, width, height, scale int, title string, fps int) error { +func Run(game Game, width, height, scale int, title string, fps int) error { + ui := new(glfw.UI) if err := ui.Start(width, height, scale, title); err != nil { return err } diff --git a/ui.go b/ui.go deleted file mode 100644 index 1c44212ee..000000000 --- a/ui.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2014 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. -*/ - -package ebiten - -type UI interface { - Start(widht, height, scale int, title string) error - DoEvents() - Terminate() - Draw(drawer GraphicsContextDrawer) error - IsClosed() bool -} - -type GraphicsContextDrawer interface { - Draw(d GraphicsContext) error -}