From: Jon A. Cruz Date: Mon, 22 Mar 2010 00:44:33 +0000 (-0700) Subject: C++-ification of paint selector. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=99f8079bc0a32aef279e4af06de4cbf4bd853563;p=inkscape.git C++-ification of paint selector. --- diff --git a/src/ui/widget/color-picker.cpp b/src/ui/widget/color-picker.cpp index d6ae50ae3..34cf1d5e3 100644 --- a/src/ui/widget/color-picker.cpp +++ b/src/ui/widget/color-picker.cpp @@ -116,12 +116,15 @@ ColorPicker::on_changed (guint32) void sp_color_picker_color_mod(SPColorSelector *csel, GObject *cp) { - if (_in_use) return; - else _in_use = true; + if (_in_use) { + return; + } else { + _in_use = true; + } SPColor color; - float alpha; - csel->base->getColorAlpha(color, &alpha); + float alpha = 0; + csel->base->getColorAlpha(color, alpha); guint32 rgba = color.toRGBA32( alpha ); ColorPicker *ptr = (ColorPicker *)(cp); diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 87cd238a7..c84a3a07e 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -190,7 +190,7 @@ sp_fill_style_widget_update (SPWidget *spw) case QUERY_STYLE_NOTHING: { /* No paint at all */ - sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_EMPTY); + psel->setMode(SP_PAINT_SELECTOR_MODE_EMPTY); break; } @@ -199,39 +199,37 @@ sp_fill_style_widget_update (SPWidget *spw) case QUERY_STYLE_MULTIPLE_SAME: { SPPaintSelectorMode pselmode = sp_style_determine_paint_selector_mode (query, true); - sp_paint_selector_set_mode (psel, pselmode); + psel->setMode(pselmode); - sp_paint_selector_set_fillrule (psel, query->fill_rule.computed == ART_WIND_RULE_NONZERO? - SP_PAINT_SELECTOR_FILLRULE_NONZERO : SP_PAINT_SELECTOR_FILLRULE_EVENODD); + psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO? + SP_PAINT_SELECTOR_FILLRULE_NONZERO : SP_PAINT_SELECTOR_FILLRULE_EVENODD); if (query->fill.set && query->fill.isColor()) { - sp_paint_selector_set_color_alpha (psel, &query->fill.value.color, SP_SCALE24_TO_FLOAT (query->fill_opacity.value)); + psel->setColorAlpha(query->fill.value.color, SP_SCALE24_TO_FLOAT(query->fill_opacity.value)); } else if (query->fill.set && query->fill.isPaintserver()) { SPPaintServer *server = SP_STYLE_FILL_SERVER (query); if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { SPGradient *vector = SP_GRADIENT(server)->getVector(); - sp_paint_selector_set_swatch( psel, vector ); + psel->setSwatch( vector ); } else if (SP_IS_LINEARGRADIENT (server)) { SPGradient *vector = SP_GRADIENT(server)->getVector(); - sp_paint_selector_set_gradient_linear (psel, vector); + psel->setGradientLinear( vector ); SPLinearGradient *lg = SP_LINEARGRADIENT (server); - sp_paint_selector_set_gradient_properties (psel, - SP_GRADIENT_UNITS (lg), - SP_GRADIENT_SPREAD (lg)); + psel->setGradientProperties( SP_GRADIENT_UNITS(lg), + SP_GRADIENT_SPREAD(lg) ); } else if (SP_IS_RADIALGRADIENT (server)) { SPGradient *vector = SP_GRADIENT(server)->getVector(); - sp_paint_selector_set_gradient_radial (psel, vector); + psel->setGradientRadial( vector ); SPRadialGradient *rg = SP_RADIALGRADIENT (server); - sp_paint_selector_set_gradient_properties (psel, - SP_GRADIENT_UNITS (rg), - SP_GRADIENT_SPREAD (rg)); + psel->setGradientProperties( SP_GRADIENT_UNITS (rg), + SP_GRADIENT_SPREAD (rg) ); } else if (SP_IS_PATTERN (server)) { SPPattern *pat = pattern_getroot (SP_PATTERN (server)); - sp_update_pattern_list (psel, pat); + psel->updatePatternList( pat ); } } break; @@ -239,7 +237,7 @@ sp_fill_style_widget_update (SPWidget *spw) case QUERY_STYLE_MULTIPLE_DIFFERENT: { - sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_MULTIPLE); + psel->setMode(SP_PAINT_SELECTOR_MODE_MULTIPLE); break; } } @@ -321,7 +319,7 @@ sp_fill_style_widget_paint_dragged (SPPaintSelector *psel, SPWidget *spw) case SP_PAINT_SELECTOR_MODE_COLOR_RGB: case SP_PAINT_SELECTOR_MODE_COLOR_CMYK: { - sp_paint_selector_set_flat_color (psel, SP_ACTIVE_DESKTOP, "fill", "fill-opacity"); + psel->setFlatColor( SP_ACTIVE_DESKTOP, "fill", "fill-opacity" ); sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE, _("Set fill color")); g_object_set_data (G_OBJECT (spw), "local", GINT_TO_POINTER (TRUE)); // local change, do not update from selection @@ -395,7 +393,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in losing release events sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0); - sp_paint_selector_set_flat_color (psel, desktop, "fill", "fill-opacity"); + psel->setFlatColor( desktop, "fill", "fill-opacity" ); sp_document_maybe_done (sp_desktop_document(desktop), undo_label, SP_VERB_DIALOG_FILL_STROKE, _("Set fill color")); // resume interruptibility @@ -422,7 +420,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - SPGradient *vector = sp_paint_selector_get_gradient_vector(psel); + SPGradient *vector = psel->getGradientVector(); if (!vector) { /* No vector in paint selector should mean that we just changed mode */ @@ -460,7 +458,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, sp_repr_css_change_recursive (SP_OBJECT_REPR (i->data), css, "style"); SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, true); - sp_gradient_selector_attrs_to_gradient (gr, psel); + psel->pushAttrsToGradient( gr ); } } @@ -475,7 +473,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, if (items) { - SPPattern *pattern = sp_paint_selector_get_pattern (psel); + SPPattern *pattern = psel->getPattern(); if (!pattern) { /* No Pattern in paint selector should mean that we just diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 147077f44..7bfe27310 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -1146,7 +1146,7 @@ static void sp_gradient_vector_color_dragged(SPColorSelector *csel, GtkObject *o SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop")); - csel->base->getColorAlpha(stop->specified_color, &stop->opacity); + csel->base->getColorAlpha(stop->specified_color, stop->opacity); stop->currentColor = false; blocked = FALSE; @@ -1185,7 +1185,7 @@ static void sp_gradient_vector_color_changed(SPColorSelector *csel, GtkObject *o SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop")); csel = static_cast(g_object_get_data(G_OBJECT(object), "cselector")); - csel->base->getColorAlpha( color, &alpha ); + csel->base->getColorAlpha( color, alpha ); rgb = color.toRGBA32( 0x00 ); sp_repr_set_css_double(SP_OBJECT_REPR(stop), "offset", stop->offset); diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 3eaec1c23..360994241 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -123,7 +123,7 @@ static bool isPaintModeGradient( SPPaintSelectorMode mode ) return isGrad; } -static SPGradientSelector *getGradientFromData(SPPaintSelector *psel) +static SPGradientSelector *getGradientFromData(SPPaintSelector const *psel) { SPGradientSelector *grad = 0; if (psel->mode == SP_PAINT_SELECTOR_MODE_SWATCH) { @@ -325,7 +325,7 @@ static void sp_paint_selector_style_button_toggled(GtkToggleButton *tb, SPPaintSelector *psel) { if (!psel->update && gtk_toggle_button_get_active(tb)) { - sp_paint_selector_set_mode(psel, (SPPaintSelectorMode)GPOINTER_TO_UINT(gtk_object_get_data(GTK_OBJECT(tb), "mode"))); + psel->setMode(static_cast(GPOINTER_TO_UINT(gtk_object_get_data(GTK_OBJECT(tb), "mode")))); } } @@ -355,11 +355,9 @@ sp_paint_selector_show_fillrule(SPPaintSelector *psel, bool is_fill) GtkWidget * sp_paint_selector_new(bool is_fill) { - SPPaintSelector *psel; + SPPaintSelector *psel = static_cast(gtk_type_new(SP_TYPE_PAINT_SELECTOR)); - psel = (SPPaintSelector*)gtk_type_new(SP_TYPE_PAINT_SELECTOR); - - sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_MULTIPLE); + psel->setMode(SP_PAINT_SELECTOR_MODE_MULTIPLE); // This silliness is here because I don't know how to pass a parameter to the // GtkObject "constructor" (sp_paint_selector_init). Remove it when paint_selector @@ -369,66 +367,64 @@ sp_paint_selector_new(bool is_fill) return GTK_WIDGET(psel); } -void -sp_paint_selector_set_mode(SPPaintSelector *psel, SPPaintSelectorMode mode) +void SPPaintSelector::setMode(SPPaintSelectorMode mode) { - if (psel->mode != mode) { - psel->update = TRUE; + if (this->mode != mode) { + update = TRUE; #ifdef SP_PS_VERBOSE - g_print("Mode change %d -> %d %s -> %s\n", psel->mode, mode, modeStrings[psel->mode], modeStrings[mode]); + g_print("Mode change %d -> %d %s -> %s\n", this->mode, mode, modeStrings[this->mode], modeStrings[mode]); #endif switch (mode) { case SP_PAINT_SELECTOR_MODE_EMPTY: - sp_paint_selector_set_mode_empty(psel); + sp_paint_selector_set_mode_empty(this); break; case SP_PAINT_SELECTOR_MODE_MULTIPLE: - sp_paint_selector_set_mode_multiple(psel); + sp_paint_selector_set_mode_multiple(this); break; case SP_PAINT_SELECTOR_MODE_NONE: - sp_paint_selector_set_mode_none(psel); + sp_paint_selector_set_mode_none(this); break; case SP_PAINT_SELECTOR_MODE_COLOR_RGB: case SP_PAINT_SELECTOR_MODE_COLOR_CMYK: - sp_paint_selector_set_mode_color(psel, mode); + sp_paint_selector_set_mode_color(this, mode); break; case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR: case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL: - sp_paint_selector_set_mode_gradient(psel, mode); + sp_paint_selector_set_mode_gradient(this, mode); break; case SP_PAINT_SELECTOR_MODE_PATTERN: - sp_paint_selector_set_mode_pattern(psel, mode); + sp_paint_selector_set_mode_pattern(this, mode); break; case SP_PAINT_SELECTOR_MODE_SWATCH: - sp_paint_selector_set_mode_swatch(psel, mode); + sp_paint_selector_set_mode_swatch(this, mode); break; case SP_PAINT_SELECTOR_MODE_UNSET: - sp_paint_selector_set_mode_unset(psel); + sp_paint_selector_set_mode_unset(this); break; default: g_warning("file %s: line %d: Unknown paint mode %d", __FILE__, __LINE__, mode); break; } - psel->mode = mode; - gtk_signal_emit(GTK_OBJECT(psel), psel_signals[MODE_CHANGED], psel->mode); - psel->update = FALSE; + this->mode = mode; + gtk_signal_emit(GTK_OBJECT(this), psel_signals[MODE_CHANGED], this->mode); + update = FALSE; } } -void -sp_paint_selector_set_fillrule(SPPaintSelector *psel, SPPaintSelectorFillRule fillrule) +void SPPaintSelector::setFillrule(SPPaintSelectorFillRule fillrule) { - if (psel->fillrulebox) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->evenodd), (fillrule == SP_PAINT_SELECTOR_FILLRULE_EVENODD)); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->nonzero), (fillrule == SP_PAINT_SELECTOR_FILLRULE_NONZERO)); + if (fillrulebox) { + // TODO this flips widgets but does not use a member to store state. Revisit + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(evenodd), (fillrule == SP_PAINT_SELECTOR_FILLRULE_EVENODD)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(nonzero), (fillrule == SP_PAINT_SELECTOR_FILLRULE_NONZERO)); } } -void -sp_paint_selector_set_color_alpha(SPPaintSelector *psel, SPColor const *color, float alpha) +void SPPaintSelector::setColorAlpha(SPColor const &color, float alpha) { g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); - SPColorSelector *csel; - guint32 rgba; + SPColorSelector *csel = 0; + guint32 rgba = 0; /* if ( sp_color_get_colorspace_type(color) == SP_COLORSPACE_TYPE_CMYK ) @@ -444,115 +440,105 @@ sp_paint_selector_set_color_alpha(SPPaintSelector *psel, SPColor const *color, f #ifdef SP_PS_VERBOSE g_print("PaintSelector set RGBA\n"); #endif - sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_COLOR_RGB); + setMode(SP_PAINT_SELECTOR_MODE_COLOR_RGB); } - csel = (SPColorSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "color-selector"); - rgba = color->toRGBA32( alpha ); - csel->base->setColorAlpha( *color, alpha ); + csel = reinterpret_cast(gtk_object_get_data(GTK_OBJECT(selector), "color-selector")); + rgba = color.toRGBA32( alpha ); + csel->base->setColorAlpha( color, alpha ); } -void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPGradient *vector ) +void SPPaintSelector::setSwatch(SPGradient *vector ) { #ifdef SP_PS_VERBOSE g_print("PaintSelector set SWATCH\n"); #endif - sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_SWATCH); + setMode(SP_PAINT_SELECTOR_MODE_SWATCH); - SwatchSelector *swatchsel = static_cast(gtk_object_get_data(GTK_OBJECT(psel->selector), "swatch-selector")); + SwatchSelector *swatchsel = static_cast(g_object_get_data(G_OBJECT(selector), "swatch-selector")); if (swatchsel) { swatchsel->setVector( (vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector ); } } -void -sp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector) +void SPPaintSelector::setGradientLinear(SPGradient *vector) { #ifdef SP_PS_VERBOSE g_print("PaintSelector set GRADIENT LINEAR\n"); #endif - sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR); + setMode(SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR); - SPGradientSelector *gsel = getGradientFromData(psel); + SPGradientSelector *gsel = getGradientFromData(this); gsel->setMode(SPGradientSelector::MODE_LINEAR); gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); } -void -sp_paint_selector_set_gradient_radial(SPPaintSelector *psel, SPGradient *vector) +void SPPaintSelector::setGradientRadial(SPGradient *vector) { #ifdef SP_PS_VERBOSE g_print("PaintSelector set GRADIENT RADIAL\n"); #endif - sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL); + setMode(SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL); - SPGradientSelector *gsel = getGradientFromData(psel); + SPGradientSelector *gsel = getGradientFromData(this); gsel->setMode(SPGradientSelector::MODE_RADIAL); gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); } -void sp_paint_selector_set_gradient_properties(SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread) +void SPPaintSelector::setGradientProperties( SPGradientUnits units, SPGradientSpread spread ) { - g_return_if_fail(SP_IS_PAINT_SELECTOR(psel)); - g_return_if_fail(isPaintModeGradient(psel->mode)); + g_return_if_fail(isPaintModeGradient(mode)); - SPGradientSelector *gsel = getGradientFromData(psel); + SPGradientSelector *gsel = getGradientFromData(this); gsel->setUnits(units); gsel->setSpread(spread); } -void sp_paint_selector_get_gradient_properties(SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread) +void SPPaintSelector::getGradientProperties( SPGradientUnits &units, SPGradientSpread &spread) const { - g_return_if_fail(SP_IS_PAINT_SELECTOR(psel)); - g_return_if_fail(isPaintModeGradient(psel->mode)); + g_return_if_fail(isPaintModeGradient(mode)); - SPGradientSelector *gsel = getGradientFromData(psel); - if (units) { - *units = gsel->getUnits(); - } - if (spread) { - *spread = gsel->getSpread(); - } + SPGradientSelector *gsel = getGradientFromData(this); + units = gsel->getUnits(); + spread = gsel->getSpread(); } /** * \post (alpha == NULL) || (*alpha in [0.0, 1.0]). */ -void -sp_paint_selector_get_color_alpha(SPPaintSelector *psel, SPColor *color, gfloat *alpha) +void SPPaintSelector::getColorAlpha(SPColor &color, gfloat &alpha) const { SPColorSelector *csel; - csel = (SPColorSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "color-selector"); + csel = reinterpret_cast(g_object_get_data(G_OBJECT(selector), "color-selector")); - csel->base->getColorAlpha( *color, alpha ); + csel->base->getColorAlpha( color, alpha ); - g_assert( !alpha - || ( ( 0.0 <= *alpha ) - && ( *alpha <= 1.0 ) ) ); + g_assert( ( 0.0 <= alpha ) + && ( alpha <= 1.0 ) ); } -SPGradient *sp_paint_selector_get_gradient_vector(SPPaintSelector *psel) +SPGradient *SPPaintSelector::getGradientVector() { SPGradient* vect = 0; - if (isPaintModeGradient(psel->mode)) { - SPGradientSelector *gsel = getGradientFromData(psel); + if (isPaintModeGradient(mode)) { + SPGradientSelector *gsel = getGradientFromData(this); vect = gsel->getVector(); } return vect; } -void -sp_gradient_selector_attrs_to_gradient(SPGradient *gr, SPPaintSelector *psel) + +void SPPaintSelector::pushAttrsToGradient( SPGradient *gr ) const { SPGradientUnits units = SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX; SPGradientSpread spread = SP_GRADIENT_SPREAD_PAD; - sp_paint_selector_get_gradient_properties(psel, &units, &spread); + getGradientProperties( units, spread ); sp_gradient_set_units(gr, units); sp_gradient_set_spread(gr, spread); SP_OBJECT(gr)->updateRepr(); @@ -655,7 +641,7 @@ sp_paint_selector_color_released(SPColorSelector *csel, SPPaintSelector *psel) static void sp_paint_selector_color_changed(SPColorSelector *csel, SPPaintSelector *psel) { - csel->base->getColorAlpha( psel->color, &psel->alpha ); + csel->base->getColorAlpha( psel->color, psel->alpha ); gtk_signal_emit(GTK_OBJECT(psel), psel_signals[CHANGED]); } @@ -968,11 +954,12 @@ ink_pattern_menu(GtkWidget *mnu) /*update pattern list*/ -void -sp_update_pattern_list( SPPaintSelector *psel, SPPattern *pattern) +void SPPaintSelector::updatePatternList( SPPattern *pattern ) { - if (psel->update) return; - GtkWidget *mnu = (GtkWidget *)g_object_get_data(G_OBJECT(psel), "patternmenu"); + if (update) { + return; + } + GtkWidget *mnu = GTK_WIDGET(g_object_get_data(G_OBJECT(this), "patternmenu")); g_assert( mnu != NULL ); /* Clear existing menu if any */ @@ -1068,13 +1055,12 @@ sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSelectorMode mo #endif } -SPPattern * -sp_paint_selector_get_pattern(SPPaintSelector *psel) +SPPattern *SPPaintSelector::getPattern() { - SPPattern *pat; - g_return_val_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_PATTERN) , NULL); + SPPattern *pat = 0; + g_return_val_if_fail((mode == SP_PAINT_SELECTOR_MODE_PATTERN) , NULL); - GtkWidget *patmnu = (GtkWidget *) g_object_get_data(G_OBJECT(psel), "patternmenu"); + GtkWidget *patmnu = (GtkWidget *) g_object_get_data(G_OBJECT(this), "patternmenu"); /* no pattern menu if we were just selected */ if ( patmnu == NULL ) return NULL; @@ -1086,24 +1072,27 @@ sp_paint_selector_get_pattern(SPPaintSelector *psel) return NULL; } gchar *patid = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(m)), - "pattern"); + "pattern"); //gchar *pattern = ""; if (strcmp(patid, "none")){ - gchar *stockid = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(m)), - "stockid"); - gchar *paturn = patid; - if (!strcmp(stockid,"true")) paturn = g_strconcat("urn:inkscape:pattern:",patid,NULL); - SPObject *pat_obj = get_stock_item(paturn); - if (pat_obj) { + gchar *stockid = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(m)), + "stockid"); + gchar *paturn = patid; + if (!strcmp(stockid,"true")) paturn = g_strconcat("urn:inkscape:pattern:",patid,NULL); + SPObject *pat_obj = get_stock_item(paturn); + if (pat_obj) { pat = SP_PATTERN(pat_obj); } } else { - pat = pattern_getroot(SP_PATTERN(g_object_get_data(G_OBJECT(gtk_menu_get_active(m)), "pattern"))); + pat = pattern_getroot(SP_PATTERN(g_object_get_data(G_OBJECT(gtk_menu_get_active(m)), "pattern"))); + } + + if (pat && !SP_IS_PATTERN(pat)) { + pat = 0; } - if SP_IS_PATTERN(pat) return pat; - return NULL; + return pat; } static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSelectorMode mode) @@ -1142,14 +1131,14 @@ static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSele #endif } -void -sp_paint_selector_set_flat_color(SPPaintSelector *psel, SPDesktop *desktop, gchar const *color_property, gchar const *opacity_property) +// 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 ) { SPCSSAttr *css = sp_repr_css_attr_new(); SPColor color; - gfloat alpha; - sp_paint_selector_get_color_alpha(psel, &color, &alpha); + gfloat alpha = 0; + getColorAlpha( color, alpha ); std::string colorStr = color.toString(); @@ -1158,7 +1147,7 @@ sp_paint_selector_set_flat_color(SPPaintSelector *psel, SPDesktop *desktop, gcha g_message("sp_paint_selector_set_flat_color() to '%s' from 0x%08x::%s", colorStr.c_str(), rgba, - (color.icc?color.icc->colorProfile.c_str():"") ); + (color.icc ? color.icc->colorProfile.c_str():"") ); #endif // SP_PS_VERBOSE sp_repr_css_set_property(css, color_property, colorStr.c_str()); diff --git a/src/widgets/paint-selector.h b/src/widgets/paint-selector.h index 2d7ac3011..9d0c5e76c 100644 --- a/src/widgets/paint-selector.h +++ b/src/widgets/paint-selector.h @@ -73,6 +73,28 @@ struct SPPaintSelector { SPColor color; float alpha; + + + void setMode( SPPaintSelectorMode mode ); + void setFillrule( SPPaintSelectorFillRule fillrule ); + + void setColorAlpha( SPColor const &color, float alpha ); + void getColorAlpha( SPColor &color, gfloat &alpha ) const; + + void setGradientLinear( SPGradient *vector ); + void setGradientRadial( SPGradient *vector ); + void setSwatch( SPGradient *vector ); + + void setGradientProperties( SPGradientUnits units, SPGradientSpread spread ); + void getGradientProperties( SPGradientUnits &units, SPGradientSpread &spread ) const; + + void pushAttrsToGradient( SPGradient *gr ) const; + SPGradient *getGradientVector(); + SPPattern * getPattern(); + void updatePatternList( SPPattern *pat ); + + // TODO move this elsewhere: + void setFlatColor( SPDesktop *desktop, const gchar *color_property, const gchar *opacity_property ); }; /// The SPPaintSelector vtable @@ -92,33 +114,7 @@ GtkType sp_paint_selector_get_type (void); GtkWidget *sp_paint_selector_new (bool is_fill); -void sp_paint_selector_set_mode (SPPaintSelector *psel, SPPaintSelectorMode mode); -void sp_paint_selector_set_fillrule (SPPaintSelector *psel, SPPaintSelectorFillRule fillrule); - -void sp_paint_selector_set_color_alpha (SPPaintSelector *psel, const SPColor *color, float alpha); - -void sp_paint_selector_set_gradient_linear (SPPaintSelector *psel, SPGradient *vector); - -void sp_paint_selector_set_gradient_radial (SPPaintSelector *psel, SPGradient *vector); - -void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPGradient *vector ); - -void sp_paint_selector_set_gradient_properties (SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread); -void sp_paint_selector_get_gradient_properties (SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread); - -void sp_gradient_selector_attrs_to_gradient (SPGradient *gr, SPPaintSelector *psel); - -void sp_paint_selector_get_color_alpha (SPPaintSelector *psel, SPColor *color, gfloat *alpha); - -SPGradient *sp_paint_selector_get_gradient_vector (SPPaintSelector *psel); - -void sp_paint_selector_system_color_set (SPPaintSelector *psel, const SPColor *color, float opacity); - -SPPattern * sp_paint_selector_get_pattern (SPPaintSelector *psel); - -void sp_update_pattern_list ( SPPaintSelector *psel, SPPattern *pat); -void sp_paint_selector_set_flat_color (SPPaintSelector *psel, SPDesktop *desktop, const gchar *color_property, const gchar *opacity_property); SPPaintSelectorMode sp_style_determine_paint_selector_mode (SPStyle *style, bool isfill); diff --git a/src/widgets/sp-color-notebook.cpp b/src/widgets/sp-color-notebook.cpp index b2df8d2a5..a249786ff 100644 --- a/src/widgets/sp-color-notebook.cpp +++ b/src/widgets/sp-color-notebook.cpp @@ -126,7 +126,7 @@ void ColorNotebook::switchPage(GtkNotebook*, if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (_book)) >= 0 ) { csel = getCurrentSelector(); - csel->base->getColorAlpha(_color, &_alpha); + csel->base->getColorAlpha(_color, _alpha); } widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), page_num); if ( widget && SP_IS_COLOR_SELECTOR (widget) ) @@ -625,7 +625,7 @@ void ColorNotebook::_entryModified (SPColorSelector *csel, SPColorNotebook *colo SPColor color; gfloat alpha = 1.0; - csel->base->getColorAlpha( color, &alpha ); + csel->base->getColorAlpha( color, alpha ); nb->_updateRgbaEntry( color, alpha ); nb->_updateInternals( color, alpha, nb->_dragging ); } diff --git a/src/widgets/sp-color-selector.cpp b/src/widgets/sp-color-selector.cpp index 312128781..203bc3c2a 100644 --- a/src/widgets/sp-color-selector.cpp +++ b/src/widgets/sp-color-selector.cpp @@ -318,15 +318,12 @@ void ColorSelector::_colorChanged() { } -void ColorSelector::getColorAlpha( SPColor& color, gfloat* alpha ) const +void ColorSelector::getColorAlpha( SPColor &color, gfloat &alpha ) const { gint i = 0; color = _color; - if ( alpha ) - { - *alpha = _alpha; - } + alpha = _alpha; // Try to catch uninitialized value usage if ( color.v.c[0] ) @@ -345,7 +342,7 @@ void ColorSelector::getColorAlpha( SPColor& color, gfloat* alpha ) const { i++; } - if ( alpha && *alpha ) + if ( alpha ) { i++; } diff --git a/src/widgets/sp-color-selector.h b/src/widgets/sp-color-selector.h index 40446fe0a..a2ad87dd5 100644 --- a/src/widgets/sp-color-selector.h +++ b/src/widgets/sp-color-selector.h @@ -26,7 +26,7 @@ public: gfloat getAlpha() const; void setColorAlpha( const SPColor& color, gfloat alpha, bool emit = false ); - void getColorAlpha( SPColor& color, gfloat* alpha ) const; + void getColorAlpha( SPColor &color, gfloat &alpha ) const; virtual void setSubmode( guint submode ); virtual guint getSubmode() const; diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index a981934dd..57dce6fff 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -189,7 +189,7 @@ sp_stroke_style_paint_update (SPWidget *spw) case QUERY_STYLE_NOTHING: { /* No paint at all */ - sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_EMPTY); + psel->setMode(SP_PAINT_SELECTOR_MODE_EMPTY); break; } @@ -198,7 +198,7 @@ sp_stroke_style_paint_update (SPWidget *spw) case QUERY_STYLE_MULTIPLE_SAME: { SPPaintSelectorMode pselmode = sp_style_determine_paint_selector_mode (query, false); - sp_paint_selector_set_mode (psel, pselmode); + psel->setMode(pselmode); if (query->stroke.set && query->stroke.isPaintserver()) { @@ -206,37 +206,34 @@ sp_stroke_style_paint_update (SPWidget *spw) if (server && server->isSwatch()) { SPGradient *vector = SP_GRADIENT(server)->getVector(); - sp_paint_selector_set_swatch( psel, vector ); + psel->setSwatch( vector ); } else if (SP_IS_LINEARGRADIENT (server)) { SPGradient *vector = SP_GRADIENT(server)->getVector(); - sp_paint_selector_set_gradient_linear (psel, vector); + psel->setGradientLinear( vector ); SPLinearGradient *lg = SP_LINEARGRADIENT (server); - sp_paint_selector_set_gradient_properties (psel, - SP_GRADIENT_UNITS (lg), - SP_GRADIENT_SPREAD (lg)); + psel->setGradientProperties( SP_GRADIENT_UNITS(lg), + SP_GRADIENT_SPREAD(lg) ); } else if (SP_IS_RADIALGRADIENT (server)) { SPGradient *vector = SP_GRADIENT(server)->getVector(); - sp_paint_selector_set_gradient_radial (psel, vector); + psel->setGradientRadial( vector ); SPRadialGradient *rg = SP_RADIALGRADIENT (server); - sp_paint_selector_set_gradient_properties (psel, - SP_GRADIENT_UNITS (rg), - SP_GRADIENT_SPREAD (rg)); + psel->setGradientProperties( SP_GRADIENT_UNITS(rg), + SP_GRADIENT_SPREAD(rg) ); } else if (SP_IS_PATTERN (server)) { SPPattern *pat = pattern_getroot (SP_PATTERN (server)); - sp_update_pattern_list (psel, pat); + psel->updatePatternList( pat ); } } else if (query->stroke.set && query->stroke.isColor()) { - sp_paint_selector_set_color_alpha (psel, &query->stroke.value.color, SP_SCALE24_TO_FLOAT (query->stroke_opacity.value)); - + psel->setColorAlpha(query->stroke.value.color, SP_SCALE24_TO_FLOAT(query->stroke_opacity.value)); } break; } case QUERY_STYLE_MULTIPLE_DIFFERENT: { - sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_MULTIPLE); + psel->setMode(SP_PAINT_SELECTOR_MODE_MULTIPLE); break; } } @@ -284,7 +281,7 @@ sp_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw) case SP_PAINT_SELECTOR_MODE_COLOR_RGB: case SP_PAINT_SELECTOR_MODE_COLOR_CMYK: { - sp_paint_selector_set_flat_color (psel, SP_ACTIVE_DESKTOP, "stroke", "stroke-opacity"); + psel->setFlatColor( SP_ACTIVE_DESKTOP, "stroke", "stroke-opacity" ); sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE, _("Set stroke color")); break; @@ -343,7 +340,7 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) case SP_PAINT_SELECTOR_MODE_COLOR_RGB: case SP_PAINT_SELECTOR_MODE_COLOR_CMYK: { - sp_paint_selector_set_flat_color (psel, desktop, "stroke", "stroke-opacity"); + psel->setFlatColor(desktop, "stroke", "stroke-opacity"); sp_document_maybe_done (sp_desktop_document(desktop), undo_label, SP_VERB_DIALOG_FILL_STROKE, _("Set stroke color")); @@ -362,7 +359,7 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) SPGradientType const gradient_type = ( psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR ? SP_GRADIENT_TYPE_LINEAR : SP_GRADIENT_TYPE_RADIAL ); - SPGradient *vector = sp_paint_selector_get_gradient_vector(psel); + SPGradient *vector = psel->getGradientVector(); if (!vector) { /* No vector in paint selector should mean that we just changed mode */ @@ -392,7 +389,7 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) vector = sp_gradient_ensure_vector_normalized(vector); for (GSList const *i = items; i != NULL; i = i->next) { SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false); - sp_gradient_selector_attrs_to_gradient(gr, psel); + psel->pushAttrsToGradient( gr ); } } @@ -405,7 +402,7 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) if (items) { - SPPattern *pattern = sp_paint_selector_get_pattern (psel); + SPPattern *pattern = psel->getPattern(); if (!pattern) { /* No Pattern in paint selector should mean that we just diff --git a/src/widgets/swatch-selector.cpp b/src/widgets/swatch-selector.cpp index 50ee632cd..602adec4f 100644 --- a/src/widgets/swatch-selector.cpp +++ b/src/widgets/swatch-selector.cpp @@ -125,7 +125,7 @@ void SwatchSelector::_changedCb(SPColorSelector */*csel*/, void *data) float alpha = 0; guint32 rgb = 0; - swsel->_csel->base->getColorAlpha( color, &alpha ); + swsel->_csel->base->getColorAlpha( color, alpha ); rgb = color.toRGBA32( 0x00 ); // TODO replace with generic shared code that also handles icc-color