mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
Add image.DrawRect / DrawRects (leaving some bugs)
This commit is contained in:
parent
5ff2b8697f
commit
7835f5cb2e
@ -26,6 +26,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
|
screen.DrawRect(0, 0, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
||||||
screen.FillRect(10, 10, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
screen.FillRect(10, 10, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
||||||
screen.FillRect(20, 20, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
screen.FillRect(20, 20, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
|
||||||
screen.DrawLine(130, 10, 140, 150, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
screen.DrawLine(130, 10, 140, 150, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
||||||
|
8
image.go
8
image.go
@ -108,6 +108,14 @@ func (i *Image) DrawLines(lines Lines) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Image) DrawRect(x, y, width, height int, clr color.Color) error {
|
||||||
|
return i.DrawLines(&rectsAsLines{&rect{x, y, width, height, clr}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Image) DrawRects(rects Rects) error {
|
||||||
|
return i.DrawLines(&rectsAsLines{rects})
|
||||||
|
}
|
||||||
|
|
||||||
// FillRect draws a filled rectangle.
|
// FillRect draws a filled rectangle.
|
||||||
func (i *Image) FillRect(x, y, width, height int, clr color.Color) error {
|
func (i *Image) FillRect(x, y, width, height int, clr color.Color) error {
|
||||||
return i.FillRects(&rect{x, y, width, height, clr})
|
return i.FillRects(&rect{x, y, width, height, clr})
|
||||||
|
27
shapes.go
27
shapes.go
@ -43,6 +43,33 @@ func (l *line) Color(i int) color.Color {
|
|||||||
return l.color
|
return l.color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type rectsAsLines struct {
|
||||||
|
Rects
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rectsAsLines) Len() int {
|
||||||
|
return r.Rects.Len() * 4
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rectsAsLines) Points(i int) (x0, y0, x1, y1 int) {
|
||||||
|
x, y, w, h := r.Rects.Rect(i / 4)
|
||||||
|
switch i % 4 {
|
||||||
|
case 0:
|
||||||
|
return x, y, x + w, y
|
||||||
|
case 1:
|
||||||
|
return x, y, x + 1, y + h
|
||||||
|
case 2:
|
||||||
|
return x, y + h, x + w, y + h
|
||||||
|
case 3:
|
||||||
|
return x + w, y, x + w, y + h
|
||||||
|
}
|
||||||
|
panic("not reach")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rectsAsLines) Color(i int) color.Color {
|
||||||
|
return r.Rects.Color(i / 4)
|
||||||
|
}
|
||||||
|
|
||||||
// A Rects represents the set of rectangles.
|
// A Rects represents the set of rectangles.
|
||||||
type Rects interface {
|
type Rects interface {
|
||||||
Len() int
|
Len() int
|
||||||
|
Loading…
Reference in New Issue
Block a user