diff --git a/.gitignore b/.gitignore index cf9dfb4..0253e55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin/ librnnoise.go version.go -licenses.go \ No newline at end of file +licenses.go +patreon.go diff --git a/assets/patreon.png b/assets/patreon.png new file mode 100644 index 0000000..2a48aa8 Binary files /dev/null and b/assets/patreon.png differ diff --git a/main.go b/main.go index a46e7e7..d83002b 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,8 @@ import ( "github.com/aarzilli/nucular/style" ) -//go:generate go run scripts/embedlibrnnoise.go +//go:generate go run scripts/embedbinary.go librnnoise_ladspa/bin/ladspa/librnnoise_ladspa.so librnnoise.go libRNNoise +//go:generate go run scripts/embedbinary.go assets/patreon.png patreon.go patreonPNG //go:generate go run scripts/embedversion.go //go:generate go run scripts/embedlicenses.go diff --git a/scripts/embedlibrnnoise.go b/scripts/embedbinary.go similarity index 59% rename from scripts/embedlibrnnoise.go rename to scripts/embedbinary.go index 43daf80..1f11ce4 100644 --- a/scripts/embedlibrnnoise.go +++ b/scripts/embedbinary.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "io/ioutil" "os" @@ -8,15 +9,17 @@ import ( ) func main() { - b, err := ioutil.ReadFile("librnnoise_ladspa/bin/ladspa/librnnoise_ladspa.so") + flag.Parse() + args := flag.Args() + b, err := ioutil.ReadFile(args[0]) if err != nil { - fmt.Printf("Couldn't read librnnoise_ladspa.so: %v\n", err) + fmt.Printf("Couldn't read '%s': %v\n", args[0], err) os.Exit(1) } - out, _ := os.Create("librnnoise.go") + out, _ := os.Create(args[1]) defer out.Close() - out.Write([]byte("package main \n\n//THIS FILE IS AUTOMATICALLY GENERATED BY `go generate` DO NOT EDIT!\n\nvar libRNNoise = []byte{\n")) + out.Write([]byte("package main \n\n//THIS FILE IS AUTOMATICALLY GENERATED BY `go generate` DO NOT EDIT!\n\nvar " + args[2] + " = []byte{\n")) for i, c := range b { out.Write([]byte(strconv.Itoa(int(c)))) out.Write([]byte(",")) diff --git a/ui.go b/ui.go index 53d5133..d4c51c2 100644 --- a/ui.go +++ b/ui.go @@ -1,8 +1,12 @@ package main import ( + "bytes" "fmt" + "image" "image/color" + "image/draw" + "image/png" "log" "os/exec" "time" @@ -33,6 +37,8 @@ var green = color.RGBA{34, 187, 69, 255} var red = color.RGBA{255, 70, 70, 255} var orange = color.RGBA{255, 140, 0, 255} +var patreonImg *image.RGBA + func updatefn(ctx *ntcontext, w *nucular.Window) { if !ctx.paClient.Connected() { @@ -57,7 +63,7 @@ func updatefn(ctx *ntcontext, w *nucular.Window) { w.MenubarBegin() - w.Row(10).Dynamic(2) + w.Row(10).Dynamic(1) if w := w.Menu(label.TA("About", "LC"), 120, nil); w != nil { w.Row(10).Dynamic(1) if w.MenuItem(label.T("Licenses")) { @@ -71,13 +77,17 @@ func updatefn(ctx *ntcontext, w *nucular.Window) { ctx.versionScreen = true } } - if w := w.Menu(label.TA("Support NoiseTorch on PATREON", "RC"), 120, nil); w != nil { - exec.Command("xdg-open", "https://patreon.com/lawl").Run() - w.Close() - } + w.MenubarEnd() - w.Row(15).Dynamic(1) + w.Row(25).Dynamic(2) + if patreonImg == nil { + patreonImg = loadPatreonImg() + } + + if imageButton(w, patreonImg) { + exec.Command("xdg-open", "https://patreon.com/lawl").Run() + } if ctx.noiseSupressorState == loaded { w.LabelColored("NoiseTorch active", "RC", green) @@ -284,3 +294,25 @@ func resetUI(ctx *ntcontext) { (*ctx.masterWindow).Changed() } } + +func loadPatreonImg() *image.RGBA { + var pat *image.RGBA + img, _ := png.Decode(bytes.NewReader(patreonPNG)) + pat = image.NewRGBA(img.Bounds()) + draw.Draw(pat, img.Bounds(), img, image.Point{}, draw.Src) + return pat +} + +func imageButton(w *nucular.Window, img *image.RGBA) bool { + style := w.Master().Style() + origButtonStyle := style.Button + style.Button.Border = 0 + style.Button.Normal.Data.Color = style.NormalWindow.Background + style.Button.Hover.Data.Color = style.NormalWindow.Background + style.Button.Active.Data.Color = style.NormalWindow.Background + + defer (func() { style.Button = origButtonStyle })() + + return w.Button(label.I(patreonImg), false) + +}