diff --git a/graphics/matrix/color.go b/graphics/matrix/color.go index 822819b6b..896df9970 100644 --- a/graphics/matrix/color.go +++ b/graphics/matrix/color.go @@ -5,15 +5,15 @@ import ( "math" ) -const colorDim = 5 +const ColorDim = 5 type Color struct { - Elements [colorDim - 1][colorDim]float64 + Elements [ColorDim - 1][ColorDim]float64 } func ColorI() Color { return Color{ - [colorDim - 1][colorDim]float64{ + [ColorDim - 1][ColorDim]float64{ {1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, @@ -23,7 +23,7 @@ func ColorI() Color { } func (matrix *Color) Dim() int { - return colorDim + return ColorDim } func (matrix *Color) Concat(other Color) { @@ -49,7 +49,7 @@ func Monochrome() Color { const g float64 = 23434.0 / 32768.0 const b float64 = 2366.0 / 32768.0 return Color{ - [colorDim - 1][colorDim]float64{ + [ColorDim - 1][ColorDim]float64{ {r, g, b, 0, 0}, {r, g, b, 0, 0}, {r, g, b, 0, 0}, diff --git a/graphics/matrix/geometry.go b/graphics/matrix/geometry.go index bb41e1b47..2274168b9 100644 --- a/graphics/matrix/geometry.go +++ b/graphics/matrix/geometry.go @@ -4,15 +4,15 @@ import ( "math" ) -const geometryDim = 3 +const GeometryDim = 3 type Geometry struct { - Elements [geometryDim - 1][geometryDim]float64 + Elements [GeometryDim - 1][GeometryDim]float64 } func GeometryI() Geometry { return Geometry{ - [geometryDim - 1][geometryDim]float64{ + [GeometryDim - 1][GeometryDim]float64{ {1, 0, 0}, {0, 1, 0}, }, @@ -20,7 +20,7 @@ func GeometryI() Geometry { } func (matrix *Geometry) Dim() int { - return geometryDim + return GeometryDim } func (matrix *Geometry) Concat(other Geometry) { diff --git a/ui/glfw/canvas.go b/ui/glfw/canvas.go index b7c200719..f368a6a53 100644 --- a/ui/glfw/canvas.go +++ b/ui/glfw/canvas.go @@ -10,22 +10,22 @@ import ( "runtime" ) -type Canvas struct { +type canvas struct { window *glfw.Window context *opengl.Context - keyboard *Keyboard + keyboard *keyboard funcs chan func() funcsDone chan struct{} } -func NewCanvas(width, height, scale int, title string) *Canvas { +func newCanvas(width, height, scale int, title string) *canvas { window, err := glfw.CreateWindow(width*scale, height*scale, title, nil, nil) if err != nil { panic(err) } - canvas := &Canvas{ + canvas := &canvas{ window: window, - keyboard: NewKeyboard(), + keyboard: newKeyboard(), funcs: make(chan func()), funcsDone: make(chan struct{}), } @@ -44,7 +44,7 @@ func NewCanvas(width, height, scale int, title string) *Canvas { return canvas } -func (c *Canvas) Draw(d ui.Drawer) (err error) { +func (c *canvas) Draw(d ui.Drawer) (err error) { c.use(func() { err = c.context.Update(d) c.window.SwapBuffers() @@ -52,11 +52,11 @@ func (c *Canvas) Draw(d ui.Drawer) (err error) { return } -func (c *Canvas) IsClosed() bool { +func (c *canvas) IsClosed() bool { return c.window.ShouldClose() } -func (c *Canvas) NewTextureID(img image.Image, filter graphics.Filter) (graphics.TextureID, error) { +func (c *canvas) NewTextureID(img image.Image, filter graphics.Filter) (graphics.TextureID, error) { var id graphics.TextureID var err error c.use(func() { @@ -65,7 +65,7 @@ func (c *Canvas) NewTextureID(img image.Image, filter graphics.Filter) (graphics return id, err } -func (c *Canvas) NewRenderTargetID(width, height int, filter graphics.Filter) (graphics.RenderTargetID, error) { +func (c *canvas) NewRenderTargetID(width, height int, filter graphics.Filter) (graphics.RenderTargetID, error) { var id graphics.RenderTargetID var err error c.use(func() { @@ -74,7 +74,7 @@ func (c *Canvas) NewRenderTargetID(width, height int, filter graphics.Filter) (g return id, err } -func (c *Canvas) run() { +func (c *canvas) run() { go func() { runtime.LockOSThread() c.window.MakeContextCurrent() @@ -87,11 +87,11 @@ func (c *Canvas) run() { }() } -func (c *Canvas) use(f func()) { +func (c *canvas) use(f func()) { c.funcs <- f <-c.funcsDone } -func (c *Canvas) update() { +func (c *canvas) update() { c.keyboard.update(c.window) } diff --git a/ui/glfw/keyboard.go b/ui/glfw/keyboard.go index 6af6b335c..3e99432e1 100644 --- a/ui/glfw/keyboard.go +++ b/ui/glfw/keyboard.go @@ -5,17 +5,17 @@ import ( "github.com/hajimehoshi/ebiten/input" ) -type Keyboard struct { +type keyboard struct { pressedKeys map[input.Key]struct{} } -func NewKeyboard() *Keyboard { - return &Keyboard{ +func newKeyboard() *keyboard { + return &keyboard{ pressedKeys: map[input.Key]struct{}{}, } } -func (k *Keyboard) IsKeyPressed(key input.Key) bool { +func (k *keyboard) IsKeyPressed(key input.Key) bool { _, ok := k.pressedKeys[key] return ok } @@ -28,7 +28,7 @@ var glfwKeyCodeToKey = map[glfw.Key]input.Key{ glfw.KeyDown: input.KeyDown, } -func (k *Keyboard) update(window *glfw.Window) { +func (k *keyboard) update(window *glfw.Window) { for g, u := range glfwKeyCodeToKey { if window.GetKey(g) == glfw.Press { k.pressedKeys[u] = struct{}{} diff --git a/ui/glfw/ui.go b/ui/glfw/ui.go index e2346f3aa..e9be7063a 100644 --- a/ui/glfw/ui.go +++ b/ui/glfw/ui.go @@ -2,19 +2,19 @@ package glfw import ( "errors" + "fmt" glfw "github.com/go-gl/glfw3" "github.com/hajimehoshi/ebiten/ui" - "log" ) func init() { glfw.SetErrorCallback(func(err glfw.ErrorCode, desc string) { - log.Fatalf("%v: %v\n", err, desc) + panic(fmt.Sprintf("%v: %v\n", err, desc)) }) } type UI struct { - canvas *Canvas + canvas *canvas } func (u *UI) Start(width, height, scale int, title string) (ui.Canvas, error) { @@ -22,7 +22,7 @@ func (u *UI) Start(width, height, scale int, title string) (ui.Canvas, error) { return nil, errors.New("glfw.Init() fails") } glfw.WindowHint(glfw.Resizable, glfw.False) - u.canvas = NewCanvas(width, height, scale, title) + u.canvas = newCanvas(width, height, scale, title) return u.canvas, nil }