gradient-drag.cpp revision 4ac75371c2e64267435b1b8731affefad5e77e00
/*
* 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 <2geom/bezier-curve.h>
#include "desktop-handles.h"
#include "selection.h"
#include "desktop.h"
#include "desktop-style.h"
#include "desktop-handles.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 "sp-item.h"
#include "style.h"
#include "knot.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "sp-mesh-gradient.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"
using Inkscape::ControlManager;
using Inkscape::CtrlLineType;
using Inkscape::DocumentUndo;
using Inkscape::allPaintTargets;
using Inkscape::CTLINE_PRIMARY;
using Inkscape::CTLINE_SECONDARY;
#define GR_KNOT_COLOR_NORMAL 0xffffff00
#define GR_KNOT_COLOR_MOUSEOVER 0xff000000
#define GR_KNOT_COLOR_SELECTED 0x0000ff00
#define GR_LINE_COLOR_FILL 0x0000ff7f
#define GR_LINE_COLOR_STROKE 0x9999007f
// screen pixels between knots when they snap:
#define SNAP_DIST 5
// absolute distance between gradient points for them to become a single dragger when the drag is created:
#define MERGE_DIST 0.1
// 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
};
const gchar *gr_knot_descr [] = {
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 ret = QUERY_STYLE_NOTHING;
float cf[4];
int count = 0;
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;
}
{
if (!selected) {
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:
os << accumulated;
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 (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // 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;
}
{
if (!selected) return 0;
float cf[4];
int count = 0;
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
{
SPGradient *gradient = 0;
//bool r1_knot = false;
// For Mesh
int divide_row = -1;
int divide_column = -1;
double divide_coord = 0.5;
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_MESHGRADIENT(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).
double closest = 1e10;
// 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
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
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;
if (lines) {
if (stop) {
return true;
}
}
}
}
return false;
}
selected(0),
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();
if (this->selected) {
} else {
desktop->gr_point_i = 0;
}
deselect_all();
}
g_list_free (this->draggers);
}
g_slist_free (this->lines);
}
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
// Merge draggers:
for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger
// 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
delete dragger;
// update the new merged dragger
d_new->fireDraggables(true, false, true);
d_new->updateKnotShape ();
d_new->updateDependencies(true);
_("Merge gradient handles"));
return;
}
}
}
Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE));
m.unSetup();
if (s.getSnapped()) {
p = s.getPoint();
sp_knot_moveto (knot, p);
}
} else if (state & GDK_CONTROL_MASK) {
Inkscape::SnapCandidatePoint scp = Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
/* 0 means no snapping. */
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) {
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();
sp_knot_moveto (knot, p);
}
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, GSList **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
double snap_fraction = 0.1;
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
double alpha = 1.0;
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);
}
if (d == dragger)
continue;
d->fireDraggables (true);
}
// make this dragger selected
}
dragger->updateDependencies(true);
// we did an undoable action
_("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:
break;
}
_("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.
*/
{
// 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.
*/
{
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)
{
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.
*/
{
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;
return false;
}
}
return true;
}
{
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 ) {
// Check draggable is of type POINT_MG_CORNER (don't allow selection of POINT_MG_HANDLE)
// Must be a mesh gradient
if ( !SP_IS_MESHGRADIENT( gradient ) ) continue;
}
}
}
// Now we do the handle moves.
// Loop over all draggables in moved corner
// 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_MESHGRADIENT( 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.
*/
void GrDragger::updateKnotShape()
{
if (!draggables)
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 (!dr_first) {
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;
// 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.
*/
{
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 = NULL;
// create the knot
sp_knot_update_ctrl(this->knot);
// move knot to the given point
sp_knot_show (this->knot);
// 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->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_midpoint_handler), this);
} else {
this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_handler), this);
}
g_signal_connect (G_OBJECT (this->knot), "doubleclicked", G_CALLBACK (gr_knot_doubleclicked_handler), this);
g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (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
g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_moved_handler), this);
g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_clicked_handler), this);
g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_doubleclicked_handler), this);
g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_grabbed_handler), this);
g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_ungrabbed_handler), this);
/* unref should call destroy */
// delete all draggables
delete ((GrDraggable *) i->data);
}
g_slist_free (this->draggables);
this->draggables = NULL;
}
/**
* Select the dragger which has the given draggable.
*/
GrDragger *GrDrag::getDraggerFor(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke)
{
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
{
}
/**
*/
void GrDrag::deselect_all()
{
while (selected) {
}
}
/**
*/
void GrDrag::deselectAll()
{
deselect_all();
}
/**
*/
{
setSelected (d, true, true);
}
}
/**
*/
{
setSelected (d, true, true);
}
}
}
}
/**
* Select draggers by stop
*/
{
}
}
}
}
/**
*/
{
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
if (selected) {
}
} else {
}
}
} else {
deselect_all();
if (dragger) {
}
}
if (seldragger) {
}
}
/**
* Deselect a dragger.
* @param dragger The dragger to deselect.
*/
{
}
}
/**
* 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(sp_desktop_controls(this->desktop), 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(sp_desktop_controls(this->desktop), 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);
// 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
*/
void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
{
// Show/hide mesh on fill/stroke. This doesn't work at the moment... and prevents node color updating.
//Inkscape::Preferences *prefs = Inkscape::Preferences::get();
bool edit_stroke = true; //abs(prefs->getBool("/tools/mesh/edit_stroke", true));
bool show_handles = true; //abs(prefs->getBool("/tools/mesh/show_handles", true));
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.
*/
void GrDrag::updateDraggers()
{
while (selected) {
}
// delete old draggers
}
g_list_free(this->draggers);
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
} else if ( SP_IS_RADIALGRADIENT(server) ) {
} else if ( SP_IS_MESHGRADIENT(server) ) {
}
}
}
// Suppress "gradientness" of solid paint
} else if ( SP_IS_LINEARGRADIENT(server) ) {
} else if ( SP_IS_RADIALGRADIENT(server) ) {
} else if ( SP_IS_MESHGRADIENT(server) ) {
}
}
}
}
}
/**
* Returns true if at least one of the draggers' knots has the mouse hovering above it.
*/
{
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.
*/
void GrDrag::updateLines()
{
// delete old lines
}
g_slist_free(this->lines);
// 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_MESHGRADIENT(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_MESHGRADIENT(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.
*/
void GrDrag::updateLevels()
{
hor_levels.clear();
vert_levels.clear();
if (rect) {
// Remember the edges of the bbox and the center axis
}
}
}
void GrDrag::selected_reverse_vector()
{
return;
}
}
{
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,
// 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)"));
}
}
}
void GrDrag::selected_move_screen(double x, double y)
{
}
/**
* Select the knot next to the last selected one and deselect all other selected.
*/
{
if (draggers)
} else {
}
if (d)
setSelected (d);
return d;
}
/**
* Select the knot previous from the last selected one and deselect all other selected.
*/
{
if (draggers)
} else {
}
if (d)
setSelected (d);
return d;
}
// FIXME: i.m.o. an ugly function that I just made to work, but... aargh! (Johan)
{
if (!selected) return;
struct StructStopInfo {
SPGradient * vector;
};
while (selected) {
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 :