Gave CoreControl the ability to shatter parent backgrounds

This commit is contained in:
Sasha Koshka 2023-04-02 22:46:38 -04:00
parent 46a4858597
commit 2d0a0cc073
2 changed files with 19 additions and 5 deletions

View File

@ -4,7 +4,6 @@ import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme" import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config" import "git.tebibyte.media/sashakoshka/tomo/default/config"
@ -189,10 +188,11 @@ func (element *Container) redoAll () {
for index, entry := range element.children { for index, entry := range element.children {
rocks[index] = entry.Bounds rocks[index] = entry.Bounds
} }
pattern := element.theme.Pattern (
tomo.PatternBackground, element.core.DrawBackgroundBoundsShatter (
tomo.State { }) element.theme.Pattern(tomo.PatternBackground, tomo.State { }),
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...) element.Bounds(),
rocks...)
// cut our canvas up and give peices to child elements // cut our canvas up and give peices to child elements
for _, entry := range element.children { for _, entry := range element.children {

View File

@ -5,6 +5,7 @@ import "image/color"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/shatter"
// Core is a struct that implements some core functionality common to most // Core is a struct that implements some core functionality common to most
// widgets. It is meant to be embedded directly into a struct. // widgets. It is meant to be embedded directly into a struct.
@ -144,6 +145,19 @@ func (control CoreControl) DrawBackgroundBounds (
} }
} }
// DrawBackgroundBoundsShatter is like DrawBackgroundBounds, but uses the
// shattering algorithm to avoid drawing in areas specified by rocks.
func (control CoreControl) DrawBackgroundBoundsShatter (
fallback artist.Pattern,
bounds image.Rectangle,
rocks ...image.Rectangle,
) {
tiles := shatter.Shatter(bounds, rocks...)
for _, tile := range tiles {
control.DrawBackgroundBounds(fallback, tile)
}
}
// Window returns the window containing the element. // Window returns the window containing the element.
func (control CoreControl) Window () tomo.Window { func (control CoreControl) Window () tomo.Window {
parent := control.Parent() parent := control.Parent()