package system import "io" import "image" import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/backend/internal/util" // System is coupled to a tomo.Backend implementation, and manages Hierarchies // and Boxes. type System struct { link BackendLink style tomo.Style styleNonce int iconsNonce int hierarchies util.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(util.Set[*Hierarchy]), } } // SetStyle sets the tomo.Style that is applied to objects, and notifies them // that the style has changed. func (this *System) SetStyle (style tomo.Style) { this.style = style this.styleNonce ++ for hierarchy := range this.hierarchies { hierarchy.setStyle() } } // SetIcons notifies objects that the icons have changed. func (this *System) SetIcons (icons tomo.Icons) { this.iconsNonce ++ for hierarchy := range this.hierarchies { hierarchy.setIcons() } } func (this *System) removeHierarchy (hierarchy *Hierarchy) { delete(this.hierarchies, hierarchy) }