diff options
Diffstat (limited to 'src/widgets/paint-selector.cpp')
| -rw-r--r-- | src/widgets/paint-selector.cpp | 101 |
1 files changed, 65 insertions, 36 deletions
diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 9466c875e..6ef910f61 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -29,14 +29,15 @@ #endif #include "widgets/swatch-selector.h" -#include "../sp-pattern.h" +#include "sp-pattern.h" #include <glibmm/i18n.h> -#include "../widgets/icon.h" +#include "widgets/icon.h" #include "widgets/widget-sizes.h" #include "xml/repr.h" #include "sp-color-notebook.h" #include "sp-linear-gradient.h" +#include "sp-mesh-gradient.h" #include "sp-radial-gradient.h" /* fixme: Move it from dialogs to here */ #include "gradient-selector.h" @@ -71,8 +72,6 @@ enum { LAST_SIGNAL }; -static void sp_paint_selector_class_init(SPPaintSelectorClass *klass); -static void sp_paint_selector_init(SPPaintSelector *slider); static void sp_paint_selector_dispose(GObject *object); static GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, gchar const *px, SPPaintSelector::Mode mode, gchar const *tip); @@ -91,7 +90,6 @@ static void sp_paint_selector_set_mode_unset(SPPaintSelector *psel); static void sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active); -static GtkVBoxClass *parent_class; static guint psel_signals[LAST_SIGNAL] = {0}; #ifdef SP_PS_VERBOSE @@ -113,10 +111,13 @@ static gchar const* modeStrings[] = { #endif -static bool isPaintModeGradient( SPPaintSelector::Mode mode ) +static bool isPaintModeGradient(SPPaintSelector::Mode mode) { bool isGrad = (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) || (mode == SPPaintSelector::MODE_GRADIENT_RADIAL) || +#ifdef WITH_MESH + (mode == SPPaintSelector::MODE_GRADIENT_MESH) || +#endif (mode == SPPaintSelector::MODE_SWATCH); return isGrad; @@ -136,34 +137,17 @@ static SPGradientSelector *getGradientFromData(SPPaintSelector const *psel) return grad; } -GType sp_paint_selector_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPPaintSelectorClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_paint_selector_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPPaintSelector), - 0, // n_preallocs - (GInstanceInitFunc)sp_paint_selector_init, - 0 // value_table - }; - type = g_type_register_static(GTK_TYPE_VBOX, "SPPaintSelector", &info, static_cast<GTypeFlags>(0)); - } - return type; -} +#if GTK_CHECK_VERSION(3,0,0) +G_DEFINE_TYPE(SPPaintSelector, sp_paint_selector, GTK_TYPE_BOX); +#else +G_DEFINE_TYPE(SPPaintSelector, sp_paint_selector, GTK_TYPE_VBOX); +#endif static void sp_paint_selector_class_init(SPPaintSelectorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); - parent_class = GTK_VBOX_CLASS(g_type_class_peek_parent(klass)); - psel_signals[MODE_CHANGED] = g_signal_new("mode_changed", G_TYPE_FROM_CLASS(object_class), (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE), @@ -216,6 +200,10 @@ sp_paint_selector_class_init(SPPaintSelectorClass *klass) static void sp_paint_selector_init(SPPaintSelector *psel) { +#if GTK_CHECK_VERSION(3,0,0) + gtk_orientable_set_orientation(GTK_ORIENTABLE(psel), GTK_ORIENTATION_VERTICAL); +#endif + psel->mode = static_cast<SPPaintSelector::Mode>(-1); // huh? do you mean 0xff? -- I think this means "not in the enum" /* Paint style button box */ @@ -238,6 +226,10 @@ sp_paint_selector_init(SPPaintSelector *psel) SPPaintSelector::MODE_GRADIENT_LINEAR, _("Linear gradient")); psel->radial = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-gradient-radial"), SPPaintSelector::MODE_GRADIENT_RADIAL, _("Radial gradient")); +#ifdef WITH_MESH + psel->mesh = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-gradient-mesh"), + SPPaintSelector::MODE_GRADIENT_MESH, _("Mesh gradient")); +#endif psel->pattern = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-pattern"), SPPaintSelector::MODE_PATTERN, _("Pattern")); psel->swatch = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-swatch"), @@ -314,8 +306,8 @@ static void sp_paint_selector_dispose(GObject *object) // clean up our long-living pattern menu g_object_set_data(G_OBJECT(psel),"patternmenu",NULL); - if ((G_OBJECT_CLASS(parent_class))->dispose) - (* (G_OBJECT_CLASS(parent_class))->dispose)(object); + if ((G_OBJECT_CLASS(sp_paint_selector_parent_class))->dispose) + (G_OBJECT_CLASS(sp_paint_selector_parent_class))->dispose(object); } static GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, @@ -413,6 +405,9 @@ void SPPaintSelector::setMode(Mode mode) break; case MODE_GRADIENT_LINEAR: case MODE_GRADIENT_RADIAL: +#ifdef WITH_MESH + case MODE_GRADIENT_MESH: +#endif sp_paint_selector_set_mode_gradient(this, mode); break; case MODE_PATTERN: @@ -511,6 +506,21 @@ void SPPaintSelector::setGradientRadial(SPGradient *vector) gsel->setVector((vector) ? vector->document : 0, vector); } +#ifdef WITH_MESH +void SPPaintSelector::setGradientMesh(SPGradient *vector) +{ +#ifdef SP_PS_VERBOSE + g_print("PaintSelector set GRADIENT MESH\n"); +#endif + setMode(MODE_GRADIENT_RADIAL); + + SPGradientSelector *gsel = getGradientFromData(this); + + gsel->setMode(SPGradientSelector::MODE_MESH); + gsel->setVector((vector) ? vector->document : 0, vector); +} +#endif + void SPPaintSelector::setGradientProperties( SPGradientUnits units, SPGradientSpread spread ) { g_return_if_fail(isPaintModeGradient(mode)); @@ -665,8 +675,8 @@ static void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelec /* Create new color selector */ /* Create vbox */ #if GTK_CHECK_VERSION(3,0,0) - GtkWidget *vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); + GtkWidget *vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); + gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); #else GtkWidget *vb = gtk_vbox_new(FALSE, 4); #endif @@ -728,9 +738,14 @@ static void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSe if (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) { sp_paint_selector_set_style_buttons(psel, psel->gradient); - } else { + } else if (mode == SPPaintSelector::MODE_GRADIENT_RADIAL) { sp_paint_selector_set_style_buttons(psel, psel->radial); } +#ifdef WITH_MESH + else { + sp_paint_selector_set_style_buttons(psel, psel->mesh); + } +#endif gtk_widget_set_sensitive(psel->style, TRUE); if ((psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR) || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL)) { @@ -756,10 +771,17 @@ static void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSe SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_LINEAR); //sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_LINEAR); gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Linear gradient</b>")); - } else { + } else if (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) { SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_RADIAL); gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Radial gradient</b>")); } +#ifdef WITH_MESH + else { + SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_RADIAL); + gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Mesh gradient</b>")); + } +#endif + #ifdef SP_PS_VERBOSE g_print("Gradient req\n"); #endif @@ -772,6 +794,9 @@ sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->solid), (active == psel->solid)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->gradient), (active == psel->gradient)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->radial), (active == psel->radial)); +#ifdef WITH_MESH + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->mesh), (active == psel->mesh)); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->pattern), (active == psel->pattern)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->swatch), (active == psel->swatch)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->unset), (active == psel->unset)); @@ -1004,8 +1029,8 @@ static void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSel /* Create vbox */ #if GTK_CHECK_VERSION(3,0,0) - tbl = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_box_set_homogeneous(GTK_BOX(tbl), FALSE); + tbl = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); + gtk_box_set_homogeneous(GTK_BOX(tbl), FALSE); #else tbl = gtk_vbox_new(FALSE, 4); #endif @@ -1218,6 +1243,10 @@ SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, Fi mode = MODE_GRADIENT_LINEAR; } else if (SP_IS_RADIALGRADIENT(server)) { mode = MODE_GRADIENT_RADIAL; +#ifdef WITH_MESH + } else if (SP_IS_MESHGRADIENT(server)) { + mode = MODE_GRADIENT_MESH; +#endif } else if (SP_IS_PATTERN(server)) { mode = MODE_PATTERN; } else { |
