| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package drawer |
| 7 |
|
| 8 |
import ( |
| 9 |
"image" |
| 10 |
"image/draw" |
| 11 |
|
| 12 |
"golang.org/x/exp/shiny/screen" |
| 13 |
"golang.org/x/image/math/f64" |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
func Copy(dst screen.Drawer, dp image.Point, src screen.Texture, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) { |
| 19 |
dst.Draw(f64.Aff3{ |
| 20 |
1, 0, float64(dp.X - sr.Min.X), |
| 21 |
0, 1, float64(dp.Y - sr.Min.Y), |
| 22 |
}, src, sr, op, opts) |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
func Scale(dst screen.Drawer, dr image.Rectangle, src screen.Texture, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) { |
| 28 |
rx := float64(dr.Dx()) / float64(sr.Dx()) |
| 29 |
ry := float64(dr.Dy()) / float64(sr.Dy()) |
| 30 |
dst.Draw(f64.Aff3{ |
| 31 |
rx, 0, float64(dr.Min.X) - rx*float64(sr.Min.X), |
| 32 |
0, ry, float64(dr.Min.Y) - ry*float64(sr.Min.Y), |
| 33 |
}, src, sr, op, opts) |
| 34 |
} |