summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2012-05-08 02:40:28 +0000
committerJon A. Cruz <jon@joncruz.org>2012-05-08 02:40:28 +0000
commit7bcfc25bacd49b7e4c8851b54203c16d90e52733 (patch)
tree7d46159442e386afbc87b37fe1949b4c05c22d4d /src
parentFix more deprecated GDK key symbols (diff)
downloadinkscape-7bcfc25bacd49b7e4c8851b54203c16d90e52733.tar.gz
inkscape-7bcfc25bacd49b7e4c8851b54203c16d90e52733.zip
Fixing to use explicit enum types instead of generic guint & bool.
(bzr r11345)
Diffstat (limited to 'src')
-rw-r--r--src/desktop.cpp4
-rw-r--r--src/desktop.h6
-rw-r--r--src/gradient-chemistry.cpp94
-rw-r--r--src/gradient-chemistry.h40
-rw-r--r--src/gradient-context.cpp41
-rw-r--r--src/gradient-drag.cpp186
-rw-r--r--src/gradient-drag.h45
-rw-r--r--src/sp-gradient.h30
-rw-r--r--src/tweak-context.cpp13
-rw-r--r--src/widgets/gradient-toolbar.cpp8
10 files changed, 267 insertions, 200 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 30e0edc25..2610d31ae 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -121,9 +121,9 @@ SPDesktop::SPDesktop() :
showing_dialogs ( false ),
guides_active( false ),
gr_item( 0 ),
- gr_point_type( 0 ),
+ gr_point_type( POINT_LG_BEGIN ),
gr_point_i( 0 ),
- gr_fill_or_stroke( true ),
+ gr_fill_or_stroke( Inkscape::FOR_FILL ),
_layer_hierarchy( 0 ),
_reconstruction_old_layer_id(), // an id attribute is not allowed to be the empty string
_display_mode(Inkscape::RENDERMODE_NORMAL),
diff --git a/src/desktop.h b/src/desktop.h
index 507aff8a6..32457b33a 100644
--- a/src/desktop.h
+++ b/src/desktop.h
@@ -35,6 +35,8 @@
#include "display/rendermode.h"
#include <glibmm/ustring.h>
+#include "sp-gradient.h" // TODO refactor enums out to their own .h file
+
class SPCSSAttr;
struct SPCanvas;
struct SPCanvasItem;
@@ -164,9 +166,9 @@ public:
// storage for selected dragger used by GrDrag as it's
// created and deleted by tools
SPItem *gr_item;
- guint gr_point_type;
+ GrPointType gr_point_type;
guint gr_point_i;
- bool gr_fill_or_stroke;
+ Inkscape::PaintTarget gr_fill_or_stroke;
Inkscape::ObjectHierarchy *_layer_hierarchy;
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index 6983849fa..32f3afeda 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -40,6 +40,24 @@
#define noSP_GR_VERBOSE
+
+namespace {
+
+Inkscape::PaintTarget paintTargetItems[] = {Inkscape::FOR_FILL, Inkscape::FOR_STROKE};
+
+std::vector<Inkscape::PaintTarget> vectorOfPaintTargets(paintTargetItems, paintTargetItems + (sizeof(paintTargetItems) / sizeof(paintTargetItems[0])));
+
+} // namespace
+
+namespace Inkscape {
+
+std::vector<PaintTarget> const &allPaintTargets()
+{
+ return vectorOfPaintTargets;
+}
+
+} // namespace Inkscape
+
// Terminology:
//
// "vector" is a gradient that has stops but not position coords. It can be referenced by one or
@@ -479,25 +497,29 @@ void sp_gradient_transform_multiply(SPGradient *gradient, Geom::Affine postmul,
g_free(c);
}
-SPGradient *sp_item_gradient(SPItem *item, bool fill_or_stroke)
+SPGradient *getGradient(SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
SPStyle *style = item->style;
SPGradient *gradient = 0;
- if (fill_or_stroke) {
- if (style && (style->fill.isPaintserver())) {
- SPPaintServer *server = item->style->getFillPaintServer();
- if ( SP_IS_GRADIENT(server) ) {
- gradient = SP_GRADIENT(server);
+ switch (fill_or_stroke)
+ {
+ case Inkscape::FOR_FILL:
+ if (style && (style->fill.isPaintserver())) {
+ SPPaintServer *server = item->style->getFillPaintServer();
+ if ( SP_IS_GRADIENT(server) ) {
+ gradient = SP_GRADIENT(server);
+ }
}
- }
- } else {
- if (style && (style->stroke.isPaintserver())) {
- SPPaintServer *server = item->style->getStrokePaintServer();
- if ( SP_IS_GRADIENT(server) ) {
- gradient = SP_GRADIENT(server);
+ break;
+ case Inkscape::FOR_STROKE:
+ if (style && (style->stroke.isPaintserver())) {
+ SPPaintServer *server = item->style->getStrokePaintServer();
+ if ( SP_IS_GRADIENT(server) ) {
+ gradient = SP_GRADIENT(server);
+ }
}
- }
+ break;
}
return gradient;
@@ -574,12 +596,13 @@ SPStop *sp_vector_add_stop(SPGradient *vector, SPStop* prev_stop, SPStop* next_s
return newstop;
}
-void sp_item_gradient_edit_stop(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
+void sp_item_gradient_edit_stop(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke)
{
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
- if (!gradient || !SP_IS_GRADIENT(gradient))
+ if (!gradient || !SP_IS_GRADIENT(gradient)) {
return;
+ }
SPGradient *vector = gradient->getVector();
switch (point_type) {
@@ -614,9 +637,9 @@ void sp_item_gradient_edit_stop(SPItem *item, guint point_type, guint point_i, b
}
}
-guint32 sp_item_gradient_stop_query_style(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
+guint32 sp_item_gradient_stop_query_style(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke)
{
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
if (!gradient || !SP_IS_GRADIENT(gradient))
return 0;
@@ -666,12 +689,12 @@ guint32 sp_item_gradient_stop_query_style(SPItem *item, guint point_type, guint
return 0;
}
-void sp_item_gradient_stop_set_style(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, SPCSSAttr *stop)
+void sp_item_gradient_stop_set_style(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke, SPCSSAttr *stop)
{
#ifdef SP_GR_VERBOSE
g_message("sp_item_gradient_stop_set_style(%p, %d, %d, %d, %p)", item, point_type, point_i, fill_or_stroke, stop);
#endif
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
if (!gradient || !SP_IS_GRADIENT(gradient))
return;
@@ -725,12 +748,12 @@ void sp_item_gradient_stop_set_style(SPItem *item, guint point_type, guint point
}
}
-void sp_item_gradient_reverse_vector(SPItem *item, bool fill_or_stroke)
+void sp_item_gradient_reverse_vector(SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
#ifdef SP_GR_VERBOSE
g_message("sp_item_gradient_reverse_vector(%p, %d)", item, fill_or_stroke);
#endif
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
if (!gradient || !SP_IS_GRADIENT(gradient))
return;
@@ -787,17 +810,17 @@ void sp_item_gradient_reverse_vector(SPItem *item, bool fill_or_stroke)
Set the position of point point_type of the gradient applied to item (either fill_or_stroke) to
p_w (in desktop coordinates). Write_repr if you want the change to become permanent.
*/
-void sp_item_gradient_set_coords(SPItem *item, guint point_type, guint point_i, Geom::Point p_w, bool fill_or_stroke, bool write_repr, bool scale)
+void sp_item_gradient_set_coords(SPItem *item, GrPointType point_type, guint point_i, Geom::Point p_w, Inkscape::PaintTarget fill_or_stroke, bool write_repr, bool scale)
{
#ifdef SP_GR_VERBOSE
- g_message("sp_item_gradient_set_coords(%p, %d, %d, ...)", item, point_type, point_i );
+ g_message("sp_item_gradient_set_coords(%p, %d, %d, (%f, %f), ...)", item, point_type, point_i, p_w[Geom::X], p_w[Geom::Y] );
#endif
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
if (!gradient || !SP_IS_GRADIENT(gradient))
return;
- gradient = sp_gradient_convert_to_userspace (gradient, item, fill_or_stroke? "fill" : "stroke");
+ gradient = sp_gradient_convert_to_userspace(gradient, item, (fill_or_stroke == Inkscape::FOR_FILL) ? "fill" : "stroke");
Geom::Affine i2d (item->i2dt_affine ());
Geom::Point p = p_w * i2d.inverse();
@@ -988,9 +1011,9 @@ void sp_item_gradient_set_coords(SPItem *item, guint point_type, guint point_i,
}
}
-SPGradient *sp_item_gradient_get_vector(SPItem *item, bool fill_or_stroke)
+SPGradient *sp_item_gradient_get_vector(SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
if (gradient) {
return gradient->getVector();
@@ -998,10 +1021,10 @@ SPGradient *sp_item_gradient_get_vector(SPItem *item, bool fill_or_stroke)
return NULL;
}
-SPGradientSpread sp_item_gradient_get_spread(SPItem *item, bool fill_or_stroke)
+SPGradientSpread sp_item_gradient_get_spread(SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
SPGradientSpread spread = SP_GRADIENT_SPREAD_PAD;
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
if (gradient) {
spread = gradient->fetchSpread();
@@ -1010,17 +1033,12 @@ SPGradientSpread sp_item_gradient_get_spread(SPItem *item, bool fill_or_stroke)
}
-/**
-Returns the position of point point_type of the gradient applied to item (either fill_or_stroke),
-in desktop coordinates.
-*/
-
-Geom::Point sp_item_gradient_get_coords(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
+Geom::Point getGradientCoords(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke)
{
#ifdef SP_GR_VERBOSE
- g_message("sp_item_gradient_get_coords(%p, %d, %d, %d)", item, point_type, point_i, fill_or_stroke);
+ g_message("getGradientCoords(%p, %d, %d, %d)", item, point_type, point_i, fill_or_stroke);
#endif
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
Geom::Point p (0, 0);
diff --git a/src/gradient-chemistry.h b/src/gradient-chemistry.h
index f797f928d..cb410856a 100644
--- a/src/gradient-chemistry.h
+++ b/src/gradient-chemistry.h
@@ -61,23 +61,39 @@ SPStop* sp_get_stop_i(SPGradient *gradient, guint i);
guint sp_number_of_stops(SPGradient const *gradient);
guint sp_number_of_stops_before_stop(SPGradient const *gradient, SPStop *target);
-guint32 average_color (guint32 c1, guint32 c2, gdouble p = 0.5);
+guint32 average_color(guint32 c1, guint32 c2, gdouble p = 0.5);
-SPStop *sp_vector_add_stop (SPGradient *vector, SPStop* prev_stop, SPStop* next_stop, gfloat offset);
+SPStop *sp_vector_add_stop(SPGradient *vector, SPStop* prev_stop, SPStop* next_stop, gfloat offset);
-void sp_gradient_transform_multiply (SPGradient *gradient, Geom::Affine postmul, bool set);
+void sp_gradient_transform_multiply(SPGradient *gradient, Geom::Affine postmul, bool set);
-SPGradient * sp_item_gradient (SPItem *item, bool fill_or_stroke);
-void sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, Geom::Point p_desk, bool fill_or_stroke, bool write_repr, bool scale);
-Geom::Point sp_item_gradient_get_coords (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
-SPGradient *sp_item_gradient_get_vector (SPItem *item, bool fill_or_stroke);
-SPGradientSpread sp_item_gradient_get_spread (SPItem *item, bool fill_or_stroke);
+
+/**
+ * Fetches either the fill or the stroke gradient from the given item.
+ *
+ * @param fill_or_stroke the gradient type (fill/stroke) to get.
+ * @return the specified gradient if set, null otherwise.
+ */
+SPGradient *getGradient(SPItem *item, Inkscape::PaintTarget fill_or_stroke);
+
+
+void sp_item_gradient_set_coords(SPItem *item, GrPointType point_type, guint point_i, Geom::Point p_desk, Inkscape::PaintTarget fill_or_stroke, bool write_repr, bool scale);
+
+/**
+ * Returns the position of point point_type of the gradient applied to item (either fill_or_stroke),
+ * in desktop coordinates.
+*/
+Geom::Point getGradientCoords(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke);
+
+SPGradient *sp_item_gradient_get_vector(SPItem *item, Inkscape::PaintTarget fill_or_stroke);
+SPGradientSpread sp_item_gradient_get_spread(SPItem *item, Inkscape::PaintTarget fill_or_stroke);
struct SPCSSAttr;
-void sp_item_gradient_stop_set_style (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, SPCSSAttr *stop);
-guint32 sp_item_gradient_stop_query_style (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
-void sp_item_gradient_edit_stop (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
-void sp_item_gradient_reverse_vector (SPItem *item, bool fill_or_stroke);
+
+void sp_item_gradient_stop_set_style(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke, SPCSSAttr *stop);
+guint32 sp_item_gradient_stop_query_style(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke);
+void sp_item_gradient_edit_stop(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke);
+void sp_item_gradient_reverse_vector(SPItem *item, Inkscape::PaintTarget fill_or_stroke);
#endif // SEEN_SP_GRADIENT_CHEMISTRY_H
diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp
index c4c1bc0f3..aa669846c 100644
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
@@ -284,7 +284,7 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi
GrDraggable *d = (GrDraggable *) j->data;
// find the gradient
- SPGradient *gradient = sp_item_gradient (d->item, d->fill_or_stroke);
+ SPGradient *gradient = getGradient(d->item, d->fill_or_stroke);
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
// these draggable types cannot have a next draggabe to insert a stop between them
@@ -300,7 +300,7 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi
SPStop *next_stop = this_stop->getNextStop();
SPStop *last_stop = sp_last_stop (vector);
- gint fs = d->fill_or_stroke;
+ Inkscape::PaintTarget fs = d->fill_or_stroke;
SPItem *item = d->item;
gint type = d->point_type;
gint p_i = d->point_i;
@@ -312,23 +312,26 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi
// (complex because it may have different types, and because in radial,
// more than one dragger may correspond to a stop, so we must distinguish)
if (type == POINT_LG_BEGIN || type == POINT_LG_MID) {
- if (next_stop == last_stop)
- dnext = drag->getDraggerFor (item, POINT_LG_END, p_i+1, fs);
- else
- dnext = drag->getDraggerFor (item, POINT_LG_MID, p_i+1, fs);
+ if (next_stop == last_stop) {
+ dnext = drag->getDraggerFor(item, POINT_LG_END, p_i+1, fs);
+ } else {
+ dnext = drag->getDraggerFor(item, POINT_LG_MID, p_i+1, fs);
+ }
} else { // radial
if (type == POINT_RG_CENTER || type == POINT_RG_MID1) {
- if (next_stop == last_stop)
- dnext = drag->getDraggerFor (item, POINT_RG_R1, p_i+1, fs);
- else
- dnext = drag->getDraggerFor (item, POINT_RG_MID1, p_i+1, fs);
+ if (next_stop == last_stop) {
+ dnext = drag->getDraggerFor(item, POINT_RG_R1, p_i+1, fs);
+ } else {
+ dnext = drag->getDraggerFor(item, POINT_RG_MID1, p_i+1, fs);
+ }
}
if ((type == POINT_RG_MID2) ||
(type == POINT_RG_CENTER && dnext && !dnext->isSelected())) {
- if (next_stop == last_stop)
- dnext = drag->getDraggerFor (item, POINT_RG_R2, p_i+1, fs);
- else
- dnext = drag->getDraggerFor (item, POINT_RG_MID2, p_i+1, fs);
+ if (next_stop == last_stop) {
+ dnext = drag->getDraggerFor(item, POINT_RG_R2, p_i+1, fs);
+ } else {
+ dnext = drag->getDraggerFor(item, POINT_RG_MID2, p_i+1, fs);
+ }
}
}
@@ -372,7 +375,7 @@ sp_gradient_context_add_stops_between_selected_stops (SPGradientContext *rc)
*/
continue;
}
- SPGradient *gradient = sp_item_gradient (d->item, d->fill_or_stroke);
+ SPGradient *gradient = getGradient(d->item, d->fill_or_stroke);
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
SPStop *this_stop = sp_get_stop_i (vector, d->point_i);
SPStop *next_stop = this_stop->getNextStop();
@@ -545,7 +548,7 @@ 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);
- guint new_fill = prefs->getInt("/tools/gradient/newfillorstroke", 1);
+ Inkscape::PaintTarget new_fill = (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);
@@ -841,8 +844,8 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
drag->selected_reverse_vector();
} else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients)
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
- sp_item_gradient_reverse_vector (SP_ITEM(i->data), true);
- sp_item_gradient_reverse_vector (SP_ITEM(i->data), false);
+ sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_FILL);
+ sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_STROKE);
}
}
// we did an undoable action
@@ -910,7 +913,7 @@ static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint
if (!selection->isEmpty()) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int type = prefs->getInt("/tools/gradient/newgradient", 1);
- int fill_or_stroke = prefs->getInt("/tools/gradient/newfillorstroke", 1);
+ Inkscape::PaintTarget fill_or_stroke = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
SPGradient *vector;
if (ec->item_to_select) {
diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp
index 629659208..e0058030d 100644
--- a/src/gradient-drag.cpp
+++ b/src/gradient-drag.cpp
@@ -50,6 +50,7 @@
#include "display/sp-canvas.h"
using Inkscape::DocumentUndo;
+using Inkscape::allPaintTargets;
#define GR_KNOT_COLOR_NORMAL 0xffffff00
#define GR_KNOT_COLOR_MOUSEOVER 0xff000000
@@ -337,19 +338,22 @@ guint32 GrDrag::getColor()
return SP_RGBA32_F_COMPOSE(cf[0], cf[1], cf[2], cf[3]);
}
+// TODO refactor early returns
SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double tolerance)
{
gfloat new_stop_offset = 0; // type of SPStop.offset = gfloat
- SPGradient *gradient;
- bool fill_or_stroke = true;
+ SPGradient *gradient = 0;
//bool r1_knot = false;
bool addknot = false;
- do {
- gradient = sp_item_gradient (item, fill_or_stroke);
+
+ for (std::vector<Inkscape::PaintTarget>::const_iterator it = allPaintTargets().begin(); (it != allPaintTargets().end()) && !addknot; ++it)
+ {
+ Inkscape::PaintTarget fill_or_stroke = *it;
+ gradient = getGradient(item, fill_or_stroke);
if (SP_IS_LINEARGRADIENT(gradient)) {
- Geom::Point begin = sp_item_gradient_get_coords(item, POINT_LG_BEGIN, 0, fill_or_stroke);
- Geom::Point end = sp_item_gradient_get_coords(item, POINT_LG_END, 0, fill_or_stroke);
+ Geom::Point begin = getGradientCoords(item, POINT_LG_BEGIN, 0, fill_or_stroke);
+ Geom::Point end = getGradientCoords(item, POINT_LG_END, 0, fill_or_stroke);
Geom::LineSegment ls(begin, end);
double offset = ls.nearestPoint(mouse_p);
Geom::Point nearest = ls.pointAt(offset);
@@ -359,11 +363,10 @@ SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double toler
new_stop_offset = distance(begin, nearest) / distance(begin, end);
// add the knot
addknot = true;
- break; // break out of the while loop: add only one knot
}
} else if (SP_IS_RADIALGRADIENT(gradient)) {
- Geom::Point begin = sp_item_gradient_get_coords(item, POINT_RG_CENTER, 0, fill_or_stroke);
- Geom::Point end = sp_item_gradient_get_coords(item, POINT_RG_R1, 0, fill_or_stroke);
+ Geom::Point begin = getGradientCoords(item, POINT_RG_CENTER, 0, fill_or_stroke);
+ Geom::Point end = getGradientCoords(item, POINT_RG_R1, 0, fill_or_stroke);
Geom::LineSegment ls(begin, end);
double offset = ls.nearestPoint(mouse_p);
Geom::Point nearest = ls.pointAt(offset);
@@ -374,25 +377,22 @@ SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double toler
// add the knot
addknot = true;
//r1_knot = true;
- break; // break out of the while loop: add only one knot
- }
-
- end = sp_item_gradient_get_coords(item, POINT_RG_R2, 0, fill_or_stroke);
- ls = Geom::LineSegment(begin, end);
- offset = ls.nearestPoint(mouse_p);
- nearest = ls.pointAt(offset);
- dist_screen = Geom::distance(mouse_p, nearest);
- if ( dist_screen < tolerance ) {
- // calculate the new stop offset
- new_stop_offset = distance(begin, nearest) / distance(begin, end);
- // add the knot
- addknot = true;
- //r1_knot = false;
- break; // break out of the while loop: add only one knot
+ } else {
+ end = getGradientCoords(item, POINT_RG_R2, 0, fill_or_stroke);
+ ls = Geom::LineSegment(begin, end);
+ offset = ls.nearestPoint(mouse_p);
+ nearest = ls.pointAt(offset);
+ dist_screen = Geom::distance(mouse_p, nearest);
+ if ( dist_screen < tolerance ) {
+ // calculate the new stop offset
+ new_stop_offset = distance(begin, nearest) / distance(begin, end);
+ // add the knot
+ addknot = true;
+ //r1_knot = false;
+ }
}
}
- fill_or_stroke = !fill_or_stroke;
- } while (!fill_or_stroke && !addknot) ;
+ }
if (addknot) {
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
@@ -535,9 +535,9 @@ GrDrag::~GrDrag()
desktop->gr_fill_or_stroke = draggable->fill_or_stroke;
} else {
desktop->gr_item = NULL;
- desktop->gr_point_type = 0;
+ desktop->gr_point_type = POINT_LG_BEGIN;
desktop->gr_point_i = 0;
- desktop->gr_fill_or_stroke = true;
+ desktop->gr_fill_or_stroke = Inkscape::FOR_FILL;
}
deselect_all();
@@ -555,14 +555,13 @@ GrDrag::~GrDrag()
this->lines = NULL;
}
-GrDraggable::GrDraggable(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
+GrDraggable::GrDraggable(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke) :
+ item(item),
+ point_type(point_type),
+ point_i(point_i),
+ fill_or_stroke(fill_or_stroke)
{
- this->item = item;
- this->point_type = point_type;
- this->point_i = point_i;
- this->fill_or_stroke = fill_or_stroke;
-
- g_object_ref (G_OBJECT (this->item));
+ g_object_ref(G_OBJECT(item));
}
GrDraggable::~GrDraggable()
@@ -573,15 +572,16 @@ GrDraggable::~GrDraggable()
SPObject *GrDraggable::getServer()
{
- if (!item) {
- return NULL;
- }
-
- SPObject *server = NULL;
- if (fill_or_stroke) {
- server = item->style->getFillPaintServer();
- }else {
- server = item->style->getStrokePaintServer();
+ SPObject *server = 0;
+ if (item) {
+ switch (fill_or_stroke) {
+ case Inkscape::FOR_FILL:
+ server = item->style->getFillPaintServer();
+ break;
+ case Inkscape::FOR_STROKE:
+ server = item->style->getStrokePaintServer();
+ break;
+ }
}
return server;
@@ -959,7 +959,7 @@ static void gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data
if ( (state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK ) ) {
// delete this knot from vector
- SPGradient *gradient = sp_item_gradient (draggable->item, draggable->fill_or_stroke);
+ SPGradient *gradient = getGradient(draggable->item, draggable->fill_or_stroke);
gradient = gradient->getVector();
if (gradient->vector.stops.size() > 2) { // 2 is the minimum
SPStop *stop = NULL;
@@ -1053,10 +1053,10 @@ void GrDragger::fireDraggables(bool write_repr, bool scale_radial, bool merging_
/**
* Checks if the dragger has a draggable with this point_type.
*/
-bool GrDragger::isA(gint point_type)
+bool GrDragger::isA(GrPointType point_type)
{
for (GSList const* i = this->draggables; i != NULL; i = i->next) {
- GrDraggable *draggable = (GrDraggable *) i->data;
+ GrDraggable *draggable = reinterpret_cast<GrDraggable *>(i->data);
if (draggable->point_type == point_type) {
return true;
}
@@ -1067,7 +1067,7 @@ bool GrDragger::isA(gint point_type)
/**
* Checks if the dragger has a draggable with this item, point_type + point_i (number), fill_or_stroke.
*/
-bool GrDragger::isA(SPItem *item, gint point_type, gint point_i, bool fill_or_stroke)
+bool GrDragger::isA(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke)
{
for (GSList const* i = this->draggables; i != NULL; i = i->next) {
GrDraggable *draggable = (GrDraggable *) i->data;
@@ -1081,7 +1081,7 @@ bool GrDragger::isA(SPItem *item, gint point_type, gint point_i, bool fill_or_st
/**
* Checks if the dragger has a draggable with this item, point_type, fill_or_stroke.
*/
-bool GrDragger::isA(SPItem *item, gint point_type, bool fill_or_stroke)
+bool GrDragger::isA(SPItem *item, GrPointType point_type, Inkscape::PaintTarget fill_or_stroke)
{
for (GSList const* i = this->draggables; i != NULL; i = i->next) {
GrDraggable *draggable = (GrDraggable *) i->data;
@@ -1158,14 +1158,14 @@ void GrDragger::updateTip()
_(gr_knot_descr[draggable->point_type]),
draggable->point_i,
item_desc,
- draggable->fill_or_stroke == false ? _(" (stroke)") : "");
+ (draggable->fill_or_stroke == Inkscape::FOR_STROKE) ? _(" (stroke)") : "");
break;
default:
this->knot->tip = g_strdup_printf (_("%s for: %s%s; drag with <b>Ctrl</b> to snap angle, with <b>Ctrl+Alt</b> to preserve angle, with <b>Ctrl+Shift</b> to scale around center"),
_(gr_knot_descr[draggable->point_type]),
item_desc,
- draggable->fill_or_stroke == false ? _(" (stroke)") : "");
+ (draggable->fill_or_stroke == Inkscape::FOR_STROKE) ? _(" (stroke)") : "");
break;
}
g_free(item_desc);
@@ -1205,17 +1205,19 @@ void GrDragger::addDraggable(GrDraggable *draggable)
/**
* Moves this dragger to the point of the given draggable, acting upon all other draggables.
*/
-void GrDragger::moveThisToDraggable(SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr)
+void GrDragger::moveThisToDraggable(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, bool write_repr)
{
- GrDraggable *dr_first = (GrDraggable *) this->draggables->data;
- if (!dr_first) return;
+ GrDraggable *dr_first = reinterpret_cast<GrDraggable *>(draggables->data);
+ if (!dr_first) {
+ return;
+ }
- this->point = sp_item_gradient_get_coords (dr_first->item, dr_first->point_type, dr_first->point_i, dr_first->fill_or_stroke);
+ this->point = getGradientCoords(dr_first->item, dr_first->point_type, dr_first->point_i, dr_first->fill_or_stroke);
this->point_original = this->point;
- sp_knot_moveto (this->knot, this->point);
+ sp_knot_moveto(this->knot, this->point);
- for (GSList const* i = this->draggables; i != NULL; i = i->next) {
+ for (GSList const* i = draggables; i != NULL; i = i->next) {
GrDraggable *da = (GrDraggable *) i->data;
if ( (da->item == item) &&
(point_type == -1 || da->point_type == point_type) &&
@@ -1223,7 +1225,7 @@ void GrDragger::moveThisToDraggable(SPItem *item, gint point_type, gint point_i,
(da->fill_or_stroke == fill_or_stroke) ) {
continue;
}
- sp_item_gradient_set_coords (da->item, da->point_type, da->point_i, this->point, da->fill_or_stroke, write_repr, false);
+ sp_item_gradient_set_coords(da->item, da->point_type, da->point_i, this->point, da->fill_or_stroke, write_repr, false);
}
// FIXME: here we should also call this->updateDependencies(write_repr); to propagate updating, but how to prevent loops?
}
@@ -1380,7 +1382,7 @@ GrDragger::~GrDragger()
/**
* Select the dragger which has the given draggable.
*/
-GrDragger *GrDrag::getDraggerFor(SPItem *item, gint point_type, gint point_i, bool fill_or_stroke)
+GrDragger *GrDrag::getDraggerFor(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke)
{
for (GList const* i = this->draggers; i != NULL; i = i->next) {
GrDragger *dragger = (GrDragger *) i->data;
@@ -1398,11 +1400,11 @@ GrDragger *GrDrag::getDraggerFor(SPItem *item, gint point_type, gint point_i, bo
}
-void GrDragger::moveOtherToDraggable(SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr)
+void GrDragger::moveOtherToDraggable(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, bool write_repr)
{
- GrDragger *d = this->parent->getDraggerFor (item, point_type, point_i, fill_or_stroke);
+ GrDragger *d = this->parent->getDraggerFor(item, point_type, point_i, fill_or_stroke);
if (d && d != this) {
- d->moveThisToDraggable (item, point_type, point_i, fill_or_stroke, write_repr);
+ d->moveThisToDraggable(item, point_type, point_i, fill_or_stroke, write_repr);
}
}
@@ -1488,7 +1490,7 @@ void GrDrag::selectByStop(SPStop *stop )
for (GSList const* j = dragger->draggables; j != NULL; j = j->next) {
GrDraggable *d = (GrDraggable *) j->data;
- SPGradient *gradient = sp_item_gradient(d->item, d->fill_or_stroke);
+ SPGradient *gradient = getGradient(d->item, d->fill_or_stroke);
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary(gradient, false);
SPStop *stop_i = sp_get_stop_i(vector, d->point_i);
@@ -1580,9 +1582,7 @@ void GrDrag::addLine(SPItem *item, Geom::Point p1, Geom::Point p2, guint32 rgba)
sp_canvas_item_move_to_z(line, 0);
line->item = item;
line->setCoords(p1, p2);
- if (rgba != GR_LINE_COLOR_FILL) { // fill is the default, so don't set color for it to speed up redraw
- line->setRgba32(rgba);
- }
+ line->setRgba32(rgba);
sp_canvas_item_show(line);
this->lines = g_slist_append(this->lines, line);
}
@@ -1593,7 +1593,7 @@ void GrDrag::addLine(SPItem *item, Geom::Point p1, Geom::Point p2, guint32 rgba)
*/
void GrDrag::addDragger(GrDraggable *draggable)
{
- Geom::Point p = sp_item_gradient_get_coords (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
+ Geom::Point p = getGradientCoords(draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
for (GList *i = this->draggers; i != NULL; i = i->next) {
GrDragger *dragger = (GrDragger *) i->data;
@@ -1613,7 +1613,7 @@ void GrDrag::addDragger(GrDraggable *draggable)
/**
* Add draggers for the radial gradient rg on item.
*/
-void GrDrag::addDraggersRadial(SPRadialGradient *rg, SPItem *item, bool fill_or_stroke)
+void GrDrag::addDraggersRadial(SPRadialGradient *rg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
rg->ensureVector();
addDragger (new GrDraggable (item, POINT_RG_CENTER, 0, fill_or_stroke));
@@ -1629,24 +1629,24 @@ void GrDrag::addDraggersRadial(SPRadialGradient *rg, SPItem *item, bool fill_or_
addDragger (new GrDraggable (item, POINT_RG_MID2, i, fill_or_stroke));
}
}
- addDragger (new GrDraggable (item, POINT_RG_R2, num-1, fill_or_stroke));
+ addDragger (new GrDraggable (item, POINT_RG_R2, num - 1, fill_or_stroke));
addDragger (new GrDraggable (item, POINT_RG_FOCUS, 0, fill_or_stroke));
}
/**
* Add draggers for the linear gradient lg on item.
*/
-void GrDrag::addDraggersLinear(SPLinearGradient *lg, SPItem *item, bool fill_or_stroke)
+void GrDrag::addDraggersLinear(SPLinearGradient *lg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
lg->ensureVector();
- addDragger (new GrDraggable (item, POINT_LG_BEGIN, 0, fill_or_stroke));
+ addDragger(new GrDraggable (item, POINT_LG_BEGIN, 0, fill_or_stroke));
guint num = lg->vector.stops.size();
if (num > 2) {
for ( guint i = 1; i < num - 1; i++ ) {
- addDragger (new GrDraggable (item, POINT_LG_MID, i, fill_or_stroke));
+ addDragger(new GrDraggable (item, POINT_LG_MID, i, fill_or_stroke));
}
}
- addDragger (new GrDraggable (item, POINT_LG_END, num-1, fill_or_stroke));
+ addDragger(new GrDraggable (item, POINT_LG_END, num - 1, fill_or_stroke));
}
/**
@@ -1662,9 +1662,9 @@ void GrDrag::grabKnot(GrDragger *dragger, gint x, gint y, guint32 etime)
/**
* Artificially grab the knot of the dragger with this draggable; used by the gradient context.
*/
-void GrDrag::grabKnot(SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime)
+void GrDrag::grabKnot(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, gint x, gint y, guint32 etime)
{
- GrDragger *dragger = getDraggerFor (item, point_type, point_i, fill_or_stroke);
+ GrDragger *dragger = getDraggerFor(item, point_type, point_i, fill_or_stroke);
if (dragger) {
sp_knot_start_dragging (dragger->knot, dragger->point, x, y, etime);
}
@@ -1697,9 +1697,9 @@ void GrDrag::updateDraggers()
if ( server && server->isSolid() ) {
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
- addDraggersLinear( SP_LINEARGRADIENT(server), item, true );
+ addDraggersLinear( SP_LINEARGRADIENT(server), item, Inkscape::FOR_FILL );
} else if ( SP_IS_RADIALGRADIENT(server) ) {
- addDraggersRadial( SP_RADIALGRADIENT(server), item, true );
+ addDraggersRadial( SP_RADIALGRADIENT(server), item, Inkscape::FOR_FILL );
}
}
@@ -1708,9 +1708,9 @@ void GrDrag::updateDraggers()
if ( server && server->isSolid() ) {
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
- addDraggersLinear( SP_LINEARGRADIENT(server), item, false );
+ addDraggersLinear( SP_LINEARGRADIENT(server), item, Inkscape::FOR_STROKE );
} else if ( SP_IS_RADIALGRADIENT(server) ) {
- addDraggersRadial( SP_RADIALGRADIENT(server), item, false );
+ addDraggersRadial( SP_RADIALGRADIENT(server), item, Inkscape::FOR_STROKE );
}
}
}
@@ -1739,12 +1739,12 @@ void GrDrag::updateLines()
{
// delete old lines
for (GSList const *i = this->lines; i != NULL; i = i->next) {
- gtk_object_destroy( GTK_OBJECT (i->data));
+ gtk_object_destroy( GTK_OBJECT(i->data) );
}
- g_slist_free (this->lines);
+ g_slist_free(this->lines);
this->lines = NULL;
- g_return_if_fail (this->selection != NULL);
+ g_return_if_fail(this->selection != NULL);
for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) {
@@ -1757,11 +1757,11 @@ void GrDrag::updateLines()
if ( server && server->isSolid() ) {
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
- this->addLine (item, sp_item_gradient_get_coords (item, POINT_LG_BEGIN, 0, true), sp_item_gradient_get_coords (item, POINT_LG_END, 0, true), GR_LINE_COLOR_FILL);
+ this->addLine(item, getGradientCoords(item, POINT_LG_BEGIN, 0, Inkscape::FOR_FILL), getGradientCoords(item, POINT_LG_END, 0, Inkscape::FOR_FILL), GR_LINE_COLOR_FILL);
} else if ( SP_IS_RADIALGRADIENT(server) ) {
- Geom::Point center = sp_item_gradient_get_coords (item, POINT_RG_CENTER, 0, true);
- this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R1, 0, true), GR_LINE_COLOR_FILL);
- this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R2, 0, true), GR_LINE_COLOR_FILL);
+ Geom::Point center = getGradientCoords(item, POINT_RG_CENTER, 0, Inkscape::FOR_FILL);
+ this->addLine(item, center, getGradientCoords(item, POINT_RG_R1, 0, Inkscape::FOR_FILL), GR_LINE_COLOR_FILL);
+ this->addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_FILL), GR_LINE_COLOR_FILL);
}
}
@@ -1770,11 +1770,11 @@ void GrDrag::updateLines()
if ( server && server->isSolid() ) {
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
- this->addLine (item, sp_item_gradient_get_coords (item, POINT_LG_BEGIN, 0, false), sp_item_gradient_get_coords (item, POINT_LG_END, 0, false), GR_LINE_COLOR_STROKE);
+ addLine(item, getGradientCoords(item, POINT_LG_BEGIN, 0, Inkscape::FOR_STROKE), getGradientCoords(item, POINT_LG_END, 0, Inkscape::FOR_STROKE), GR_LINE_COLOR_STROKE);
} else if ( SP_IS_RADIALGRADIENT(server) ) {
- Geom::Point center = sp_item_gradient_get_coords (item, POINT_RG_CENTER, 0, false);
- this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R1, 0, false), GR_LINE_COLOR_STROKE);
- this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R2, 0, false), GR_LINE_COLOR_STROKE);
+ Geom::Point center = getGradientCoords(item, POINT_RG_CENTER, 0, Inkscape::FOR_STROKE);
+ addLine(item, center, getGradientCoords(item, POINT_RG_R1, 0, Inkscape::FOR_STROKE), GR_LINE_COLOR_STROKE);
+ addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_STROKE), GR_LINE_COLOR_STROKE);
}
}
}
@@ -1974,7 +1974,7 @@ void GrDrag::deleteSelected(bool just_one)
GrDragger *dragger = (GrDragger*) selected->data;
for (GSList * drgble = dragger->draggables; drgble != NULL; drgble = drgble->next) {
GrDraggable *draggable = (GrDraggable*) drgble->data;
- SPGradient *gradient = sp_item_gradient (draggable->item, draggable->fill_or_stroke);
+ SPGradient *gradient = getGradient(draggable->item, draggable->fill_or_stroke);
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
switch (draggable->point_type) {
@@ -2163,14 +2163,14 @@ void GrDrag::deleteSelected(bool just_one)
}
if (unselectedrepr == NULL) {
- if (stopinfo->draggable->fill_or_stroke) {
+ if (stopinfo->draggable->fill_or_stroke == Inkscape::FOR_FILL) {
sp_repr_css_unset_property (css, "fill");
} else {
sp_repr_css_unset_property (css, "stroke");
}
} else {
SPCSSAttr *stopcss = sp_repr_css_attr(unselectedrepr, "style");
- if (stopinfo->draggable->fill_or_stroke) {
+ if (stopinfo->draggable->fill_or_stroke == Inkscape::FOR_FILL) {
sp_repr_css_set_property(css, "fill", sp_repr_css_property(stopcss, "stop-color", "inkscape:unset"));
sp_repr_css_set_property(css, "fill-opacity", sp_repr_css_property(stopcss, "stop-opacity", "1"));
} else {
diff --git a/src/gradient-drag.h b/src/gradient-drag.h
index a16b48759..6d23f486d 100644
--- a/src/gradient-drag.h
+++ b/src/gradient-drag.h
@@ -7,7 +7,9 @@
* Authors:
* bulia byak <bulia@users.sf.net>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ * Jon A. Cruz <jon@joncruz.org>
*
+ * Copyright (C) 2012 Authors
* Copyright (C) 2007 Johan Engelen
* Copyright (C) 2005 Authors
*
@@ -23,6 +25,7 @@
#include <2geom/point.h>
#include "knot-enums.h"
+#include "sp-gradient.h" // TODO refactor enums to external .h file
struct SPKnot;
@@ -44,13 +47,13 @@ which has the gradient, whether it's fill or stroke, the point type (from the
GrPointType enum), and the point number (needed if more than 2 stops are present).
*/
struct GrDraggable {
- GrDraggable(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
+ GrDraggable(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke);
virtual ~GrDraggable();
SPItem *item;
- gint point_type;
+ GrPointType point_type;
gint point_i; // the stop number of this point ( = 0 POINT_LG_BEGIN and POINT_RG_CENTER)
- bool fill_or_stroke;
+ Inkscape::PaintTarget fill_or_stroke;
SPObject *getServer();
@@ -95,19 +98,19 @@ struct GrDragger {
void deselect();
bool isSelected();
- void moveThisToDraggable (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr);
- void moveOtherToDraggable (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr);
+ void moveThisToDraggable(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, bool write_repr);
+ void moveOtherToDraggable(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, bool write_repr);
void updateMidstopDependencies (GrDraggable *draggable, bool write_repr);
void updateDependencies (bool write_repr);
- bool mayMerge (GrDragger *other);
- bool mayMerge (GrDraggable *da2);
+ bool mayMerge(GrDragger *other);
+ bool mayMerge(GrDraggable *da2);
- bool isA (gint point_type);
- bool isA (SPItem *item, gint point_type, bool fill_or_stroke);
- bool isA (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke);
+ bool isA(GrPointType point_type);
+ bool isA(SPItem *item, GrPointType point_type, Inkscape::PaintTarget fill_or_stroke);
+ bool isA(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke);
- void fireDraggables (bool write_repr, bool scale_radial = false, bool merging_focus = false);
+ void fireDraggables(bool write_repr, bool scale_radial = false, bool merging_focus = false);
};
/**
@@ -147,10 +150,10 @@ public: // FIXME: make more of this private!
bool keep_selection;
- GrDragger *getDraggerFor (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke);
+ GrDragger *getDraggerFor(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke);
- void grabKnot (GrDragger *dragger, gint x, gint y, guint32 etime);
- void grabKnot (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime);
+ void grabKnot(GrDragger *dragger, gint x, gint y, guint32 etime);
+ void grabKnot(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, gint x, gint y, guint32 etime);
bool local_change;
@@ -185,8 +188,8 @@ private:
void addDragger (GrDraggable *draggable);
- void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
- void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
+ void addDraggersRadial (SPRadialGradient *rg, SPItem *item, Inkscape::PaintTarget fill_or_stroke);
+ void addDraggersLinear (SPLinearGradient *lg, SPItem *item, Inkscape::PaintTarget fill_or_stroke);
bool styleSet( const SPCSSAttr *css );
@@ -201,3 +204,13 @@ private:
};
#endif // SEEN_GRADIENT_DRAG_H
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/sp-gradient.h b/src/sp-gradient.h
index e6d5b5e60..9322b3f43 100644
--- a/src/sp-gradient.h
+++ b/src/sp-gradient.h
@@ -14,6 +14,7 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
+#include <vector>
#include <gdk/gdk.h>
#include <glibmm/ustring.h>
#include <2geom/affine.h>
@@ -34,20 +35,20 @@ class SPStop;
#define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT))
#define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT))
-typedef enum {
+enum SPGradientType {
SP_GRADIENT_TYPE_UNKNOWN,
SP_GRADIENT_TYPE_LINEAR,
SP_GRADIENT_TYPE_RADIAL
-} SPGradientType;
+};
-typedef enum {
+enum SPGradientState {
SP_GRADIENT_STATE_UNKNOWN,
SP_GRADIENT_STATE_VECTOR,
SP_GRADIENT_STATE_PRIVATE
-} SPGradientState;
+};
-typedef enum {
- POINT_LG_BEGIN =0, //start enum at 0 (for indexing into gr_knot_shapes array for example)
+enum GrPointType {
+ POINT_LG_BEGIN = 0, //start enum at 0 (for indexing into gr_knot_shapes array for example)
POINT_LG_END,
POINT_LG_MID,
POINT_RG_CENTER,
@@ -59,7 +60,22 @@ typedef enum {
// insert new point types here.
POINT_G_INVALID
-} GrPointType;
+};
+
+namespace Inkscape {
+
+enum PaintTarget {
+ FOR_FILL,
+ FOR_STROKE
+};
+
+/**
+ * Convenience function to access a common vector of all enum values.
+ */
+std::vector<PaintTarget> const &allPaintTargets();
+
+} // namespace Inkscape
+
/**
* Gradient
diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp
index b0395bcf1..f6bbd6992 100644
--- a/src/tweak-context.cpp
+++ b/src/tweak-context.cpp
@@ -801,12 +801,11 @@ tweak_profile (double dist, double radius)
}
}
-void
-tweak_colors_in_gradient (SPItem *item, bool fill_or_stroke,
- guint32 const rgb_goal, Geom::Point p_w, double radius, double force, guint mode,
- bool do_h, bool do_s, bool do_l, bool /*do_o*/)
+void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or_stroke,
+ guint32 const rgb_goal, Geom::Point p_w, double radius, double force, guint mode,
+ bool do_h, bool do_s, bool do_l, bool /*do_o*/)
{
- SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
if (!gradient || !SP_IS_GRADIENT(gradient)) {
return;
@@ -1028,7 +1027,7 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
if (do_fill) {
if (style->fill.isPaintserver()) {
- tweak_colors_in_gradient (item, true, fill_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o);
+ tweak_colors_in_gradient(item, Inkscape::FOR_FILL, fill_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o);
did = true;
} else if (style->fill.isColor()) {
tweak_color (mode, style->fill.value.color.v.c, fill_goal, this_force, do_h, do_s, do_l);
@@ -1038,7 +1037,7 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
}
if (do_stroke) {
if (style->stroke.isPaintserver()) {
- tweak_colors_in_gradient (item, false, stroke_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o);
+ tweak_colors_in_gradient(item, Inkscape::FOR_STROKE, stroke_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o);
did = true;
} else if (style->stroke.isColor()) {
tweak_color (mode, style->stroke.value.color.v.c, stroke_goal, this_force, do_h, do_s, do_l);
diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp
index 92ed82845..52cda966d 100644
--- a/src/widgets/gradient-toolbar.cpp
+++ b/src/widgets/gradient-toolbar.cpp
@@ -127,7 +127,7 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
SPGradientType new_type = static_cast<SPGradientType>(prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR));
- guint new_fill = prefs->getBool("/tools/gradient/newfillorstroke", true);
+ Inkscape::PaintTarget new_fill = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
// GRADIENTFIXME: make this work for multiple selected draggers.
@@ -661,8 +661,8 @@ static void gr_reverse(GtkWidget * /*button*/, gpointer data)
drag->selected_reverse_vector();
} else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients)
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
- sp_item_gradient_reverse_vector(SP_ITEM(i->data), true);
- sp_item_gradient_reverse_vector(SP_ITEM(i->data), false);
+ sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_FILL);
+ sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_STROKE);
}
}
// we did an undoable action
@@ -959,7 +959,7 @@ 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->setBool("/tools/gradient/newfillorstroke", fillmode);
+ prefs->setInt("/tools/gradient/newfillorstroke", fillmode); // 1 for fill, 0 for stroke
}
/*