22fbce2c9a4679de349ed64e851edbcc3441563c
1 #define __GRADIENT_DRAG_C__
3 /*
4 * On-canvas gradient dragging
5 *
6 * Authors:
7 * bulia byak <buliabyak@users.sf.net>
8 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
9 *
10 * Copyright (C) 2007 Johan Engelen
11 * Copyright (C) 2005 Authors
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
20 #include <glibmm/i18n.h>
22 #include "desktop-handles.h"
23 #include "selection.h"
24 #include "desktop.h"
25 #include "desktop-style.h"
26 #include "document.h"
27 #include "display/sp-ctrlline.h"
29 #include "xml/repr.h"
30 #include "svg/css-ostringstream.h"
32 #include "svg/svg.h"
34 #include "prefs-utils.h"
35 #include "sp-item.h"
36 #include "style.h"
37 #include "knot.h"
38 #include "sp-linear-gradient.h"
39 #include "sp-radial-gradient.h"
40 #include "gradient-chemistry.h"
41 #include "gradient-drag.h"
42 #include "sp-stop.h"
44 #include "snap.h"
45 #include "sp-namedview.h"
48 #define GR_KNOT_COLOR_NORMAL 0xffffff00
49 #define GR_KNOT_COLOR_SELECTED 0x0000ff00
51 #define GR_LINE_COLOR_FILL 0x0000ff7f
52 #define GR_LINE_COLOR_STROKE 0x9999007f
54 // screen pixels between knots when they snap:
55 #define SNAP_DIST 5
57 // absolute distance between gradient points for them to become a single dragger when the drag is created:
58 #define MERGE_DIST 0.1
60 // knot shapes corresponding to GrPointType enum
61 SPKnotShapeType gr_knot_shapes [] = {
62 SP_KNOT_SHAPE_SQUARE, //POINT_LG_BEGIN
63 SP_KNOT_SHAPE_CIRCLE, //POINT_LG_END
64 SP_KNOT_SHAPE_DIAMOND, //POINT_LG_MID
65 SP_KNOT_SHAPE_SQUARE, // POINT_RG_CENTER
66 SP_KNOT_SHAPE_CIRCLE, // POINT_RG_R1
67 SP_KNOT_SHAPE_CIRCLE, // POINT_RG_R2
68 SP_KNOT_SHAPE_CROSS, // POINT_RG_FOCUS
69 SP_KNOT_SHAPE_DIAMOND, //POINT_RG_MID1
70 SP_KNOT_SHAPE_DIAMOND //POINT_RG_MID2
71 };
73 const gchar *gr_knot_descr [] = {
74 N_("Linear gradient <b>start</b>"), //POINT_LG_BEGIN
75 N_("Linear gradient <b>end</b>"),
76 N_("Linear gradient <b>midstop</b>"),
77 N_("Radial gradient <b>center</b>"),
78 N_("Radial gradient <b>radius</b>"),
79 N_("Radial gradient <b>radius</b>"),
80 N_("Radial gradient <b>focus</b>"), // POINT_RG_FOCUS
81 N_("Linear gradient <b>midstop</b>"),
82 N_("Linear gradient <b>midstop</b>")
83 };
85 static void
86 gr_drag_sel_changed(Inkscape::Selection *selection, gpointer data)
87 {
88 GrDrag *drag = (GrDrag *) data;
89 drag->updateDraggers ();
90 drag->updateLines ();
91 drag->updateLevels ();
92 }
94 static void
95 gr_drag_sel_modified (Inkscape::Selection *selection, guint flags, gpointer data)
96 {
97 GrDrag *drag = (GrDrag *) data;
98 if (drag->local_change) {
99 drag->local_change = false;
100 } else {
101 drag->updateDraggers ();
102 }
103 drag->updateLines ();
104 drag->updateLevels ();
105 }
107 /**
108 When a _query_style_signal is received, check that \a property requests fill/stroke/opacity (otherwise
109 skip), and fill the \a style with the averaged color of all draggables of the selected dragger, if
110 any.
111 */
112 int
113 gr_drag_style_query (SPStyle *style, int property, gpointer data)
114 {
115 GrDrag *drag = (GrDrag *) data;
117 if (property != QUERY_STYLE_PROPERTY_FILL && property != QUERY_STYLE_PROPERTY_STROKE && property != QUERY_STYLE_PROPERTY_MASTEROPACITY) {
118 return QUERY_STYLE_NOTHING;
119 }
121 if (!drag->selected) {
122 return QUERY_STYLE_NOTHING;
123 } else {
124 int ret = QUERY_STYLE_NOTHING;
126 float cf[4];
127 cf[0] = cf[1] = cf[2] = cf[3] = 0;
129 int count = 0;
131 for (GSList const* i = ((GrDragger*)drag->selected->data)->draggables; i != NULL; i = i->next) { // for all draggables of dragger
132 GrDraggable *draggable = (GrDraggable *) i->data;
134 if (ret == QUERY_STYLE_NOTHING) {
135 ret = QUERY_STYLE_SINGLE;
136 } else if (ret == QUERY_STYLE_SINGLE) {
137 ret = QUERY_STYLE_MULTIPLE_AVERAGED;
138 }
140 guint32 c = sp_item_gradient_stop_query_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
141 cf[0] += SP_RGBA32_R_F (c);
142 cf[1] += SP_RGBA32_G_F (c);
143 cf[2] += SP_RGBA32_B_F (c);
144 cf[3] += SP_RGBA32_A_F (c);
146 count ++;
147 }
149 if (count) {
150 cf[0] /= count;
151 cf[1] /= count;
152 cf[2] /= count;
153 cf[3] /= count;
155 // set both fill and stroke with our stop-color and stop-opacity
156 style->fill.clear();
157 style->fill.setColor( cf[0], cf[1], cf[2] );
158 style->fill.set = TRUE;
159 style->stroke.clear();
160 style->stroke.setColor( cf[0], cf[1], cf[2] );
161 style->stroke.set = TRUE;
163 style->fill_opacity.value = SP_SCALE24_FROM_FLOAT (1.0);
164 style->fill_opacity.set = TRUE;
165 style->stroke_opacity.value = SP_SCALE24_FROM_FLOAT (1.0);
166 style->stroke_opacity.set = TRUE;
168 style->opacity.value = SP_SCALE24_FROM_FLOAT (cf[3]);
169 style->opacity.set = TRUE;
170 }
172 return ret;
173 }
174 }
176 bool
177 gr_drag_style_set (const SPCSSAttr *css, gpointer data)
178 {
179 GrDrag *drag = (GrDrag *) data;
181 if (!drag->selected)
182 return false;
184 SPCSSAttr *stop = sp_repr_css_attr_new ();
186 // See if the css contains interesting properties, and if so, translate them into the format
187 // acceptable for gradient stops
189 // any of color properties, in order of increasing priority:
190 if (css->attribute("flood-color"))
191 sp_repr_css_set_property (stop, "stop-color", css->attribute("flood-color"));
193 if (css->attribute("lighting-color"))
194 sp_repr_css_set_property (stop, "stop-color", css->attribute("lighting-color"));
196 if (css->attribute("color"))
197 sp_repr_css_set_property (stop, "stop-color", css->attribute("color"));
199 if (css->attribute("stroke") && strcmp(css->attribute("stroke"), "none"))
200 sp_repr_css_set_property (stop, "stop-color", css->attribute("stroke"));
202 if (css->attribute("fill") && strcmp(css->attribute("fill"), "none"))
203 sp_repr_css_set_property (stop, "stop-color", css->attribute("fill"));
205 if (css->attribute("stop-color"))
206 sp_repr_css_set_property (stop, "stop-color", css->attribute("stop-color"));
209 if (css->attribute("stop-opacity")) { // direct setting of stop-opacity has priority
210 sp_repr_css_set_property (stop, "stop-opacity", css->attribute("stop-opacity"));
211 } else { // multiply all opacity properties:
212 gdouble accumulated = 1.0;
213 accumulated *= sp_svg_read_percentage(css->attribute("flood-opacity"), 1.0);
214 accumulated *= sp_svg_read_percentage(css->attribute("opacity"), 1.0);
215 accumulated *= sp_svg_read_percentage(css->attribute("stroke-opacity"), 1.0);
216 accumulated *= sp_svg_read_percentage(css->attribute("fill-opacity"), 1.0);
218 Inkscape::CSSOStringStream os;
219 os << accumulated;
220 sp_repr_css_set_property (stop, "stop-opacity", os.str().c_str());
222 if ((css->attribute("fill") && !strcmp(css->attribute("fill"), "none")) ||
223 (css->attribute("stroke") && !strcmp(css->attribute("stroke"), "none")))
224 sp_repr_css_set_property (stop, "stop-opacity", "0"); // if set to none, don't change color, set opacity to 0
225 }
227 if (!stop->attributeList()) { // nothing for us here, pass it on
228 sp_repr_css_attr_unref(stop);
229 return false;
230 }
232 for (GList const* sel = drag->selected; sel != NULL; sel = sel->next) { // for all selected draggers
233 GrDragger* dragger = (GrDragger*) sel->data;
234 for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger
235 GrDraggable *draggable = (GrDraggable *) i->data;
237 drag->local_change = true;
238 sp_item_gradient_stop_set_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke, stop);
239 }
240 }
242 //sp_repr_css_print(stop);
243 sp_repr_css_attr_unref(stop);
244 return true;
245 }
247 GrDrag::GrDrag(SPDesktop *desktop) {
249 this->desktop = desktop;
251 this->selection = sp_desktop_selection(desktop);
253 this->draggers = NULL;
254 this->lines = NULL;
255 this->selected = NULL;
257 this->hor_levels.clear();
258 this->vert_levels.clear();
260 this->local_change = false;
262 this->sel_changed_connection = this->selection->connectChanged(
263 sigc::bind (
264 sigc::ptr_fun(&gr_drag_sel_changed),
265 (gpointer)this )
267 );
268 this->sel_modified_connection = this->selection->connectModified(
269 sigc::bind(
270 sigc::ptr_fun(&gr_drag_sel_modified),
271 (gpointer)this )
272 );
274 this->style_set_connection = this->desktop->connectSetStyle(
275 sigc::bind(
276 sigc::ptr_fun(&gr_drag_style_set),
277 (gpointer)this )
278 );
280 this->style_query_connection = this->desktop->connectQueryStyle(
281 sigc::bind(
282 sigc::ptr_fun(&gr_drag_style_query),
283 (gpointer)this )
284 );
286 this->updateDraggers ();
287 this->updateLines ();
288 this->updateLevels ();
290 if (desktop->gr_item) {
291 this->setSelected (getDraggerFor (desktop->gr_item, desktop->gr_point_type, desktop->gr_point_i, desktop->gr_fill_or_stroke));
292 }
293 }
295 GrDrag::~GrDrag()
296 {
297 this->sel_changed_connection.disconnect();
298 this->sel_modified_connection.disconnect();
299 this->style_set_connection.disconnect();
300 this->style_query_connection.disconnect();
302 if (this->selected) {
303 GrDraggable *draggable = (GrDraggable *) ((GrDragger*)this->selected->data)->draggables->data;
304 desktop->gr_item = draggable->item;
305 desktop->gr_point_type = draggable->point_type;
306 desktop->gr_point_i = draggable->point_i;
307 desktop->gr_fill_or_stroke = draggable->fill_or_stroke;
308 } else {
309 desktop->gr_item = NULL;
310 desktop->gr_point_type = 0;
311 desktop->gr_point_i = 0;
312 desktop->gr_fill_or_stroke = true;
313 }
315 deselect_all();
316 for (GList *l = this->draggers; l != NULL; l = l->next) {
317 delete ((GrDragger *) l->data);
318 }
319 g_list_free (this->draggers);
320 this->draggers = NULL;
321 this->selected = NULL;
323 for (GSList *l = this->lines; l != NULL; l = l->next) {
324 gtk_object_destroy( GTK_OBJECT (l->data));
325 }
326 g_slist_free (this->lines);
327 this->lines = NULL;
328 }
330 GrDraggable::GrDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
331 {
332 this->item = item;
333 this->point_type = point_type;
334 this->point_i = point_i;
335 this->fill_or_stroke = fill_or_stroke;
337 g_object_ref (G_OBJECT (this->item));
338 }
340 GrDraggable::~GrDraggable ()
341 {
342 g_object_unref (G_OBJECT (this->item));
343 }
345 // FIXME: make global function in libnr or somewhere.
346 static NR::Point *
347 get_snap_vector (NR::Point p, NR::Point o, double snap, double initial)
348 {
349 double r = NR::L2 (p - o);
350 if (r < 1e-3)
351 return NULL;
352 double angle = NR::atan2 (p - o);
353 // snap angle to snaps increments, starting from initial:
354 double a_snapped = initial + floor((angle - initial)/snap + 0.5) * snap;
355 // calculate the new position and subtract p to get the vector:
356 return new NR::Point (o + r * NR::Point(cos(a_snapped), sin(a_snapped)) - p);
357 }
359 // FIXME: make global function in libnr or somewhere.
360 static NR::Point
361 snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap)
362 {
363 double length = NR::L2(end - begin);
364 NR::Point be = (end - begin) / length;
365 double r = NR::dot(p - begin, be);
367 if (r < 0.0) return begin;
368 if (r > length) return end;
370 double snapdist = length * snap;
371 double r_snapped = (snap==0) ? r : floor(r/(snapdist + 0.5)) * snapdist;
373 return (begin + r_snapped * be);
374 }
376 static void
377 gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpointer data)
378 {
379 GrDragger *dragger = (GrDragger *) data;
380 GrDrag *drag = dragger->parent;
382 NR::Point p = *ppointer;
384 // FIXME: take from prefs
385 double snap_dist = SNAP_DIST / dragger->parent->desktop->current_zoom();
387 if (state & GDK_SHIFT_MASK) {
388 // with Shift; unsnap if we carry more than one draggable
389 if (dragger->draggables && dragger->draggables->next) {
390 // create a new dragger
391 GrDragger *dr_new = new GrDragger (dragger->parent, dragger->point, NULL);
392 dragger->parent->draggers = g_list_prepend (dragger->parent->draggers, dr_new);
393 // relink to it all but the first draggable in the list
394 for (GSList const* i = dragger->draggables->next; i != NULL; i = i->next) {
395 GrDraggable *draggable = (GrDraggable *) i->data;
396 dr_new->addDraggable (draggable);
397 }
398 dr_new->updateKnotShape();
399 g_slist_free (dragger->draggables->next);
400 dragger->draggables->next = NULL;
401 dragger->updateKnotShape();
402 dragger->updateTip();
403 }
404 } else if (!(state & GDK_CONTROL_MASK)) {
405 // without Shift or Ctrl; see if we need to snap to another dragger
406 for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) {
407 GrDragger *d_new = (GrDragger *) di->data;
408 if (dragger->mayMerge(d_new) && NR::L2 (d_new->point - p) < snap_dist) {
410 // Merge draggers:
411 for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger
412 GrDraggable *draggable = (GrDraggable *) i->data;
413 // copy draggable to d_new:
414 GrDraggable *da_new = new GrDraggable (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
415 d_new->addDraggable (da_new);
416 }
418 // unlink and delete this dragger
419 dragger->parent->draggers = g_list_remove (dragger->parent->draggers, dragger);
420 delete dragger;
422 // update the new merged dragger
423 d_new->fireDraggables(true, false, true);
424 d_new->parent->updateLines();
425 d_new->parent->setSelected (d_new);
426 d_new->updateKnotShape ();
427 d_new->updateTip ();
428 d_new->updateDependencies(true);
429 sp_document_done (sp_desktop_document (d_new->parent->desktop), SP_VERB_CONTEXT_GRADIENT,
430 _("Merge gradient handles"));
431 return;
432 }
433 }
434 }
436 if (!((state & GDK_SHIFT_MASK) || ((state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK)))) {
437 // Try snapping to the grid or guides
438 SnapManager const &m = dragger->parent->desktop->namedview->snap_manager;
439 Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p, NULL);
440 if (s.getDistance() < 1e6) {
441 p = s.getPoint();
442 sp_knot_moveto (knot, &p);
443 } else {
444 // No snapping so far, let's see if we need to snap to any of the levels
445 for (guint i = 0; i < dragger->parent->hor_levels.size(); i++) {
446 if (fabs(p[NR::Y] - dragger->parent->hor_levels[i]) < snap_dist) {
447 p[NR::Y] = dragger->parent->hor_levels[i];
448 sp_knot_moveto (knot, &p);
449 }
450 }
451 for (guint i = 0; i < dragger->parent->vert_levels.size(); i++) {
452 if (fabs(p[NR::X] - dragger->parent->vert_levels[i]) < snap_dist) {
453 p[NR::X] = dragger->parent->vert_levels[i];
454 sp_knot_moveto (knot, &p);
455 }
456 }
457 }
458 }
460 if (state & GDK_CONTROL_MASK) {
461 unsigned snaps = abs(prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12));
462 /* 0 means no snapping. */
464 // This list will store snap vectors from all draggables of dragger
465 GSList *snap_vectors = NULL;
467 for (GSList const* i = dragger->draggables; i != NULL; i = i->next) {
468 GrDraggable *draggable = (GrDraggable *) i->data;
470 NR::Point *dr_snap = NULL;
472 if (draggable->point_type == POINT_LG_BEGIN || draggable->point_type == POINT_LG_END) {
473 for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) {
474 GrDragger *d_new = (GrDragger *) di->data;
475 if (d_new == dragger)
476 continue;
477 if (d_new->isA (draggable->item,
478 draggable->point_type == POINT_LG_BEGIN? POINT_LG_END : POINT_LG_BEGIN,
479 draggable->point_i,
480 draggable->fill_or_stroke)) {
481 // found the other end of the linear gradient;
482 if (state & GDK_SHIFT_MASK) {
483 // moving linear around center
484 NR::Point center = NR::Point (0.5*(d_new->point + dragger->point));
485 dr_snap = ¢er;
486 } else {
487 // moving linear around the other end
488 dr_snap = &d_new->point;
489 }
490 }
491 }
492 } else if (draggable->point_type == POINT_RG_R1 || draggable->point_type == POINT_RG_R2 || draggable->point_type == POINT_RG_FOCUS) {
493 for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) {
494 GrDragger *d_new = (GrDragger *) di->data;
495 if (d_new == dragger)
496 continue;
497 if (d_new->isA (draggable->item,
498 POINT_RG_CENTER,
499 draggable->point_i,
500 draggable->fill_or_stroke)) {
501 // found the center of the radial gradient;
502 dr_snap = &(d_new->point);
503 }
504 }
505 } else if (draggable->point_type == POINT_RG_CENTER) {
506 // radial center snaps to hor/vert relative to its original position
507 dr_snap = &(dragger->point_original);
508 }
510 NR::Point *snap_vector = NULL;
511 if (dr_snap) {
512 if (state & GDK_MOD1_MASK) {
513 // with Alt, snap to the original angle and its perpendiculars
514 snap_vector = get_snap_vector (p, *dr_snap, M_PI/2, NR::atan2 (dragger->point_original - *dr_snap));
515 } else {
516 // with Ctrl, snap to M_PI/snaps
517 snap_vector = get_snap_vector (p, *dr_snap, M_PI/snaps, 0);
518 }
519 }
520 if (snap_vector) {
521 snap_vectors = g_slist_prepend (snap_vectors, snap_vector);
522 }
523 }
525 // Move by the smallest of snap vectors:
526 NR::Point move(9999, 9999);
527 for (GSList const *i = snap_vectors; i != NULL; i = i->next) {
528 NR::Point *snap_vector = (NR::Point *) i->data;
529 if (NR::L2(*snap_vector) < NR::L2(move))
530 move = *snap_vector;
531 }
532 if (move[NR::X] < 9999) {
533 p += move;
534 sp_knot_moveto (knot, &p);
535 }
537 g_slist_free(snap_vectors);
538 }
540 drag->keep_selection = (bool) g_list_find(drag->selected, dragger);
541 bool scale_radial = (state & GDK_CONTROL_MASK) && (state & GDK_SHIFT_MASK);
543 if (drag->keep_selection) {
544 NR::Point diff = p - dragger->point;
545 drag->selected_move_nowrite (diff[NR::X], diff[NR::Y], scale_radial);
546 } else {
547 dragger->point = p;
548 dragger->fireDraggables (false, scale_radial);
549 dragger->updateDependencies(false);
550 }
552 }
555 /**
556 Called when a midpoint knot is dragged.
557 */
558 static void
559 gr_knot_moved_midpoint_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpointer data)
560 {
561 GrDragger *dragger = (GrDragger *) data;
562 GrDrag *drag = dragger->parent;
563 // a midpoint dragger can (logically) only contain one GrDraggable
564 GrDraggable *draggable = (GrDraggable *) dragger->draggables->data;
566 // FIXME: take from prefs
567 double snap_fraction = 0.1;
569 NR::Point p = *ppointer;
570 NR::Point begin(0,0), end(0,0);
572 SPObject *server;
573 if (draggable->fill_or_stroke)
574 server = SP_OBJECT_STYLE_FILL_SERVER (draggable->item);
575 else
576 server = SP_OBJECT_STYLE_STROKE_SERVER (draggable->item);
579 // get begin and end points between which dragging is allowed:
580 // the draglimits are between knot(lowest_i - 1) and knot(highest_i + 1)
581 GSList *moving = NULL;
582 moving = g_slist_append(moving, dragger);
584 guint lowest_i = draggable->point_i;
585 guint highest_i = draggable->point_i;
586 GrDragger *lowest_dragger = dragger;
587 GrDragger *highest_dragger = dragger;
588 bool is_selected = g_list_find(drag->selected, dragger);
589 if (is_selected) {
590 GrDragger* d_add;
591 while ( true )
592 {
593 d_add = drag->getDraggerFor(draggable->item, draggable->point_type, lowest_i - 1, draggable->fill_or_stroke);
594 if ( d_add && g_list_find(drag->selected, d_add) ) {
595 lowest_i = lowest_i - 1;
596 moving = g_slist_prepend(moving, d_add);
597 lowest_dragger = d_add;
598 } else {
599 break;
600 }
601 }
603 while ( true )
604 {
605 d_add = drag->getDraggerFor(draggable->item, draggable->point_type, highest_i + 1, draggable->fill_or_stroke);
606 if ( d_add && g_list_find(drag->selected, d_add) ) {
607 highest_i = highest_i + 1;
608 moving = g_slist_append(moving, d_add);
609 highest_dragger = d_add;
610 } else {
611 break;
612 }
613 }
614 }
616 if ( SP_IS_LINEARGRADIENT(server) ) {
617 GrDragger *d_temp;
618 if (lowest_i == 1) {
619 d_temp = drag->getDraggerFor (draggable->item, POINT_LG_BEGIN, 0, draggable->fill_or_stroke);
620 } else {
621 d_temp = drag->getDraggerFor (draggable->item, POINT_LG_MID, lowest_i - 1, draggable->fill_or_stroke);
622 }
623 if (d_temp) begin = d_temp->point;
625 d_temp = drag->getDraggerFor (draggable->item, POINT_LG_MID, highest_i + 1, draggable->fill_or_stroke);
626 if (d_temp == NULL) {
627 d_temp = drag->getDraggerFor (draggable->item, POINT_LG_END, 0, draggable->fill_or_stroke);
628 }
629 if (d_temp) end = d_temp->point;
630 } else if ( SP_IS_RADIALGRADIENT(server) ) {
631 GrDragger *d_temp;
632 if (lowest_i == 1) {
633 d_temp = drag->getDraggerFor (draggable->item, POINT_RG_CENTER, 0, draggable->fill_or_stroke);
634 } else {
635 d_temp = drag->getDraggerFor (draggable->item, draggable->point_type, lowest_i - 1, draggable->fill_or_stroke);
636 }
637 if (d_temp) begin = d_temp->point;
639 d_temp = drag->getDraggerFor (draggable->item, draggable->point_type, highest_i + 1, draggable->fill_or_stroke);
640 if (d_temp == NULL) {
641 d_temp = drag->getDraggerFor (draggable->item, (draggable->point_type==POINT_RG_MID1) ? POINT_RG_R1 : POINT_RG_R2, 0, draggable->fill_or_stroke);
642 }
643 if (d_temp) end = d_temp->point;
644 }
646 NR::Point low_lim = dragger->point - (lowest_dragger->point - begin);
647 NR::Point high_lim = dragger->point - (highest_dragger->point - end);
649 if (state & GDK_CONTROL_MASK) {
650 p = snap_vector_midpoint (p, low_lim, high_lim, snap_fraction);
651 } else {
652 p = snap_vector_midpoint (p, low_lim, high_lim, 0);
653 }
654 NR::Point displacement = p - dragger->point;
656 for (GSList const* i = moving; i != NULL; i = i->next) {
657 GrDragger *drg = (GrDragger*) i->data;
658 SPKnot *drgknot = drg->knot;
659 drg->point += displacement;
660 sp_knot_moveto (drgknot, & drg->point);
661 drg->fireDraggables (false);
662 drg->updateDependencies(false);
663 }
665 drag->keep_selection = is_selected;
666 }
670 static void
671 gr_knot_grabbed_handler (SPKnot *knot, unsigned int state, gpointer data)
672 {
673 GrDragger *dragger = (GrDragger *) data;
675 sp_canvas_force_full_redraw_after_interruptions(dragger->parent->desktop->canvas, 5);
676 }
678 /**
679 Called when the mouse releases a dragger knot; changes gradient writing to repr, updates other draggers if needed
680 */
681 static void
682 gr_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, gpointer data)
683 {
684 GrDragger *dragger = (GrDragger *) data;
686 sp_canvas_end_forced_full_redraws(dragger->parent->desktop->canvas);
688 dragger->point_original = dragger->point = knot->pos;
690 if ((state & GDK_CONTROL_MASK) && (state & GDK_SHIFT_MASK)) {
691 dragger->fireDraggables (true, true);
692 } else {
693 dragger->fireDraggables (true);
694 }
696 // make this dragger selected
697 if (!dragger->parent->keep_selection) {
698 dragger->parent->setSelected (dragger);
699 }
700 dragger->parent->keep_selection = false;
702 dragger->updateDependencies(true);
704 // we did an undoable action
705 sp_document_done (sp_desktop_document (dragger->parent->desktop), SP_VERB_CONTEXT_GRADIENT,
706 _("Move gradient handle"));
707 }
709 /**
710 Called when a dragger knot is clicked; selects the dragger or deletes it depending on the
711 state of the keyboard keys
712 */
713 static void
714 gr_knot_clicked_handler(SPKnot *knot, guint state, gpointer data)
715 {
716 GrDragger *dragger = (GrDragger *) data;
717 GrDraggable *draggable = (GrDraggable *) dragger->draggables->data;
718 if (!draggable) return;
720 if ( (state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK ) ) {
721 // delete this knot from vector
722 SPGradient *gradient = sp_item_gradient (draggable->item, draggable->fill_or_stroke);
723 gradient = sp_gradient_get_vector (gradient, false);
724 if (gradient->vector.stops.size() > 2) { // 2 is the minimum
725 SPStop *stop = NULL;
726 switch (draggable->point_type) { // if we delete first or last stop, move the next/previous to the edge
727 case POINT_LG_BEGIN:
728 case POINT_RG_CENTER:
729 stop = sp_first_stop(gradient);
730 {
731 SPStop *next = sp_next_stop (stop);
732 if (next) {
733 next->offset = 0;
734 sp_repr_set_css_double (SP_OBJECT_REPR (next), "offset", 0);
735 }
736 }
737 break;
738 case POINT_LG_END:
739 case POINT_RG_R1:
740 case POINT_RG_R2:
741 stop = sp_last_stop(gradient);
742 {
743 SPStop *prev = sp_prev_stop (stop, gradient);
744 if (prev) {
745 prev->offset = 1;
746 sp_repr_set_css_double (SP_OBJECT_REPR (prev), "offset", 1);
747 }
748 }
749 break;
750 case POINT_LG_MID:
751 case POINT_RG_MID1:
752 case POINT_RG_MID2:
753 stop = sp_get_stop_i(gradient, draggable->point_i);
754 break;
755 }
757 SP_OBJECT_REPR(gradient)->removeChild(SP_OBJECT_REPR(stop));
758 sp_document_done (SP_OBJECT_DOCUMENT (gradient), SP_VERB_CONTEXT_GRADIENT,
759 _("Delete gradient stop"));
760 }
761 } else {
762 // select the dragger
763 dragger->point_original = dragger->point;
765 if ( state & GDK_SHIFT_MASK ) {
766 dragger->parent->setSelected (dragger, true, false);
767 } else {
768 dragger->parent->setSelected (dragger);
769 }
770 }
771 }
773 /**
774 Called when a dragger knot is doubleclicked; opens gradient editor with the stop from the first draggable
775 */
776 static void
777 gr_knot_doubleclicked_handler (SPKnot *knot, guint state, gpointer data)
778 {
779 GrDragger *dragger = (GrDragger *) data;
781 dragger->point_original = dragger->point;
783 if (dragger->draggables == NULL)
784 return;
786 GrDraggable *draggable = (GrDraggable *) dragger->draggables->data;
787 sp_item_gradient_edit_stop (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
788 }
790 /**
791 Act upon all draggables of the dragger, setting them to the dragger's point
792 */
793 void
794 GrDragger::fireDraggables (bool write_repr, bool scale_radial, bool merging_focus)
795 {
796 for (GSList const* i = this->draggables; i != NULL; i = i->next) {
797 GrDraggable *draggable = (GrDraggable *) i->data;
799 // set local_change flag so that selection_changed callback does not regenerate draggers
800 this->parent->local_change = true;
802 // change gradient, optionally writing to repr; prevent focus from moving if it's snapped
803 // to the center, unless it's the first update upon merge when we must snap it to the point
804 if (merging_focus ||
805 !(draggable->point_type == POINT_RG_FOCUS && this->isA(draggable->item, POINT_RG_CENTER, draggable->point_i, draggable->fill_or_stroke)))
806 {
807 sp_item_gradient_set_coords (draggable->item, draggable->point_type, draggable->point_i, this->point, draggable->fill_or_stroke, write_repr, scale_radial);
808 }
809 }
810 }
812 /**
813 Checks if the dragger has a draggable with this point_type
814 */
815 bool
816 GrDragger::isA (guint point_type)
817 {
818 for (GSList const* i = this->draggables; i != NULL; i = i->next) {
819 GrDraggable *draggable = (GrDraggable *) i->data;
820 if (draggable->point_type == point_type) {
821 return true;
822 }
823 }
824 return false;
825 }
827 /**
828 Checks if the dragger has a draggable with this item, point_type, fill_or_stroke
829 */
830 bool
831 GrDragger::isA (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
832 {
833 for (GSList const* i = this->draggables; i != NULL; i = i->next) {
834 GrDraggable *draggable = (GrDraggable *) i->data;
835 if ( (draggable->point_type == point_type) && (draggable->point_i == point_i) && (draggable->item == item) && (draggable->fill_or_stroke == fill_or_stroke) ) {
836 return true;
837 }
838 }
839 return false;
840 }
842 bool
843 GrDraggable::mayMerge (GrDraggable *da2)
844 {
845 if ((this->item == da2->item) && (this->fill_or_stroke == da2->fill_or_stroke)) {
846 // we must not merge the points of the same gradient!
847 if (!((this->point_type == POINT_RG_FOCUS && da2->point_type == POINT_RG_CENTER) ||
848 (this->point_type == POINT_RG_CENTER && da2->point_type == POINT_RG_FOCUS))) {
849 // except that we can snap center and focus together
850 return false;
851 }
852 }
853 // disable merging of midpoints.
854 if ( (this->point_type == POINT_LG_MID) || (da2->point_type == POINT_LG_MID)
855 || (this->point_type == POINT_RG_MID1) || (da2->point_type == POINT_RG_MID1)
856 || (this->point_type == POINT_RG_MID2) || (da2->point_type == POINT_RG_MID2) )
857 return false;
859 return true;
860 }
862 bool
863 GrDragger::mayMerge (GrDragger *other)
864 {
865 if (this == other)
866 return false;
868 for (GSList const* i = this->draggables; i != NULL; i = i->next) { // for all draggables of this
869 GrDraggable *da1 = (GrDraggable *) i->data;
870 for (GSList const* j = other->draggables; j != NULL; j = j->next) { // for all draggables of other
871 GrDraggable *da2 = (GrDraggable *) j->data;
872 if (!da1->mayMerge(da2))
873 return false;
874 }
875 }
876 return true;
877 }
879 bool
880 GrDragger::mayMerge (GrDraggable *da2)
881 {
882 for (GSList const* i = this->draggables; i != NULL; i = i->next) { // for all draggables of this
883 GrDraggable *da1 = (GrDraggable *) i->data;
884 if (!da1->mayMerge(da2))
885 return false;
886 }
887 return true;
888 }
890 /**
891 Updates the statusbar tip of the dragger knot, based on its draggables
892 */
893 void
894 GrDragger::updateTip ()
895 {
896 if (this->knot && this->knot->tip) {
897 g_free (this->knot->tip);
898 this->knot->tip = NULL;
899 }
901 if (g_slist_length (this->draggables) == 1) {
902 GrDraggable *draggable = (GrDraggable *) this->draggables->data;
903 char *item_desc = sp_item_description(draggable->item);
904 switch (draggable->point_type) {
905 case POINT_LG_MID:
906 case POINT_RG_MID1:
907 case POINT_RG_MID2:
908 this->knot->tip = g_strdup_printf (_("%s %d for: %s%s; drag with <b>Ctrl</b> to snap offset; click with <b>Ctrl+Alt</b> to delete stop"),
909 _(gr_knot_descr[draggable->point_type]),
910 draggable->point_i,
911 item_desc,
912 draggable->fill_or_stroke == false ? _(" (stroke)") : "");
913 break;
915 default:
916 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"),
917 _(gr_knot_descr[draggable->point_type]),
918 item_desc,
919 draggable->fill_or_stroke == false ? _(" (stroke)") : "");
920 break;
921 }
922 g_free(item_desc);
923 } else if (g_slist_length (draggables) == 2 && isA (POINT_RG_CENTER) && isA (POINT_RG_FOCUS)) {
924 this->knot->tip = g_strdup_printf (_("Radial gradient <b>center</b> and <b>focus</b>; drag with <b>Shift</b> to separate focus"));
925 } else {
926 int length = g_slist_length (this->draggables);
927 this->knot->tip = g_strdup_printf (ngettext("Gradient point shared by <b>%d</b> gradient; drag with <b>Shift</b> to separate",
928 "Gradient point shared by <b>%d</b> gradients; drag with <b>Shift</b> to separate",
929 length),
930 length);
931 }
932 }
934 /**
935 Adds a draggable to the dragger
936 */
937 void
938 GrDragger::updateKnotShape ()
939 {
940 if (!draggables)
941 return;
942 GrDraggable *last = (GrDraggable *) g_slist_last(draggables)->data;
943 g_object_set (G_OBJECT (this->knot->item), "shape", gr_knot_shapes[last->point_type], NULL);
944 }
946 /**
947 Adds a draggable to the dragger
948 */
949 void
950 GrDragger::addDraggable (GrDraggable *draggable)
951 {
952 this->draggables = g_slist_prepend (this->draggables, draggable);
954 this->updateTip();
955 }
958 /**
959 Moves this dragger to the point of the given draggable, acting upon all other draggables
960 */
961 void
962 GrDragger::moveThisToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr)
963 {
964 this->point = sp_item_gradient_get_coords (item, point_type, point_i, fill_or_stroke);
965 this->point_original = this->point;
967 sp_knot_moveto (this->knot, &(this->point));
969 for (GSList const* i = this->draggables; i != NULL; i = i->next) {
970 GrDraggable *da = (GrDraggable *) i->data;
971 if ( (da->item == item) && (da->point_type == point_type) && (da->point_i == point_i) && (da->fill_or_stroke == fill_or_stroke) ) {
972 continue;
973 }
974 sp_item_gradient_set_coords (da->item, da->point_type, da->point_i, this->point, da->fill_or_stroke, write_repr, false);
975 }
976 // FIXME: here we should also call this->updateDependencies(write_repr); to propagate updating, but how to prevent loops?
977 }
980 /**
981 Moves all midstop draggables that depend on this one
982 */
983 void
984 GrDragger::updateMidstopDependencies (GrDraggable *draggable, bool write_repr) {
985 SPObject *server;
986 if (draggable->fill_or_stroke)
987 server = SP_OBJECT_STYLE_FILL_SERVER (draggable->item);
988 else
989 server = SP_OBJECT_STYLE_STROKE_SERVER (draggable->item);
990 guint num = SP_GRADIENT(server)->vector.stops.size();
991 if (num <= 2) return;
993 if ( SP_IS_LINEARGRADIENT(server) ) {
994 for ( guint i = 1; i < num - 1; i++ ) {
995 this->moveOtherToDraggable (draggable->item, POINT_LG_MID, i, draggable->fill_or_stroke, write_repr);
996 }
997 } else if ( SP_IS_RADIALGRADIENT(server) ) {
998 for ( guint i = 1; i < num - 1; i++ ) {
999 this->moveOtherToDraggable (draggable->item, POINT_RG_MID1, i, draggable->fill_or_stroke, write_repr);
1000 this->moveOtherToDraggable (draggable->item, POINT_RG_MID2, i, draggable->fill_or_stroke, write_repr);
1001 }
1002 }
1003 }
1006 /**
1007 Moves all draggables that depend on this one
1008 */
1009 void
1010 GrDragger::updateDependencies (bool write_repr)
1011 {
1012 for (GSList const* i = this->draggables; i != NULL; i = i->next) {
1013 GrDraggable *draggable = (GrDraggable *) i->data;
1014 switch (draggable->point_type) {
1015 case POINT_LG_BEGIN:
1016 {
1017 // the end point is dependent only when dragging with ctrl+shift
1018 this->moveOtherToDraggable (draggable->item, POINT_LG_END, 0, draggable->fill_or_stroke, write_repr);
1020 this->updateMidstopDependencies (draggable, write_repr);
1021 }
1022 break;
1023 case POINT_LG_END:
1024 {
1025 // the begin point is dependent only when dragging with ctrl+shift
1026 this->moveOtherToDraggable (draggable->item, POINT_LG_BEGIN, 0, draggable->fill_or_stroke, write_repr);
1028 this->updateMidstopDependencies (draggable, write_repr);
1029 }
1030 break;
1031 case POINT_LG_MID:
1032 // no other nodes depend on mid points.
1033 break;
1034 case POINT_RG_R2:
1035 this->moveOtherToDraggable (draggable->item, POINT_RG_R1, 0, draggable->fill_or_stroke, write_repr);
1036 this->moveOtherToDraggable (draggable->item, POINT_RG_FOCUS, 0, draggable->fill_or_stroke, write_repr);
1037 this->updateMidstopDependencies (draggable, write_repr);
1038 break;
1039 case POINT_RG_R1:
1040 this->moveOtherToDraggable (draggable->item, POINT_RG_R2, 0, draggable->fill_or_stroke, write_repr);
1041 this->moveOtherToDraggable (draggable->item, POINT_RG_FOCUS, 0, draggable->fill_or_stroke, write_repr);
1042 this->updateMidstopDependencies (draggable, write_repr);
1043 break;
1044 case POINT_RG_CENTER:
1045 this->moveOtherToDraggable (draggable->item, POINT_RG_R1, 0, draggable->fill_or_stroke, write_repr);
1046 this->moveOtherToDraggable (draggable->item, POINT_RG_R2, 0, draggable->fill_or_stroke, write_repr);
1047 this->moveOtherToDraggable (draggable->item, POINT_RG_FOCUS, 0, draggable->fill_or_stroke, write_repr);
1048 this->updateMidstopDependencies (draggable, write_repr);
1049 break;
1050 case POINT_RG_FOCUS:
1051 // nothing can depend on that
1052 break;
1053 case POINT_RG_MID1:
1054 this->moveOtherToDraggable (draggable->item, POINT_RG_MID2, draggable->point_i, draggable->fill_or_stroke, write_repr);
1055 break;
1056 case POINT_RG_MID2:
1057 this->moveOtherToDraggable (draggable->item, POINT_RG_MID1, draggable->point_i, draggable->fill_or_stroke, write_repr);
1058 break;
1059 default:
1060 break;
1061 }
1062 }
1063 }
1067 GrDragger::GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable)
1068 {
1069 this->draggables = NULL;
1071 this->parent = parent;
1073 this->point = p;
1074 this->point_original = p;
1076 // create the knot
1077 this->knot = sp_knot_new (parent->desktop, NULL);
1078 this->knot->setMode(SP_KNOT_MODE_XOR);
1079 this->knot->setFill(GR_KNOT_COLOR_NORMAL, GR_KNOT_COLOR_NORMAL, GR_KNOT_COLOR_NORMAL);
1080 this->knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff);
1081 sp_knot_update_ctrl(this->knot);
1083 // move knot to the given point
1084 sp_knot_set_position (this->knot, &p, SP_KNOT_STATE_NORMAL);
1085 sp_knot_show (this->knot);
1087 // connect knot's signals
1088 if ( (draggable) // it can be NULL if a node in unsnapped (eg. focus point unsnapped from center)
1089 // luckily, midstops never snap to other nodes so are never unsnapped...
1090 && ( (draggable->point_type == POINT_LG_MID)
1091 || (draggable->point_type == POINT_RG_MID1)
1092 || (draggable->point_type == POINT_RG_MID2) ) )
1093 {
1094 this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_midpoint_handler), this);
1095 } else {
1096 this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_handler), this);
1097 }
1098 g_signal_connect (G_OBJECT (this->knot), "clicked", G_CALLBACK (gr_knot_clicked_handler), this);
1099 g_signal_connect (G_OBJECT (this->knot), "doubleclicked", G_CALLBACK (gr_knot_doubleclicked_handler), this);
1100 g_signal_connect (G_OBJECT (this->knot), "grabbed", G_CALLBACK (gr_knot_grabbed_handler), this);
1101 g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (gr_knot_ungrabbed_handler), this);
1103 // add the initial draggable
1104 if (draggable)
1105 this->addDraggable (draggable);
1106 updateKnotShape();
1107 }
1109 GrDragger::~GrDragger ()
1110 {
1111 // unselect if it was selected
1112 this->parent->setDeselected(this);
1114 // disconnect signals
1115 g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_moved_handler), this);
1116 g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_clicked_handler), this);
1117 g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_doubleclicked_handler), this);
1118 g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_grabbed_handler), this);
1119 g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_ungrabbed_handler), this);
1121 /* unref should call destroy */
1122 g_object_unref (G_OBJECT (this->knot));
1124 // delete all draggables
1125 for (GSList const* i = this->draggables; i != NULL; i = i->next) {
1126 delete ((GrDraggable *) i->data);
1127 }
1128 g_slist_free (this->draggables);
1129 this->draggables = NULL;
1130 }
1132 /**
1133 Select the dragger which has the given draggable.
1134 */
1135 GrDragger *
1136 GrDrag::getDraggerFor (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
1137 {
1138 for (GList const* i = this->draggers; i != NULL; i = i->next) {
1139 GrDragger *dragger = (GrDragger *) i->data;
1140 for (GSList const* j = dragger->draggables; j != NULL; j = j->next) {
1141 GrDraggable *da2 = (GrDraggable *) j->data;
1142 if ( (da2->item == item) && (da2->point_type == point_type) && (da2->point_i == point_i) && (da2->fill_or_stroke == fill_or_stroke)) {
1143 return (dragger);
1144 }
1145 }
1146 }
1147 return NULL;
1148 }
1151 void
1152 GrDragger::moveOtherToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr)
1153 {
1154 GrDragger *d = this->parent->getDraggerFor (item, point_type, point_i, fill_or_stroke);
1155 if (d && d != this) {
1156 d->moveThisToDraggable (item, point_type, point_i, fill_or_stroke, write_repr);
1157 }
1158 }
1161 /**
1162 Draw this dragger as selected
1163 */
1164 void
1165 GrDragger::select()
1166 {
1167 this->knot->fill [SP_KNOT_STATE_NORMAL] = GR_KNOT_COLOR_SELECTED;
1168 g_object_set (G_OBJECT (this->knot->item), "fill_color", GR_KNOT_COLOR_SELECTED, NULL);
1169 }
1171 /**
1172 Draw this dragger as normal (deselected)
1173 */
1174 void
1175 GrDragger::deselect()
1176 {
1177 this->knot->fill [SP_KNOT_STATE_NORMAL] = GR_KNOT_COLOR_NORMAL;
1178 g_object_set (G_OBJECT (this->knot->item), "fill_color", GR_KNOT_COLOR_NORMAL, NULL);
1179 }
1183 /**
1184 \brief Deselect all stops/draggers (private)
1185 */
1186 void
1187 GrDrag::deselect_all()
1188 {
1189 while (selected) {
1190 ( (GrDragger*) selected->data)->deselect();
1191 selected = g_list_remove(selected, selected->data);
1192 }
1193 }
1195 /**
1196 \brief Deselect all stops/draggers (public; emits signal)
1197 */
1198 void
1199 GrDrag::deselectAll()
1200 {
1201 deselect_all();
1202 this->desktop->emitToolSubselectionChanged(NULL);
1203 }
1205 /**
1206 \brief Select all stops/draggers (public; emits signal)
1207 */
1208 void
1209 GrDrag::selectAll()
1210 {
1211 for (GList *l = this->draggers; l != NULL; l = l->next) {
1212 GrDragger *d = ((GrDragger *) l->data);
1213 setSelected (d, true, true);
1214 }
1215 }
1218 /**
1219 \brief Select a dragger
1220 \param dragger The dragger to select
1221 \param add_to_selection If true, add to selection, otherwise deselect others
1222 \param override If true, always select this node, otherwise toggle selected status
1223 */
1224 void
1225 GrDrag::setSelected (GrDragger *dragger, bool add_to_selection, bool override)
1226 {
1227 GrDragger *seldragger = NULL;
1229 if (add_to_selection) {
1230 if (!dragger) return;
1231 if (override) {
1232 if (!g_list_find(selected, dragger)) {
1233 selected = g_list_prepend(selected, dragger);
1234 }
1235 dragger->select();
1236 seldragger = dragger;
1237 } else { // toggle
1238 if (g_list_find(selected, dragger)) {
1239 selected = g_list_remove(selected, dragger);
1240 dragger->deselect();
1241 if (selected) {
1242 seldragger = (GrDragger*) selected->data; // select the dragger that is first in the list
1243 }
1244 } else {
1245 selected = g_list_prepend(selected, dragger);
1246 dragger->select();
1247 seldragger = dragger;
1248 }
1249 }
1250 } else {
1251 deselect_all();
1252 if (dragger) {
1253 selected = g_list_prepend(selected, dragger);
1254 dragger->select();
1255 seldragger = dragger;
1256 }
1257 }
1258 if (seldragger) {
1259 this->desktop->emitToolSubselectionChanged((gpointer) seldragger);
1260 }
1261 }
1263 /**
1264 \brief Deselect a dragger
1265 \param dragger The dragger to deselect
1266 */
1267 void
1268 GrDrag::setDeselected (GrDragger *dragger)
1269 {
1270 if (g_list_find(selected, dragger)) {
1271 selected = g_list_remove(selected, dragger);
1272 dragger->deselect();
1273 }
1274 this->desktop->emitToolSubselectionChanged((gpointer) (selected ? selected->data : NULL ));
1275 }
1279 /**
1280 Create a line from p1 to p2 and add it to the lines list
1281 */
1282 void
1283 GrDrag::addLine (NR::Point p1, NR::Point p2, guint32 rgba)
1284 {
1285 SPCanvasItem *line = sp_canvas_item_new(sp_desktop_controls(this->desktop),
1286 SP_TYPE_CTRLLINE, NULL);
1287 sp_ctrlline_set_coords(SP_CTRLLINE(line), p1, p2);
1288 if (rgba != GR_LINE_COLOR_FILL) // fill is the default, so don't set color for it to speed up redraw
1289 sp_ctrlline_set_rgba32 (SP_CTRLLINE(line), rgba);
1290 sp_canvas_item_show (line);
1291 this->lines = g_slist_append (this->lines, line);
1292 }
1294 /**
1295 If there already exists a dragger within MERGE_DIST of p, add the draggable to it; otherwise create
1296 new dragger and add it to draggers list
1297 */
1298 void
1299 GrDrag::addDragger (GrDraggable *draggable)
1300 {
1301 NR::Point p = sp_item_gradient_get_coords (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
1303 for (GList *i = this->draggers; i != NULL; i = i->next) {
1304 GrDragger *dragger = (GrDragger *) i->data;
1305 if (dragger->mayMerge (draggable) && NR::L2 (dragger->point - p) < MERGE_DIST) {
1306 // distance is small, merge this draggable into dragger, no need to create new dragger
1307 dragger->addDraggable (draggable);
1308 dragger->updateKnotShape();
1309 return;
1310 }
1311 }
1313 GrDragger *new_dragger = new GrDragger(this, p, draggable);
1314 // fixme: draggers should be added AFTER the last one: this way tabbing through them will be from begin to end.
1315 this->draggers = g_list_append (this->draggers, new_dragger);
1316 }
1318 /**
1319 Add draggers for the radial gradient rg on item
1320 */
1321 void
1322 GrDrag::addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke)
1323 {
1324 addDragger (new GrDraggable (item, POINT_RG_CENTER, 0, fill_or_stroke));
1325 guint num = rg->vector.stops.size();
1326 if (num > 2) {
1327 for ( guint i = 1; i < num - 1; i++ ) {
1328 addDragger (new GrDraggable (item, POINT_RG_MID1, i, fill_or_stroke));
1329 }
1330 }
1331 addDragger (new GrDraggable (item, POINT_RG_R1, 0, fill_or_stroke));
1332 if (num > 2) {
1333 for ( guint i = 1; i < num - 1; i++ ) {
1334 addDragger (new GrDraggable (item, POINT_RG_MID2, i, fill_or_stroke));
1335 }
1336 }
1337 addDragger (new GrDraggable (item, POINT_RG_R2, 0, fill_or_stroke));
1338 addDragger (new GrDraggable (item, POINT_RG_FOCUS, 0, fill_or_stroke));
1339 }
1341 /**
1342 Add draggers for the linear gradient lg on item
1343 */
1344 void
1345 GrDrag::addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke)
1346 {
1347 addDragger (new GrDraggable (item, POINT_LG_BEGIN, 0, fill_or_stroke));
1348 guint num = lg->vector.stops.size();
1349 if (num > 2) {
1350 for ( guint i = 1; i < num - 1; i++ ) {
1351 addDragger (new GrDraggable (item, POINT_LG_MID, i, fill_or_stroke));
1352 }
1353 }
1354 addDragger (new GrDraggable (item, POINT_LG_END, 0, fill_or_stroke));
1355 }
1357 /**
1358 Artificially grab the knot of the dragger with this draggable; used by the gradient context
1359 */
1360 void
1361 GrDrag::grabKnot (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime)
1362 {
1363 GrDragger *dragger = getDraggerFor (item, point_type, point_i, fill_or_stroke);
1364 if (dragger) {
1365 sp_knot_start_dragging (dragger->knot, dragger->point, x, y, etime);
1366 }
1367 }
1369 /**
1370 Regenerates the draggers list from the current selection; is called when selection is changed or
1371 modified, also when a radial dragger needs to update positions of other draggers in the gradient
1372 */
1373 void
1374 GrDrag::updateDraggers ()
1375 {
1376 while (selected) {
1377 selected = g_list_remove(selected, selected->data);
1378 }
1379 // delete old draggers
1380 for (GList const* i = this->draggers; i != NULL; i = i->next) {
1381 delete ((GrDragger *) i->data);
1382 }
1383 g_list_free (this->draggers);
1384 this->draggers = NULL;
1386 g_return_if_fail (this->selection != NULL);
1388 for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) {
1390 SPItem *item = SP_ITEM(i->data);
1391 SPStyle *style = SP_OBJECT_STYLE (item);
1393 if (style && (style->fill.isPaintserver())) {
1394 SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
1395 if (SP_IS_LINEARGRADIENT (server)) {
1396 addDraggersLinear (SP_LINEARGRADIENT (server), item, true);
1397 } else if (SP_IS_RADIALGRADIENT (server)) {
1398 addDraggersRadial (SP_RADIALGRADIENT (server), item, true);
1399 }
1400 }
1402 if (style && (style->stroke.isPaintserver())) {
1403 SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
1404 if (SP_IS_LINEARGRADIENT (server)) {
1405 addDraggersLinear (SP_LINEARGRADIENT (server), item, false);
1406 } else if (SP_IS_RADIALGRADIENT (server)) {
1407 addDraggersRadial (SP_RADIALGRADIENT (server), item, false);
1408 }
1409 }
1410 }
1411 }
1413 /**
1414 Regenerates the lines list from the current selection; is called on each move of a dragger, so that
1415 lines are always in sync with the actual gradient
1416 */
1417 void
1418 GrDrag::updateLines ()
1419 {
1420 // delete old lines
1421 for (GSList const *i = this->lines; i != NULL; i = i->next) {
1422 gtk_object_destroy( GTK_OBJECT (i->data));
1423 }
1424 g_slist_free (this->lines);
1425 this->lines = NULL;
1427 g_return_if_fail (this->selection != NULL);
1429 for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) {
1431 SPItem *item = SP_ITEM(i->data);
1433 SPStyle *style = SP_OBJECT_STYLE (item);
1435 if (style && (style->fill.isPaintserver())) {
1436 SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
1437 if (SP_IS_LINEARGRADIENT (server)) {
1438 this->addLine (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);
1439 } else if (SP_IS_RADIALGRADIENT (server)) {
1440 NR::Point center = sp_item_gradient_get_coords (item, POINT_RG_CENTER, 0, true);
1441 this->addLine (center, sp_item_gradient_get_coords (item, POINT_RG_R1, 0, true), GR_LINE_COLOR_FILL);
1442 this->addLine (center, sp_item_gradient_get_coords (item, POINT_RG_R2, 0, true), GR_LINE_COLOR_FILL);
1443 }
1444 }
1446 if (style && (style->stroke.isPaintserver())) {
1447 SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
1448 if (SP_IS_LINEARGRADIENT (server)) {
1449 this->addLine (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);
1450 } else if (SP_IS_RADIALGRADIENT (server)) {
1451 NR::Point center = sp_item_gradient_get_coords (item, POINT_RG_CENTER, 0, false);
1452 this->addLine (center, sp_item_gradient_get_coords (item, POINT_RG_R1, 0, false), GR_LINE_COLOR_STROKE);
1453 this->addLine (center, sp_item_gradient_get_coords (item, POINT_RG_R2, 0, false), GR_LINE_COLOR_STROKE);
1454 }
1455 }
1456 }
1457 }
1459 /**
1460 Regenerates the levels list from the current selection
1461 */
1462 void
1463 GrDrag::updateLevels ()
1464 {
1465 hor_levels.clear();
1466 vert_levels.clear();
1468 g_return_if_fail (this->selection != NULL);
1470 for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) {
1471 SPItem *item = SP_ITEM(i->data);
1472 NR::Maybe<NR::Rect> rect = sp_item_bbox_desktop (item);
1473 if (rect) {
1474 // Remember the edges of the bbox and the center axis
1475 hor_levels.push_back(rect->min()[NR::Y]);
1476 hor_levels.push_back(rect->max()[NR::Y]);
1477 hor_levels.push_back(0.5 * (rect->min()[NR::Y] + rect->max()[NR::Y]));
1478 vert_levels.push_back(rect->min()[NR::X]);
1479 vert_levels.push_back(rect->max()[NR::X]);
1480 vert_levels.push_back(0.5 * (rect->min()[NR::X] + rect->max()[NR::X]));
1481 }
1482 }
1483 }
1485 void
1486 GrDrag::selected_reverse_vector ()
1487 {
1488 if (selected == NULL)
1489 return;
1491 for (GSList const* i = ( (GrDragger*) selected->data )->draggables; i != NULL; i = i->next) {
1492 GrDraggable *draggable = (GrDraggable *) i->data;
1494 sp_item_gradient_reverse_vector (draggable->item, draggable->fill_or_stroke);
1495 }
1496 }
1498 void
1499 GrDrag::selected_move_nowrite (double x, double y, bool scale_radial)
1500 {
1501 selected_move (x, y, false, scale_radial);
1502 }
1504 void
1505 GrDrag::selected_move (double x, double y, bool write_repr, bool scale_radial)
1506 {
1507 if (selected == NULL)
1508 return;
1510 bool did = false;
1512 for (GList *i = selected; i != NULL; i = i->next) {
1513 GrDragger *d = (GrDragger *) i->data;
1515 if (!d->isA(POINT_LG_MID) && !d->isA(POINT_RG_MID1) && !d->isA(POINT_RG_MID2)) {
1516 // if this is a an endpoint,
1518 // Moving an rg center moves its focus and radii as well.
1519 // therefore, if this is a focus or radius and if selection
1520 // contains the center as well, do not move this one
1521 bool skip_radius_with_center = false;
1522 if (d->isA(POINT_RG_R1) || d->isA(POINT_RG_R2) ||
1523 (d->isA(POINT_RG_FOCUS) && !d->isA(POINT_RG_CENTER))) {
1524 for (GList *di = selected; di != NULL; di = di->next) {
1525 GrDragger *d_new = (GrDragger *) di->data;
1526 if (d_new->isA (((GrDraggable *) d->draggables->data)->item,
1527 POINT_RG_CENTER,
1528 ((GrDraggable *) d->draggables->data)->point_i,
1529 ((GrDraggable *) d->draggables->data)->fill_or_stroke)) {
1530 // FIXME: here we take into account only the first draggable!
1531 skip_radius_with_center = true;
1532 }
1533 }
1534 if (skip_radius_with_center)
1535 continue;
1536 }
1538 did = true;
1539 d->point += NR::Point (x, y);
1540 d->point_original = d->point;
1541 sp_knot_moveto (d->knot, &(d->point));
1543 d->fireDraggables (write_repr, scale_radial);
1545 d->updateDependencies(write_repr);
1546 }
1547 }
1549 if (!did) { // none of the end draggers are selected, so let's try to move the mids
1550 for (GList *i = selected; i != NULL; i = i->next) {
1551 GrDragger *d = (GrDragger *) i->data;
1553 if (d->isA(POINT_LG_MID) || !d->isA(POINT_RG_MID1) || !d->isA(POINT_RG_MID2)) {
1554 }
1555 }
1556 }
1558 if (write_repr && did) {
1559 // we did an undoable action
1560 sp_document_maybe_done (sp_desktop_document (desktop), "grmove", SP_VERB_CONTEXT_GRADIENT,
1561 _("Move gradient handle"));
1562 }
1563 }
1565 void
1566 GrDrag::selected_move_screen (double x, double y)
1567 {
1568 gdouble zoom = desktop->current_zoom();
1569 gdouble zx = x / zoom;
1570 gdouble zy = y / zoom;
1572 selected_move (zx, zy);
1573 }
1575 /**
1576 Select the knot next to the last selected one and deselect all other selected.
1577 */
1578 void
1579 GrDrag::select_next ()
1580 {
1581 if (selected == NULL || g_list_find(draggers, selected->data)->next == NULL) {
1582 if (draggers)
1583 setSelected ((GrDragger *) draggers->data);
1584 } else {
1585 setSelected ((GrDragger *) g_list_find(draggers, selected->data)->next->data);
1586 }
1587 }
1589 /**
1590 Select the knot previous from the last selected one and deselect all other selected.
1591 */
1592 void
1593 GrDrag::select_prev ()
1594 {
1595 if (selected == NULL || g_list_find(draggers, selected->data)->prev == NULL) {
1596 if (draggers)
1597 setSelected ((GrDragger *) g_list_last (draggers)->data);
1598 } else {
1599 setSelected ((GrDragger *) g_list_find(draggers, selected->data)->prev->data);
1600 }
1601 }
1604 // FIXME: i.m.o. an ugly function that I just made to work, but... aargh! (Johan)
1605 void
1606 GrDrag::deleteSelected (bool just_one)
1607 {
1608 if (!selected) return;
1610 SPDocument *document = false;
1612 struct StructStopInfo {
1613 SPStop * spstop;
1614 GrDraggable * draggable;
1615 SPGradient * gradient;
1616 SPGradient * vector;
1617 };
1619 GSList *midstoplist = NULL; // list of stops that must be deleted (will be deleted first)
1620 GSList *endstoplist = NULL; // list of stops that must be deleted
1621 while (selected) {
1622 GrDragger *dragger = (GrDragger*) selected->data;
1623 for (GSList * drgble = dragger->draggables; drgble != NULL; drgble = drgble->next) {
1624 GrDraggable *draggable = (GrDraggable*) drgble->data;
1625 SPGradient *gradient = sp_item_gradient (draggable->item, draggable->fill_or_stroke);
1626 SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
1628 switch (draggable->point_type) {
1629 case POINT_LG_MID:
1630 case POINT_RG_MID1:
1631 case POINT_RG_MID2:
1632 {
1633 SPStop *stop = sp_get_stop_i(vector, draggable->point_i);
1634 // check if already present in list. (e.g. when both RG_MID1 and RG_MID2 were selected)
1635 bool present = false;
1636 for (GSList const * l = midstoplist; l != NULL; l = l->next) {
1637 if ( (SPStop*)l->data == stop ) {
1638 present = true;
1639 break; // no need to search further.
1640 }
1641 }
1642 if (!present)
1643 midstoplist = g_slist_append(midstoplist, stop);
1644 }
1645 break;
1646 case POINT_LG_BEGIN:
1647 case POINT_LG_END:
1648 case POINT_RG_CENTER:
1649 case POINT_RG_R1:
1650 case POINT_RG_R2:
1651 {
1652 SPStop *stop = NULL;
1653 if ( (draggable->point_type == POINT_LG_BEGIN) || (draggable->point_type == POINT_RG_CENTER) ) {
1654 stop = sp_first_stop(vector);
1655 } else {
1656 stop = sp_last_stop(vector);
1657 }
1658 if (stop) {
1659 StructStopInfo *stopinfo = new StructStopInfo;
1660 stopinfo->spstop = stop;
1661 stopinfo->draggable = draggable;
1662 stopinfo->gradient = gradient;
1663 stopinfo->vector = vector;
1664 // check if already present in list. (e.g. when both R1 and R2 were selected)
1665 bool present = false;
1666 for (GSList const * l = endstoplist; l != NULL; l = l->next) {
1667 if ( ((StructStopInfo*)l->data)->spstop == stopinfo->spstop ) {
1668 present = true;
1669 break; // no need to search further.
1670 }
1671 }
1672 if (!present)
1673 endstoplist = g_slist_append(endstoplist, stopinfo);
1674 }
1675 }
1676 break;
1677 default:
1678 break;
1679 }
1680 }
1681 selected = g_list_remove(selected, dragger);
1682 if ( just_one ) break; // iterate once if just_one is set.
1683 }
1684 while (midstoplist) {
1685 SPStop *stop = (SPStop*) midstoplist->data;
1686 document = SP_OBJECT_DOCUMENT (stop);
1687 Inkscape::XML::Node * parent = SP_OBJECT_REPR(stop)->parent();
1688 parent->removeChild(SP_OBJECT_REPR(stop));
1689 midstoplist = g_slist_remove(midstoplist, stop);
1690 }
1691 while (endstoplist) {
1692 StructStopInfo *stopinfo = (StructStopInfo*) endstoplist->data;
1693 document = SP_OBJECT_DOCUMENT (stopinfo->spstop);
1695 // 2 is the minimum, cannot delete more than that without deleting the whole vector
1696 // cannot use vector->vector.stops.size() because the vector might be invalidated by deletion of a midstop
1697 // manually count the children, don't know if there already exists a function for this...
1698 int len = 0;
1699 for ( SPObject *child = sp_object_first_child(stopinfo->vector) ;
1700 child != NULL ;
1701 child = SP_OBJECT_NEXT(child) )
1702 {
1703 if ( SP_IS_STOP(child) ) len ++;
1704 }
1705 if (len > 2)
1706 {
1707 switch (stopinfo->draggable->point_type) {
1708 case POINT_LG_BEGIN:
1709 {
1710 SP_OBJECT_REPR(stopinfo->vector)->removeChild(SP_OBJECT_REPR(stopinfo->spstop));
1712 SPLinearGradient *lg = SP_LINEARGRADIENT(stopinfo->gradient);
1713 NR::Point oldbegin = NR::Point (lg->x1.computed, lg->y1.computed);
1714 NR::Point end = NR::Point (lg->x2.computed, lg->y2.computed);
1715 SPStop *stop = sp_first_stop(stopinfo->vector);
1716 gdouble offset = stop->offset;
1717 NR::Point newbegin = oldbegin + offset * (end - oldbegin);
1718 lg->x1.computed = newbegin[NR::X];
1719 lg->y1.computed = newbegin[NR::Y];
1721 Inkscape::XML::Node *repr = SP_OBJECT_REPR(stopinfo->gradient);
1722 sp_repr_set_svg_double(repr, "x1", lg->x1.computed);
1723 sp_repr_set_svg_double(repr, "y1", lg->y1.computed);
1724 stop->offset = 0;
1725 sp_repr_set_css_double (SP_OBJECT_REPR (stop), "offset", 0);
1727 // iterate through midstops to set new offset values such that they won't move on canvas.
1728 SPStop *laststop = sp_last_stop(stopinfo->vector);
1729 stop = sp_next_stop(stop);
1730 while ( stop != laststop ) {
1731 stop->offset = (stop->offset - offset)/(1 - offset);
1732 sp_repr_set_css_double (SP_OBJECT_REPR (stop), "offset", stop->offset);
1733 stop = sp_next_stop(stop);
1734 }
1735 }
1736 break;
1737 case POINT_LG_END:
1738 {
1739 SP_OBJECT_REPR(stopinfo->vector)->removeChild(SP_OBJECT_REPR(stopinfo->spstop));
1741 SPLinearGradient *lg = SP_LINEARGRADIENT(stopinfo->gradient);
1742 NR::Point begin = NR::Point (lg->x1.computed, lg->y1.computed);
1743 NR::Point oldend = NR::Point (lg->x2.computed, lg->y2.computed);
1744 SPStop *laststop = sp_last_stop(stopinfo->vector);
1745 gdouble offset = laststop->offset;
1746 NR::Point newend = begin + offset * (oldend - begin);
1747 lg->x2.computed = newend[NR::X];
1748 lg->y2.computed = newend[NR::Y];
1750 Inkscape::XML::Node *repr = SP_OBJECT_REPR(stopinfo->gradient);
1751 sp_repr_set_svg_double(repr, "x2", lg->x2.computed);
1752 sp_repr_set_svg_double(repr, "y2", lg->y2.computed);
1753 laststop->offset = 1;
1754 sp_repr_set_css_double (SP_OBJECT_REPR (laststop), "offset", 1);
1756 // iterate through midstops to set new offset values such that they won't move on canvas.
1757 SPStop *stop = sp_first_stop(stopinfo->vector);
1758 stop = sp_next_stop(stop);
1759 while ( stop != laststop ) {
1760 stop->offset = stop->offset / offset;
1761 sp_repr_set_css_double (SP_OBJECT_REPR (stop), "offset", stop->offset);
1762 stop = sp_next_stop(stop);
1763 }
1764 }
1765 break;
1766 case POINT_RG_CENTER:
1767 {
1768 SPStop *newfirst = sp_next_stop (stopinfo->spstop);
1769 if (newfirst) {
1770 newfirst->offset = 0;
1771 sp_repr_set_css_double (SP_OBJECT_REPR (newfirst), "offset", 0);
1772 }
1773 SP_OBJECT_REPR(stopinfo->vector)->removeChild(SP_OBJECT_REPR(stopinfo->spstop));
1774 }
1775 break;
1776 case POINT_RG_R1:
1777 case POINT_RG_R2:
1778 SP_OBJECT_REPR(stopinfo->vector)->removeChild(SP_OBJECT_REPR(stopinfo->spstop));
1780 SPRadialGradient *rg = SP_RADIALGRADIENT(stopinfo->gradient);
1781 double oldradius = rg->r.computed;
1782 SPStop *laststop = sp_last_stop(stopinfo->vector);
1783 gdouble offset = laststop->offset;
1784 double newradius = offset * oldradius;
1785 rg->r.computed = newradius;
1787 Inkscape::XML::Node *repr = SP_OBJECT_REPR(rg);
1788 sp_repr_set_svg_double(repr, "r", rg->r.computed);
1789 laststop->offset = 1;
1790 sp_repr_set_css_double (SP_OBJECT_REPR (laststop), "offset", 1);
1792 // iterate through midstops to set new offset values such that they won't move on canvas.
1793 SPStop *stop = sp_first_stop(stopinfo->vector);
1794 stop = sp_next_stop(stop);
1795 while ( stop != laststop ) {
1796 stop->offset = stop->offset / offset;
1797 sp_repr_set_css_double (SP_OBJECT_REPR (stop), "offset", stop->offset);
1798 stop = sp_next_stop(stop);
1799 }
1800 break;
1801 }
1802 }
1803 else
1804 { // delete the gradient from the object. set fill to unset FIXME: set to fill of unselected node?
1805 SPCSSAttr *css = sp_repr_css_attr_new ();
1807 // stopinfo->spstop is the selected stop
1808 Inkscape::XML::Node *unselectedrepr = SP_OBJECT_REPR(stopinfo->vector)->firstChild();
1809 if (unselectedrepr == SP_OBJECT_REPR(stopinfo->spstop) ) {
1810 unselectedrepr = unselectedrepr->next();
1811 }
1813 if (unselectedrepr == NULL) {
1814 if (stopinfo->draggable->fill_or_stroke) {
1815 sp_repr_css_unset_property (css, "fill");
1816 } else {
1817 sp_repr_css_unset_property (css, "stroke");
1818 }
1819 } else {
1820 SPCSSAttr *stopcss = sp_repr_css_attr(unselectedrepr, "style");
1821 if (stopinfo->draggable->fill_or_stroke) {
1822 sp_repr_css_set_property(css, "fill", sp_repr_css_property(stopcss, "stop-color", "inkscape:unset"));
1823 sp_repr_css_set_property(css, "fill-opacity", sp_repr_css_property(stopcss, "stop-opacity", "1"));
1824 } else {
1825 sp_repr_css_set_property(css, "stroke", sp_repr_css_property(stopcss, "stop-color", "inkscape:unset"));
1826 sp_repr_css_set_property(css, "stroke-opacity", sp_repr_css_property(stopcss, "stop-opacity", "1"));
1827 }
1828 sp_repr_css_attr_unref (stopcss);
1829 }
1831 sp_repr_css_change (SP_OBJECT_REPR (stopinfo->draggable->item), css, "style");
1832 sp_repr_css_attr_unref (css);
1833 }
1835 endstoplist = g_slist_remove(endstoplist, stopinfo);
1836 delete stopinfo;
1837 }
1839 if (document) {
1840 sp_document_done ( document, SP_VERB_CONTEXT_GRADIENT, _("Delete gradient stop(s)") );
1841 }
1842 }
1845 /*
1846 Local Variables:
1847 mode:c++
1848 c-file-style:"stroustrup"
1849 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1850 indent-tabs-mode:nil
1851 fill-column:99
1852 End:
1853 */
1854 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :