2020-01-18 23:28:06 -05:00
|
|
|
package zenity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
|
2020-01-19 06:57:05 -05:00
|
|
|
"github.com/ncruces/zenity/internal/zenutil"
|
2020-01-18 23:28:06 -05:00
|
|
|
)
|
|
|
|
|
2021-03-04 07:42:30 -05:00
|
|
|
func selectColor(opts options) (color.Color, error) {
|
2022-06-01 19:00:08 -04:00
|
|
|
var data zenutil.Color
|
2022-06-02 07:49:31 -04:00
|
|
|
if opts.attach != nil {
|
|
|
|
data.Application = opts.attach
|
2022-06-08 18:52:44 -04:00
|
|
|
}
|
|
|
|
if i, ok := opts.windowIcon.(string); ok {
|
2022-06-01 19:00:08 -04:00
|
|
|
data.WindowIcon = i
|
|
|
|
}
|
|
|
|
|
2020-12-11 13:28:16 -05:00
|
|
|
var col color.Color
|
2020-01-18 23:28:06 -05:00
|
|
|
if opts.color != nil {
|
2020-12-11 13:28:16 -05:00
|
|
|
col = opts.color
|
|
|
|
} else {
|
|
|
|
col = color.White
|
2020-01-18 23:28:06 -05:00
|
|
|
}
|
2020-12-11 13:28:16 -05:00
|
|
|
r, g, b, _ := col.RGBA()
|
2022-06-01 19:00:08 -04:00
|
|
|
data.Color = [3]float32{
|
2021-02-18 21:20:57 -05:00
|
|
|
float32(r) / 0xffff,
|
|
|
|
float32(g) / 0xffff,
|
|
|
|
float32(b) / 0xffff,
|
2022-06-01 19:00:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
out, err := zenutil.Run(opts.ctx, "color", data)
|
2021-04-29 11:05:28 -04:00
|
|
|
str, err := strResult(opts, out, err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-01-18 23:28:06 -05:00
|
|
|
}
|
2021-04-29 11:05:28 -04:00
|
|
|
return zenutil.ParseColor(str), nil
|
2020-01-18 23:28:06 -05:00
|
|
|
}
|