Add SetTextureCenter
This commit is contained in:
parent
dd201f1b5f
commit
a5830c9823
55
box.go
55
box.go
@ -9,23 +9,29 @@ import "git.tebibyte.media/tomo/tomo/input"
|
||||
import "git.tebibyte.media/tomo/tomo/event"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
|
||||
type textureMode int; const (
|
||||
textureModeTile textureMode = iota
|
||||
textureModeCenter
|
||||
)
|
||||
|
||||
type box struct {
|
||||
backend *Backend
|
||||
parent parent
|
||||
outer anyBox
|
||||
|
||||
bounds image.Rectangle
|
||||
minSize image.Point
|
||||
userMinSize image.Point
|
||||
bounds image.Rectangle
|
||||
minSize image.Point
|
||||
userMinSize image.Point
|
||||
innerClippingBounds image.Rectangle
|
||||
|
||||
minSizeQueued bool
|
||||
focusQueued *bool
|
||||
|
||||
padding tomo.Inset
|
||||
border []tomo.Border
|
||||
color color.Color
|
||||
texture *xcanvas.Texture
|
||||
padding tomo.Inset
|
||||
border []tomo.Border
|
||||
color color.Color
|
||||
texture *xcanvas.Texture
|
||||
textureMode textureMode
|
||||
|
||||
dndData data.Data
|
||||
dndAccept []data.Mime
|
||||
@ -116,12 +122,20 @@ func (this *box) SetColor (c color.Color) {
|
||||
this.invalidateDraw()
|
||||
}
|
||||
|
||||
func (this *box) SetTexture (texture canvas.Texture) {
|
||||
if this.texture == texture { return }
|
||||
func (this *box) SetTextureTile (texture canvas.Texture) {
|
||||
if this.texture == texture && this.textureMode == textureModeTile { return }
|
||||
this.textureMode = textureModeTile
|
||||
this.texture = xcanvas.AssertTexture(texture)
|
||||
this.invalidateDraw()
|
||||
}
|
||||
|
||||
func (this *box) SetTextureCenter (texture canvas.Texture) {
|
||||
if this.texture == texture && this.textureMode == textureModeCenter { return }
|
||||
this.texture = xcanvas.AssertTexture(texture)
|
||||
this.textureMode = textureModeCenter
|
||||
this.invalidateDraw()
|
||||
}
|
||||
|
||||
func (this *box) SetBorder (borders ...tomo.Border) {
|
||||
previousBorderSum := this.borderSum()
|
||||
previousBorders := this.border
|
||||
@ -299,13 +313,30 @@ func (this *box) handleKeyUp (key input.Key, numberPad bool) {
|
||||
func (this *box) Draw (can canvas.Canvas) {
|
||||
if can == nil { return }
|
||||
pen := can.Pen()
|
||||
bounds := this.Bounds()
|
||||
|
||||
// background
|
||||
pen.Fill(this.color)
|
||||
pen.Texture(this.texture)
|
||||
|
||||
if this.textureMode == textureModeTile {
|
||||
pen.Texture(this.texture)
|
||||
}
|
||||
if this.transparent() && this.parent != nil {
|
||||
this.parent.drawBackgroundPart(can)
|
||||
}
|
||||
pen.Rectangle(this.Bounds())
|
||||
pen.Rectangle(bounds)
|
||||
|
||||
// centered texture
|
||||
if this.textureMode == textureModeCenter {
|
||||
textureBounds := this.texture.Bounds()
|
||||
textureOrigin := image.Pt (
|
||||
textureBounds.Dx() / -2,
|
||||
textureBounds.Dy() / -2).
|
||||
Add(bounds.Min)
|
||||
|
||||
pen.Fill(color.Transparent)
|
||||
pen.Texture(this.texture)
|
||||
pen.Rectangle(textureBounds.Sub(textureBounds.Min).Add(textureOrigin))
|
||||
}
|
||||
}
|
||||
|
||||
func (this *box) drawBorders (can canvas.Canvas) {
|
||||
|
Reference in New Issue
Block a user