forked from joejulian/gio
gpu,widget,op/paint,gpu: remove support for ImageOp.Rect
This is effectively a revert of commit gioui.org/commit/69dfd2e3a5541. ImageOp.Rect is the wrong abstraction; it implies a clipping operation that is better handled by package clip. API change. Uses of ImageOp.Rect should apply a clip.Rect before the PaintOp, or use image.RGBA.SubImage (or similar). Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+6
-13
@@ -130,7 +130,6 @@ type clipOp struct {
|
|||||||
|
|
||||||
// imageOpData is the shadow of paint.ImageOp.
|
// imageOpData is the shadow of paint.ImageOp.
|
||||||
type imageOpData struct {
|
type imageOpData struct {
|
||||||
rect image.Rectangle
|
|
||||||
src *image.RGBA
|
src *image.RGBA
|
||||||
handle interface{}
|
handle interface{}
|
||||||
}
|
}
|
||||||
@@ -170,18 +169,7 @@ func decodeImageOp(data []byte, refs []interface{}) imageOpData {
|
|||||||
if handle == nil {
|
if handle == nil {
|
||||||
return imageOpData{}
|
return imageOpData{}
|
||||||
}
|
}
|
||||||
bo := binary.LittleEndian
|
|
||||||
return imageOpData{
|
return imageOpData{
|
||||||
rect: image.Rectangle{
|
|
||||||
Min: image.Point{
|
|
||||||
X: int(int32(bo.Uint32(data[1:]))),
|
|
||||||
Y: int(int32(bo.Uint32(data[5:]))),
|
|
||||||
},
|
|
||||||
Max: image.Point{
|
|
||||||
X: int(int32(bo.Uint32(data[9:]))),
|
|
||||||
Y: int(int32(bo.Uint32(data[13:]))),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
src: refs[0].(*image.RGBA),
|
src: refs[0].(*image.RGBA),
|
||||||
handle: handle,
|
handle: handle,
|
||||||
}
|
}
|
||||||
@@ -962,7 +950,12 @@ func (d *drawState) materialFor(cache *resourceCache, rect f32.Rectangle, off f3
|
|||||||
m.material = materialTexture
|
m.material = materialTexture
|
||||||
dr := boundRectF(rect.Add(off))
|
dr := boundRectF(rect.Add(off))
|
||||||
sz := d.image.src.Bounds().Size()
|
sz := d.image.src.Bounds().Size()
|
||||||
sr := layout.FRect(d.image.rect)
|
sr := f32.Rectangle{
|
||||||
|
Max: f32.Point{
|
||||||
|
X: float32(sz.X),
|
||||||
|
Y: float32(sz.Y),
|
||||||
|
},
|
||||||
|
}
|
||||||
if dx := float32(dr.Dx()); dx != 0 {
|
if dx := float32(dr.Dx()); dx != 0 {
|
||||||
// Don't clip 1 px width sources.
|
// Don't clip 1 px width sources.
|
||||||
if sdx := sr.Dx(); sdx > 1 {
|
if sdx := sr.Dx(); sdx > 1 {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const (
|
|||||||
TypeTransformLen = 1 + 4*6
|
TypeTransformLen = 1 + 4*6
|
||||||
TypeLayerLen = 1
|
TypeLayerLen = 1
|
||||||
TypeRedrawLen = 1 + 8
|
TypeRedrawLen = 1 + 8
|
||||||
TypeImageLen = 1 + 4*4
|
TypeImageLen = 1
|
||||||
TypePaintLen = 1 + 4*4
|
TypePaintLen = 1 + 4*4
|
||||||
TypeColorLen = 1 + 4
|
TypeColorLen = 1 + 4
|
||||||
TypeLinearGradientLen = 1 + 8*2 + 4*2
|
TypeLinearGradientLen = 1 + 8*2 + 4*2
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ import (
|
|||||||
// Note: the ImageOp may keep a reference to the backing image.
|
// Note: the ImageOp may keep a reference to the backing image.
|
||||||
// See NewImageOp for details.
|
// See NewImageOp for details.
|
||||||
type ImageOp struct {
|
type ImageOp struct {
|
||||||
// Rect is the section if the backing image to use.
|
|
||||||
Rect image.Rectangle
|
|
||||||
|
|
||||||
uniform bool
|
uniform bool
|
||||||
color color.RGBA
|
color color.RGBA
|
||||||
src *image.RGBA
|
src *image.RGBA
|
||||||
@@ -74,7 +71,6 @@ func NewImageOp(src image.Image) ImageOp {
|
|||||||
bounds := src.Bounds()
|
bounds := src.Bounds()
|
||||||
if bounds.Min == (image.Point{}) && src.Stride == bounds.Dx()*4 {
|
if bounds.Min == (image.Point{}) && src.Stride == bounds.Dx()*4 {
|
||||||
return ImageOp{
|
return ImageOp{
|
||||||
Rect: src.Bounds(),
|
|
||||||
src: src,
|
src: src,
|
||||||
handle: new(int),
|
handle: new(int),
|
||||||
}
|
}
|
||||||
@@ -88,7 +84,6 @@ func NewImageOp(src image.Image) ImageOp {
|
|||||||
})
|
})
|
||||||
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
||||||
return ImageOp{
|
return ImageOp{
|
||||||
Rect: dst.Bounds(),
|
|
||||||
src: dst,
|
src: dst,
|
||||||
handle: new(int),
|
handle: new(int),
|
||||||
}
|
}
|
||||||
@@ -110,11 +105,6 @@ func (i ImageOp) Add(o *op.Ops) {
|
|||||||
}
|
}
|
||||||
data := o.Write(opconst.TypeImageLen, i.src, i.handle)
|
data := o.Write(opconst.TypeImageLen, i.src, i.handle)
|
||||||
data[0] = byte(opconst.TypeImage)
|
data[0] = byte(opconst.TypeImage)
|
||||||
bo := binary.LittleEndian
|
|
||||||
bo.PutUint32(data[1:], uint32(i.Rect.Min.X))
|
|
||||||
bo.PutUint32(data[5:], uint32(i.Rect.Min.Y))
|
|
||||||
bo.PutUint32(data[9:], uint32(i.Rect.Max.X))
|
|
||||||
bo.PutUint32(data[13:], uint32(i.Rect.Max.Y))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ColorOp) Add(o *op.Ops) {
|
func (c ColorOp) Add(o *op.Ops) {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ func (im Image) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
if scale == 0 {
|
if scale == 0 {
|
||||||
scale = 160.0 / 72.0
|
scale = 160.0 / 72.0
|
||||||
}
|
}
|
||||||
size := im.Src.Rect.Size()
|
size := im.Src.Size()
|
||||||
wf, hf := float32(size.X), float32(size.Y)
|
wf, hf := float32(size.X), float32(size.Y)
|
||||||
w, h := gtx.Px(unit.Dp(wf*scale)), gtx.Px(unit.Dp(hf*scale))
|
w, h := gtx.Px(unit.Dp(wf*scale)), gtx.Px(unit.Dp(hf*scale))
|
||||||
cs := gtx.Constraints
|
cs := gtx.Constraints
|
||||||
|
|||||||
Reference in New Issue
Block a user