From bac07369b5a7234183c0e9785ccf86c971bd11ff Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 7 Mar 2010 20:27:39 -0800 Subject: [PATCH] Cleanup of gradient-selector to allow for new mode. --- src/widgets/gradient-selector.cpp | 73 ++++++++++++------------------- src/widgets/gradient-selector.h | 47 +++++++++++--------- src/widgets/paint-selector.cpp | 28 +++++++----- 3 files changed, 71 insertions(+), 77 deletions(-) diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index f24a6781b..1a98c68dc 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -4,9 +4,11 @@ * Authors: * Lauris Kaplinski * bulia byak + * Jon A. Cruz * * Copyright (C) 2001-2002 Lauris Kaplinski * Copyright (C) 2001 Ximian, Inc. + * Copyright (C) 2010 Jon A. Cruz * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -120,7 +122,7 @@ sp_gradient_selector_init (SPGradientSelector *sel) { GtkWidget *hb, *l, *m, *mi; - sel->mode = SP_GRADIENT_SELECTOR_MODE_LINEAR; + sel->mode = SPGradientSelector::MODE_LINEAR; sel->gradientUnits = SP_GRADIENT_UNITS_USERSPACEONUSE; sel->gradientSpread = SP_GRADIENT_SPREAD_PAD; @@ -206,77 +208,58 @@ sp_gradient_selector_new (void) return (GtkWidget *) sel; } -void -sp_gradient_selector_set_mode (SPGradientSelector *sel, guint mode) +void SPGradientSelector::setMode(SelectorMode mode) { - g_return_if_fail (sel != NULL); - g_return_if_fail (SP_IS_GRADIENT_SELECTOR (sel)); - - sel->mode = mode; + this->mode = mode; } -void -sp_gradient_selector_set_units (SPGradientSelector *sel, guint units) +void SPGradientSelector::setUnits(SPGradientUnits units) { - g_return_if_fail (sel != NULL); - g_return_if_fail (SP_IS_GRADIENT_SELECTOR (sel)); - - sel->gradientUnits = (SPGradientUnits)units; + gradientUnits = units; } -void -sp_gradient_selector_set_spread (SPGradientSelector *sel, guint spread) +void SPGradientSelector::setSpread(SPGradientSpread spread) { - g_return_if_fail (sel != NULL); - g_return_if_fail (SP_IS_GRADIENT_SELECTOR (sel)); - - sel->gradientSpread = (SPGradientSpread)spread; + gradientSpread = spread; - gtk_option_menu_set_history (GTK_OPTION_MENU (sel->spread), sel->gradientSpread); + gtk_option_menu_set_history(GTK_OPTION_MENU(spread), gradientSpread); } -SPGradientUnits -sp_gradient_selector_get_units (SPGradientSelector *sel) +SPGradientUnits SPGradientSelector::getUnits() { - return (SPGradientUnits) sel->gradientUnits; + //return (SPGradientUnits) sel->gradientUnits; + return gradientUnits; } -SPGradientSpread -sp_gradient_selector_get_spread (SPGradientSelector *sel) +SPGradientSpread SPGradientSelector::getSpread() { - return (SPGradientSpread) sel->gradientSpread; + return gradientSpread; } -void -sp_gradient_selector_set_vector (SPGradientSelector *sel, SPDocument *doc, SPGradient *vector) +void SPGradientSelector::setVector(SPDocument *doc, SPGradient *vector) { - g_return_if_fail (sel != NULL); - g_return_if_fail (SP_IS_GRADIENT_SELECTOR (sel)); - g_return_if_fail (!vector || SP_IS_GRADIENT (vector)); - g_return_if_fail (!vector || (SP_OBJECT_DOCUMENT (vector) == doc)); + g_return_if_fail(!vector || SP_IS_GRADIENT(vector)); + g_return_if_fail(!vector || (SP_OBJECT_DOCUMENT(vector) == doc)); - if (vector && !SP_GRADIENT_HAS_STOPS (vector)) + if (vector && !SP_GRADIENT_HAS_STOPS(vector)) { return; + } - sp_gradient_vector_selector_set_gradient (SP_GRADIENT_VECTOR_SELECTOR (sel->vectors), doc, vector); + sp_gradient_vector_selector_set_gradient(SP_GRADIENT_VECTOR_SELECTOR(vectors), doc, vector); if (vector) { - gtk_widget_set_sensitive (sel->edit, TRUE); - gtk_widget_set_sensitive (sel->add, TRUE); + gtk_widget_set_sensitive(edit, TRUE); + gtk_widget_set_sensitive(add, TRUE); } else { - gtk_widget_set_sensitive (sel->edit, FALSE); - gtk_widget_set_sensitive (sel->add, (doc != NULL)); + gtk_widget_set_sensitive(edit, FALSE); + gtk_widget_set_sensitive(add, (doc != NULL)); } } -SPGradient * -sp_gradient_selector_get_vector (SPGradientSelector *sel) +SPGradient *SPGradientSelector::getVector() { - if (sel == NULL || !SP_IS_GRADIENT_SELECTOR (sel)) - return NULL; - /* fixme: */ - return SP_GRADIENT_VECTOR_SELECTOR (sel->vectors)->gr; + return SP_GRADIENT_VECTOR_SELECTOR(vectors)->gr; } static void @@ -287,7 +270,7 @@ sp_gradient_selector_vector_set (SPGradientVectorSelector */*gvs*/, SPGradient * if (!blocked) { blocked = TRUE; gr = sp_gradient_ensure_vector_normalized (gr); - sp_gradient_selector_set_vector (sel, (gr) ? SP_OBJECT_DOCUMENT (gr) : NULL, gr); + sel->setVector((gr) ? SP_OBJECT_DOCUMENT (gr) : 0, gr); g_signal_emit (G_OBJECT (sel), signals[CHANGED], 0, gr); blocked = FALSE; } diff --git a/src/widgets/gradient-selector.h b/src/widgets/gradient-selector.h index e68dfecfc..85674b4a9 100644 --- a/src/widgets/gradient-selector.h +++ b/src/widgets/gradient-selector.h @@ -6,16 +6,21 @@ * * Authors: * Lauris Kaplinski + * Jon A. Cruz * * Copyright (C) 2001-2002 Lauris Kaplinski * Copyright (C) 2001 Ximian, Inc. + * Copyright (C) 2010 Jon A. Cruz * * Released under GNU GPL, read the file 'COPYING' for more information */ #include +#include +#include "sp-gradient.h" #include "sp-gradient-spread.h" #include "sp-gradient-units.h" + class SPGradient; #define SP_TYPE_GRADIENT_SELECTOR (sp_gradient_selector_get_type ()) @@ -24,32 +29,41 @@ class SPGradient; #define SP_IS_GRADIENT_SELECTOR(o) (GTK_CHECK_TYPE ((o), SP_TYPE_GRADIENT_SELECTOR)) #define SP_IS_GRADIENT_SELECTOR_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), SP_TYPE_GRADIENT_SELECTOR)) -#include -#include -#include "../forward.h" -#include -enum { - SP_GRADIENT_SELECTOR_MODE_LINEAR, - SP_GRADIENT_SELECTOR_MODE_RADIAL -}; struct SPGradientSelector { GtkVBox vbox; - guint mode : 1; + enum SelectorMode { + MODE_LINEAR, + MODE_RADIAL + }; + + SelectorMode mode; - SPGradientUnits gradientUnits : 1; - SPGradientSpread gradientSpread : 2; + SPGradientUnits gradientUnits; + SPGradientSpread gradientSpread; /* Vector selector */ GtkWidget *vectors; + /* Editing buttons */ - GtkWidget *edit, *add; + GtkWidget *edit; + GtkWidget *add; + /* Position widget */ GtkWidget *position; + /* Spread selector */ GtkWidget *spread; + + void setMode(SelectorMode mode); + void setUnits(SPGradientUnits units); + void setSpread(SPGradientSpread spread); + void setVector(SPDocument *doc, SPGradient *vector); + SPGradientUnits getUnits(); + SPGradientSpread getSpread(); + SPGradient *getVector(); }; struct SPGradientSelectorClass { @@ -65,17 +79,8 @@ GType sp_gradient_selector_get_type(void); GtkWidget *sp_gradient_selector_new (void); -void sp_gradient_selector_set_mode (SPGradientSelector *sel, guint mode); -void sp_gradient_selector_set_units (SPGradientSelector *sel, guint units); -void sp_gradient_selector_set_spread (SPGradientSelector *sel, guint spread); -void sp_gradient_selector_set_vector (SPGradientSelector *sel, SPDocument *doc, SPGradient *vector); void sp_gradient_selector_set_bbox (SPGradientSelector *sel, gdouble x0, gdouble y0, gdouble x1, gdouble y1); -SPGradientUnits sp_gradient_selector_get_units (SPGradientSelector *sel); -SPGradientSpread sp_gradient_selector_get_spread (SPGradientSelector *sel); - -SPGradient *sp_gradient_selector_get_vector (SPGradientSelector *sel); - #endif // SEEN_GRADIENT_SELECTOR_H diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index b91f24105..59312b0d2 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -426,8 +426,8 @@ sp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector) gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); - sp_gradient_selector_set_mode(gsel, SP_GRADIENT_SELECTOR_MODE_LINEAR); - sp_gradient_selector_set_vector(gsel, (vector) ? SP_OBJECT_DOCUMENT(vector) : NULL, vector); + gsel->setMode(SPGradientSelector::MODE_LINEAR); + gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); } void @@ -441,8 +441,9 @@ sp_paint_selector_set_gradient_radial(SPPaintSelector *psel, SPGradient *vector) gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); - sp_gradient_selector_set_mode(gsel, SP_GRADIENT_SELECTOR_MODE_RADIAL); - sp_gradient_selector_set_vector(gsel, (vector) ? SP_OBJECT_DOCUMENT(vector) : NULL, vector); + gsel->setMode(SPGradientSelector::MODE_RADIAL); + + gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); } void @@ -453,8 +454,8 @@ sp_paint_selector_set_gradient_properties(SPPaintSelector *psel, SPGradientUnits g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) || (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL)); gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); - sp_gradient_selector_set_units(gsel, units); - sp_gradient_selector_set_spread(gsel, spread); + gsel->setUnits(units); + gsel->setSpread(spread); } void @@ -465,8 +466,12 @@ sp_paint_selector_get_gradient_properties(SPPaintSelector *psel, SPGradientUnits g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) || (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL)); gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); - if (units) *units = sp_gradient_selector_get_units(gsel); - if (spread) *spread = sp_gradient_selector_get_spread(gsel); + if (units) { + *units = gsel->getUnits(); + } + if (spread) { + *spread = gsel->getSpread(); + } } /** @@ -496,7 +501,7 @@ sp_paint_selector_get_gradient_vector(SPPaintSelector *psel) gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); - return sp_gradient_selector_get_vector(gsel); + return gsel->getVector(); } void @@ -720,10 +725,11 @@ sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSelectorMode m /* Actually we have to set option menu history here */ if (mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) { - sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_LINEAR); + SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_LINEAR); + //sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_LINEAR); gtk_frame_set_label(GTK_FRAME(psel->frame), _("Linear gradient")); } else { - sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_RADIAL); + SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_RADIAL); gtk_frame_set_label(GTK_FRAME(psel->frame), _("Radial gradient")); } #ifdef SP_PS_VERBOSE -- 2.30.2