2024-06-01 14:39:14 -06:00
|
|
|
package system
|
|
|
|
|
2024-06-02 11:34:11 -06:00
|
|
|
import "io"
|
2024-06-01 14:39:14 -06:00
|
|
|
import "image"
|
|
|
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
2024-08-10 18:24:25 -06:00
|
|
|
import "git.tebibyte.media/tomo/backend/style"
|
2024-06-11 16:12:47 -06:00
|
|
|
import "git.tebibyte.media/tomo/backend/internal/util"
|
2024-06-01 14:39:14 -06:00
|
|
|
|
2024-06-02 11:23:03 -06:00
|
|
|
// System is coupled to a tomo.Backend implementation, and manages Hierarchies
|
|
|
|
// and Boxes.
|
2024-06-01 14:39:14 -06:00
|
|
|
type System struct {
|
2024-06-11 22:39:00 -06:00
|
|
|
link BackendLink
|
|
|
|
|
2024-08-10 18:24:25 -06:00
|
|
|
style *style.Style
|
|
|
|
iconSet style.IconSet
|
|
|
|
faceSet style.FaceSet
|
|
|
|
styleNonce int
|
|
|
|
iconSetNonce int
|
2024-06-11 22:39:00 -06:00
|
|
|
|
2024-06-11 16:12:47 -06:00
|
|
|
hierarchies util.Set[*Hierarchy]
|
2024-06-01 14:39:14 -06:00
|
|
|
}
|
|
|
|
|
2024-06-02 11:33:59 -06:00
|
|
|
// BackendLink allows the System to call up into the tomo.Backend implementation
|
2024-06-02 11:23:03 -06:00
|
|
|
// which contains it in order to do things such as create new textures.
|
2024-06-01 14:39:14 -06:00
|
|
|
type BackendLink interface {
|
2024-06-02 11:33:59 -06:00
|
|
|
// NewTexture creates a new texture from an image.
|
2024-06-01 14:39:14 -06:00
|
|
|
NewTexture (image.Image) canvas.TextureCloser
|
2024-06-02 11:33:59 -06:00
|
|
|
// NewSurface creates a new surface with the specified bounds.
|
2024-06-02 20:47:17 -06:00
|
|
|
NewSurface (image.Rectangle) (SurfaceLink, error)
|
2024-06-01 14:39:14 -06:00
|
|
|
}
|
|
|
|
|
2024-06-02 11:23:03 -06:00
|
|
|
// SurfaceLink wraps a Surface created by the backend implementation, allowing
|
|
|
|
// the System a higher level of control over it.
|
2024-06-01 14:39:14 -06:00
|
|
|
type SurfaceLink interface {
|
2024-06-02 11:34:11 -06:00
|
|
|
io.Closer
|
2024-06-01 14:39:14 -06:00
|
|
|
GetSurface () any
|
|
|
|
SetSize (image.Rectangle)
|
|
|
|
}
|
|
|
|
|
2024-06-02 11:23:03 -06:00
|
|
|
// New creates a new System.
|
2024-06-01 14:39:14 -06:00
|
|
|
func New (link BackendLink) *System {
|
|
|
|
return &System {
|
2024-06-11 16:12:47 -06:00
|
|
|
link: link,
|
|
|
|
hierarchies: make(util.Set[*Hierarchy]),
|
2024-06-01 14:39:14 -06:00
|
|
|
}
|
|
|
|
}
|
2024-06-11 16:12:47 -06:00
|
|
|
|
2024-08-10 18:24:25 -06:00
|
|
|
// SetStyle sets the style that is applied to objects, and notifies them
|
2024-06-11 16:12:47 -06:00
|
|
|
// that the style has changed.
|
2024-08-10 18:24:25 -06:00
|
|
|
func (this *System) SetStyle (style *style.Style) {
|
2024-06-11 22:39:00 -06:00
|
|
|
this.style = style
|
|
|
|
this.styleNonce ++
|
2024-06-11 16:12:47 -06:00
|
|
|
for hierarchy := range this.hierarchies {
|
2024-06-11 22:39:00 -06:00
|
|
|
hierarchy.setStyle()
|
2024-06-11 16:12:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-10 18:24:25 -06:00
|
|
|
// 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 ++
|
2024-06-11 16:12:47 -06:00
|
|
|
for hierarchy := range this.hierarchies {
|
2024-07-25 11:01:15 -06:00
|
|
|
hierarchy.setIconSet()
|
2024-06-11 16:12:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-10 18:24:25 -06:00
|
|
|
// SetFaceSet sets the face set that provides font faces.
|
|
|
|
func (this *System) SetFaceSet (faceSet style.FaceSet) {
|
|
|
|
this.faceSet = faceSet
|
|
|
|
}
|
|
|
|
|
2024-06-11 16:12:47 -06:00
|
|
|
func (this *System) removeHierarchy (hierarchy *Hierarchy) {
|
|
|
|
delete(this.hierarchies, hierarchy)
|
|
|
|
}
|