76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package system
|
|
|
|
import "io"
|
|
import "image"
|
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
|
import "git.tebibyte.media/tomo/backend/style"
|
|
import "git.tebibyte.media/sashakoshka/goutil/container"
|
|
|
|
// System is coupled to a tomo.Backend implementation, and manages Hierarchies
|
|
// and Boxes.
|
|
type System struct {
|
|
link BackendLink
|
|
|
|
style *style.Style
|
|
iconSet style.IconSet
|
|
faceSet style.FaceSet
|
|
styleNonce int
|
|
iconSetNonce int
|
|
|
|
hierarchies ucontainer.Set[*Hierarchy]
|
|
}
|
|
|
|
// BackendLink allows the System to call up into the tomo.Backend implementation
|
|
// which contains it in order to do things such as create new textures.
|
|
type BackendLink interface {
|
|
// NewTexture creates a new texture from an image.
|
|
NewTexture (image.Image) canvas.TextureCloser
|
|
// NewSurface creates a new surface with the specified bounds.
|
|
NewSurface (image.Rectangle) (SurfaceLink, error)
|
|
}
|
|
|
|
// SurfaceLink wraps a Surface created by the backend implementation, allowing
|
|
// the System a higher level of control over it.
|
|
type SurfaceLink interface {
|
|
io.Closer
|
|
GetSurface () any
|
|
SetSize (image.Rectangle)
|
|
}
|
|
|
|
// New creates a new System.
|
|
func New (link BackendLink) *System {
|
|
return &System {
|
|
link: link,
|
|
hierarchies: make(ucontainer.Set[*Hierarchy]),
|
|
}
|
|
}
|
|
|
|
// SetStyle sets the style that is applied to objects, and notifies them
|
|
// that the style has changed.
|
|
func (this *System) SetStyle (style *style.Style) {
|
|
this.style = style
|
|
this.styleNonce ++
|
|
for hierarchy := range this.hierarchies {
|
|
hierarchy.setStyle()
|
|
}
|
|
}
|
|
|
|
// SetIconSet sets the icon set that provides icon textures, and notifies
|
|
// objects that the icons have changed.
|
|
func (this *System) SetIconSet (iconSet style.IconSet) {
|
|
this.iconSet = iconSet
|
|
this.iconSetNonce ++
|
|
for hierarchy := range this.hierarchies {
|
|
hierarchy.setIconSet()
|
|
}
|
|
}
|
|
|
|
// SetFaceSet sets the face set that provides font faces.
|
|
func (this *System) SetFaceSet (faceSet style.FaceSet) {
|
|
this.faceSet = faceSet
|
|
}
|
|
|
|
func (this *System) removeHierarchy (hierarchy *Hierarchy) {
|
|
delete(this.hierarchies, hierarchy)
|
|
}
|