draw the grid explicitly thus leading to full cells w/o the grid

This commit is contained in:
2024-06-15 13:57:54 +02:00
committed by T.v.Dein
parent 6685207fde
commit f3e7428775
2 changed files with 47 additions and 18 deletions

View File

@@ -46,22 +46,22 @@ type ScenePlay struct {
Clear bool Clear bool
Grids []*Grid // 2 grids: one current, one next Grids []*Grid // 2 grids: one current, one next
History History // holds state of past dead cells for evolution traces History History // holds state of past dead cells for evolution traces
Index int // points to current grid Index int // points to current grid
Generations int64 // Stats Generations int64 // Stats
TicksElapsed int // tick counter for game speed TicksElapsed int // tick counter for game speed
Camera Camera // for zoom+move Camera Camera // for zoom+move
World, Cache *ebiten.Image // actual image we render to World, Cache, GridImage *ebiten.Image // actual image we render to
WheelTurned bool // when user turns wheel multiple times, zoom faster WheelTurned bool // when user turns wheel multiple times, zoom faster
Dragging bool // middle mouse is pressed, move canvas Dragging bool // middle mouse is pressed, move canvas
LastCursorPos []float64 // used to check if the user is dragging LastCursorPos []float64 // used to check if the user is dragging
MarkTaken bool // true when mouse1 pressed MarkTaken bool // true when mouse1 pressed
MarkDone bool // true when mouse1 released, copy cells between Mark+Point MarkDone bool // true when mouse1 released, copy cells between Mark+Point
Mark, Point image.Point // area to marks+save Mark, Point image.Point // area to marks+save
RunOneStep bool // mutable flags from config RunOneStep bool // mutable flags from config
TPG int // current game speed (ticks per game) TPG int // current game speed (ticks per game)
Theme Theme Theme Theme
} }
func NewPlayScene(game *Game, config *Config) Scene { func NewPlayScene(game *Game, config *Config) Scene {
@@ -485,6 +485,13 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
} }
} }
if scene.Config.ShowGrid {
// draw the pre-drawn grid onto the world
op.GeoM.Reset()
op.GeoM.Translate(0, 0)
scene.World.DrawImage(scene.GridImage, op)
}
scene.DrawMark(scene.World) scene.DrawMark(scene.World)
scene.Camera.Render(scene.World, screen) scene.Camera.Render(scene.World, screen)
@@ -589,6 +596,13 @@ func (scene *ScenePlay) InitCache() {
} }
for y := 0; y < scene.Config.Height; y++ { for y := 0; y < scene.Config.Height; y++ {
// horizontal grid line
vector.StrokeLine(scene.GridImage,
float32(0), float32(y*scene.Config.Cellsize),
float32(scene.Config.Width*scene.Config.Cellsize), float32(y*scene.Config.Cellsize),
1, scene.Theme.Color(ColGrid), false,
)
for x := 0; x < scene.Config.Width; x++ { for x := 0; x < scene.Config.Width; x++ {
op.GeoM.Reset() op.GeoM.Reset()
op.GeoM.Translate( op.GeoM.Translate(
@@ -597,6 +611,13 @@ func (scene *ScenePlay) InitCache() {
) )
scene.Cache.DrawImage(scene.Theme.Tile(ColDead), op) scene.Cache.DrawImage(scene.Theme.Tile(ColDead), op)
// vertical grid line
vector.StrokeLine(scene.GridImage,
float32(x*scene.Config.Cellsize), float32(0),
float32(x*scene.Config.Cellsize), float32(scene.Config.Height*scene.Config.Cellsize),
1, scene.Theme.Color(ColGrid), false,
)
} }
} }
} }
@@ -615,6 +636,7 @@ func (scene *ScenePlay) InitGrid() {
} }
scene.History = NewHistory(scene.Config.Height, scene.Config.Width) scene.History = NewHistory(scene.Config.Height, scene.Config.Width)
} }
func (scene *ScenePlay) Init() { func (scene *ScenePlay) Init() {
@@ -642,10 +664,17 @@ func (scene *ScenePlay) Init() {
scene.Config.Height*scene.Config.Cellsize, scene.Config.Height*scene.Config.Cellsize,
) )
scene.GridImage = ebiten.NewImage(
scene.Config.Width*scene.Config.Cellsize,
scene.Config.Height*scene.Config.Cellsize,
)
scene.Theme = scene.Config.ThemeManager.GetCurrentTheme() scene.Theme = scene.Config.ThemeManager.GetCurrentTheme()
scene.InitCache() scene.InitCache()
if scene.Config.DelayedStart && !scene.Config.Empty { if scene.Config.DelayedStart && !scene.Config.Empty {
// do not fill the grid when the main menu comes up first, the
// user decides interactively what to do
scene.Config.Empty = true scene.Config.Empty = true
scene.InitGrid() scene.InitGrid()
scene.Config.Empty = false scene.Config.Empty = false

View File

@@ -155,8 +155,8 @@ func (manager *ThemeManager) SetCurrentTheme(theme string) {
func FillCell(tile *ebiten.Image, cellsize int, col color.RGBA) { func FillCell(tile *ebiten.Image, cellsize int, col color.RGBA) {
vector.DrawFilledRect( vector.DrawFilledRect(
tile, tile,
float32(1), float32(0),
float32(1), float32(0),
float32(cellsize), float32(cellsize),
float32(cellsize), float32(cellsize),
col, false, col, false,