gradient-context.cpp revision 8b09069bfd32e57cfdc7f62359ebdfa08dda34af
3832N/A#ifdef HAVE_CONFIG_H
3832N/A#include "document.h"
3832N/A#include "selection.h"
3832N/A#include "desktop-handles.h"
3832N/A#include "message-context.h"
3832N/A#include "message-stack.h"
3832N/A#include "pixmaps/cursor-gradient.xpm"
3832N/A#include "pixmaps/cursor-gradient-add.xpm"
3832N/A#include "gradient-context.h"
3832N/A#include "gradient-chemistry.h"
3832N/A#include "preferences.h"
3832N/A#include "gradient-drag.h"
3832N/A#include "gradient-chemistry.h"
4978N/A#include "display/sp-ctrlline.h"
3832N/A#include "sp-linear-gradient.h"
3832N/A#include "sp-radial-gradient.h"
3832N/A#include "svg/css-ostringstream.h"
3832N/A#include "svg/svg-color.h"
3832N/A#include "sp-namedview.h"
4714N/A#include "rubberband.h"
4714N/A#include "document-undo.h"
4714N/A#include "selection-chemistry.h"
4714N/Astatic gint sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event);
4714N/Astatic void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint state, guint32 etime);
4714N/A sizeof(SPGradientContextClass),
4714N/A sizeof(SPGradientContext),
3832N/A type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPGradientContext", &info, (GTypeFlags) 0);
//The use of ngettext in the following code is intentional even if the English singular form would never be used
//TRANSLATORS: %s will be substituted with the point name (see previous messages); This is part of a compound message
//TRANSLATORS: This is a part of a compound message (out of two more indicating: grandint handle count & object count)
"One handle merging %d stops (drag with <b>Shift</b> to separate) selected",drag->singleSelectedDraggerNumDraggables()),
rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj);
//TRANSLATORS: The plural refers to number of selected gradient handles. This is part of a compound message (part two indicates selected object count)
gchar * message = g_strconcat(ngettext("<b>%d</b> gradient handle selected out of %d","<b>%d</b> gradient handles selected out of %d",n_sel),
//TRANSLATORS: Mind the space in front. (Refers to gradient handles selected). This is part of a compound message
} else if (n_sel == 0) {
rc->selcon = new sigc::connection (selection->connectChanged( sigc::bind (sigc::ptr_fun(&gradient_selection_changed), rc)));
rc->subselcon = new sigc::connection (ec->desktop->connectToolSubselectionChanged(sigc::bind (sigc::ptr_fun(&gradient_subselection_changed), rc)));
return close;
if (next_stop) {
return coords;
std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, &these_stops, &next_stops);
double sqr(double x) {return x*x;}
std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, &these_stops, &next_stops);
if (next_next) {
double diff =
sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item, Geom::Point mouse_p, guint32 /*etime*/)
SPStop *newstop = ec->get_drag()->addStopNearPoint (item, mouse_p, tolerance/desktop->current_zoom());
static gint
static bool dragging;
double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
case GDK_2BUTTON_PRESS:
bool over_line = false;
over_line |= sp_gradient_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
if (over_line) {
sp_gradient_context_add_stop_near_point(rc, SP_ITEM(selection->itemList()->data), rc->mousepoint_doc, event->button.time);
SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR);
Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, item, fsmode);
case GDK_BUTTON_PRESS:
dragging = true;
event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
m.unSetup();
case GDK_MOTION_NOTIFY:
if ( dragging
event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw around</b> handles to select them"));
m.unSetup();
bool over_line = false;
over_line |= sp_gradient_context_is_over_line (rc, (SPItem*) l->data, Geom::Point(event->motion.x, event->motion.y));
case GDK_BUTTON_RELEASE:
bool over_line = false;
over_line = sp_gradient_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
if (over_line)
dragging = false;
case GDK_KEY_PRESS:
case GDK_KEY_Alt_L:
case GDK_KEY_Alt_R:
case GDK_KEY_Control_L:
case GDK_KEY_Control_R:
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
case GDK_KEY_Meta_R:
NULL);
case GDK_KEY_x:
case GDK_KEY_X:
if (MOD__ALT_ONLY) {
case GDK_KEY_A:
case GDK_KEY_a:
case GDK_KEY_L:
case GDK_KEY_l:
case GDK_KEY_Escape:
case GDK_KEY_KP_Left:
case GDK_KEY_KP_4:
case GDK_KEY_KP_Up:
case GDK_KEY_KP_8:
case GDK_KEY_KP_Right:
case GDK_KEY_KP_6:
case GDK_KEY_KP_Down:
case GDK_KEY_KP_2:
case GDK_KEY_r:
case GDK_KEY_R:
if (MOD__SHIFT_ONLY) {
case GDK_KEY_Insert:
case GDK_KEY_KP_Insert:
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
case GDK_KEY_BackSpace:
case GDK_KEY_RELEASE:
case GDK_KEY_Alt_L:
case GDK_KEY_Alt_R:
case GDK_KEY_Control_L:
case GDK_KEY_Control_R:
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
case GDK_KEY_Meta_R:
if (!ret) {
return ret;
static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint /*state*/, guint32 etime)
Inkscape::PaintTarget fill_or_stroke = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(g_slist_last(items)->data), fill_or_stroke);
// HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false);
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false);
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient."));