Skip to content

Commit

Permalink
Make image paths relative to the .deck file they're referenced from
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jun 3, 2021
1 parent d3df978 commit c98040d
Show file tree
Hide file tree
Showing 60 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion deck.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func LoadDeck(dev *streamdeck.Device, base string, deck string) (*Deck, error) {
File: abs,
}
if dc.Background != "" {
if err := d.loadBackground(dc.Background); err != nil {
bgpath := findImage(filepath.Dir(abs), dc.Background)
if err := d.loadBackground(bgpath); err != nil {
return nil, err
}
}
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
17 changes: 17 additions & 0 deletions images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"path/filepath"
)

func findImage(base, icon string) string {
if !filepath.IsAbs(icon) {
icon = filepath.Join(base, icon)
}
abs, err := filepath.Abs(icon)
if err != nil {
return icon
}

return abs
}
11 changes: 9 additions & 2 deletions widget_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"image"
"path/filepath"
"sync"

"github.com/muesli/streamdeck"
Expand Down Expand Up @@ -31,7 +32,10 @@ func (w *ButtonWidget) Update(dev *streamdeck.Device) error {
bounds := img.Bounds()

if w.icon != "" {
err = drawImage(img, w.icon, iconsize, image.Pt(-1, margin))
err = drawImage(img,
findImage(filepath.Dir(deck.File), w.icon),
iconsize,
image.Pt(-1, margin))

bounds.Min.Y += iconsize + margin
bounds.Max.Y -= margin
Expand All @@ -44,7 +48,10 @@ func (w *ButtonWidget) Update(dev *streamdeck.Device) error {
w.fontsize,
image.Pt(-1, -1))
} else if w.icon != "" {
err = drawImage(img, w.icon, height, image.Pt(-1, -1))
err = drawImage(img,
findImage(filepath.Dir(deck.File), w.icon),
height,
image.Pt(-1, -1))
}

if err != nil {
Expand Down

0 comments on commit c98040d

Please sign in to comment.