/*
* On-canvas gradient dragging
*
* Authors:
* bulia byak <buliabyak@users.sf.net>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
* Tavmjong Bah <tavmjong@free.fr>
*
* Copyright (C) 2007 Johan Engelen
* Copyright (C) 2005,2010 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cstring>
#include <string>
#include "selection.h"
#include "desktop.h"
#include "desktop-style.h"
#include "document.h"
#include "document-undo.h"
#include "display/sp-ctrlline.h"
#include "display/sp-ctrlcurve.h"
#include "display/sp-canvas-util.h"
#include "xml/sp-css-attr.h"
#include "svg/css-ostringstream.h"
#include "preferences.h"
#include "inkscape.h"
#include "sp-item.h"
#include "style.h"
#include "knot.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "sp-mesh.h"
#include "sp-mesh-row.h"
#include "sp-mesh-patch.h"
#include "gradient-chemistry.h"
#include "gradient-drag.h"
#include "sp-stop.h"
#include "snap.h"
#include "sp-namedview.h"
#include "selection-chemistry.h"
#include "verbs.h"
#include "display/sp-canvas.h"
#include "ui/control-manager.h"
#include "ui/tools/tool-base.h"
using Inkscape::ControlManager;
using Inkscape::CtrlLineType;
using Inkscape::DocumentUndo;
using Inkscape::allPaintTargets;
using Inkscape::CTLINE_PRIMARY;
using Inkscape::CTLINE_SECONDARY;
// screen pixels between knots when they snap:
// absolute distance between gradient points for them to become a single dragger when the drag is created:
// knot shapes corresponding to GrPointType enum (in sp-gradient.h)
SPKnotShapeType gr_knot_shapes [] = {
SP_KNOT_SHAPE_SQUARE, // POINT_LG_BEGIN
SP_KNOT_SHAPE_CIRCLE, // POINT_LG_END
SP_KNOT_SHAPE_DIAMOND, // POINT_LG_MID
SP_KNOT_SHAPE_SQUARE, // POINT_RG_CENTER
SP_KNOT_SHAPE_CIRCLE, // POINT_RG_R1
SP_KNOT_SHAPE_CIRCLE, // POINT_RG_R2
SP_KNOT_SHAPE_CROSS, // POINT_RG_FOCUS
SP_KNOT_SHAPE_DIAMOND, // POINT_RG_MID1
SP_KNOT_SHAPE_DIAMOND, // POINT_RG_MID2
SP_KNOT_SHAPE_DIAMOND, // POINT_MG_CORNER
SP_KNOT_SHAPE_CIRCLE, // POINT_MG_HANDLE
SP_KNOT_SHAPE_SQUARE // POINT_MG_TENSOR
};
N_("Linear gradient <b>end</b>"),
N_("Linear gradient <b>mid stop</b>"),
N_("Radial gradient <b>center</b>"),
N_("Radial gradient <b>radius</b>"),
N_("Radial gradient <b>radius</b>"),
N_("Radial gradient <b>mid stop</b>"),
N_("Radial gradient <b>mid stop</b>"),
N_("Mesh gradient <b>corner</b>"),
N_("Mesh gradient <b>handle</b>"),
N_("Mesh gradient <b>tensor</b>")
};
static void
{
drag->updateDraggers ();
drag->updateLines ();
drag->updateLevels ();
}
static void gr_drag_sel_modified(Inkscape::Selection */*selection*/, guint /*flags*/, gpointer data)
{
if (drag->local_change) {
drag->local_change = false;
} else {
drag->updateDraggers ();
}
drag->updateLines ();
drag->updateLevels ();
}
/**
* When a _query_style_signal is received, check that \a property requests fill/stroke/opacity (otherwise
* skip), and fill the \a style with the averaged color of all draggables of the selected dragger, if
* any.
*/
{
if (property != QUERY_STYLE_PROPERTY_FILL && property != QUERY_STYLE_PROPERTY_STROKE && property != QUERY_STYLE_PROPERTY_MASTEROPACITY) {
return QUERY_STYLE_NOTHING;
}
return QUERY_STYLE_NOTHING;
} else {
int count = 0;
for(std::set<GrDragger *>::const_iterator it = drag->selected.begin(); it != drag->selected.end(); ++it) { //for all selected draggers
for(std::vector<GrDraggable *>::const_iterator it2 = d->draggables.begin(); it2 != d->draggables.end(); ++it2 ) { //for all draggables of dragger
if (ret == QUERY_STYLE_NOTHING) {
} else if (ret == QUERY_STYLE_SINGLE) {
}
guint32 c = sp_item_gradient_stop_query_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
cf[0] += SP_RGBA32_R_F (c);
count ++;
}
}
if (count) {
// set both fill and stroke with our stop-color and stop-opacity
}
return ret;
}
}
{
if ( str ) {
isNull = false;
if (firstStop) {
if (firstStop->currentColor) {
} else {
}
if ( !stopColorStr.empty() ) {
}
}
break;
}
}
}
} else {
isNull = true;
}
return colorStr;
}
{
return false;
}
// See if the css contains interesting properties, and if so, translate them into the format
// acceptable for gradient stops
// any of color properties, in order of increasing priority:
}
}
}
}
}
}
// Make sure the style is allowed for gradient stops.
bool stopIsNull = false;
Glib::ustring tmp = makeStopSafeColor( sp_repr_css_property( stop, "stop-color", "" ), stopIsNull );
}
}
} else { // multiply all opacity properties:
if ((css->attribute("fill") && !css->attribute("stroke") && !strcmp(css->attribute("fill"), "none")) ||
(css->attribute("stroke") && !css->attribute("fill") && !strcmp(css->attribute("stroke"), "none"))) {
sp_repr_css_set_property(stop, "stop-opacity", "0"); // if a single fill/stroke property is set to none, don't change color, set opacity to 0
}
}
return false;
}
for(std::set<GrDragger *>::const_iterator it = selected.begin(); it != selected.end(); ++it) { //for all selected draggers
for(std::vector<GrDraggable *>::const_iterator it2 = d->draggables.begin(); it2 != d->draggables.end(); ++it2 ) { //for all draggables of dragger
local_change = true;
sp_item_gradient_stop_set_style(draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke, stop);
}
}
//sp_repr_css_print(stop);
return true;
}
{
int count = 0;
for(std::set<GrDragger *>::const_iterator it = selected.begin(); it != selected.end(); ++it) { //for all selected draggers
for(std::vector<GrDraggable *>::const_iterator it2 = d->draggables.begin(); it2 != d->draggables.end(); ++it2 ) { //for all draggables of dragger
guint32 c = sp_item_gradient_stop_query_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
cf[0] += SP_RGBA32_R_F (c);
count ++;
}
}
if (count) {
}
}
// TODO refactor early returns
{
//bool r1_knot = false;
// For Mesh
bool addknot = false;
for (std::vector<Inkscape::PaintTarget>::const_iterator it = allPaintTargets().begin(); (it != allPaintTargets().end()) && !addknot; ++it)
{
if (SP_IS_LINEARGRADIENT(gradient)) {
if ( dist_screen < tolerance ) {
// calculate the new stop offset
// add the knot
addknot = true;
}
} else if (SP_IS_RADIALGRADIENT(gradient)) {
if ( dist_screen < tolerance ) {
// calculate the new stop offset
// add the knot
addknot = true;
//r1_knot = true;
} else {
if ( dist_screen < tolerance ) {
// calculate the new stop offset
// add the knot
addknot = true;
//r1_knot = false;
}
}
} else if (SP_IS_MESH(gradient)) {
// add_stop_near_point()
// Find out which curve pointer is over and use that curve to determine
// which row or column will be divided.
// This is silly as we already should know which line we are over...
// but that information is not saved (sp_gradient_context_is_over_line).
// Top line
{
if ( dist_screen < closest ) {
divide_row = -1;
divide_column = j;
}
}
// Right line (only for last column)
if( j == columns - 1 ) {
if ( dist_screen < closest ) {
divide_row = i;
divide_column = -1;
}
}
// Bottom line (only for last row)
if( i == rows - 1 ) {
if ( dist_screen < closest ) {
divide_row = -1;
divide_column = j;
}
}
// Left line
{
if ( dist_screen < closest ) {
divide_row = i;
divide_column = -1;
}
}
} // End loop over columns
} // End loop rows
addknot = true;
}
} // End if mesh
}
if (addknot) {
guint i = 1;
i++;
}
if (!next_stop) {
// logical error: the endstop should have offset 1 and should always be more than this offset here
return NULL;
}
gradient->ensureVector();
// so that it does not automatically update draggers in idle loop, as this would deselect
local_change = true;
// select the newly created stop
return newstop;
} else {
if( divide_row > -1 ) {
} else {
}
// Update repr
sp_mesh_repr_write( mg );
mg->ensureArray();
// How do we do this?
_("Added patch row or column"));
} // Mesh
}
return NULL;
}
{
// Note: not sure if a null pointer can come in for the style, but handle that just in case
bool stopIsNull = false;
// first, see if we can drop onto one of the existing draggers
for(std::vector<GrDragger *>::const_iterator i = draggers.begin(); i != draggers.end(); ++i) { //for all draggers
GrDragger *d = *i ;
for(std::vector<GrDraggable *>::const_iterator j = d->draggables.begin(); j != d->draggables.end(); ++j) { //for all draggables of dragger
local_change = true;
sp_item_gradient_stop_set_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke, stop);
}
return true;
}
}
// now see if we're over line and create a new stop
bool over_line = false;
for (std::vector<SPCtrlLine *>::const_iterator l = lines.begin(); l != lines.end() && (!over_line); ++l) {
if (stop) {
return true;
}
}
}
}
return false;
}
keep_selection(false),
local_change(false),
hor_levels(),
vert_levels(),
draggers(0),
lines(0),
{
(gpointer)this )
);
(gpointer)this )
);
(gpointer)this )
);
updateLines();
updateLevels();
GrDragger *dragger = getDraggerFor(desktop->gr_item, desktop->gr_point_type, desktop->gr_point_i, desktop->gr_fill_or_stroke);
if (dragger) {
}
}
}
{
this->sel_changed_connection.disconnect();
this->sel_modified_connection.disconnect();
this->style_set_connection.disconnect();
this->style_query_connection.disconnect();
} else {
desktop->gr_point_i = 0;
}
deselect_all();
for (std::vector<GrDragger *>::const_iterator it = this->draggers.begin(); it != this->draggers.end(); ++it) {
delete (*it);
}
for (std::vector<SPCtrlLine *>::const_iterator it = this->lines.begin(); it != this->lines.end(); ++it) {
}
}
GrDraggable::GrDraggable(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke) :
{
//g_object_ref(G_OBJECT(item));
}
{
//g_object_unref (G_OBJECT (this->item));
sp_object_unref(this->item);
}
{
if (item) {
switch (fill_or_stroke) {
break;
case Inkscape::FOR_STROKE:
break;
}
}
return server;
}
static void gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gpointer data)
{
if (state & GDK_SHIFT_MASK) {
// with Shift; unsnap if we carry more than one draggable
// create a new dragger
// relink to it all but the first draggable in the list
}
}
}
} else if (!(state & GDK_CONTROL_MASK)) {
// without Shift or Ctrl; see if we need to snap to another dragger
for (std::vector<GrDragger *>::const_iterator di = dragger->parent->draggers.begin(); di != dragger->parent->draggers.end() ; ++di) {
// Merge draggers:
for (std::vector<GrDraggable *>::const_iterator i = dragger->draggables.begin(); i != dragger->draggables.end(); ++i) {
// copy draggable to d_new:
GrDraggable *da_new = new GrDraggable (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
}
// unlink and delete this dragger
dragger->parent->draggers.erase(std::remove(dragger->parent->draggers.begin(),dragger->parent->draggers.end(), dragger),dragger->parent->draggers.end());
d_new->parent->draggers.erase(std::remove(d_new->parent->draggers.begin(),d_new->parent->draggers.end(), dragger),d_new->parent->draggers.end());
delete dragger;
// throw out delayed snap context
// update the new merged dragger
d_new->fireDraggables(true, false, true);
d_new->updateKnotShape ();
d_new->updateDependencies(true);
DocumentUndo::done(d_new->parent->desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Merge gradient handles"));
return;
}
}
}
Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE));
m.unSetup();
if (s.getSnapped()) {
p = s.getPoint();
}
} else if (state & GDK_CONTROL_MASK) {
Inkscape::SnapCandidatePoint scp = Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
/* 0 means no snapping. */
for (std::vector<GrDraggable *>::const_iterator i = dragger->draggables.begin(); i != dragger->draggables.end(); ++i) {
for (std::vector<GrDragger *>::const_iterator di = dragger->parent->draggers.begin() ; di != dragger->parent->draggers.end() ; ++di) {
continue;
draggable->fill_or_stroke)) {
// found the other end of the linear gradient;
if (state & GDK_SHIFT_MASK) {
// moving linear around center
} else {
// moving linear around the other end
}
}
}
} else if (draggable->point_type == POINT_RG_R1 || draggable->point_type == POINT_RG_R2 || draggable->point_type == POINT_RG_FOCUS) {
for (std::vector<GrDragger *>::const_iterator di = dragger->parent->draggers.begin(); di != dragger->parent->draggers.end(); ++di) {
continue;
draggable->fill_or_stroke)) {
// found the center of the radial gradient;
}
}
// std::cout << " gr_knot_moved_handler: Got mesh point!" << std::endl;
}
// dr_snap contains the origin of the gradient, whereas p will be the new endpoint which we will try to snap now
if (state & GDK_MOD1_MASK) {
// with Alt, snap to the original angle and its perpendiculars
} else {
}
m.unSetup();
}
}
m.unSetup();
if (!bsp.getSnapped()) {
// If we didn't truly snap to an object or to a grid, then we will still have to look for the
// closest projection onto one of the constraints. findBestSnap() will not do this for us
for (std::list<Inkscape::SnappedPoint>::const_iterator i = isr.points.begin(); i != isr.points.end(); ++i) {
}
}
}
//p = isr.points.front().getPoint();
}
if (drag->keep_selection) {
} else {
dragger->updateDependencies(false);
}
}
static void gr_midpoint_limits(GrDragger *dragger, SPObject *server, Geom::Point *begin, Geom::Point *end, Geom::Point *low_lim, Geom::Point *high_lim, std::vector<GrDragger *> &moving)
{
// a midpoint dragger can (logically) only contain one GrDraggable
// get begin and end points between which dragging is allowed:
// the draglimits are between knot(lowest_i - 1) and knot(highest_i + 1)
if (dragger->isSelected()) {
while ( true )
{
d_add = drag->getDraggerFor(draggable->item, draggable->point_type, lowest_i - 1, draggable->fill_or_stroke);
} else {
break;
}
}
while ( true )
{
d_add = drag->getDraggerFor(draggable->item, draggable->point_type, highest_i + 1, draggable->fill_or_stroke);
} else {
break;
}
}
}
if ( SP_IS_LINEARGRADIENT(server) ) {
if (lowest_i == 1) {
} else {
d_temp = drag->getDraggerFor (draggable->item, POINT_LG_MID, lowest_i - 1, draggable->fill_or_stroke);
}
if (d_temp)
d_temp = drag->getDraggerFor (draggable->item, POINT_LG_MID, highest_i + 1, draggable->fill_or_stroke);
}
if (d_temp)
} else if ( SP_IS_RADIALGRADIENT(server) ) {
if (lowest_i == 1) {
} else {
d_temp = drag->getDraggerFor (draggable->item, draggable->point_type, lowest_i - 1, draggable->fill_or_stroke);
}
if (d_temp)
d_temp = drag->getDraggerFor (draggable->item, draggable->point_type, highest_i + 1, draggable->fill_or_stroke);
d_temp = drag->getDraggerFor (draggable->item, (draggable->point_type==POINT_RG_MID1) ? POINT_RG_R1 : POINT_RG_R2, num-1, draggable->fill_or_stroke);
}
if (d_temp)
}
}
/**
* Called when a midpoint knot is dragged.
*/
static void gr_knot_moved_midpoint_handler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state, gpointer data)
{
// a midpoint dragger can (logically) only contain one GrDraggable
// FIXME: take from prefs
if (state & GDK_CONTROL_MASK) {
} else {
if (!(state & GDK_SHIFT_MASK)) {
m.unSetup();
}
}
if (state & GDK_MOD1_MASK) {
// FIXME: unify all these profiles (here, in nodepath, in tweak) in one place
if (Geom::L2(drg->point - dragger->point) + Geom::L2(drg->point - begin) - 1e-3 > Geom::L2(dragger->point - begin)) { // drg is on the end side from dragger
} else { // drg is on the begin side from dragger
}
}
drg->fireDraggables (false);
drg->updateDependencies(false);
}
}
{
}
/**
* Called when the mouse releases a dragger knot; changes gradient writing to repr, updates other draggers if needed.
*/
{
dragger->fireDraggables (true, true);
} else {
dragger->fireDraggables (true);
}
for (std::set<GrDragger *>::const_iterator it = dragger->parent->selected.begin(); it != dragger->parent->selected.end() ; ++it ) {
continue;
(*it)->fireDraggables (true);
}
// make this dragger selected
}
dragger->updateDependencies(true);
// we did an undoable action
DocumentUndo::done(dragger->parent->desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Move gradient handle"));
}
/**
* Called when a dragger knot is clicked; selects the dragger or deletes it depending on the
* state of the keyboard keys.
*/
{
if (!draggable) return;
// delete this knot from vector
switch (draggable->point_type) { // if we delete first or last stop, move the next/previous to the edge
case POINT_LG_BEGIN:
case POINT_RG_CENTER:
{
if (next) {
}
}
break;
case POINT_LG_END:
case POINT_RG_R1:
case POINT_RG_R2:
{
if (prev) {
}
}
break;
case POINT_LG_MID:
case POINT_RG_MID1:
case POINT_RG_MID2:
break;
default:
return;
}
_("Delete gradient stop"));
}
} else {
// select the dragger
if ( state & GDK_SHIFT_MASK ) {
} else {
}
}
}
/**
* Called when a dragger knot is doubleclicked;
*/
{
return;
/*
* 2012/4 - Do nothing (gradient editor to be disabled)
*/
//GrDraggable *draggable = (GrDraggable *) dragger->draggables->data;
//sp_item_gradient_edit_stop (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
}
/**
* Act upon all draggables of the dragger, setting them to the dragger's point.
*/
{
for (std::vector<GrDraggable *>::const_iterator i = this->draggables.begin(); i != this->draggables.end(); ++i) {
// set local_change flag so that selection_changed callback does not regenerate draggers
this->parent->local_change = true;
// 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 ||
!(draggable->point_type == POINT_RG_FOCUS && this->isA(draggable->item, POINT_RG_CENTER, draggable->point_i, draggable->fill_or_stroke)))
{
sp_item_gradient_set_coords (draggable->item, draggable->point_type, draggable->point_i, this->point, draggable->fill_or_stroke, write_repr, scale_radial);
}
}
}
/**
* Checks if the dragger has a draggable with this point_type.
*/
{
for (std::vector<GrDraggable *>::const_iterator i = this->draggables.begin(); i != this->draggables.end(); ++i) {
return true;
}
}
return false;
}
/**
* Checks if the dragger has a draggable with this item, point_type + point_i (number), fill_or_stroke.
*/
bool GrDragger::isA(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke)
{
for (std::vector<GrDraggable *>::const_iterator i = this->draggables.begin(); i != this->draggables.end(); ++i) {
if ( (draggable->point_type == point_type) && (draggable->point_i == point_i) && (draggable->item == item) && (draggable->fill_or_stroke == fill_or_stroke) ) {
return true;
}
}
return false;
}
/**
* Checks if the dragger has a draggable with this item, point_type, fill_or_stroke.
*/
{
for (std::vector<GrDraggable *>::const_iterator i = this->draggables.begin(); i != this->draggables.end(); ++i) {
if ( (draggable->point_type == point_type) && (draggable->item == item) && (draggable->fill_or_stroke == fill_or_stroke) ) {
return true;
}
}
return false;
}
{
// we must not merge the points of the same gradient!
// except that we can snap center and focus together
return false;
}
}
// disable merging of midpoints.
return false;
return true;
}
{
if (this == other)
return false;
for (std::vector<GrDraggable *>::const_iterator i = this->draggables.begin(); i != this->draggables.end(); ++i) {
for (std::vector<GrDraggable *>::const_iterator j = other->draggables.begin(); j != other->draggables.end(); ++j) {
return false;
}
}
return true;
}
{
for (std::vector<GrDraggable *>::const_iterator i = this->draggables.begin(); i != this->draggables.end(); ++i) {
return false;
}
return true;
}
/**
* Update mesh handles when mesh corner is moved.
* pc_old: old position of corner (could be changed to dp if we figure out transforms).
* op: how other nodes (handles, tensors) should be moved.
* Scaling takes place only between a selected and an unselected corner,
* other wise a handle is displaced the same distance as the adjacent corner.
* If a side is a line, then the handles are always placed 1/3 of side length
* from each corner.
*
* Ooops, needs to be reimplemented.
*/
void
{
// This routine might more properly be in mesh-context.cpp but moving knots is
// handled here rather than there.
// We need to update two places:
// 1. In SPMeshArrayI with object coordinates
// This routine is more complicated than it might need to be inorder to allow
// corner points to be selected in multiple meshes at the same time... with some
// sharing the same dragger (overkill, perhaps?).
// If no corner point in GrDragger then do nothing.
if( !isA (POINT_MG_CORNER ) ) return;
// We need a list of selected corners per mesh if scaling.
bool scale = false;
if( scale == true ) {
for( std::set<GrDragger *>::const_iterator it = drag->selected.begin(); it != drag->selected.end(); ++it ) {
for (std::vector<GrDraggable *>::const_iterator it2 = dragger->draggables.begin(); it2 != dragger->draggables.end(); ++it2 ) {
// Check draggable is of type POINT_MG_CORNER (don't allow selection of POINT_MG_HANDLE)
// Must be a mesh gradient
if ( !SP_IS_MESH( gradient ) ) continue;
}
}
}
// Now we do the handle moves.
// Loop over all draggables in moved corner
for (std::vector<GrDraggable *>::const_iterator j = draggables.begin(); j != draggables.end(); ++j ) {
// Check draggable is of type POINT_MG_CORNER (don't allow selection of POINT_MG_HANDLE)
if( point_type != POINT_MG_CORNER ) continue;
// Must be a mesh gradient
if ( !SP_IS_MESH( gradient ) ) continue;
// pc_old is the old corner position in desktop coordinates, we need it in gradient coordinate.
gradient = sp_gradient_convert_to_userspace (gradient, item, (fill_or_stroke == Inkscape::FOR_FILL) ? "fill" : "stroke");
// Move on-screen knots
}
}
} // Loop over draggables.
}
/**
* Updates the statusbar tip of the dragger knot, based on its draggables.
*/
{
}
switch (draggable->point_type) {
case POINT_LG_MID:
case POINT_RG_MID1:
case POINT_RG_MID2:
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"),
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"),
break;
}
this->knot->tip = g_strdup_printf ("%s", _("Radial gradient <b>center</b> and <b>focus</b>; drag with <b>Shift</b> to separate focus"));
} else {
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);
}
}
/**
* Adds a draggable to the dragger.
*/
{
if (draggables.empty())
return;
}
/**
* Adds a draggable to the dragger.
*/
{
this->updateTip();
}
/**
* Moves this dragger to the point of the given draggable, acting upon all other draggables.
*/
void GrDragger::moveThisToDraggable(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, bool write_repr)
{
if (draggables.empty())
return;
this->point = getGradientCoords(dr_first->item, dr_first->point_type, dr_first->point_i, dr_first->fill_or_stroke);
this->point_original = this->point;
for (std::vector<GrDraggable *>::const_iterator j = draggables.begin(); j != draggables.end(); ++j ) {
// Don't move initial draggable
continue;
}
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?
}
/**
* Moves all midstop draggables that depend on this one.
*/
{
if (!server)
return;
if (num <= 2) return;
if ( SP_IS_LINEARGRADIENT(server) ) {
this->moveOtherToDraggable (draggable->item, POINT_LG_MID, i, draggable->fill_or_stroke, write_repr);
}
} else if ( SP_IS_RADIALGRADIENT(server) ) {
this->moveOtherToDraggable (draggable->item, POINT_RG_MID1, i, draggable->fill_or_stroke, write_repr);
this->moveOtherToDraggable (draggable->item, POINT_RG_MID2, i, draggable->fill_or_stroke, write_repr);
}
}
}
/**
* Moves all draggables that depend on this one.
*/
{
for (std::vector<GrDraggable *>::const_iterator j = draggables.begin(); j != draggables.end(); ++j ) {
switch (draggable->point_type) {
case POINT_LG_BEGIN:
{
// the end point is dependent only when dragging with ctrl+shift
this->moveOtherToDraggable (draggable->item, POINT_LG_END, -1, draggable->fill_or_stroke, write_repr);
}
break;
case POINT_LG_END:
{
// the begin point is dependent only when dragging with ctrl+shift
this->moveOtherToDraggable (draggable->item, POINT_LG_BEGIN, 0, draggable->fill_or_stroke, write_repr);
}
break;
case POINT_LG_MID:
// no other nodes depend on mid points.
break;
case POINT_RG_R2:
this->moveOtherToDraggable (draggable->item, POINT_RG_R1, -1, draggable->fill_or_stroke, write_repr);
this->moveOtherToDraggable (draggable->item, POINT_RG_FOCUS, -1, draggable->fill_or_stroke, write_repr);
break;
case POINT_RG_R1:
this->moveOtherToDraggable (draggable->item, POINT_RG_R2, -1, draggable->fill_or_stroke, write_repr);
this->moveOtherToDraggable (draggable->item, POINT_RG_FOCUS, -1, draggable->fill_or_stroke, write_repr);
break;
case POINT_RG_CENTER:
this->moveOtherToDraggable (draggable->item, POINT_RG_R1, -1, draggable->fill_or_stroke, write_repr);
this->moveOtherToDraggable (draggable->item, POINT_RG_R2, -1, draggable->fill_or_stroke, write_repr);
this->moveOtherToDraggable (draggable->item, POINT_RG_FOCUS, -1, draggable->fill_or_stroke, write_repr);
break;
case POINT_RG_FOCUS:
// nothing can depend on that
break;
case POINT_RG_MID1:
this->moveOtherToDraggable (draggable->item, POINT_RG_MID2, draggable->point_i, draggable->fill_or_stroke, write_repr);
break;
case POINT_RG_MID2:
this->moveOtherToDraggable (draggable->item, POINT_RG_MID1, draggable->point_i, draggable->fill_or_stroke, write_repr);
break;
default:
break;
}
}
}
: point(p),
{
this->draggables.clear();
// create the knot
this->knot->updateCtrl();
// move knot to the given point
// connect knot's signals
if ( (draggable) // it can be NULL if a node in unsnapped (eg. focus point unsnapped from center)
// luckily, midstops never snap to other nodes so are never unsnapped...
{
this->_moved_connection = this->knot->moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_midpoint_handler), this));
} else {
this->_moved_connection = this->knot->moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_handler), this));
}
this->_clicked_connection = this->knot->click_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_clicked_handler), this));
this->_doubleclicked_connection = this->knot->doubleclicked_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_doubleclicked_handler), this));
this->_grabbed_connection = this->knot->grabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_grabbed_handler), this));
this->_ungrabbed_connection = this->knot->ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_ungrabbed_handler), this));
// add the initial draggable
if (draggable) {
this->addDraggable (draggable);
}
}
{
// unselect if it was selected
// Hmm, this causes a race condition as it triggers a call to gradient_selection_changed which
// can be executed while a list of draggers is being deleted. It doesn't acutally seem to be
// necessary.
//this->parent->setDeselected(this);
// disconnect signals
this->_moved_connection.disconnect();
this->_clicked_connection.disconnect();
this->_doubleclicked_connection.disconnect();
this->_grabbed_connection.disconnect();
this->_ungrabbed_connection.disconnect();
/* unref should call destroy */
knot_unref(this->knot);
// delete all draggables
for (std::vector<GrDraggable *>::const_iterator j = this->draggables.begin(); j != this->draggables.end(); ++j ) {
delete (*j);
}
this->draggables.clear();
}
/**
* Select the dragger which has the given draggable.
*/
GrDragger *GrDrag::getDraggerFor(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke)
{
for (std::vector<GrDragger *>::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i ) {
for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end(); ++j ) {
return (dragger);
}
}
}
return NULL;
}
void GrDragger::moveOtherToDraggable(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, bool write_repr)
{
if (d && d != this) {
}
}
/**
* Draw this dragger as selected.
*/
{
//if( isA(POINT_MG_CORNER) ) {
// for (GSList * drgble = this->draggables; drgble != NULL; drgble = drgble->next) {
// GrDraggable *draggable = (GrDraggable*) drgble->data;
// //if( draggable != NULL ) std::cout << " draggable" << std::endl;
// }
//}
}
/**
* Draw this dragger as normal (deselected).
*/
{
}
bool
{
}
/**
*/
{
}
/**
*/
{
deselect_all();
}
/**
*/
{
for (std::vector<GrDragger *>::const_iterator l = this->draggers.begin(); l != this->draggers.end(); ++l) {
GrDragger *d = *l;
setSelected (d, true, true);
}
}
/**
*/
{
for (std::vector<GrDragger *>::const_iterator l = this->draggers.begin(); l != this->draggers.end(); ++l) {
GrDragger *d = *l;
setSelected (d, true, true);
}
}
}
}
/**
* Select draggers by stop
*/
{
for (std::vector<GrDragger *>::const_iterator l = this->draggers.begin(); l != this->draggers.end(); ++l) {
for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end(); ++j) {
GrDraggable *d = *j;
}
}
}
}
/**
*/
{
for (std::vector<GrDragger *>::const_iterator l = this->draggers.begin(); l != this->draggers.end(); ++l) {
GrDragger *d = *l;
setSelected (d, true, true);
}
}
}
/**
* Select a dragger.
* @param dragger The dragger to select.
* @param add_to_selection If true, add to selection, otherwise deselect others.
* @param override If true, always select this node, otherwise toggle selected status.
*/
{
// Don't allow selecting a mesh handle or mesh tensor.
// We might want to rethink since a dragger can have draggables of different types.
if (add_to_selection) {
if (!dragger) return;
if (override) {
} else { // toggle
}
} else {
}
}
} else {
deselect_all();
if (dragger) {
}
}
if (seldragger) {
}
}
/**
* Deselect a dragger.
* @param dragger The dragger to deselect.
*/
{
}
this->desktop->emitToolSubselectionChanged((gpointer) (selected.empty() ? NULL :*(selected.begin())));
}
/**
* Create a line from p1 to p2 and add it to the lines list.
*/
void GrDrag::addLine(SPItem *item, Geom::Point p1, Geom::Point p2, Inkscape::PaintTarget fill_or_stroke)
{
SPCtrlLine *line = ControlManager::getManager().createControlLine(this->desktop->getControls(), p1, p2, type);
}
/**
* Create a curve from p0 to p3 and add it to the lines list. Used for mesh sides.
*/
void GrDrag::addCurve(SPItem *item, Geom::Point p0, Geom::Point p1, Geom::Point p2, Geom::Point p3, Inkscape::PaintTarget fill_or_stroke)
{
SPCtrlCurve *line = ControlManager::getManager().createControlCurve(this->desktop->getControls(), p0, p1, p2, p3, type);
}
/**
* 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.
*/
{
Geom::Point p = getGradientCoords(draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
for (std::vector<GrDragger *>::const_iterator l = this->draggers.begin(); l != this->draggers.end(); ++l) {
// distance is small, merge this draggable into dragger, no need to create new dragger
return;
}
}
// fixme: draggers should be added AFTER the last one: this way tabbing through them will be from begin to end.
}
/**
* Add draggers for the radial gradient rg on item.
*/
void GrDrag::addDraggersRadial(SPRadialGradient *rg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
rg->ensureVector();
if (num > 2) {
}
}
if (num > 2) {
}
}
}
/**
* Add draggers for the linear gradient lg on item.
*/
void GrDrag::addDraggersLinear(SPLinearGradient *lg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
lg->ensureVector();
if (num > 2) {
}
}
}
/**
*Add draggers for the mesh gradient mg on item
*/
{
// Show/hide mesh on fill/stroke. This doesn't work at the moment... and prevents node color updating.
//Inkscape::Preferences *prefs = Inkscape::Preferences::get();
return;
}
// Make sure we have at least one patch defined.
return;
}
// std::cout << " Draggers: " << i << " " << j << " " << nodes[i][j]->node_type << std::endl;
case MG_NODE_TYPE_CORNER:
{
addDragger ( corner );
++icorner;
break;
}
case MG_NODE_TYPE_HANDLE:
{
if( show_handles ) {
addDragger ( handle );
++ihandle;
break;
}
}
case MG_NODE_TYPE_TENSOR:
{
if( show_handles ) {
addDragger ( tensor );
++itensor;
break;
}
}
default:
break;
}
}
}
}
}
/**
* Artificially grab the knot of this dragger; used by the gradient context.
* Not used at the moment.
*/
{
if (dragger) {
}
}
/**
* Artificially grab the knot of the dragger with this draggable; used by the gradient context.
* This allows setting the final point from the end of the drag when creating a new gradient.
*/
void GrDrag::grabKnot(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, gint x, gint y, guint32 etime)
{
if (dragger) {
}
}
/**
* Regenerates the draggers list from the current selection; is called when selection is changed or
* modified, also when a radial dragger needs to update positions of other draggers in the gradient.
*/
{
// delete old draggers
for (std::vector<GrDragger *>::const_iterator l = this->draggers.begin(); l != this->draggers.end(); ++l) {
delete (*l);
}
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
} else if ( SP_IS_RADIALGRADIENT(server) ) {
} else if ( SP_IS_MESH(server) ) {
}
}
}
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
} else if ( SP_IS_RADIALGRADIENT(server) ) {
} else if ( SP_IS_MESH(server) ) {
}
}
}
}
}
/**
* Returns true if at least one of the draggers' knots has the mouse hovering above it.
*/
{
for (std::vector<GrDragger *>::const_iterator l = this->draggers.begin(); l != this->draggers.end(); ++l) {
GrDragger *d = *l;
return true;
}
}
return false;
}
/**
* Regenerates the lines list from the current selection; is called on each move of a dragger, so that
* lines are always in sync with the actual gradient.
*/
{
// delete old lines
for (std::vector<SPCtrlLine *>::const_iterator i = this->lines.begin(); i != this->lines.end(); ++i) {
}
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
addLine(item, getGradientCoords(item, POINT_LG_BEGIN, 0, Inkscape::FOR_FILL), getGradientCoords(item, POINT_LG_END, 0, Inkscape::FOR_FILL), Inkscape::FOR_FILL);
} else if ( SP_IS_RADIALGRADIENT(server) ) {
addLine(item, center, getGradientCoords(item, POINT_RG_R1, 0, Inkscape::FOR_FILL), Inkscape::FOR_FILL);
addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_FILL), Inkscape::FOR_FILL);
} else if ( SP_IS_MESH(server) ) {
// Top line
h = patch.getPointsForSide( 0 );
for( guint p = 0; p < 4; ++p ) {
}
// Right line
if( j == columns - 1 ) {
for( guint p = 0; p < 4; ++p ) {
}
}
// Bottom line
if( i == rows - 1 ) {
for( guint p = 0; p < 4; ++p ) {
}
}
// Left line
for( guint p = 0; p < 4; ++p ) {
}
}
}
}
}
}
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
addLine(item, getGradientCoords(item, POINT_LG_BEGIN, 0, Inkscape::FOR_STROKE), getGradientCoords(item, POINT_LG_END, 0, Inkscape::FOR_STROKE), Inkscape::FOR_STROKE);
} else if ( SP_IS_RADIALGRADIENT(server) ) {
addLine(item, center, getGradientCoords(item, POINT_RG_R1, 0, Inkscape::FOR_STROKE), Inkscape::FOR_STROKE);
addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_STROKE), Inkscape::FOR_STROKE);
} else if ( SP_IS_MESH(server) ) {
// MESH FIXME: TURN ROUTINE INTO FUNCTION AND CALL FOR BOTH FILL AND STROKE.
// Top line
h = patch.getPointsForSide( 0 );
for( guint p = 0; p < 4; ++p ) {
}
// Right line
if( j == columns - 1 ) {
for( guint p = 0; p < 4; ++p ) {
}
}
// Bottom line
if( i == rows - 1 ) {
for( guint p = 0; p < 4; ++p ) {
}
}
// Left line
for( guint p = 0; p < 4; ++p ) {
}
}
}
}
}
}
}
}
/**
* Regenerates the levels list from the current selection.
* Levels correspond to bounding box edges and midpoints.
*/
{
hor_levels.clear();
vert_levels.clear();
if (rect) {
// Remember the edges of the bbox and the center axis
}
}
}
{
return;
for(std::vector<GrDraggable *>::const_iterator it = (*(selected.begin()))->draggables.begin(); it != (*(selected.begin()))->draggables.end(); ++it) {
}
}
{
selected_move (x, y, false, scale_radial);
}
{
return;
bool did = false;
// if this is an endpoint,
// Moving an rg center moves its focus and radii as well.
// therefore, if this is a focus or radius and if selection
// contains the center as well, do not move this one
bool skip_radius_with_center = false;
0,
(d->draggables[0])->fill_or_stroke)) {
// FIXME: here we take into account only the first draggable!
skip_radius_with_center = true;
}
}
continue;
}
did = true;
d->point_original = d->point;
}
}
if (write_repr && did) {
// we did an undoable action
_("Move gradient handle(s)"));
return;
}
if (!did) { // none of the end draggers are selected, so let's try to move the mids
// a midpoint dragger can (logically) only contain one GrDraggable
drg->fireDraggables (true);
drg->updateDependencies(true);
did = true;
}
if (write_repr && did) {
// we did an undoable action
_("Move gradient mid stop(s)"));
}
}
}
{
}
/**
* Select the knot next to the last selected one and deselect all other selected.
*/
{
if (selected.empty() || (++find(draggers.begin(),draggers.end(),*(selected.begin())))==draggers.end()) {
d = draggers[0];
} else {
}
if (d)
setSelected (d);
return d;
}
/**
* Select the knot previous from the last selected one and deselect all other selected.
*/
{
} else {
}
if (d)
setSelected (d);
return d;
}
// FIXME: i.m.o. an ugly function that I just made to work, but... aargh! (Johan)
{
struct StructStopInfo {
};
for(std::vector<GrDraggable *>::const_iterator drgble = dragger->draggables.begin(); drgble != dragger->draggables.end(); ++drgble) {
switch (draggable->point_type) {
case POINT_LG_MID:
case POINT_RG_MID1:
case POINT_RG_MID2:
{
// check if already present in list. (e.g. when both RG_MID1 and RG_MID2 were selected)
bool present = false;
present = true;
break; // no need to search further.
}
}
if (!present)
}
break;
case POINT_LG_BEGIN:
case POINT_LG_END:
case POINT_RG_CENTER:
case POINT_RG_R1:
case POINT_RG_R2:
{
} else {
}
if (stop) {
// check if already present in list. (e.g. when both R1 and R2 were selected)
bool present = false;
present = true;
break; // no need to search further.
}
}
if (!present)
}
}
break;
default:
break;
}
}
if ( just_one ) break; // iterate once if just_one is set.
}
while (midstoplist) {
}
while (endstoplist) {
// 2 is the minimum, cannot delete more than that without deleting the whole vector
// cannot use vector->vector.stops.size() because the vector might be invalidated by deletion of a midstop
// manually count the children, don't know if there already exists a function for this...
int len = 0;
{
if ( SP_IS_STOP(child) ) {
len ++;
}
}
if (len > 2)
{
case POINT_LG_BEGIN:
{
// iterate through midstops to set new offset values such that they won't move on canvas.
}
}
break;
case POINT_LG_END:
{
// iterate through midstops to set new offset values such that they won't move on canvas.
}
}
break;
case POINT_RG_CENTER:
{
if (newfirst) {
}
}
break;
case POINT_RG_R1:
case POINT_RG_R2:
{
// iterate through midstops to set new offset values such that they won't move on canvas.
}
}
break;
default:
break;
}
}
else
{ // delete the gradient from the object. set fill to unset FIXME: set to fill of unselected node?
// stopinfo->spstop is the selected stop
}
if (unselectedrepr == NULL) {
} else {
}
} else {
sp_repr_css_set_property(css, "fill", sp_repr_css_property(stopcss, "stop-color", "inkscape:unset"));
} else {
sp_repr_css_set_property(css, "stroke", sp_repr_css_property(stopcss, "stop-color", "inkscape:unset"));
sp_repr_css_set_property(css, "stroke-opacity", sp_repr_css_property(stopcss, "stop-opacity", "1"));
}
}
}
delete stopinfo;
}
if (document) {
}
}
/*
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 :