~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/pencil-context.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Kees Cook, Ted Gould
  • Date: 2008-02-10 14:20:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080210142016-vcnb2zqyhszu0xvb
Tags: 0.46~pre1-0ubuntu1
[ Kees Cook ]
* debian/control:
  - add libgtkspell-dev build-dep to gain GtkSpell features (LP: #183547).
  - update Standards version (no changes needed).
  - add Vcs and Homepage fields.
  - switch to new python-lxml dep.
* debian/{control,rules}: switch from dpatch to quilt for more sanity.
* debian/patches/20_fix_glib_and_gxx43_ftbfs.patch:
  - merged against upstream fixes.
  - added additional fixes for newly written code.
* debian/rules: enable parallel building.

[ Ted Gould ]
* Updating POTFILES.in to make it so things build correctly.
* debian/control:
  - add ImageMagick++ and libboost-dev to build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "desktop.h"
22
22
#include "desktop-handles.h"
23
23
#include "selection.h"
 
24
#include "selection-chemistry.h"
24
25
#include "draw-anchor.h"
25
26
#include "message-stack.h"
26
27
#include "message-context.h"
36
37
#include "libnr/n-art-bpath.h"
37
38
#include "context-fns.h"
38
39
#include "sp-namedview.h"
 
40
#include "xml/repr.h"
 
41
#include "document.h"
 
42
#include "desktop-style.h"
 
43
#include "macros.h"
39
44
 
40
45
static void sp_pencil_context_class_init(SPPencilContextClass *klass);
41
46
static void sp_pencil_context_init(SPPencilContext *pc);
197
202
pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &bevent)
198
203
{
199
204
    gint ret = FALSE;
200
 
    if ( bevent.button == 1 ) {
 
205
    SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
 
206
    if ( bevent.button == 1  && !event_context->space_panning) {
201
207
 
202
208
        SPDrawContext *dc = SP_DRAW_CONTEXT (pc);
203
209
        SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
222
228
                break;
223
229
            default:
224
230
                /* Set first point of sequence */
 
231
                if (bevent.state & GDK_CONTROL_MASK) {
 
232
                    freehand_create_single_dot(event_context, p, "tools.freehand.pencil", bevent.state);
 
233
                    ret = true;
 
234
                    break;
 
235
                }
225
236
                if (anchor) {
226
237
                    p = anchor->dp;
227
238
                    desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
235
246
                        selection->clear();
236
247
                        desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
237
248
                        SnapManager const &m = desktop->namedview->snap_manager;
238
 
                        p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
 
249
                        p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
239
250
                    } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
240
251
                        desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
241
252
                    }
254
265
static gint
255
266
pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent)
256
267
{
 
268
    if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) {
 
269
        // mouse was accidentally moved during Ctrl+click;
 
270
        // ignore the motion and create a single point
 
271
        pc->is_drawing = false;
 
272
        return TRUE;
 
273
    }
257
274
    gint ret = FALSE;
258
275
    SPDesktop *const dt = pc->desktop;
259
276
 
260
 
    if (mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
261
 
        // allow middle-button scrolling
 
277
    SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
 
278
    if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
 
279
        // allow scrolling
262
280
        return FALSE;
263
281
    }
264
282
 
304
322
                    p = anchor->dp;
305
323
                } else if ((mevent.state & GDK_SHIFT_MASK) == 0) {
306
324
                    SnapManager const &m = dt->namedview->snap_manager;
307
 
                    p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
 
325
                    p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
308
326
                }
309
327
                if ( pc->npoints != 0 ) { // buttonpress may have happened before we entered draw context!
310
328
                    spdc_add_freehand_point(pc, p, mevent.state);
340
358
{
341
359
    gint ret = FALSE;
342
360
 
343
 
    if ( revent.button == 1 && pc->is_drawing) {
 
361
    SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
 
362
    if ( revent.button == 1 && pc->is_drawing && !event_context->space_panning) {
344
363
        SPDesktop *const dt = pc->desktop;
345
364
 
346
365
        pc->is_drawing = false;
356
375
            case SP_PENCIL_CONTEXT_IDLE:
357
376
                /* Releasing button in idle mode means single click */
358
377
                /* We have already set up start point/anchor in button_press */
359
 
                pc->state = SP_PENCIL_CONTEXT_ADDLINE;
 
378
                if (!(revent.state & GDK_CONTROL_MASK)) {
 
379
                    // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed
 
380
                    pc->state = SP_PENCIL_CONTEXT_ADDLINE;
 
381
                }
360
382
                ret = TRUE;
361
383
                break;
362
384
            case SP_PENCIL_CONTEXT_ADDLINE:
402
424
            pc->grab = NULL;
403
425
        }
404
426
 
 
427
        ret = TRUE;
 
428
    }
 
429
    return ret;
 
430
}
 
431
 
 
432
static void
 
433
pencil_cancel (SPPencilContext *const pc) 
 
434
{
 
435
    if (pc->grab) {
 
436
        /* Release grab now */
 
437
        sp_canvas_item_ungrab(pc->grab, 0);
405
438
        pc->grab = NULL;
406
 
        ret = TRUE;
407
 
    }
408
 
    return ret;
 
439
    }
 
440
 
 
441
    pc->is_drawing = false;
 
442
 
 
443
    pc->state = SP_PENCIL_CONTEXT_IDLE;
 
444
 
 
445
    sp_curve_reset(pc->red_curve);
 
446
    sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
 
447
    while (pc->green_bpaths) {
 
448
        gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
 
449
        pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
 
450
    }
 
451
    sp_curve_reset(pc->green_curve);
 
452
    if (pc->green_anchor) {
 
453
        pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
 
454
    }
 
455
 
 
456
    pc->_message_context->clear();
 
457
    pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
 
458
 
 
459
    sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
409
460
}
410
461
 
 
462
 
411
463
static gint
412
464
pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint const state)
413
465
{
422
474
                ret = TRUE;
423
475
            }
424
476
            break;
 
477
        case GDK_Escape:
 
478
            if (pc->npoints != 0) {
 
479
                // if drawing, cancel, otherwise pass it up for deselecting
 
480
                if (pc->is_drawing) {
 
481
                    pencil_cancel (pc);
 
482
                    ret = TRUE;
 
483
                }
 
484
            }
 
485
            break;
 
486
        case GDK_z:
 
487
        case GDK_Z:
 
488
            if (mod_ctrl_only(state) && pc->npoints != 0) {
 
489
                // if drawing, cancel, otherwise pass it up for undo
 
490
                if (pc->is_drawing) {
 
491
                    pencil_cancel (pc);
 
492
                    ret = TRUE;
 
493
                }
 
494
            }
 
495
            break;
 
496
        case GDK_g:
 
497
        case GDK_G:
 
498
            if (mod_shift_only(state)) {
 
499
                sp_selection_to_guides();
 
500
                ret = true;
 
501
            }
 
502
            break;
425
503
        default:
426
504
            break;
427
505
    }
504
582
}
505
583
 
506
584
static void
507
 
spdc_add_freehand_point(SPPencilContext *pc, NR::Point p, guint state)
 
585
spdc_add_freehand_point(SPPencilContext *pc, NR::Point p, guint /*state*/)
508
586
{
509
587
    g_assert( pc->npoints > 0 );
510
588
    g_return_if_fail(unsigned(pc->npoints) < G_N_ELEMENTS(pc->p));