Code

Placemark for gradient export
[inkscape.git] / src / gradient-drag.cpp
index ffc1b7fc638596b2ed06907f914de073b8030336..cb61a9890e044440e7e1a4b4e97595d1e923f9fa 100644 (file)
@@ -62,7 +62,7 @@ const gchar *gr_knot_descr [] = {
     N_("Radial gradient <b>focus</b>") // POINT_RG_FOCUS
 };
 
-static void 
+static void
 gr_drag_sel_changed(Inkscape::Selection *selection, gpointer data)
 {
        GrDrag *drag = (GrDrag *) data;
@@ -195,7 +195,7 @@ gr_drag_style_set (const SPCSSAttr *css, gpointer data)
     if (css->attribute("fill-opacity")) // TODO: multiply
         sp_repr_css_set_property (stop, "stop-opacity", css->attribute("fill-opacity"));
 
-    if ((css->attribute("fill") && !strcmp(css->attribute("fill"), "none")) || 
+    if ((css->attribute("fill") && !strcmp(css->attribute("fill"), "none")) ||
         (css->attribute("stroke") && !strcmp(css->attribute("stroke"), "none")))
         sp_repr_css_set_property (stop, "stop-opacity", "0"); // if set to none, don't change color, set opacity to 0
 
@@ -223,7 +223,7 @@ GrDrag::GrDrag(SPDesktop *desktop) {
 
     this->desktop = desktop;
 
-    this->selection = SP_DT_SELECTION(desktop);
+    this->selection = sp_desktop_selection(desktop);
 
     this->draggers = NULL;
     this->lines = NULL;
@@ -236,7 +236,7 @@ GrDrag::GrDrag(SPDesktop *desktop) {
 
     this->sel_changed_connection = this->selection->connectChanged(
         sigc::bind (
-            sigc::ptr_fun(&gr_drag_sel_changed), 
+            sigc::ptr_fun(&gr_drag_sel_changed),
             (gpointer)this )
 
         );
@@ -267,7 +267,7 @@ GrDrag::GrDrag(SPDesktop *desktop) {
     }
 }
 
-GrDrag::~GrDrag() 
+GrDrag::~GrDrag()
 {
     this->sel_changed_connection.disconnect();
     this->sel_modified_connection.disconnect();
@@ -317,7 +317,7 @@ NR::Point *
 get_snap_vector (NR::Point p, NR::Point o, double snap, double initial)
 {
     double r = NR::L2 (p - o);
-    if (r < 1e-3) 
+    if (r < 1e-3)
         return NULL;
     double angle = NR::atan2 (p - o);
     // snap angle to snaps increments, starting from initial:
@@ -364,7 +364,7 @@ gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpoi
                     GrDraggable *draggable = (GrDraggable *) i->data;
                     // copy draggable to d_new:
                     GrDraggable *da_new = new GrDraggable (draggable->item, draggable->point_num, draggable->fill_or_stroke);
-                    d_new->addDraggable (da_new); 
+                    d_new->addDraggable (da_new);
                 }
 
                 // unlink and delete this dragger
@@ -378,13 +378,13 @@ gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpoi
                 d_new->updateKnotShape ();
                 d_new->updateTip ();
                 d_new->updateDependencies(true);
-                sp_document_done (SP_DT_DOCUMENT (d_new->parent->desktop));
+                sp_document_done (sp_desktop_document (d_new->parent->desktop));
                 return;
             }
         }
     }
 
-    if (!((state & GDK_SHIFT_MASK) || ((state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK)))) { 
+    if (!((state & GDK_SHIFT_MASK) || ((state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK)))) {
         // See if we need to snap to any of the levels
         for (guint i = 0; i < dragger->parent->hor_levels.size(); i++) {
             if (fabs(p[NR::Y] - dragger->parent->hor_levels[i]) < snap_dist) {
@@ -417,7 +417,7 @@ gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpoi
                     GrDragger *d_new = (GrDragger *) di->data;
                     if (d_new == dragger)
                         continue;
-                    if (d_new->isA (draggable->item, 
+                    if (d_new->isA (draggable->item,
                                     draggable->point_num == POINT_LG_P1? POINT_LG_P2 : POINT_LG_P1,
                                     draggable->fill_or_stroke)) {
                         // found the other end of the linear gradient;
@@ -436,7 +436,7 @@ gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpoi
                     GrDragger *d_new = (GrDragger *) di->data;
                     if (d_new == dragger)
                         continue;
-                    if (d_new->isA (draggable->item, 
+                    if (d_new->isA (draggable->item,
                                     POINT_RG_CENTER,
                                     draggable->fill_or_stroke)) {
                         // found the center of the radial gradient;
@@ -509,7 +509,7 @@ gr_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, gpointer data)
     dragger->updateDependencies(true);
 
     // we did an undoable action
-    sp_document_done (SP_DT_DOCUMENT (dragger->parent->desktop));
+    sp_document_done (sp_desktop_document (dragger->parent->desktop));
 }
 
 /**
@@ -542,7 +542,7 @@ gr_knot_doubleclicked_handler (SPKnot *knot, guint state, gpointer data)
    sp_item_gradient_edit_stop (draggable->item, draggable->point_num, draggable->fill_or_stroke);
 }
 
-/**  
+/**
 Act upon all draggables of the dragger, setting them to the dragger's point
 */
 void
@@ -556,7 +556,7 @@ GrDragger::fireDraggables (bool write_repr, bool scale_radial, bool merging_focu
 
         // change gradient, optionally writing to repr; prevent focus from moving if it's snapped
         // to the center, unless it's the first update upon merge when we must snap it to the point
-        if (merging_focus || 
+        if (merging_focus ||
             !(draggable->point_num == POINT_RG_FOCUS && this->isA(draggable->item, POINT_RG_CENTER, draggable->fill_or_stroke)))
             sp_item_gradient_set_coords (draggable->item, draggable->point_num, this->point, draggable->fill_or_stroke, write_repr, scale_radial);
     }
@@ -648,7 +648,7 @@ GrDragger::updateTip ()
     if (g_slist_length (this->draggables) == 1) {
         GrDraggable *draggable = (GrDraggable *) this->draggables->data;
         char *item_desc = sp_item_description(draggable->item);
-        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"), 
+        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_num]),
                                            item_desc,
                                            draggable->fill_or_stroke == false ? _(" (stroke)") : "");
@@ -656,8 +656,11 @@ GrDragger::updateTip ()
     } else if (g_slist_length (draggables) == 2 && isA (POINT_RG_CENTER) && isA (POINT_RG_FOCUS)) {
         this->knot->tip = g_strdup_printf (_("Radial gradient <b>center</b> and <b>focus</b>; drag with <b>Shift</b> to separate focus"));
     } else {
-        this->knot->tip = g_strdup_printf (_("Gradient point shared by <b>%d</b> gradients; drag with <b>Shift</b> to separate"), 
-                                           g_slist_length (this->draggables));
+        int length = g_slist_length (this->draggables);
+        this->knot->tip = g_strdup_printf (ngettext("Gradient point shared by <b>%d</b> gradient; drag with <b>Shift</b> to separate",
+                                                    "Gradient point shared by <b>%d</b> gradients; drag with <b>Shift</b> to separate",
+                                                    length),
+                                           length);
     }
 }
 
@@ -747,7 +750,7 @@ GrDragger::updateDependencies (bool write_repr)
 
 
 
-GrDragger::GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable) 
+GrDragger::GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable)
 {
     this->draggables = NULL;
 
@@ -758,12 +761,10 @@ GrDragger::GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable)
 
     // create the knot
     this->knot = sp_knot_new (parent->desktop, NULL);
-    g_object_set (G_OBJECT (this->knot->item), "mode", SP_KNOT_MODE_XOR, NULL);
-    this->knot->fill [SP_KNOT_STATE_NORMAL] = GR_KNOT_COLOR_NORMAL;
-    this->knot->stroke [SP_KNOT_STATE_NORMAL] = 0x000000ff;
-    this->knot->stroke [SP_KNOT_STATE_DRAGGING] = 0x000000ff;
-    this->knot->stroke [SP_KNOT_STATE_MOUSEOVER] = 0x000000ff;
-    g_object_set (G_OBJECT (this->knot->item), "stroke_color", 0x000000ff, NULL);
+    this->knot->setMode(SP_KNOT_MODE_XOR);
+    this->knot->setFill(GR_KNOT_COLOR_NORMAL, GR_KNOT_COLOR_NORMAL, GR_KNOT_COLOR_NORMAL);
+    this->knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff);
+    sp_knot_update_ctrl(this->knot);
 
     // move knot to the given point
     sp_knot_set_position (this->knot, &p, SP_KNOT_STATE_NORMAL);
@@ -823,7 +824,7 @@ GrDragger::moveOtherToDraggable (SPItem *item, guint point_num, bool fill_or_str
     GrDragger *d = this->parent->getDraggerFor (item, point_num, fill_or_stroke);
     if (d && d !=  this) {
         d->moveThisToDraggable (item, point_num, fill_or_stroke, write_repr);
-    } 
+    }
 }
 
 
@@ -831,7 +832,7 @@ GrDragger::moveOtherToDraggable (SPItem *item, guint point_num, bool fill_or_str
 Set selected dragger
 */
 void
-GrDrag::setSelected (GrDragger *dragger) 
+GrDrag::setSelected (GrDragger *dragger)
 {
     if (this->selected) {
        this->selected->knot->fill [SP_KNOT_STATE_NORMAL] = GR_KNOT_COLOR_NORMAL;
@@ -850,9 +851,9 @@ GrDrag::setSelected (GrDragger *dragger)
 Create a line from p1 to p2 and add it to the lines list
  */
 void
-GrDrag::addLine (NR::Point p1, NR::Point p2, guint32 rgba) 
+GrDrag::addLine (NR::Point p1, NR::Point p2, guint32 rgba)
 {
-    SPCanvasItem *line = sp_canvas_item_new(SP_DT_CONTROLS(this->desktop),
+    SPCanvasItem *line = sp_canvas_item_new(sp_desktop_controls(this->desktop),
                                                             SP_TYPE_CTRLLINE, NULL);
     sp_ctrlline_set_coords(SP_CTRLLINE(line), p1, p2);
     if (rgba != GR_LINE_COLOR_FILL) // fill is the default, so don't set color for it to speed up redraw
@@ -865,7 +866,7 @@ GrDrag::addLine (NR::Point p1, NR::Point p2, guint32 rgba)
 If there already exists a dragger within MERGE_DIST of p, add the draggable to it; otherwise create
 new dragger and add it to draggers list
  */
-void 
+void
 GrDrag::addDragger (GrDraggable *draggable)
 {
     NR::Point p = sp_item_gradient_get_coords (draggable->item, draggable->point_num, draggable->fill_or_stroke);
@@ -887,7 +888,7 @@ GrDrag::addDragger (GrDraggable *draggable)
 /**
 Add draggers for the radial gradient rg on item
 */
-void 
+void
 GrDrag::addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke)
 {
     addDragger (new GrDraggable (item, POINT_RG_CENTER, fill_or_stroke));
@@ -899,7 +900,7 @@ GrDrag::addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stro
 /**
 Add draggers for the linear gradient lg on item
 */
-void 
+void
 GrDrag::addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke)
 {
     addDragger (new GrDraggable (item, POINT_LG_P1, fill_or_stroke));
@@ -940,7 +941,7 @@ GrDrag::updateDraggers ()
         SPItem *item = SP_ITEM(i->data);
         SPStyle *style = SP_OBJECT_STYLE (item);
 
-        if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) { 
+        if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) {
             SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
             if (SP_IS_LINEARGRADIENT (server)) {
                 addDraggersLinear (SP_LINEARGRADIENT (server), item, true);
@@ -949,7 +950,7 @@ GrDrag::updateDraggers ()
             }
         }
 
-        if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) { 
+        if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) {
             SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
             if (SP_IS_LINEARGRADIENT (server)) {
                 addDraggersLinear (SP_LINEARGRADIENT (server), item, false);
@@ -984,7 +985,7 @@ GrDrag::updateLines ()
 
         SPStyle *style = SP_OBJECT_STYLE (item);
 
-        if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) { 
+        if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) {
             SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
             if (SP_IS_LINEARGRADIENT (server)) {
                 this->addLine (sp_item_gradient_get_coords (item, POINT_LG_P1, true), sp_item_gradient_get_coords (item, POINT_LG_P2, true), GR_LINE_COLOR_FILL);
@@ -995,7 +996,7 @@ GrDrag::updateLines ()
             }
         }
 
-        if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) { 
+        if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) {
             SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
             if (SP_IS_LINEARGRADIENT (server)) {
                 this->addLine (sp_item_gradient_get_coords (item, POINT_LG_P1, false), sp_item_gradient_get_coords (item, POINT_LG_P2, false), GR_LINE_COLOR_STROKE);
@@ -1060,7 +1061,7 @@ GrDrag::selected_move (double x, double y)
     selected->updateDependencies(true);
 
     // we did an undoable action
-    sp_document_done (SP_DT_DOCUMENT (desktop));
+    sp_document_done (sp_desktop_document (desktop));
 }
 
 void