paint-selector.cpp revision c730b7fa118ad88d7cc6047dcc78e7098cdf79ca
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SPPaintSelector: Generic paint selector widget.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Authors:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Lauris Kaplinski
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bulia byak <buliabyak@users.sf.net>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * John Cliff <simarilius@yahoo.com>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Jon A. Cruz <jon@joncruz.org>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Abhishek Sharma
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright (C) Lauris Kaplinski 2002
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright (C) 2010 Authors
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include "../sp-pattern.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include "../widgets/icon.h"
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright/* fixme: Move it from dialogs to here */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#endif // SP_PS_VERBOSE
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void sp_paint_selector_class_init(SPPaintSelectorClass *klass);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void sp_paint_selector_init(SPPaintSelector *slider);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void sp_paint_selector_destroy(GtkObject *object);
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wrightstatic GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, gchar const *px, SPPaintSelector::Mode mode, gchar const *tip);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void sp_paint_selector_style_button_toggled(GtkToggleButton *tb, SPPaintSelector *psel);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void sp_paint_selector_fillrule_toggled(GtkToggleButton *tb, SPPaintSelector *psel);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void sp_paint_selector_set_mode_empty(SPPaintSelector *psel);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void sp_paint_selector_set_mode_multiple(SPPaintSelector *psel);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic void sp_paint_selector_set_mode_none(SPPaintSelector *psel);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelector::Mode mode);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSelector::Mode mode);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSelector::Mode mode);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSelector::Mode mode);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic void sp_paint_selector_set_mode_unset(SPPaintSelector *psel);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic void sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross "MODE_EMPTY",
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright "MODE_MULTIPLE",
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright "MODE_NONE",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States "MODE_COLOR_RGB",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States "MODE_COLOR_CMYK",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States "MODE_GRADIENT_LINEAR",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States "MODE_GRADIENT_RADIAL",
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States "MODE_PATTERN",
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown "MODE_SWATCH",
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright "MODE_UNSET",
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brownstatic bool isPaintModeGradient( SPPaintSelector::Mode mode )
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown bool isGrad = (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) ||
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown (mode == SPPaintSelector::MODE_GRADIENT_RADIAL) ||
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brownstatic SPGradientSelector *getGradientFromData(SPPaintSelector const *psel)
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown if (psel->mode == SPPaintSelector::MODE_SWATCH) {
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown grad = reinterpret_cast<SPGradientSelector*>(g_object_get_data(G_OBJECT(psel->selector), "gradient-selector"));
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown 0, // base_init
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown 0, // base_finalize
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown 0, // class_finalize
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown 0, // class_data
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown 0, // n_preallocs
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright 0 // value_table
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown type = g_type_register_static(GTK_TYPE_VBOX, "SPPaintSelector", &info, static_cast<GTypeFlags>(0));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsp_paint_selector_class_init(SPPaintSelectorClass *klass)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright GtkObjectClass *object_class = (GtkObjectClass *) klass;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright parent_class = (GtkVBoxClass*)g_type_class_peek_parent(klass);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright psel_signals[MODE_CHANGED] = g_signal_new("mode_changed",
12b65585e720714b31036daaa2b30eb76014048eGordon Ross (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright G_STRUCT_OFFSET(SPPaintSelectorClass, mode_changed),
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
12b65585e720714b31036daaa2b30eb76014048eGordon Ross (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright psel_signals[RELEASED] = g_signal_new("released",
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright G_STRUCT_OFFSET(SPPaintSelectorClass, released),
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States psel_signals[CHANGED] = g_signal_new("changed",
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown G_STRUCT_OFFSET(SPPaintSelectorClass, changed),
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh psel_signals[FILLRULE_CHANGED] = g_signal_new("fillrule_changed",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright G_STRUCT_OFFSET(SPPaintSelectorClass, fillrule_changed),
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross object_class->destroy = sp_paint_selector_destroy;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
psel->mode = static_cast<SPPaintSelector::Mode>(-1); // huh? do you mean 0xff? -- I think this means "not in the enum"
GtkWidget *w;
// TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
gtk_widget_set_tooltip_text(psel->evenodd, _("Any path self-intersections or subpaths create holes in the fill (fill-rule: evenodd)"));
g_object_set_data(G_OBJECT(psel->evenodd), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_EVENODD));
g_signal_connect(G_OBJECT(psel->evenodd), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
// TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
gtk_widget_set_tooltip_text(psel->nonzero, _("Fill is solid unless a subpath is counterdirectional (fill-rule: nonzero)"));
g_object_set_data(G_OBJECT(psel->nonzero), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_NONZERO));
g_signal_connect(G_OBJECT(psel->nonzero), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
GtkWidget *b, *w;
b = gtk_toggle_button_new();
gtk_widget_show(b);
gtk_widget_show(w);
psel->setMode(static_cast<SPPaintSelector::Mode>(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(tb), "mode"))));
SPPaintSelector::FillRule fr = static_cast<SPPaintSelector::FillRule>(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(tb), "mode")));
if (is_fill) {
return psel;
#ifdef SP_PS_VERBOSE
g_print("Mode change %d -> %d %s -> %s\n", this->mode, mode, modeStrings[this->mode], modeStrings[mode]);
switch (mode) {
case MODE_EMPTY:
case MODE_MULTIPLE:
case MODE_NONE:
case MODE_COLOR_RGB:
case MODE_COLOR_CMYK:
case MODE_GRADIENT_LINEAR:
case MODE_GRADIENT_RADIAL:
case MODE_PATTERN:
case MODE_SWATCH:
case MODE_UNSET:
if (fillrulebox) {
#ifdef SP_PS_VERBOSE
#ifdef SP_PS_VERBOSE
SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(selector), "swatch-selector"));
if (swatchsel) {
#ifdef SP_PS_VERBOSE
#ifdef SP_PS_VERBOSE
void SPPaintSelector::getGradientProperties( SPGradientUnits &units, SPGradientSpread &spread) const
return vect;
if ((psel->mode == SPPaintSelector::MODE_COLOR_RGB) || (psel->mode == SPPaintSelector::MODE_COLOR_CMYK)) {
#ifdef SP_PS_VERBOSE
if ((psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR) || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL)) {
g_signal_connect(G_OBJECT(gsel), "released", G_CALLBACK(sp_paint_selector_gradient_released), psel);
#ifdef SP_PS_VERBOSE
GSList *
return NULL;
if (SP_PATTERN(l->data) == pattern_getroot(SP_PATTERN(l->data))) { // only if this is a root pattern
return pl;
* Adds menu items for pattern list - derived from marker code, left hb etc in to make addition of previews easier at some point.
gtk_widget_show(i);
GtkWidget *l;
gtk_widget_show(l);
static void sp_pattern_list_from_doc (GtkWidget *m, SPDocument * /*current_doc*/, SPDocument *source, SPDocument * /*pattern_doc*/)
// find and load patterns.svg
gtk_widget_show(i);
// suck in from patterns.svg
if (patterns_doc) {
static GtkWidget*
gtk_widget_show(m);
if (!doc) {
GtkWidget *i;
gtk_widget_show(i);
return mnu;
if (update) {
int patpos = 0;
patpos = i;
gtk_label_set_markup(GTK_LABEL(l), _("Use the <b>Node tool</b> to adjust position, scale, and rotation of the pattern on canvas. Use <b>Object > Pattern > Objects to Pattern</b> to create a new pattern from selection."));
#ifdef SP_PS_VERBOSE
return NULL;
if (pat_obj) {
pat = 0;
return pat;
swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
#ifdef SP_PS_VERBOSE
// TODO this seems very bad to be taking in a desktop pointer to muck with. Logic probably belongs elsewhere
void SPPaintSelector::setFlatColor( SPDesktop *desktop, gchar const *color_property, gchar const *opacity_property )
#ifdef SP_PS_VERBOSE
rgba,
SPPaintServer const *server = (kind == FILL) ? style.getFillPaintServer() : style.getStrokePaintServer();
#ifdef SP_PS_VERBOSE
g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n"));
return mode;