Skip to content

Commit

Permalink
shiny/screen: add Bounds convenience methods.
Browse files Browse the repository at this point in the history
Change-Id: I995c7b5b3ae341a849521e77fad5a38a8864ac94
Reviewed-on: https://go-review.googlesource.com/13057
Reviewed-by: Rob Pike <[email protected]>
  • Loading branch information
nigeltao committed Aug 4, 2015
1 parent 5670e61 commit e0ea89a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
7 changes: 4 additions & 3 deletions shiny/driver/gldriver/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type bufferImpl struct {
size image.Point
}

func (b *bufferImpl) Release() {}
func (b *bufferImpl) Size() image.Point { return b.size }
func (b *bufferImpl) RGBA() *image.RGBA { return b.rgba }
func (b *bufferImpl) Release() {}
func (b *bufferImpl) Size() image.Point { return b.size }
func (b *bufferImpl) Bounds() image.Rectangle { return image.Rectangle{Max: b.size} }
func (b *bufferImpl) RGBA() *image.RGBA { return b.rgba }
5 changes: 3 additions & 2 deletions shiny/driver/gldriver/texture.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ type textureImpl struct {
size image.Point
}

func (t *textureImpl) Size() image.Point { return t.size }
func (t *textureImpl) Bounds() image.Rectangle { return image.Rectangle{Max: t.size} }

func (t *textureImpl) Release() {
// TODO
}

func (t *textureImpl) Size() image.Point { return t.size }

func (t *textureImpl) Upload(dp image.Point, src screen.Buffer, sr image.Rectangle, sender screen.Sender) {
}
5 changes: 3 additions & 2 deletions shiny/driver/x11driver/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ type bufferImpl struct {
cleanedUp bool
}

func (b *bufferImpl) Size() image.Point { return b.size }
func (b *bufferImpl) RGBA() *image.RGBA { return &b.rgba }
func (b *bufferImpl) Size() image.Point { return b.size }
func (b *bufferImpl) Bounds() image.Rectangle { return image.Rectangle{Max: b.size} }
func (b *bufferImpl) RGBA() *image.RGBA { return &b.rgba }

func (b *bufferImpl) preUpload() {
b.mu.Lock()
Expand Down
3 changes: 2 additions & 1 deletion shiny/driver/x11driver/texture.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type textureImpl struct {
released bool
}

func (t *textureImpl) Size() image.Point { return t.size }
func (t *textureImpl) Size() image.Point { return t.size }
func (t *textureImpl) Bounds() image.Rectangle { return image.Rectangle{Max: t.size} }

func (t *textureImpl) Release() {
t.mu.Lock()
Expand Down
6 changes: 3 additions & 3 deletions shiny/example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ func main() {
}
defer b.Release()
fill(b.RGBA())
w.Upload(image.Point{}, b, b.RGBA().Bounds(), w)
w.Upload(image.Point{}, b, b.Bounds(), w)

t, err := s.NewTexture(size)
if err != nil {
log.Fatal(err)
}
defer t.Release()
t.Upload(image.Point{}, b, b.RGBA().Bounds(), w)
t.Upload(image.Point{}, b, b.Bounds(), w)

w.Draw(f64.Aff3{
1, 0, 100,
0, 1, 200,
}, t, image.Rectangle{Max: size}, screen.Over, nil)
}, t, t.Bounds(), screen.Over, nil)

for e := range w.Events() {
switch e := e.(type) {
Expand Down
8 changes: 8 additions & 0 deletions shiny/screen/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ type Buffer interface {
// Size returns the size of the Buffer's image.
Size() image.Point

// Bounds returns the bounds of the Buffer's image. It is equal to
// image.Rectangle{Max: b.Size()}.
Bounds() image.Rectangle

// RGBA returns the pixel buffer as an *image.RGBA.
//
// Its contents should not be accessed while the Buffer is uploading.
Expand All @@ -95,6 +99,10 @@ type Texture interface {
// Size returns the size of the Texture's image.
Size() image.Point

// Bounds returns the bounds of the Texture's image. It is equal to
// image.Rectangle{Max: t.Size()}.
Bounds() image.Rectangle

Uploader

// TODO: also implement Drawer? If so, merge the Uploader and Drawer
Expand Down

0 comments on commit e0ea89a

Please sign in to comment.