add PictureColor properties to Canvas TargetPicture
This commit is contained in:
parent
79bffcc7e8
commit
d63590a799
|
@ -123,6 +123,7 @@ func (c *Canvas) MakePicture(p pixel.Picture) pixel.TargetPicture {
|
|||
|
||||
cp := &canvasPicture{
|
||||
tex: tex,
|
||||
pixels: pixels,
|
||||
borders: pixel.R(
|
||||
float64(bx), float64(by),
|
||||
float64(bw), float64(bh),
|
||||
|
@ -353,6 +354,7 @@ func (ct *canvasTriangles) Draw() {
|
|||
|
||||
type canvasPicture struct {
|
||||
tex *glhf.Texture
|
||||
pixels []uint8
|
||||
borders pixel.Rect
|
||||
bounds pixel.Rect
|
||||
|
||||
|
@ -375,6 +377,21 @@ func (cp *canvasPicture) Original() pixel.Picture {
|
|||
return cp.orig
|
||||
}
|
||||
|
||||
func (cp *canvasPicture) Color(at pixel.Vec) pixel.NRGBA {
|
||||
if !cp.bounds.Contains(at) {
|
||||
return pixel.NRGBA{}
|
||||
}
|
||||
bx, by, bw, _ := intBounds(cp.borders)
|
||||
x, y := int(at.X())-bx, int(at.Y())-by
|
||||
off := y*bw + x
|
||||
return pixel.NRGBA{
|
||||
R: float64(cp.pixels[off*4+0]) / 255,
|
||||
G: float64(cp.pixels[off*4+1]) / 255,
|
||||
B: float64(cp.pixels[off*4+2]) / 255,
|
||||
A: float64(cp.pixels[off*4+3]) / 255,
|
||||
}
|
||||
}
|
||||
|
||||
func (cp *canvasPicture) Draw(t pixel.TargetTriangles) {
|
||||
ct := t.(*canvasTriangles)
|
||||
if cp.dst != ct.dst {
|
||||
|
@ -404,6 +421,13 @@ func (ccp *canvasCanvasPicture) Original() pixel.Picture {
|
|||
return ccp.orig
|
||||
}
|
||||
|
||||
func (ccp *canvasCanvasPicture) Color(at pixel.Vec) pixel.NRGBA {
|
||||
if !ccp.bounds.Contains(at) {
|
||||
return pixel.NRGBA{}
|
||||
}
|
||||
return ccp.src.Color(at)
|
||||
}
|
||||
|
||||
func (ccp *canvasCanvasPicture) Draw(t pixel.TargetTriangles) {
|
||||
ct := t.(*canvasTriangles)
|
||||
if ccp.dst != ct.dst {
|
||||
|
|
Loading…
Reference in New Issue