drawdfs query? nope lol
This commit is contained in:
parent
106ecb6d0c
commit
e00782ea6c
1 changed files with 48 additions and 11 deletions
|
@ -30,16 +30,52 @@ type DrawDFS struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
if d.Hidden() {
|
if true {
|
||||||
return
|
d.drawRecursive(d, screen, *opts)
|
||||||
|
} else {
|
||||||
|
d.drawWithQuery(screen, opts)
|
||||||
}
|
}
|
||||||
d.drawRecursive(d.Child, screen, *opts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManagesDrawingSubcomponents is present so DrawDFS is recognised as a
|
// ManagesDrawingSubcomponents is present so DrawDFS is recognised as a
|
||||||
// DrawManager.
|
// DrawManager.
|
||||||
func (DrawDFS) ManagesDrawingSubcomponents() {}
|
func (DrawDFS) ManagesDrawingSubcomponents() {}
|
||||||
|
|
||||||
|
// This doesn't work! This misses Hiders, Transformers that are not Drawers.
|
||||||
|
func (d *DrawDFS) drawWithQuery(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
|
stack := []ebiten.DrawImageOptions{*opts}
|
||||||
|
d.game.Query(d, DrawerType,
|
||||||
|
// visitPre
|
||||||
|
func(x interface{}) error {
|
||||||
|
if h, ok := x.(Hider); ok && h.Hidden() {
|
||||||
|
return Skip
|
||||||
|
}
|
||||||
|
opts := stack[len(stack)-1]
|
||||||
|
if tf, ok := x.(Transformer); ok {
|
||||||
|
opts = concatOpts(tf.Transform(), opts)
|
||||||
|
stack = append(stack, opts)
|
||||||
|
}
|
||||||
|
if x == d {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if dr, ok := x.(Drawer); ok {
|
||||||
|
dr.Draw(screen, &opts)
|
||||||
|
}
|
||||||
|
if _, isDM := x.(DrawManager); isDM {
|
||||||
|
return Skip
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
// visitPost
|
||||||
|
func(x interface{}) error {
|
||||||
|
if _, ok := x.(Transformer); ok {
|
||||||
|
stack = stack[:len(stack)-1]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DrawDFS) drawRecursive(component interface{}, screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
func (d *DrawDFS) drawRecursive(component interface{}, screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
||||||
// Hidden? stop drawing
|
// Hidden? stop drawing
|
||||||
if h, ok := component.(Hider); ok && h.Hidden() {
|
if h, ok := component.(Hider); ok && h.Hidden() {
|
||||||
|
@ -49,16 +85,17 @@ func (d *DrawDFS) drawRecursive(component interface{}, screen *ebiten.Image, opt
|
||||||
if tf, ok := component.(Transformer); ok {
|
if tf, ok := component.(Transformer); ok {
|
||||||
opts = concatOpts(tf.Transform(), opts)
|
opts = concatOpts(tf.Transform(), opts)
|
||||||
}
|
}
|
||||||
// Does it draw itself? Draw
|
if component != d {
|
||||||
if dr, ok := component.(Drawer); ok {
|
// Does it draw itself? Draw
|
||||||
dr.Draw(screen, &opts)
|
if dr, ok := component.(Drawer); ok {
|
||||||
}
|
dr.Draw(screen, &opts)
|
||||||
// Is it a DrawManager? It manages drawing all its subcomponents.
|
}
|
||||||
if _, ok := component.(DrawManager); ok {
|
// Is it a DrawManager? It manages drawing all its subcomponents.
|
||||||
return
|
if _, ok := component.(DrawManager); ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Has subcomponents? recurse
|
// Has subcomponents? recurse
|
||||||
// TODO: use g.Query?
|
|
||||||
d.game.Children(component).Scan(func(x interface{}) error {
|
d.game.Children(component).Scan(func(x interface{}) error {
|
||||||
d.drawRecursive(x, screen, opts)
|
d.drawRecursive(x, screen, opts)
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue