Compare commits
No commits in common. "8aa8dc9570a8d13cebb5af86b773c34fe629f327" and "2af42a3568979215b7e6b27b7bb114caa99c3d48" have entirely different histories.
8aa8dc9570
...
2af42a3568
@ -27,15 +27,12 @@ type box struct {
|
|||||||
focusQueued *bool
|
focusQueued *bool
|
||||||
|
|
||||||
attrColor attrHierarchy[tomo.AttrColor]
|
attrColor attrHierarchy[tomo.AttrColor]
|
||||||
attrIcon attrHierarchy[tomo.AttrIcon]
|
|
||||||
attrTexture attrHierarchy[tomo.AttrTexture]
|
attrTexture attrHierarchy[tomo.AttrTexture]
|
||||||
attrTextureMode attrHierarchy[tomo.AttrTextureMode]
|
attrTextureMode attrHierarchy[tomo.AttrTextureMode]
|
||||||
attrBorder attrHierarchy[tomo.AttrBorder]
|
attrBorder attrHierarchy[tomo.AttrBorder]
|
||||||
attrMinimumSize attrHierarchy[tomo.AttrMinimumSize]
|
attrMinimumSize attrHierarchy[tomo.AttrMinimumSize]
|
||||||
attrPadding attrHierarchy[tomo.AttrPadding]
|
attrPadding attrHierarchy[tomo.AttrPadding]
|
||||||
|
|
||||||
icon canvas.Texture
|
|
||||||
|
|
||||||
dndData data.Data
|
dndData data.Data
|
||||||
dndAccept []data.Mime
|
dndAccept []data.Mime
|
||||||
focusable bool
|
focusable bool
|
||||||
@ -195,11 +192,6 @@ func (this *box) setAttr (attr tomo.Attr, user bool) {
|
|||||||
this.invalidateDraw()
|
this.invalidateDraw()
|
||||||
}
|
}
|
||||||
|
|
||||||
case tomo.AttrIcon:
|
|
||||||
if this.attrIcon.Set(attr, user) {
|
|
||||||
this.handleIconChange()
|
|
||||||
}
|
|
||||||
|
|
||||||
case tomo.AttrTexture:
|
case tomo.AttrTexture:
|
||||||
if this.attrTexture.Set(attr, user) {
|
if this.attrTexture.Set(attr, user) {
|
||||||
this.invalidateDraw()
|
this.invalidateDraw()
|
||||||
@ -235,11 +227,6 @@ func (this *box) unsetAttr (kind tomo.AttrKind, user bool) {
|
|||||||
this.invalidateDraw()
|
this.invalidateDraw()
|
||||||
}
|
}
|
||||||
|
|
||||||
case tomo.AttrKindIcon:
|
|
||||||
if this.attrIcon.Unset(user) {
|
|
||||||
this.handleIconChange()
|
|
||||||
}
|
|
||||||
|
|
||||||
case tomo.AttrKindTexture:
|
case tomo.AttrKindTexture:
|
||||||
if this.attrTexture.Unset(user) {
|
if this.attrTexture.Unset(user) {
|
||||||
this.invalidateDraw()
|
this.invalidateDraw()
|
||||||
@ -436,31 +423,20 @@ func (this *box) Draw (can canvas.Canvas) {
|
|||||||
|
|
||||||
// centered texture
|
// centered texture
|
||||||
if textureMode == tomo.TextureModeCenter && texture != nil {
|
if textureMode == tomo.TextureModeCenter && texture != nil {
|
||||||
this.centeredTexture(can, texture)
|
textureBounds := texture.Bounds()
|
||||||
|
textureOrigin :=
|
||||||
|
bounds.Min.
|
||||||
|
Add(image.Pt (
|
||||||
|
bounds.Dx() / 2,
|
||||||
|
bounds.Dy() / 2)).
|
||||||
|
Sub(image.Pt (
|
||||||
|
textureBounds.Dx() / 2,
|
||||||
|
textureBounds.Dy() / 2))
|
||||||
|
|
||||||
|
pen.Fill(color.Transparent)
|
||||||
|
pen.Texture(texture)
|
||||||
|
pen.Rectangle(textureBounds.Sub(textureBounds.Min).Add(textureOrigin))
|
||||||
}
|
}
|
||||||
|
|
||||||
// centered icon
|
|
||||||
if this.icon != nil {
|
|
||||||
this.centeredTexture(can, this.icon)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *box) centeredTexture (can canvas.Canvas, texture canvas.Texture) {
|
|
||||||
pen := can.Pen()
|
|
||||||
bounds := this.Bounds()
|
|
||||||
textureBounds := texture.Bounds()
|
|
||||||
textureOrigin :=
|
|
||||||
bounds.Min.
|
|
||||||
Add(image.Pt (
|
|
||||||
bounds.Dx() / 2,
|
|
||||||
bounds.Dy() / 2)).
|
|
||||||
Sub(image.Pt (
|
|
||||||
textureBounds.Dx() / 2,
|
|
||||||
textureBounds.Dy() / 2))
|
|
||||||
|
|
||||||
pen.Fill(color.Transparent)
|
|
||||||
pen.Texture(texture)
|
|
||||||
pen.Rectangle(textureBounds.Sub(textureBounds.Min).Add(textureOrigin))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *box) drawBorders (can canvas.Canvas) {
|
func (this *box) drawBorders (can canvas.Canvas) {
|
||||||
@ -600,15 +576,6 @@ func (this *box) handleBorderChange (previousBorderSum tomo.Inset, different boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *box) handleIconChange () {
|
|
||||||
this.icon = nil
|
|
||||||
hierarchy := this.getHierarchy()
|
|
||||||
if hierarchy == nil { return }
|
|
||||||
icon := this.attrIcon.Value()
|
|
||||||
if icon.Icon == tomo.IconUnknown { return }
|
|
||||||
this.icon = hierarchy.getIconSet().Icon(icon.Icon, icon.Size)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *box) invalidateStyle () {
|
func (this *box) invalidateStyle () {
|
||||||
hierarchy := this.getHierarchy()
|
hierarchy := this.getHierarchy()
|
||||||
if hierarchy == nil { return }
|
if hierarchy == nil { return }
|
||||||
|
34
x/backend.go
34
x/backend.go
@ -4,9 +4,7 @@ import "image"
|
|||||||
import "errors"
|
import "errors"
|
||||||
import "git.tebibyte.media/tomo/tomo"
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
import "git.tebibyte.media/tomo/xgbkb"
|
import "git.tebibyte.media/tomo/xgbkb"
|
||||||
import "git.tebibyte.media/tomo/tomo/data"
|
|
||||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||||
import "git.tebibyte.media/tomo/backend/style"
|
|
||||||
import "git.tebibyte.media/tomo/backend/x/canvas"
|
import "git.tebibyte.media/tomo/backend/x/canvas"
|
||||||
import "git.tebibyte.media/tomo/backend/internal/system"
|
import "git.tebibyte.media/tomo/backend/internal/system"
|
||||||
|
|
||||||
@ -19,9 +17,6 @@ import "github.com/jezek/xgbutil/mousebind"
|
|||||||
type Backend struct {
|
type Backend struct {
|
||||||
x *xgbutil.XUtil
|
x *xgbutil.XUtil
|
||||||
system *system.System
|
system *system.System
|
||||||
|
|
||||||
style *style.Style
|
|
||||||
iconSet style.IconSet
|
|
||||||
|
|
||||||
doChannel chan func()
|
doChannel chan func()
|
||||||
windows map[xproto.Window] *window
|
windows map[xproto.Window] *window
|
||||||
@ -131,40 +126,19 @@ func (this *Backend) NewCanvas (bounds image.Rectangle) canvas.CanvasCloser {
|
|||||||
return xcanvas.NewCanvas(this.x, bounds)
|
return xcanvas.NewCanvas(this.x, bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Backend) ColorRGBA (id tomo.Color) (r, g, b, a uint32) {
|
func (this *Backend) SetStyle (style *tomo.Style) {
|
||||||
if col, ok := this.style.Colors[id]; ok {
|
|
||||||
return col.RGBA()
|
|
||||||
}
|
|
||||||
return 0xFFFF, 0, 0xFFFF, 0xFFFF // punish bad styles
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Backend) IconTexture (id tomo.Icon, size tomo.IconSize) canvas.Texture {
|
|
||||||
return this.iconSet.Icon(id, size)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Backend) MimeIconTexture (mime data.Mime, size tomo.IconSize) canvas.Texture {
|
|
||||||
return this.iconSet.MimeIcon(mime, size)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Backend) SetStyle (style *style.Style) {
|
|
||||||
this.style = style
|
|
||||||
this.system.SetStyle(style)
|
this.system.SetStyle(style)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Backend) SetIconSet (iconSet style.IconSet) {
|
func (this *Backend) SetIconSet (icons tomo.IconSet) {
|
||||||
this.iconSet = iconSet
|
this.system.SetIconSet(icons)
|
||||||
this.system.SetIconSet(iconSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Backend) SetFaceSet (faceSet style.FaceSet) {
|
|
||||||
this.system.SetFaceSet(faceSet)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Backend) assert () {
|
func (this *Backend) assert () {
|
||||||
if this == nil { panic("x: nil backend") }
|
if this == nil { panic("x: nil backend") }
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Backend) afterEvent () {
|
func (this *Backend) afterEvent () {
|
||||||
for _, window := range this.windows {
|
for _, window := range this.windows {
|
||||||
window.hierarchy.AfterEvent()
|
window.hierarchy.AfterEvent()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user