Code

naming: avoid unintentional double-meanings (part 1)
[inkscape.git] / src / tweak-context.cpp
1 #define __SP_TWEAK_CONTEXT_C__
3 /*
4  * tweaking paths without node editing
5  *
6  * Authors:
7  *   bulia byak 
8  *
9  * Copyright (C) 2007 authors
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #define noTWEAK_VERBOSE
16 #include "config.h"
18 #include <gtk/gtk.h>
19 #include <gdk/gdkkeysyms.h>
20 #include <glibmm/i18n.h>
22 #include <numeric>
24 #include "svg/svg.h"
25 #include "display/canvas-bpath.h"
26 #include "display/bezier-utils.h"
28 #include <glib/gmem.h>
29 #include "macros.h"
30 #include "document.h"
31 #include "selection.h"
32 #include "desktop.h"
33 #include "desktop-events.h"
34 #include "desktop-handles.h"
35 #include "desktop-affine.h"
36 #include "desktop-style.h"
37 #include "message-context.h"
38 #include "pixmaps/cursor-thin.xpm"
39 #include "pixmaps/cursor-thicken.xpm"
40 #include "pixmaps/cursor-push.xpm"
41 #include "pixmaps/cursor-roughen.xpm"
42 #include "libnr/n-art-bpath.h"
43 #include "libnr/nr-path.h"
44 #include "libnr/nr-matrix-ops.h"
45 #include "libnr/nr-scale-translate-ops.h"
46 #include "xml/repr.h"
47 #include "context-fns.h"
48 #include "sp-item.h"
49 #include "inkscape.h"
50 #include "color.h"
51 #include "splivarot.h"
52 #include "sp-item-group.h"
53 #include "sp-shape.h"
54 #include "sp-path.h"
55 #include "path-chemistry.h"
56 #include "sp-text.h"
57 #include "sp-flowtext.h"
58 #include "display/canvas-bpath.h"
59 #include "display/canvas-arena.h"
60 #include "livarot/Shape.h"
61 #include "isnan.h"
62 #include "prefs-utils.h"
64 #include "tweak-context.h"
66 #define DDC_RED_RGBA 0xff0000ff
68 #define DYNA_MIN_WIDTH 1.0e-6
70 // FIXME: move it to some shared file to be reused by both calligraphy and dropper
71 #define C1 0.552
72 static NArtBpath const hatch_area_circle[] = {
73     { NR_MOVETO, 0, 0, 0, 0, -1, 0 },
74     { NR_CURVETO, -1, C1, -C1, 1, 0, 1 },
75     { NR_CURVETO, C1, 1, 1, C1, 1, 0 },
76     { NR_CURVETO, 1, -C1, C1, -1, 0, -1 },
77     { NR_CURVETO, -C1, -1, -1, -C1, -1, 0 },
78     { NR_END, 0, 0, 0, 0, 0, 0 }
79 };
80 #undef C1
83 static void sp_tweak_context_class_init(SPTweakContextClass *klass);
84 static void sp_tweak_context_init(SPTweakContext *ddc);
85 static void sp_tweak_context_dispose(GObject *object);
87 static void sp_tweak_context_setup(SPEventContext *ec);
88 static void sp_tweak_context_set(SPEventContext *ec, gchar const *key, gchar const *val);
89 static gint sp_tweak_context_root_handler(SPEventContext *ec, GdkEvent *event);
91 static SPEventContextClass *parent_class;
93 GtkType
94 sp_tweak_context_get_type(void)
95 {
96     static GType type = 0;
97     if (!type) {
98         GTypeInfo info = {
99             sizeof(SPTweakContextClass),
100             NULL, NULL,
101             (GClassInitFunc) sp_tweak_context_class_init,
102             NULL, NULL,
103             sizeof(SPTweakContext),
104             4,
105             (GInstanceInitFunc) sp_tweak_context_init,
106             NULL,   /* value_table */
107         };
108         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPTweakContext", &info, (GTypeFlags)0);
109     }
110     return type;
113 static void
114 sp_tweak_context_class_init(SPTweakContextClass *klass)
116     GObjectClass *object_class = (GObjectClass *) klass;
117     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
119     parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
121     object_class->dispose = sp_tweak_context_dispose;
123     event_context_class->setup = sp_tweak_context_setup;
124     event_context_class->set = sp_tweak_context_set;
125     event_context_class->root_handler = sp_tweak_context_root_handler;
128 static void
129 sp_tweak_context_init(SPTweakContext *tc)
131     SPEventContext *event_context = SP_EVENT_CONTEXT(tc);
133     event_context->cursor_shape = cursor_push_xpm;
134     event_context->hot_x = 4;
135     event_context->hot_y = 4;
137     /* attributes */
138     tc->dragging = FALSE;
140     tc->width = 0.2;
141     tc->force = 0.2;
142     tc->pressure = TC_DEFAULT_PRESSURE;
144     tc->is_dilating = false;
145     tc->has_dilated = false;
148 static void
149 sp_tweak_context_dispose(GObject *object)
151     SPTweakContext *tc = SP_TWEAK_CONTEXT(object);
153     if (tc->dilate_area) {
154         gtk_object_destroy(GTK_OBJECT(tc->dilate_area));
155         tc->dilate_area = NULL;
156     }
158     if (tc->_message_context) {
159         delete tc->_message_context;
160     }
162     G_OBJECT_CLASS(parent_class)->dispose(object);
165 void
166 sp_tweak_update_cursor (SPTweakContext *tc, gint mode)
168     SPEventContext *event_context = SP_EVENT_CONTEXT(tc);
169    switch (mode) {
170        case TWEAK_MODE_PUSH:
171            event_context->cursor_shape = cursor_push_xpm;
172            break;
173        case TWEAK_MODE_MELT:
174            event_context->cursor_shape = cursor_thin_xpm;
175            break;
176        case TWEAK_MODE_INFLATE:
177            event_context->cursor_shape = cursor_thicken_xpm;
178            break;
179        case TWEAK_MODE_ROUGHEN:
180            event_context->cursor_shape = cursor_roughen_xpm;
181            break;
182    }
183    sp_event_context_update_cursor(event_context);
186 static void
187 sp_tweak_context_setup(SPEventContext *ec)
189     SPTweakContext *tc = SP_TWEAK_CONTEXT(ec);
191     if (((SPEventContextClass *) parent_class)->setup)
192         ((SPEventContextClass *) parent_class)->setup(ec);
194     {
195         SPCurve *c = sp_curve_new_from_foreign_bpath(hatch_area_circle);
196         tc->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c);
197         sp_curve_unref(c);
198         sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(tc->dilate_area), 0x00000000,(SPWindRule)0);
199         sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(tc->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
200         sp_canvas_item_hide(tc->dilate_area);
201     }
203     sp_event_context_read(ec, "width");
204     sp_event_context_read(ec, "mode");
205     sp_event_context_read(ec, "fidelity");
206     sp_event_context_read(ec, "force");
207     sp_event_context_read(ec, "usepressure");
209     tc->is_drawing = false;
211     tc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
214 static void
215 sp_tweak_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
217     SPTweakContext *tc = SP_TWEAK_CONTEXT(ec);
219     if (!strcmp(key, "width")) {
220         double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.1 );
221         tc->width = CLAMP(dval, -1000.0, 1000.0);
222     } else if (!strcmp(key, "mode")) {
223         gint64 const dval = ( val ? g_ascii_strtoll (val, NULL, 10) : 0 );
224         tc->mode = dval;
225         sp_tweak_update_cursor(tc, tc->mode);
226     } else if (!strcmp(key, "fidelity")) {
227         double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.0 );
228         tc->fidelity = CLAMP(dval, 0.0, 1.0);
229     } else if (!strcmp(key, "force")) {
230         double const dval = ( val ? g_ascii_strtod (val, NULL) : 1.0 );
231         tc->force = CLAMP(dval, 0, 1.0);
232     } else if (!strcmp(key, "usepressure")) {
233         tc->usepressure = (val && strcmp(val, "0"));
234     } 
237 static void
238 sp_tweak_extinput(SPTweakContext *tc, GdkEvent *event)
240     if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &tc->pressure))
241         tc->pressure = CLAMP (tc->pressure, TC_MIN_PRESSURE, TC_MAX_PRESSURE);
242     else
243         tc->pressure = TC_DEFAULT_PRESSURE;
246 double
247 get_dilate_radius (SPTweakContext *tc)
249     // 10 times the pen width:
250     return 500 * tc->width/SP_EVENT_CONTEXT(tc)->desktop->current_zoom(); 
253 double
254 get_dilate_force (SPTweakContext *tc)
256     double force = 8 * (tc->usepressure? tc->pressure : TC_DEFAULT_PRESSURE)
257         /sqrt(SP_EVENT_CONTEXT(tc)->desktop->current_zoom()); 
258     if (force > 3) {
259         force += 4 * (force - 3);
260     }
261     return force * tc->force;
264 bool
265 sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, NR::Point p, NR::Point vector, gint mode, double radius, double force, double fidelity)
267     bool did = false;
269     if (SP_IS_GROUP(item)) {
270         for (SPObject *child = sp_object_first_child(SP_OBJECT(item)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
271             if (SP_IS_ITEM(child)) {
272                 if (sp_tweak_dilate_recursive (selection, SP_ITEM(child), p, vector, mode, radius, force, fidelity))
273                     did = true;
274             }
275         }
277     } else if (SP_IS_PATH(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
279         Inkscape::XML::Node *newrepr = NULL;
280         gint pos = 0;
281         Inkscape::XML::Node *parent = NULL;
282         char const *id = NULL;
283         if (!SP_IS_PATH(item)) {
284             newrepr = sp_selected_item_to_curved_repr(item, 0);
285             if (!newrepr)
286                 return false;
288             // remember the position of the item
289             pos = SP_OBJECT_REPR(item)->position();
290             // remember parent
291             parent = SP_OBJECT_REPR(item)->parent();
292             // remember id
293             id = SP_OBJECT_REPR(item)->attribute("id");
294         }
297         // skip those paths whose bboxes are entirely out of reach with our radius
298         NR::Maybe<NR::Rect> bbox = item->getBounds(sp_item_i2doc_affine(item));
299         if (bbox) {
300             bbox->growBy(radius);
301             if (!bbox->contains(p)) {
302                 return false;
303             }
304         }
306         Path *orig = Path_for_item(item, false);
307         if (orig == NULL) {
308             return false;
309         }
310         Path *res = new Path;
311         res->SetBackData(false);
313         Shape *theShape = new Shape;
314         Shape *theRes = new Shape;
316         orig->ConvertWithBackData(0.08 - (0.07 * fidelity)); // default 0.059
317         orig->Fill(theShape, 0);
319         SPCSSAttr *css = sp_repr_css_attr(SP_OBJECT_REPR(item), "style");
320         gchar const *val = sp_repr_css_property(css, "fill-rule", NULL);
321         if (val && strcmp(val, "nonzero") == 0)
322         {
323             theRes->ConvertToShape(theShape, fill_nonZero);
324         }
325         else if (val && strcmp(val, "evenodd") == 0)
326         {
327             theRes->ConvertToShape(theShape, fill_oddEven);
328         }
329         else
330         {
331             theRes->ConvertToShape(theShape, fill_nonZero);
332         }
334         if (NR::L2(vector) != 0)
335             vector = 1/NR::L2(vector) * vector;
337         bool did_this = false;
338         NR::Matrix i2doc(sp_item_i2doc_affine(item));
339         if (mode == TWEAK_MODE_MELT || mode == TWEAK_MODE_INFLATE) {
340             if (theShape->MakeOffset(theRes, 
341                                  mode == TWEAK_MODE_INFLATE? force : -force,
342                                  join_straight, 4.0,
343                                  true, p[NR::X], p[NR::Y], radius, &i2doc) == 0) // 0 means the shape was actually changed
344               did_this = true;
345         } else if (mode == TWEAK_MODE_PUSH) {
346             if (theShape->MakePush(theRes, 
347                                  join_straight, 4.0,
348                                  true, p, force*2*vector, radius, &i2doc) == 0)
349               did_this = true;
350         } else if (mode == TWEAK_MODE_ROUGHEN) {
351             if (theShape->MakeJitter(theRes, 
352                                  join_straight, 4.0,
353                                  true, p, force, radius, &i2doc) == 0)
354               did_this = true;
355         }
357         // the rest only makes sense if we actually changed the path
358         if (did_this) {
359             theRes->ConvertToShape(theShape, fill_positive);
361             res->Reset();
362             theRes->ConvertToForme(res);
364             double th_max = 0.6 - 0.59*sqrt(fidelity);
365             double threshold = MAX(th_max, th_max*force);
366             res->ConvertEvenLines(threshold);
367             res->Simplify(threshold);
369             if (newrepr) { // converting to path, need to replace the repr
370                 bool is_selected = selection->includes(item);
371                 if (is_selected)
372                     selection->remove(item);
374                 // It's going to resurrect, so we delete without notifying listeners.
375                 SP_OBJECT(item)->deleteObject(false);
377                 // restore id
378                 newrepr->setAttribute("id", id);
379                 // add the new repr to the parent
380                 parent->appendChild(newrepr);
381                 // move to the saved position
382                 newrepr->setPosition(pos > 0 ? pos : 0);
384                 if (is_selected)
385                     selection->add(newrepr);
386             }
388             if (res->descr_cmd.size() > 1) { 
389                 gchar *str = res->svg_dump_path();
390                 if (newrepr)
391                     newrepr->setAttribute("d", str);
392                 else
393                     SP_OBJECT_REPR(item)->setAttribute("d", str);
394                 g_free(str);
395             } else {
396                 // TODO: if there's 0 or 1 node left, delete this path altogether
397             }
399             if (newrepr) {
400                 Inkscape::GC::release(newrepr);
401                 newrepr = NULL;
402             }
403         }
405         delete theShape;
406         delete theRes;
407         delete orig;
408         delete res;
410         if (did_this) 
411             did = true;
412     }
414     return did;
418 bool
419 sp_tweak_dilate (SPTweakContext *tc, NR::Point p, NR::Point vector)
421     Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(tc)->desktop);
423     if (selection->isEmpty()) {
424         return false;
425     }
427     bool did = false;
428     double radius = get_dilate_radius(tc); 
429     double force = get_dilate_force(tc); 
430     if (radius == 0 || force == 0) {
431         return false;
432     }
434     for (GSList *items = g_slist_copy((GSList *) selection->itemList());
435          items != NULL;
436          items = items->next) {
438         SPItem *item = (SPItem *) items->data;
440         if (sp_tweak_dilate_recursive (selection, item, p, vector, tc->mode, radius, force, tc->fidelity))
441             did = true;
443     }
445     return did;
448 void
449 sp_tweak_update_area (SPTweakContext *tc)
451         double radius = get_dilate_radius(tc);
452         NR::Matrix const sm (NR::scale(radius, radius) * NR::translate(SP_EVENT_CONTEXT(tc)->desktop->point()));
453         sp_canvas_item_affine_absolute(tc->dilate_area, sm);
454         sp_canvas_item_show(tc->dilate_area);
457 void
458 sp_tweak_switch_mode (SPTweakContext *tc, gint mode)
460     SP_EVENT_CONTEXT(tc)->desktop->setToolboxSelectOneValue ("tweak_tool_mode", mode);
461     // need to set explicitly, because the prefs may not have changed by the previous
462     tc->mode = mode;
463     sp_tweak_update_cursor (tc, mode);
466 void
467 sp_tweak_switch_mode_temporarily (SPTweakContext *tc, gint mode)
469    // Juggling about so that prefs have the old value but tc->mode and the button show new mode:
470    gint now_mode = prefs_get_int_attribute("tools.tweak", "mode", 0);
471    SP_EVENT_CONTEXT(tc)->desktop->setToolboxSelectOneValue ("tweak_tool_mode", mode);
472    sp_tweak_update_cursor (tc, mode);
473    // button has changed prefs, restore
474    prefs_set_int_attribute("tools.tweak", "mode", now_mode);
475    // changing prefs changed tc->mode, restore back :)
476    tc->mode = mode;
479 gint
480 sp_tweak_context_root_handler(SPEventContext *event_context,
481                                   GdkEvent *event)
483     SPTweakContext *tc = SP_TWEAK_CONTEXT(event_context);
484     SPDesktop *desktop = event_context->desktop;
486     gint ret = FALSE;
488     switch (event->type) {
489         case GDK_BUTTON_PRESS:
490             if (event->button.button == 1 && !event_context->space_panning) {
492                 if (Inkscape::have_viable_layer(desktop, tc->_message_context) == false) {
493                     return TRUE;
494                 }
496                 NR::Point const button_w(event->button.x,
497                                          event->button.y);
498                 NR::Point const button_dt(desktop->w2d(button_w));
499                 tc->last_push = desktop->dt2doc(button_dt);
501                 sp_tweak_extinput(tc, event);
503                 sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 3);
504                 tc->is_drawing = true;
505                 tc->is_dilating = true;
506                 tc->has_dilated = false;
508                 ret = TRUE;
509             }
510             break;
511         case GDK_MOTION_NOTIFY:
512         {
513             NR::Point const motion_w(event->motion.x,
514                                      event->motion.y);
515             NR::Point motion_dt(desktop->w2d(motion_w));
516             NR::Point motion_doc(desktop->dt2doc(motion_dt));
517             sp_tweak_extinput(tc, event);
519             // draw the dilating cursor
520                 double radius = get_dilate_radius(tc);
521                 NR::Matrix const sm (NR::scale(radius, radius) * NR::translate(desktop->w2d(motion_w)));
522                 sp_canvas_item_affine_absolute(tc->dilate_area, sm);
523                 sp_canvas_item_show(tc->dilate_area);
525                 guint num = 0;
526                 if (!desktop->selection->isEmpty()) {
527                     num = g_slist_length((GSList *) desktop->selection->itemList());
528                 }
529                 if (num == 0) {
530                     tc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Select objects</b> to tweak"));
531                 } else {
532                     switch (tc->mode) {
533                         case TWEAK_MODE_PUSH:
534                            tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
535                                                       _("<b>Pushing %d</b> selected object(s)"), num);  
536                            break;
537                         case TWEAK_MODE_MELT:
538                            tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
539                                                       _("<b>Melting %d</b> selected object(s)"), num);
540                            break;
541                         case TWEAK_MODE_INFLATE:
542                            tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
543                                                       _("<b>Blowing %d</b> selected object(s)"), num);
544                            break;
545                         case TWEAK_MODE_ROUGHEN:
546                            tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
547                                                       _("<b>Roughening %d</b> selected object(s)"), num);
548                            break;
549                     }
550                 }
553             // dilating:
554             if (tc->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) {  
555                 sp_tweak_dilate (tc, motion_doc, motion_doc - tc->last_push);
556                 //tc->last_push = motion_doc;
557                 tc->has_dilated = true;
558                 // it's slow, so prevent clogging up with events
559                 gobble_motion_events(GDK_BUTTON1_MASK);
560                 return TRUE;
561             }
563         }
564         break;
567     case GDK_BUTTON_RELEASE:
568     {
569         NR::Point const motion_w(event->button.x, event->button.y);
570         NR::Point const motion_dt(desktop->w2d(motion_w));
572         sp_canvas_end_forced_full_redraws(desktop->canvas);
573         tc->is_drawing = false;
575         if (tc->is_dilating && event->button.button == 1 && !event_context->space_panning) {
576             if (!tc->has_dilated) {
577                 // if we did not rub, do a light tap
578                 tc->pressure = 0.03;
579                 sp_tweak_dilate (tc, desktop->dt2doc(motion_dt), NR::Point(0,0));
580             }
581             tc->is_dilating = false;
582             tc->has_dilated = false;
583             sp_document_done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), 
584                          SP_VERB_CONTEXT_TWEAK,
585                              (tc->mode==TWEAK_MODE_INFLATE ? _("Blow tweak") : (tc->mode==TWEAK_MODE_MELT ? _("Melt tweak") : (tc->mode==TWEAK_MODE_PUSH ? _("Push tweak") : _("Roughen tweak")))));
586             ret = TRUE;
588         } 
589         break;
590     }
592     case GDK_KEY_PRESS:
593         switch (get_group0_keyval (&event->key)) {
594         case GDK_p:
595         case GDK_P:
596         case GDK_1:
597             if (MOD__SHIFT_ONLY) {
598                 sp_tweak_switch_mode(tc, TWEAK_MODE_PUSH);
599                 ret = TRUE;
600             }
601             break;
602         case GDK_m:
603         case GDK_M:
604         case GDK_2:
605             if (MOD__SHIFT_ONLY) {
606                 sp_tweak_switch_mode(tc, TWEAK_MODE_MELT);
607                 ret = TRUE;
608             }
609             break;
610         case GDK_b:
611         case GDK_B:
612         case GDK_3:
613             if (MOD__SHIFT_ONLY) {
614                 sp_tweak_switch_mode(tc, TWEAK_MODE_INFLATE);
615                 ret = TRUE;
616             }
617             break;
618         case GDK_r:
619         case GDK_R:
620         case GDK_4:
621             if (MOD__SHIFT_ONLY) {
622                 sp_tweak_switch_mode(tc, TWEAK_MODE_ROUGHEN);
623                 ret = TRUE;
624             }
625             break;
627         case GDK_Up:
628         case GDK_KP_Up:
629             if (!MOD__CTRL_ONLY) {
630                 tc->force += 0.05;
631                 if (tc->force > 1.0)
632                     tc->force = 1.0;
633                 desktop->setToolboxAdjustmentValue ("tweak-force", tc->force * 100);
634                 ret = TRUE;
635             }
636             break;
637         case GDK_Down:
638         case GDK_KP_Down:
639             if (!MOD__CTRL_ONLY) {
640                 tc->force -= 0.05;
641                 if (tc->force < 0.0)
642                     tc->force = 0.0;
643                 desktop->setToolboxAdjustmentValue ("tweak-force", tc->force * 100);
644                 ret = TRUE;
645             }
646             break;
647         case GDK_Right:
648         case GDK_KP_Right:
649             if (!MOD__CTRL_ONLY) {
650                 tc->width += 0.01;
651                 if (tc->width > 1.0)
652                     tc->width = 1.0;
653                 desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100); // the same spinbutton is for alt+x
654                 sp_tweak_update_area(tc);
655                 ret = TRUE;
656             }
657             break;
658         case GDK_Left:
659         case GDK_KP_Left:
660             if (!MOD__CTRL_ONLY) {
661                 tc->width -= 0.01;
662                 if (tc->width < 0.01)
663                     tc->width = 0.01;
664                 desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100);
665                 sp_tweak_update_area(tc);
666                 ret = TRUE;
667             }
668             break;
669         case GDK_Home:
670         case GDK_KP_Home:
671             tc->width = 0.01;
672             desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100);
673             sp_tweak_update_area(tc);
674             ret = TRUE;
675             break;
676         case GDK_End:
677         case GDK_KP_End:
678             tc->width = 1.0;
679             desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100);
680             sp_tweak_update_area(tc);
681             ret = TRUE;
682             break;
683         case GDK_x:
684         case GDK_X:
685             if (MOD__ALT_ONLY) {
686                 desktop->setToolboxFocusTo ("altx-tweak");
687                 ret = TRUE;
688             }
689             break;
691         case GDK_Control_L:
692         case GDK_Control_R:
693             if (MOD__SHIFT) {
694                 sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_INFLATE);
695             } else {
696                 sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_MELT);
697             }
698             break;
699         case GDK_Shift_L:
700         case GDK_Shift_R:
701             if (MOD__CTRL) {
702                 sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_INFLATE);
703             }
704             break;
705         default:
706             break;
707         }
708         break;
710     case GDK_KEY_RELEASE:
711         switch (get_group0_keyval(&event->key)) {
712             case GDK_Control_L:
713             case GDK_Control_R:
714                 sp_tweak_switch_mode (tc, prefs_get_int_attribute("tools.tweak", "mode", 0));
715                 tc->_message_context->clear();
716                 break;
717             case GDK_Shift_L:
718             case GDK_Shift_R:
719                 if (MOD__CTRL) {
720                     sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_MELT);
721                 }
722                 break;
723             break;
724             default:
725                 sp_tweak_switch_mode (tc, prefs_get_int_attribute("tools.tweak", "mode", 0));
726                 break;
727         }
729     default:
730         break;
731     }
733     if (!ret) {
734         if (((SPEventContextClass *) parent_class)->root_handler) {
735             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
736         }
737     }
739     return ret;
743 /*
744   Local Variables:
745   mode:c++
746   c-file-style:"stroustrup"
747   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
748   indent-tabs-mode:nil
749   fill-column:99
750   End:
751 */
752 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :