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;
111 }
113 static void
114 sp_tweak_context_class_init(SPTweakContextClass *klass)
115 {
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;
126 }
128 static void
129 sp_tweak_context_init(SPTweakContext *tc)
130 {
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;
146 }
148 static void
149 sp_tweak_context_dispose(GObject *object)
150 {
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);
163 }
165 void
166 sp_tweak_update_cursor (SPTweakContext *tc, gint mode)
167 {
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_SUCK:
174 event_context->cursor_shape = cursor_thin_xpm;
175 break;
176 case TWEAK_MODE_BLOW:
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);
184 }
186 static void
187 sp_tweak_context_setup(SPEventContext *ec)
188 {
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());
212 }
214 static void
215 sp_tweak_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
216 {
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 }
235 }
237 static void
238 sp_tweak_extinput(SPTweakContext *tc, GdkEvent *event)
239 {
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;
244 }
246 double
247 get_dilate_radius (SPTweakContext *tc)
248 {
249 // 10 times the pen width:
250 return 500 * tc->width/SP_EVENT_CONTEXT(tc)->desktop->current_zoom();
251 }
253 double
254 get_dilate_force (SPTweakContext *tc)
255 {
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;
262 }
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)
266 {
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_SUCK || mode == TWEAK_MODE_BLOW) {
340 if (theShape->MakeOffset(theRes,
341 mode == TWEAK_MODE_BLOW? 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 selection->remove(item);
373 // It's going to resurrect, so we delete without notifying listeners.
374 SP_OBJECT(item)->deleteObject(false);
376 // restore id
377 newrepr->setAttribute("id", id);
378 // add the new repr to the parent
379 parent->appendChild(newrepr);
380 // move to the saved position
381 newrepr->setPosition(pos > 0 ? pos : 0);
383 if (is_selected)
384 selection->add(newrepr);
385 }
387 if (res->descr_cmd.size() > 1) {
388 gchar *str = res->svg_dump_path();
389 if (newrepr)
390 newrepr->setAttribute("d", str);
391 else
392 SP_OBJECT_REPR(item)->setAttribute("d", str);
393 g_free(str);
394 } else {
395 // TODO: if there's 0 or 1 node left, delete this path altogether
396 }
398 if (newrepr) {
399 Inkscape::GC::release(newrepr);
400 newrepr = NULL;
401 }
402 }
404 delete theShape;
405 delete theRes;
406 delete orig;
407 delete res;
409 if (did_this)
410 did = true;
411 }
413 return did;
414 }
417 bool
418 sp_tweak_dilate (SPTweakContext *tc, NR::Point p, NR::Point vector)
419 {
420 Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(tc)->desktop);
422 if (selection->isEmpty()) {
423 return false;
424 }
426 bool did = false;
427 double radius = get_dilate_radius(tc);
428 double force = get_dilate_force(tc);
429 if (radius == 0 || force == 0) {
430 return false;
431 }
433 for (GSList *items = g_slist_copy((GSList *) selection->itemList());
434 items != NULL;
435 items = items->next) {
437 SPItem *item = (SPItem *) items->data;
439 if (sp_tweak_dilate_recursive (selection, item, p, vector, tc->mode, radius, force, tc->fidelity))
440 did = true;
442 }
444 return did;
445 }
447 void
448 sp_tweak_update_area (SPTweakContext *tc)
449 {
450 double radius = get_dilate_radius(tc);
451 NR::Matrix const sm (NR::scale(radius, radius) * NR::translate(SP_EVENT_CONTEXT(tc)->desktop->point()));
452 sp_canvas_item_affine_absolute(tc->dilate_area, sm);
453 sp_canvas_item_show(tc->dilate_area);
454 }
456 void
457 sp_tweak_switch_mode (SPTweakContext *tc, gint mode)
458 {
459 SP_EVENT_CONTEXT(tc)->desktop->setToolboxSelectOneValue ("tweak_tool_mode", mode);
460 // need to set explicitly, because the prefs may not have changed by the previous
461 tc->mode = mode;
462 sp_tweak_update_cursor (tc, mode);
463 }
465 void
466 sp_tweak_switch_mode_temporarily (SPTweakContext *tc, gint mode)
467 {
468 // Juggling about so that prefs have the old value but tc->mode and the button show new mode:
469 gint now_mode = prefs_get_int_attribute("tools.tweak", "mode", 0);
470 SP_EVENT_CONTEXT(tc)->desktop->setToolboxSelectOneValue ("tweak_tool_mode", mode);
471 sp_tweak_update_cursor (tc, mode);
472 // button has changed prefs, restore
473 prefs_set_int_attribute("tools.tweak", "mode", now_mode);
474 // changing prefs changed tc->mode, restore back :)
475 tc->mode = mode;
476 }
478 gint
479 sp_tweak_context_root_handler(SPEventContext *event_context,
480 GdkEvent *event)
481 {
482 SPTweakContext *tc = SP_TWEAK_CONTEXT(event_context);
483 SPDesktop *desktop = event_context->desktop;
485 gint ret = FALSE;
487 switch (event->type) {
488 case GDK_BUTTON_PRESS:
489 if (event->button.button == 1 && !event_context->space_panning) {
491 if (Inkscape::have_viable_layer(desktop, tc->_message_context) == false) {
492 return TRUE;
493 }
495 NR::Point const button_w(event->button.x,
496 event->button.y);
497 NR::Point const button_dt(desktop->w2d(button_w));
498 tc->last_push = desktop->dt2doc(button_dt);
500 sp_tweak_extinput(tc, event);
502 sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 3);
503 tc->is_drawing = true;
504 tc->is_dilating = true;
505 tc->has_dilated = false;
507 ret = TRUE;
508 }
509 break;
510 case GDK_MOTION_NOTIFY:
511 {
512 NR::Point const motion_w(event->motion.x,
513 event->motion.y);
514 NR::Point motion_dt(desktop->w2d(motion_w));
515 NR::Point motion_doc(desktop->dt2doc(motion_dt));
516 sp_tweak_extinput(tc, event);
518 // draw the dilating cursor
519 double radius = get_dilate_radius(tc);
520 NR::Matrix const sm (NR::scale(radius, radius) * NR::translate(desktop->w2d(motion_w)));
521 sp_canvas_item_affine_absolute(tc->dilate_area, sm);
522 sp_canvas_item_show(tc->dilate_area);
524 guint num = 0;
525 if (!desktop->selection->isEmpty()) {
526 num = g_slist_length((GSList *) desktop->selection->itemList());
527 }
528 if (num == 0) {
529 tc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Select paths</b> to tweak"));
530 } else {
531 switch (tc->mode) {
532 case TWEAK_MODE_PUSH:
533 tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
534 _("<b>Pushing %d</b> selected path(s)"), num);
535 break;
536 case TWEAK_MODE_SUCK:
537 tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
538 _("<b>Melting %d</b> selected path(s)"), num);
539 break;
540 case TWEAK_MODE_BLOW:
541 tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
542 _("<b>Blowing %d</b> selected path(s)"), num);
543 break;
544 case TWEAK_MODE_ROUGHEN:
545 tc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
546 _("<b>Roughening %d</b> selected path(s)"), num);
547 break;
548 }
549 }
552 // dilating:
553 if (tc->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) {
554 sp_tweak_dilate (tc, motion_doc, motion_doc - tc->last_push);
555 //tc->last_push = motion_doc;
556 tc->has_dilated = true;
557 // it's slow, so prevent clogging up with events
558 gobble_motion_events(GDK_BUTTON1_MASK);
559 return TRUE;
560 }
562 }
563 break;
566 case GDK_BUTTON_RELEASE:
567 {
568 NR::Point const motion_w(event->button.x, event->button.y);
569 NR::Point const motion_dt(desktop->w2d(motion_w));
571 sp_canvas_end_forced_full_redraws(desktop->canvas);
572 tc->is_drawing = false;
574 if (tc->is_dilating && event->button.button == 1 && !event_context->space_panning) {
575 if (!tc->has_dilated) {
576 // if we did not rub, do a light tap
577 tc->pressure = 0.03;
578 sp_tweak_dilate (tc, desktop->dt2doc(motion_dt), NR::Point(0,0));
579 }
580 tc->is_dilating = false;
581 tc->has_dilated = false;
582 sp_document_done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop),
583 SP_VERB_CONTEXT_TWEAK,
584 (tc->mode==TWEAK_MODE_BLOW ? _("Blow tweak") : (tc->mode==TWEAK_MODE_SUCK ? _("Melt tweak") : (tc->mode==TWEAK_MODE_PUSH ? _("Push tweak") : _("Roughen tweak")))));
585 ret = TRUE;
587 }
588 break;
589 }
591 case GDK_KEY_PRESS:
592 switch (get_group0_keyval (&event->key)) {
593 case GDK_p:
594 case GDK_P:
595 case GDK_1:
596 if (MOD__SHIFT_ONLY) {
597 sp_tweak_switch_mode(tc, TWEAK_MODE_PUSH);
598 ret = TRUE;
599 }
600 break;
601 case GDK_m:
602 case GDK_M:
603 case GDK_2:
604 if (MOD__SHIFT_ONLY) {
605 sp_tweak_switch_mode(tc, TWEAK_MODE_SUCK);
606 ret = TRUE;
607 }
608 break;
609 case GDK_b:
610 case GDK_B:
611 case GDK_3:
612 if (MOD__SHIFT_ONLY) {
613 sp_tweak_switch_mode(tc, TWEAK_MODE_BLOW);
614 ret = TRUE;
615 }
616 break;
617 case GDK_r:
618 case GDK_R:
619 case GDK_4:
620 if (MOD__SHIFT_ONLY) {
621 sp_tweak_switch_mode(tc, TWEAK_MODE_ROUGHEN);
622 ret = TRUE;
623 }
624 break;
626 case GDK_Up:
627 case GDK_KP_Up:
628 if (!MOD__CTRL_ONLY) {
629 tc->force += 0.05;
630 if (tc->force > 1.0)
631 tc->force = 1.0;
632 desktop->setToolboxAdjustmentValue ("tweak-force", tc->force * 100);
633 ret = TRUE;
634 }
635 break;
636 case GDK_Down:
637 case GDK_KP_Down:
638 if (!MOD__CTRL_ONLY) {
639 tc->force -= 0.05;
640 if (tc->force < 0.0)
641 tc->force = 0.0;
642 desktop->setToolboxAdjustmentValue ("tweak-force", tc->force * 100);
643 ret = TRUE;
644 }
645 break;
646 case GDK_Right:
647 case GDK_KP_Right:
648 if (!MOD__CTRL_ONLY) {
649 tc->width += 0.01;
650 if (tc->width > 1.0)
651 tc->width = 1.0;
652 desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100); // the same spinbutton is for alt+x
653 sp_tweak_update_area(tc);
654 ret = TRUE;
655 }
656 break;
657 case GDK_Left:
658 case GDK_KP_Left:
659 if (!MOD__CTRL_ONLY) {
660 tc->width -= 0.01;
661 if (tc->width < 0.01)
662 tc->width = 0.01;
663 desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100);
664 sp_tweak_update_area(tc);
665 ret = TRUE;
666 }
667 break;
668 case GDK_Home:
669 case GDK_KP_Home:
670 tc->width = 0.01;
671 desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100);
672 sp_tweak_update_area(tc);
673 ret = TRUE;
674 break;
675 case GDK_End:
676 case GDK_KP_End:
677 tc->width = 1.0;
678 desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100);
679 sp_tweak_update_area(tc);
680 ret = TRUE;
681 break;
682 case GDK_x:
683 case GDK_X:
684 if (MOD__ALT_ONLY) {
685 desktop->setToolboxFocusTo ("altx-tweak");
686 ret = TRUE;
687 }
688 break;
690 case GDK_Control_L:
691 case GDK_Control_R:
692 if (MOD__SHIFT) {
693 sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_BLOW);
694 } else {
695 sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_SUCK);
696 }
697 break;
698 case GDK_Shift_L:
699 case GDK_Shift_R:
700 if (MOD__CTRL) {
701 sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_BLOW);
702 }
703 break;
704 default:
705 break;
706 }
707 break;
709 case GDK_KEY_RELEASE:
710 switch (get_group0_keyval(&event->key)) {
711 case GDK_Control_L:
712 case GDK_Control_R:
713 sp_tweak_switch_mode (tc, prefs_get_int_attribute("tools.tweak", "mode", 0));
714 tc->_message_context->clear();
715 break;
716 case GDK_Shift_L:
717 case GDK_Shift_R:
718 if (MOD__CTRL) {
719 sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_SUCK);
720 }
721 break;
722 break;
723 default:
724 sp_tweak_switch_mode (tc, prefs_get_int_attribute("tools.tweak", "mode", 0));
725 break;
726 }
728 default:
729 break;
730 }
732 if (!ret) {
733 if (((SPEventContextClass *) parent_class)->root_handler) {
734 ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
735 }
736 }
738 return ret;
739 }
742 /*
743 Local Variables:
744 mode:c++
745 c-file-style:"stroustrup"
746 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
747 indent-tabs-mode:nil
748 fill-column:99
749 End:
750 */
751 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :