gradient-context.cpp revision 484e9373386f07216f975bc4622772ffaab74c3d
#define __SP_GRADIENT_CONTEXT_C__
/*
* Gradient drawing and editing tool
*
* Authors:
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gdk/gdkkeysyms.h>
#include "macros.h"
#include "document.h"
#include "selection.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "message-context.h"
#include "message-stack.h"
#include "pixmaps/cursor-gradient.xpm"
#include "gradient-context.h"
#include "prefs-utils.h"
#include "gradient-drag.h"
#include "gradient-chemistry.h"
#include "sp-item.h"
static void sp_gradient_drag(SPGradientContext &rc, NR::Point const pt, guint state, guint32 etime);
static SPEventContextClass *parent_class;
{
if (!type) {
sizeof(SPGradientContextClass),
sizeof(SPGradientContext),
4,
NULL, /* value_table */
};
}
return type;
}
{
}
{
event_context->xp = 0;
event_context->yp = 0;
event_context->tolerance = 0;
event_context->within_tolerance = false;
}
{
ec->enableGrDrag(false);
if (rc->_message_context) {
delete rc->_message_context;
}
}
{
}
ec->enableSelectionCue();
}
ec->enableGrDrag();
}
void
{
drag->select_next();
}
void
{
drag->select_prev();
}
{
static bool dragging;
event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100);
double const nudge = prefs_get_double_attribute_limited("options.nudgedistance", "value", 2, 0, 1000); // in px
case GDK_2BUTTON_PRESS:
SPGradientType new_type = (SPGradientType) prefs_get_int_attribute ("tools.gradient", "newgradient", SP_GRADIENT_TYPE_LINEAR);
SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, SP_OBJECT (item), new_fill);
}
_("Create default gradient"));
}
break;
case GDK_BUTTON_PRESS:
// save drag origin
event_context->within_tolerance = true;
// remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to
// enable Ctrl+doubleclick of exactly the selected item(s)
event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
dragging = true;
/* Position center */
/* Snap center to nearest magnetic point */
}
break;
case GDK_MOTION_NOTIFY:
if ( dragging
{
break; // do not drag if we're within tolerance from origin
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to draw, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
event_context->within_tolerance = false;
}
break;
case GDK_BUTTON_RELEASE:
dragging = false;
// unless clicked with Ctrl (to enable Ctrl+doubleclick)
break;
}
if (!event_context->within_tolerance) {
// we've been dragging, do nothing (grdrag handles that)
} else if (event_context->item_to_select) {
// no dragging, select clicked item if any
} else {
}
} else {
// click in an empty space; do the same as Esc
} else {
}
}
}
break;
case GDK_KEY_PRESS:
case GDK_Alt_L:
case GDK_Alt_R:
case GDK_Control_L:
case GDK_Control_R:
case GDK_Shift_L:
case GDK_Shift_R:
case GDK_Meta_L: // Meta is when you press Shift+Alt (at least on my machine)
case GDK_Meta_R:
_("<b>Ctrl</b>: snap gradient angle"),
_("<b>Shift</b>: draw gradient around the starting point"),
NULL);
break;
case GDK_x:
case GDK_X:
if (MOD__ALT_ONLY) {
}
break;
case GDK_Escape:
} else {
}
//TODO: make dragging escapable by Esc
break;
case GDK_Left: // move handle left
case GDK_KP_Left:
case GDK_KP_4:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_Up: // move handle up
case GDK_KP_Up:
case GDK_KP_8:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_Right: // move handle right
case GDK_KP_Right:
case GDK_KP_6:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_Down: // move handle down
case GDK_KP_Down:
case GDK_KP_2:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_r:
case GDK_R:
if (MOD__SHIFT_ONLY) {
// First try selected dragger
} else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients)
}
}
// we did an undoable action
_("Invert gradient"));
}
break;
default:
break;
}
break;
case GDK_KEY_RELEASE:
case GDK_Alt_L:
case GDK_Alt_R:
case GDK_Control_L:
case GDK_Control_R:
case GDK_Shift_L:
case GDK_Shift_R:
case GDK_Meta_L: // Meta is when you press Shift+Alt
case GDK_Meta_R:
break;
default:
break;
}
break;
default:
break;
}
if (!ret) {
}
}
return ret;
}
{
if (ec->item_to_select) {
} else {
vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(selection->itemList()->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
//FIXME: see above
if (type == SP_GRADIENT_TYPE_LINEAR) {
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_P1, rc.origin, fill_or_stroke, true, false);
} else if (type == SP_GRADIENT_TYPE_RADIAL) {
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_CENTER, rc.origin, fill_or_stroke, true, false);
}
}
// prevent regenerating draggers by selection modified signal, which sometimes
// comes too late and thus destroys the knot which we will now grab:
// and therefore are already out of tolerance
}
// We did an undoable action, but sp_document_done will be called by the knot when released
// status text; we do not track coords because this branch is run once, not all the time
// during drag
ngettext("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle",
"<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects),
} else {
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient."));
}
}
/*
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:encoding=utf-8:textwidth=99 :