Add SetTextureCenter
This commit is contained in:
parent
dd201f1b5f
commit
a5830c9823
41
box.go
41
box.go
@ -9,6 +9,11 @@ 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
|
||||
@ -26,6 +31,7 @@ type box struct {
|
||||
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()
|
||||
pen.Fill(this.color)
|
||||
pen.Texture(this.texture)
|
||||
bounds := this.Bounds()
|
||||
|
||||
// background
|
||||
pen.Fill(this.color)
|
||||
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