summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2012-05-08 06:37:38 +0000
committerJon A. Cruz <jon@joncruz.org>2012-05-08 06:37:38 +0000
commit6f85c122e081723e51e8064dd1c71dcce1e76315 (patch)
tree478956ccd8fd9d0e475d2cb4002c81920f5b03f7 /src
parentFix for 986446 : Refactor toolbox into tool specific files (diff)
downloadinkscape-6f85c122e081723e51e8064dd1c71dcce1e76315.tar.gz
inkscape-6f85c122e081723e51e8064dd1c71dcce1e76315.zip
Follow-up conversion from bool.
(bzr r11347)
Diffstat (limited to 'src')
-rw-r--r--src/gradient-chemistry.cpp37
-rw-r--r--src/gradient-chemistry.h27
-rw-r--r--src/gradient-context.cpp6
-rw-r--r--src/widgets/fill-style.cpp12
-rw-r--r--src/widgets/gradient-toolbar.cpp58
5 files changed, 61 insertions, 79 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index 32f3afeda..119adfc79 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -1105,16 +1105,10 @@ Geom::Point getGradientCoords(SPItem *item, GrPointType point_type, guint point_
}
-/**
- * Sets item fill or stroke to the gradient of the specified type with given vector, creating
- * new private gradient, if needed.
- * gr has to be a normalized vector.
- */
-
-SPGradient *sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_fill)
+SPGradient *sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, Inkscape::PaintTarget fill_or_stroke)
{
#ifdef SP_GR_VERBOSE
- g_message("sp_item_set_gradient(%p, %p, %d, %d)", item, gr, type, is_fill);
+ g_message("sp_item_set_gradient(%p, %p, %d, %d)", item, gr, type, fill_or_stroke);
#endif
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(SP_IS_ITEM(item), NULL);
@@ -1126,8 +1120,9 @@ SPGradient *sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType ty
g_assert(style != NULL);
SPPaintServer *ps = NULL;
- if (is_fill? style->fill.isPaintserver() : style->stroke.isPaintserver())
- ps = is_fill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style);
+ if ((fill_or_stroke == Inkscape::FOR_FILL) ? style->fill.isPaintserver() : style->stroke.isPaintserver()) {
+ ps = (fill_or_stroke == Inkscape::FOR_FILL) ? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style);
+ }
if (ps
&& ( (type == SP_GRADIENT_TYPE_LINEAR && SP_IS_LINEARGRADIENT(ps)) ||
@@ -1165,7 +1160,7 @@ SPGradient *sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType ty
/* We have to change object style here; recursive because this is used from
* fill&stroke and must work for groups etc. */
- sp_style_set_property_url(item, is_fill? "fill" : "stroke", normalized, true);
+ sp_style_set_property_url(item, (fill_or_stroke == Inkscape::FOR_FILL) ? "fill" : "stroke", normalized, true);
}
item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
return normalized;
@@ -1175,7 +1170,7 @@ SPGradient *sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType ty
/* Current fill style is not a gradient or wrong type, so construct everything */
SPGradient *constructed = sp_gradient_get_private_normalized(item->document, gr, type);
constructed = sp_gradient_reset_to_userspace(constructed, item);
- sp_style_set_property_url(item, ( is_fill ? "fill" : "stroke" ), constructed, true);
+ sp_style_set_property_url(item, ( (fill_or_stroke == Inkscape::FOR_FILL) ? "fill" : "stroke" ), constructed, true);
item->requestDisplayUpdate(( SP_OBJECT_MODIFIED_FLAG |
SP_OBJECT_STYLE_MODIFIED_FLAG ));
return constructed;
@@ -1257,34 +1252,28 @@ SPGradient *sp_document_default_gradient_vector( SPDocument *document, SPColor c
return gr;
}
-/**
-Return the preferred vector for \a o, made from (in order of preference) its current vector,
-current fill or stroke color, or from desktop style if \a o is NULL or doesn't have style.
-*/
SPGradient *sp_gradient_vector_for_object( SPDocument *const doc, SPDesktop *const desktop,
- SPObject *const o, bool const is_fill, bool singleStop )
+ SPObject *const o, Inkscape::PaintTarget const fill_or_stroke, bool singleStop )
{
SPColor color;
if ( (o == NULL) || (o->style == NULL) ) {
- color = sp_desktop_get_color(desktop, is_fill);
+ color = sp_desktop_get_color(desktop, (fill_or_stroke == Inkscape::FOR_FILL));
} else {
// take the color of the object
SPStyle const &style = *(o->style);
- SPIPaint const &paint = ( is_fill
- ? style.fill
- : style.stroke );
+ SPIPaint const &paint = ( (fill_or_stroke == Inkscape::FOR_FILL) ? style.fill : style.stroke );
if (paint.isPaintserver()) {
- SPObject *server = is_fill? o->style->getFillPaintServer() : o->style->getStrokePaintServer();
+ SPObject *server = (fill_or_stroke == Inkscape::FOR_FILL) ? o->style->getFillPaintServer() : o->style->getStrokePaintServer();
if ( SP_IS_GRADIENT(server) ) {
return SP_GRADIENT(server)->getVector(true);
} else {
- color = sp_desktop_get_color(desktop, is_fill);
+ color = sp_desktop_get_color(desktop, (fill_or_stroke == Inkscape::FOR_FILL));
}
} else if (paint.isColor()) {
color = paint.value.color;
} else {
// if o doesn't use flat color, then take current color of the desktop.
- color = sp_desktop_get_color(desktop, is_fill);
+ color = sp_desktop_get_color(desktop, (fill_or_stroke == Inkscape::FOR_FILL));
}
}
diff --git a/src/gradient-chemistry.h b/src/gradient-chemistry.h
index cb410856a..2f3ea4303 100644
--- a/src/gradient-chemistry.h
+++ b/src/gradient-chemistry.h
@@ -22,29 +22,32 @@
class SPItem;
-/*
+/**
* Either normalizes given gradient to vector, or returns fresh normalized
- * vector - in latter case, original gradient is flattened and stops cleared
+ * vector - in latter case, original gradient is flattened and stops cleared.
* No transrefing - i.e. caller shouldn't hold reference to original and
* does not get one to new automatically (doc holds ref of every object anyways)
*/
+SPGradient *sp_gradient_ensure_vector_normalized(SPGradient *gradient);
-SPGradient *sp_gradient_ensure_vector_normalized (SPGradient *gradient);
-
-
-/*
- * Sets item fill/stroke to lineargradient with given vector, creating
- * new private gradient, if needed
- * gr has to be normalized vector
+
+/**
+ * Sets item fill or stroke to the gradient of the specified type with given vector, creating
+ * new private gradient, if needed.
+ * gr has to be a normalized vector.
*/
-
-SPGradient *sp_item_set_gradient (SPItem *item, SPGradient *gr, SPGradientType type, bool is_fill);
+SPGradient *sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, Inkscape::PaintTarget fill_or_stroke);
/*
* Get default normalized gradient vector of document, create if there is none
*/
SPGradient *sp_document_default_gradient_vector( SPDocument *document, SPColor const &color, bool singleStop );
-SPGradient *sp_gradient_vector_for_object( SPDocument *doc, SPDesktop *desktop, SPObject *o, bool is_fill, bool singleStop = false );
+
+/**
+ * Return the preferred vector for \a o, made from (in order of preference) its current vector,
+ * current fill or stroke color, or from desktop style if \a o is NULL or doesn't have style.
+ */
+SPGradient *sp_gradient_vector_for_object( SPDocument *doc, SPDesktop *desktop, SPObject *o, Inkscape::PaintTarget fill_or_stroke, bool singleStop = false );
void sp_object_ensure_fill_gradient_normalized (SPObject *object);
void sp_object_ensure_stroke_gradient_normalized (SPObject *object);
diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp
index aa669846c..1689e5353 100644
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
@@ -548,11 +548,11 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
SPItem *item = SP_ITEM(i->data);
SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR);
- Inkscape::PaintTarget new_fill = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
- SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, item, new_fill);
+ SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, item, fsmode);
- SPGradient *priv = sp_item_set_gradient(item, vector, new_type, new_fill);
+ SPGradient *priv = sp_item_set_gradient(item, vector, new_type, fsmode);
sp_gradient_reset_to_userspace(priv, item);
}
diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp
index d9d818643..fe24d0165 100644
--- a/src/widgets/fill-style.cpp
+++ b/src/widgets/fill-style.cpp
@@ -566,15 +566,19 @@ void FillNStroke::updateFromPaint()
}
if (!vector) {
- SPGradient *gr = sp_gradient_vector_for_object( document, desktop, reinterpret_cast<SPObject*>(i->data), kind == FILL, createSwatch );
+ SPGradient *gr = sp_gradient_vector_for_object( document,
+ desktop,
+ reinterpret_cast<SPObject*>(i->data),
+ (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE,
+ createSwatch );
if ( gr && createSwatch ) {
gr->setSwatch();
}
sp_item_set_gradient(SP_ITEM(i->data),
gr,
- gradient_type, kind == FILL);
+ gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE);
} else {
- sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, kind == FILL);
+ sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE);
}
}
} else {
@@ -587,7 +591,7 @@ void FillNStroke::updateFromPaint()
sp_repr_css_change_recursive(reinterpret_cast<SPObject*>(i->data)->getRepr(), css, "style");
}
- SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, kind == FILL);
+ SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE);
psel->pushAttrsToGradient( gr );
}
}
diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp
index 52cda966d..f60705b6c 100644
--- a/src/widgets/gradient-toolbar.cpp
+++ b/src/widgets/gradient-toolbar.cpp
@@ -61,7 +61,7 @@
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
-void gr_apply_gradient_to_item( SPItem *item, SPGradient *gr, SPGradientType new_type, guint new_fill, bool do_fill, bool do_stroke );
+void gr_apply_gradient_to_item( SPItem *item, SPGradient *gr, SPGradientType initialType, Inkscape::PaintTarget initialMode, Inkscape::PaintTarget mode );
void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient *gr);
gboolean gr_vector_list(GtkWidget *combo_box, SPDesktop *desktop, bool selection_empty, SPGradient *gr_selected, bool gr_multi);
void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr_selected);
@@ -84,36 +84,23 @@ static gboolean blocked = FALSE;
//## Gradient ##
//########################
-void gr_apply_gradient_to_item( SPItem *item, SPGradient *gr, SPGradientType new_type, guint new_fill, bool do_fill, bool do_stroke )
+void gr_apply_gradient_to_item( SPItem *item, SPGradient *gr, SPGradientType initialType, Inkscape::PaintTarget initialMode, Inkscape::PaintTarget mode )
{
SPStyle *style = item->style;
-
- if (do_fill) {
- if (style && (style->fill.isPaintserver()) &&
- SP_IS_GRADIENT( item->style->getFillPaintServer() )) {
- SPPaintServer *server = item->style->getFillPaintServer();
- if ( SP_IS_LINEARGRADIENT(server) ) {
- sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_LINEAR, true);
- } else if ( SP_IS_RADIALGRADIENT(server) ) {
- sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_RADIAL, true);
- }
- } else if (new_fill) {
- sp_item_set_gradient(item, gr, new_type, true);
+ bool isFill = (mode == Inkscape::FOR_FILL);
+ if (style
+ && (isFill ? style->fill.isPaintserver() : style->stroke.isPaintserver())
+ && SP_IS_GRADIENT(isFill ? style->getFillPaintServer() : style->getStrokePaintServer()) ) {
+ SPPaintServer *server = isFill ? style->getFillPaintServer() : style->getStrokePaintServer();
+ if ( SP_IS_LINEARGRADIENT(server) ) {
+ sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_LINEAR, mode);
+ } else if ( SP_IS_RADIALGRADIENT(server) ) {
+ sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_RADIAL, mode);
}
}
-
- if (do_stroke) {
- if (style && (style->stroke.isPaintserver()) &&
- SP_IS_GRADIENT( item->style->getStrokePaintServer() )) {
- SPPaintServer *server = item->style->getStrokePaintServer();
- if ( SP_IS_LINEARGRADIENT(server) ) {
- sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_LINEAR, false);
- } else if ( SP_IS_RADIALGRADIENT(server) ) {
- sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_RADIAL, false);
- }
- } else if (!new_fill) {
- sp_item_set_gradient(item, gr, new_type, false);
- }
+ else if (initialMode == mode)
+ {
+ sp_item_set_gradient(item, gr, initialType, mode);
}
}
@@ -126,8 +113,8 @@ gradient.
void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient *gr)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- SPGradientType new_type = static_cast<SPGradientType>(prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR));
- Inkscape::PaintTarget new_fill = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ SPGradientType initialType = static_cast<SPGradientType>(prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR));
+ Inkscape::PaintTarget initialMode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
// GRADIENTFIXME: make this work for multiple selected draggers.
@@ -136,14 +123,14 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient
GrDragger *dragger = static_cast<GrDragger*>(drag->selected->data);
for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger
GrDraggable *draggable = (GrDraggable *) i->data;
- gr_apply_gradient_to_item(draggable->item, gr, new_type, new_fill, draggable->fill_or_stroke, !draggable->fill_or_stroke);
+ gr_apply_gradient_to_item(draggable->item, gr, initialType, initialMode, draggable->fill_or_stroke);
}
return;
}
// If no drag or no dragger selected, act on selection
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
- gr_apply_gradient_to_item(SP_ITEM(i->data), gr, new_type, new_fill, new_fill, !new_fill);
+ gr_apply_gradient_to_item(SP_ITEM(i->data), gr, initialType, initialMode, initialMode);
}
}
@@ -958,8 +945,8 @@ static void gr_new_type_changed( EgeSelectOneAction *act, GObject * /*tbl*/ )
static void gr_new_fillstroke_changed( EgeSelectOneAction *act, GObject * /*tbl*/ )
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- bool fillmode = ege_select_one_action_get_active( act ) == 0;
- prefs->setInt("/tools/gradient/newfillorstroke", fillmode); // 1 for fill, 0 for stroke
+ Inkscape::PaintTarget fsmode = (ege_select_one_action_get_active( act ) == 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ prefs->setInt("/tools/gradient/newfillorstroke", (fsmode == Inkscape::FOR_FILL) ? 1 : 0);
}
/*
@@ -1140,10 +1127,9 @@ void sp_gradient_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions,
ege_select_one_action_set_icon_column( act, 2 );
ege_select_one_action_set_tooltip_column( act, 1 );
- /// @todo Convert to boolean?
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- bool fillstrokemode = !prefs->getBool("/tools/gradient/newfillorstroke", true);
- ege_select_one_action_set_active( act, fillstrokemode );
+ Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ ege_select_one_action_set_active( act, (fsmode == Inkscape::FOR_FILL) ? 0 : 1 );
g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(gr_new_fillstroke_changed), holder );
}