Beispiel #1
0
// ColorSelector adds a color selector widget.
//
func ColorSelector(key *cftype.Key) {
	values := key.Value().ListFloat()
	if len(values) == 3 {
		values = append(values, 1) // no transparency.
	}
	gdkColor := gdk.NewRGBA(values...)
	widget := newgtk.ColorButtonWithRGBA(gdkColor)

	var getValue func() interface{}
	switch key.Type {
	case cftype.KeyColorSelectorRGB:
		key.NbElements = 3
		getValue = func() interface{} { return widget.GetRGBA().Floats()[:3] } // Need to trunk ?

	case cftype.KeyColorSelectorRGBA:
		key.NbElements = 4
		getValue = func() interface{} { return widget.GetRGBA().Floats() }
	}

	widget.Set("use-alpha", key.IsType(cftype.KeyColorSelectorRGBA))

	key.PackKeyWidget(key,
		getValue,
		func(uncast interface{}) { widget.SetRGBA(gdk.NewRGBA(uncast.([]float64)...)) },
		widget,
	)
	oldval, e := key.Storage().Default(key.Group, key.Name)
	if e == nil {
		PackReset(key, oldval.ListFloat())
	}
}
Beispiel #2
0
// LookupColor is a wrapper around gtk_style_context_lookup_color().
func (v *StyleContext) LookupColor(colorName string) (*gdk.RGBA, bool) {
	cstr := (*C.gchar)(C.CString(colorName))
	defer C.free(unsafe.Pointer(cstr))
	gdkColor := gdk.NewRGBA()
	ret := C.gtk_style_context_lookup_color(v.native(), cstr, (*C.GdkRGBA)(unsafe.Pointer(gdkColor.Native())))
	return gdkColor, gobool(ret)
}
Beispiel #3
0
// GetRGBA() is a wrapper around gtk_color_chooser_get_rgba().
func (v *ColorChooser) GetRGBA() *gdk.RGBA {
	gdkColor := gdk.NewRGBA()
	C.gtk_color_chooser_get_rgba(v.native(), (*C.GdkRGBA)(unsafe.Pointer(gdkColor.Native())))
	return gdkColor
}
Beispiel #4
0
// GetColor is a wrapper around gtk_style_context_get_color().
func (v *StyleContext) GetColor(state StateFlags) *gdk.RGBA {
	gdkColor := gdk.NewRGBA()
	C.gtk_style_context_get_color(v.native(), C.GtkStateFlags(state), (*C.GdkRGBA)(unsafe.Pointer(gdkColor.Native())))
	return gdkColor
}