8 Commits

6 changed files with 48 additions and 12 deletions

3
go.mod
View File

@@ -3,9 +3,10 @@ module git.tebibyte.media/tomo/backend
go 1.20 go 1.20
require ( require (
git.tebibyte.media/tomo/tomo v0.38.0 git.tebibyte.media/tomo/tomo v0.40.0
git.tebibyte.media/tomo/typeset v0.7.1 git.tebibyte.media/tomo/typeset v0.7.1
git.tebibyte.media/tomo/xgbkb v1.0.1 git.tebibyte.media/tomo/xgbkb v1.0.1
git.tebibyte.media/tomo/xgbsel/v2 v2.0.0-alpha.1
github.com/jezek/xgb v1.1.1 github.com/jezek/xgb v1.1.1
github.com/jezek/xgbutil v0.0.0-20231116234834-47f30c120111 github.com/jezek/xgbutil v0.0.0-20231116234834-47f30c120111
golang.org/x/image v0.11.0 golang.org/x/image v0.11.0

6
go.sum
View File

@@ -1,10 +1,12 @@
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q= git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
git.tebibyte.media/tomo/tomo v0.38.0 h1:K5TP67RxnszudeNfmGZiU5cFTRjFueXiI3NCsgw+05U= git.tebibyte.media/tomo/tomo v0.40.0 h1:X1ffSGE+dXI1VkJ97vM+RMfSfchCvSbP0vRbLJ9qoDE=
git.tebibyte.media/tomo/tomo v0.38.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps= git.tebibyte.media/tomo/tomo v0.40.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8= git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8=
git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g= git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE= git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=
git.tebibyte.media/tomo/xgbkb v1.0.1/go.mod h1:P5Du0yo5hUsojchW08t+Mds0XPIJXwMi733ZfklzjRw= git.tebibyte.media/tomo/xgbkb v1.0.1/go.mod h1:P5Du0yo5hUsojchW08t+Mds0XPIJXwMi733ZfklzjRw=
git.tebibyte.media/tomo/xgbsel/v2 v2.0.0-alpha.1 h1:B9Z2UZzfHlZZUbKiz3WFOSMUgVO5FvH0bYQ1m0cC0dk=
git.tebibyte.media/tomo/xgbsel/v2 v2.0.0-alpha.1/go.mod h1:NIyIbAPQQbevOKDmkKRgIUizEcPFMYCR4unj/mvvXcA=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA= github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ= github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g= github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=

View File

@@ -203,7 +203,10 @@ func (this *box) SetPadding (padding tomo.Inset) {
} }
func (this *box) SetRole (role tomo.Role) { func (this *box) SetRole (role tomo.Role) {
if this.role == role { return }
this.role = role this.role = role
this.lastStyleNonce = -1
this.outer.recursiveReApply()
} }
func (this *box) SetDNDData (dat data.Data) { func (this *box) SetDNDData (dat data.Data) {

View File

@@ -29,7 +29,10 @@ func (this *canvasBox) Invalidate () {
} }
func (this *canvasBox) Draw (can canvas.Canvas) { func (this *canvasBox) Draw (can canvas.Canvas) {
if can == nil { return }
this.box.Draw(can) this.box.Draw(can)
this.userDrawer.Draw ( if this.userDrawer != nil {
can.SubCanvas(this.padding.Apply(this.innerClippingBounds))) this.userDrawer.Draw (
can.SubCanvas(this.padding.Apply(this.innerClippingBounds)))
}
} }

View File

@@ -1,6 +1,7 @@
package xcanvas package xcanvas
import "sort" import "sort"
import "math"
import "image" import "image"
import "github.com/jezek/xgbutil/xgraphics" import "github.com/jezek/xgbutil/xgraphics"
@@ -158,12 +159,12 @@ func (this *pen) fillPolygon (c xgraphics.BGRA, points ...image.Point) {
area = this.image.Bounds().Intersect(area) area = this.image.Bounds().Intersect(area)
if area.Empty() { return } if area.Empty() { return }
boundaries := make([]int, len(points))
context := fillingContext { context := fillingContext {
image: this.image, image: this.image,
color: this.fill, color: this.fill,
min: area.Min.X, min: area.Min.X,
max: area.Max.X, max: area.Max.X,
boundaries: make([]int, len(points)),
points: points, points: points,
} }
@@ -181,19 +182,19 @@ func (this *pen) fillPolygon (c xgraphics.BGRA, points ...image.Point) {
(fPointY < fy && fPrevY >= fy) || (fPointY < fy && fPrevY >= fy) ||
(fPrevY < fy && fPointY >= fy) (fPrevY < fy && fPointY >= fy)
if addboundary { if addboundary {
context.boundaries[boundaryCount] = int ( boundaries[boundaryCount] = int(math.Round (
fPointX + fPointX +
(fy - fPointY) / (fy - fPointY) /
(fPrevY - fPointY) * (fPrevY - fPointY) *
(fPrevX - fPointX)) (fPrevX - fPointX)))
boundaryCount ++ boundaryCount ++
} }
prevPoint = point prevPoint = point
} }
// sort boundary list // sort boundary list
cutBoundaries := context.boundaries[:boundaryCount] context.boundaries = boundaries[:boundaryCount]
sort.Ints(cutBoundaries) sort.Ints(context.boundaries)
// fill pixels between boundary pairs // fill pixels between boundary pairs
if c.A == 255 { if c.A == 255 {
@@ -215,7 +216,7 @@ type fillingContext struct {
} }
func (context *fillingContext) fillPolygonHotOpaque () { func (context *fillingContext) fillPolygonHotOpaque () {
for index := 0; index < len(context.boundaries); index += 2 { for index := 0; index < len(context.boundaries) - 1; index += 2 {
left := context.boundaries[index] left := context.boundaries[index]
right := context.boundaries[index + 1] right := context.boundaries[index + 1]
@@ -240,7 +241,7 @@ func (context *fillingContext) fillPolygonHotOpaque () {
} }
func (context *fillingContext) fillPolygonHotTransparent () { func (context *fillingContext) fillPolygonHotTransparent () {
for index := 0; index < len(context.boundaries); index += 2 { for index := 0; index < len(context.boundaries) - 1; index += 2 {
left := context.boundaries[index] left := context.boundaries[index]
right := context.boundaries[index + 1] right := context.boundaries[index + 1]

26
x/selection.go Normal file
View File

@@ -0,0 +1,26 @@
package x
import "io"
import "strings"
import "git.tebibyte.media/tomo/xgbsel/v2"
import "git.tebibyte.media/tomo/tomo/data"
type selectionData struct {
data data.Data
}
func (this selectionData) Convert (target xgbsel.Target) (io.ReadSeekCloser, bool) {
mimeStr, _ := target.ToMime()
ty, subty, _ := strings.Cut(string(mimeStr), "/")
mime := data.M(ty, subty)
stream, ok := this.data[mime]
stream.Seek(0, io.SeekStart)
return stream, ok
}
func (this selectionData) Supported () (targets []xgbsel.Target) {
for mime := range this.data {
targets = append(targets, xgbsel.MimeToTargets(mime.String())...)
}
return targets
}