Skip to content

Commit

Permalink
Merge pull request #22 from OpenSauce/Render-Debug-Depth
Browse files Browse the repository at this point in the history
Added in Debug Rendering as a BFS to Render Depth
  • Loading branch information
yohamta authored Aug 4, 2022
2 parents e629005 + db38dbc commit 71c2af2
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 407 deletions.
15 changes: 0 additions & 15 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package furex

import (
"image"
"image/color"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
Expand All @@ -22,26 +21,12 @@ func (ct *containerEmbed) processEvent() {

// Draw draws it's children
func (ct *containerEmbed) Draw(screen *ebiten.Image) {
if Debug {
G.DrawRect(screen, &DrawRectOpts{
Rect: ct.frame,
Color: color.RGBA{0xff, 0xff, 0, 0xff},
StrokeWidth: 2,
})
}
for _, c := range ct.children {
b := c.bounds.Add(ct.frame.Min)
if c.item.Handler != nil {
c.item.Handler.HandleDraw(screen, b)
}
c.item.Draw(screen)
if Debug {
G.DrawRect(screen, &DrawRectOpts{
Rect: b,
Color: color.RGBA{0xff, 0, 0xff, 0xff},
StrokeWidth: 2,
})
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions examples/nesting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func (g *Game) setupUI() {
func main() {
ebiten.SetWindowSize(480, 640)

furex.Debug = true

game, err := NewGame()
if err != nil {
panic(err)
Expand Down
49 changes: 48 additions & 1 deletion furex.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
package furex

var Debug = false
import (
"image/color"

"github.com/hajimehoshi/ebiten/v2"
)

var (
Debug = false
debugColor = color.RGBA{0xff, 0, 0, 0xff}
debugColorShift = ebiten.ColorM{}
)

func debugBorders(screen *ebiten.Image, root containerEmbed) {
queue := []containerEmbed{}
queue = append(queue, root)
renderColor := resetDebugColor()

for len(queue) > 0 {
levelSize := len(queue)
for levelSize != 0 {
curr := queue[0]
queue = queue[1:]

G.DrawRect(screen, &DrawRectOpts{
Rect: curr.frame,
Color: renderColor,
StrokeWidth: 2,
})

for _, c := range curr.children {
queue = append(queue, c.item.containerEmbed)
}
levelSize--
}

renderColor = rotateDebugColor()
}
}

func rotateDebugColor() color.Color {
debugColorShift.RotateHue(1.66)
return debugColorShift.Apply(debugColor)
}

func resetDebugColor() color.Color {
debugColorShift = ebiten.ColorM{}
return debugColor
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/yohamta/furex/v2
go 1.16

require (
github.com/hajimehoshi/ebiten/v2 v2.2.0
github.com/stretchr/testify v1.7.1
golang.org/x/exp v0.0.0-20211008200323-95152d363a1c
golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
github.com/hajimehoshi/ebiten/v2 v2.3.7
github.com/stretchr/testify v1.8.0
golang.org/x/exp/shiny v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105 // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
)
Loading

0 comments on commit 71c2af2

Please sign in to comment.