Skip to content

Commit 82c238a

Browse files
authored
Merge pull request magicmonkey#24 from magicmonkey/magicmonkey/issue22
Made a copy of the image returned by ImageFileButton so that subsequent changes don't pollute the original image.
2 parents a7b3bab + ae43a54 commit 82c238a

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

buttons/imagefile.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ type ImageFileButton struct {
1717
}
1818

1919
func (btn *ImageFileButton) GetImageForButton() image.Image {
20-
return btn.img
20+
// TODO base the 96 on the image bounds
21+
newimg := image.NewRGBA(image.Rect(0, 0, 96, 96))
22+
draw.Draw(newimg, newimg.Bounds(), btn.img, image.Point{0, 0}, draw.Src)
23+
return newimg
2124
}
2225

2326
func (btn *ImageFileButton) SetButtonIndex(btnIndex int) {
@@ -49,6 +52,7 @@ func (btn *ImageFileButton) loadImage() error {
4952
var newimg *image.RGBA
5053
newimg, ok := img.(*image.RGBA)
5154
if !ok {
55+
// TODO base the 96 on the button size
5256
newimg = image.NewRGBA(image.Rect(0, 0, 96, 96))
5357
draw.Draw(newimg, newimg.Bounds(), img, image.Point{0, 0}, draw.Src)
5458
}

examples/client3/client3.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"image/color"
5+
"time"
6+
streamdeck "github.com/magicmonkey/go-streamdeck"
7+
"github.com/magicmonkey/go-streamdeck/buttons"
8+
"github.com/magicmonkey/go-streamdeck/decorators"
9+
_ "github.com/magicmonkey/go-streamdeck/devices"
10+
)
11+
12+
func main() {
13+
14+
sd, err := streamdeck.New()
15+
if err != nil {
16+
panic(err)
17+
}
18+
19+
btn1 := buttons.NewTextButton("Hello")
20+
sd.AddButton(1, btn1)
21+
btn2, _ := buttons.NewImageFileButton("examples/test/play.jpg")
22+
sd.AddButton(2, btn2)
23+
24+
25+
greenBorder := decorators.NewBorder(10, color.RGBA{0, 255, 0, 255})
26+
sd.SetDecorator(1, greenBorder)
27+
sd.SetDecorator(2, greenBorder)
28+
29+
time.Sleep(1 * time.Second)
30+
31+
sd.UnsetDecorator(1)
32+
sd.UnsetDecorator(2)
33+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.13
44

55
require (
66
github.com/disintegration/gift v1.2.1
7-
github.com/disintegration/imaging v1.6.2
7+
github.com/disintegration/imaging v1.6.2 // indirect
88
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
99
github.com/karalabe/hid v1.0.1-0.20190806082151-9c14560f9ee8
1010
golang.org/x/image v0.0.0-20200430140353-33d19683fad8

0 commit comments

Comments
 (0)