diff --git a/example/mapeditor/mapeditor/maptools.go b/example/mapeditor/mapeditor/maptools.go index b085a5343..584f97c42 100644 --- a/example/mapeditor/mapeditor/maptools.go +++ b/example/mapeditor/mapeditor/maptools.go @@ -17,9 +17,18 @@ package mapeditor import ( "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/ebitenutil" + "image/color" _ "image/png" ) +type MapTool int + +const ( + MapToolScroll MapTool = iota + MapToolPen + MapToolFill +) + var mapToolsImage *ebiten.Image func init() { @@ -32,6 +41,7 @@ func init() { type MapTools struct { focused bool + current MapTool } func NewMapTools() *MapTools { @@ -41,7 +51,13 @@ func NewMapTools() *MapTools { func (m *MapTools) Update() { } +func (m *MapTools) Current() MapTool { + return m.current +} + func (m *MapTools) Draw(i *ebiten.Image, x, y, width, height int) error { + i.DrawFilledRect(x+int(m.current)*32, y, 32, 32, color.White) + op := &ebiten.DrawImageOptions{} op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Scale(2, 2) diff --git a/example/mapeditor/mapeditor/mapview.go b/example/mapeditor/mapeditor/mapview.go index 7ba2ea1dd..8ee2618db 100644 --- a/example/mapeditor/mapeditor/mapview.go +++ b/example/mapeditor/mapeditor/mapview.go @@ -60,8 +60,12 @@ func (m *MapView) Update(input *Input, ox, oy, width, height int, tileSet *TileS if input.MouseButtonState(ebiten.MouseButtonLeft) == 1 { m.focused = true } - if m.focused && ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { - m.m.SetTile(m.cursorX, m.cursorY, selectedTile) + + switch m.mapTools.Current() { + case MapToolPen: + if m.focused && ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { + m.m.SetTile(m.cursorX, m.cursorY, selectedTile) + } } return nil } @@ -72,7 +76,7 @@ func (m *MapView) Draw(i *ebiten.Image, x, y, width, height int) error { return err } - if m.cursorX != -1 && m.cursorY != -1 { + if m.mapTools.Current() != MapToolScroll && m.cursorX != -1 && m.cursorY != -1 { sx := mapX + m.cursorX*TileWidth sy := mapY + m.cursorY*TileHeight i.DrawRect(sx, sy, TileWidth, TileHeight, color.Black)