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

« back to all changes in this revision

Viewing changes to src/star-context.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "sp-namedview.h"
31
31
#include "selection.h"
32
32
#include "desktop-handles.h"
33
 
#include "desktop-affine.h"
34
33
#include "snap.h"
35
34
#include "desktop.h"
36
35
#include "desktop-style.h"
38
37
#include "pixmaps/cursor-star.xpm"
39
38
#include "sp-metrics.h"
40
39
#include <glibmm/i18n.h>
41
 
#include "prefs-utils.h"
 
40
#include "preferences.h"
42
41
#include "xml/repr.h"
43
42
#include "xml/node-event-vector.h"
44
43
#include "object-edit.h"
45
44
#include "context-fns.h"
 
45
#include "shape-editor.h"
46
46
 
47
47
#include "star-context.h"
48
48
 
51
51
static void sp_star_context_dispose (GObject *object);
52
52
 
53
53
static void sp_star_context_setup (SPEventContext *ec);
54
 
static void sp_star_context_set (SPEventContext *ec, const gchar *key, const gchar *val);
 
54
static void sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val);
55
55
static gint sp_star_context_root_handler (SPEventContext *ec, GdkEvent *event);
56
56
 
57
 
static void sp_star_drag (SPStarContext * sc, NR::Point p, guint state);
 
57
static void sp_star_drag (SPStarContext * sc, Geom::Point p, guint state);
58
58
static void sp_star_finish (SPStarContext * sc);
59
59
 
60
60
static SPEventContextClass * parent_class;
108
108
    event_context->within_tolerance = false;
109
109
    event_context->item_to_select = NULL;
110
110
 
111
 
    event_context->shape_repr = NULL;
112
 
    event_context->shape_knot_holder = NULL;
113
 
 
114
111
    star_context->item = NULL;
115
112
 
116
113
    star_context->magnitude = 5;
131
128
    sc->sel_changed_connection.disconnect();
132
129
    sc->sel_changed_connection.~connection();
133
130
 
134
 
    if (ec->shape_knot_holder) {
135
 
        sp_knot_holder_destroy (ec->shape_knot_holder);
136
 
        ec->shape_knot_holder = NULL;
137
 
    }
138
 
 
139
 
    if (ec->shape_repr) { // remove old listener
140
 
        sp_repr_remove_listener_by_data (ec->shape_repr, ec);
141
 
        Inkscape::GC::release(ec->shape_repr);
142
 
        ec->shape_repr = 0;
143
 
    }
 
131
    delete ec->shape_editor;
 
132
    ec->shape_editor = NULL;
144
133
 
145
134
    /* fixme: This is necessary because we do not grab */
146
135
    if (sc->item) sp_star_finish (sc);
152
141
    G_OBJECT_CLASS (parent_class)->dispose (object);
153
142
}
154
143
 
155
 
static Inkscape::XML::NodeEventVector ec_shape_repr_events = {
156
 
    NULL, /* child_added */
157
 
    NULL, /* child_removed */
158
 
    ec_shape_event_attr_changed,
159
 
    NULL, /* content_changed */
160
 
    NULL  /* order_changed */
161
 
};
162
 
 
163
144
/**
164
145
\brief  Callback that processes the "changed" signal on the selection;
165
146
destroys old and creates new knotholder
173
154
    SPStarContext *sc = SP_STAR_CONTEXT (data);
174
155
    SPEventContext *ec = SP_EVENT_CONTEXT (sc);
175
156
 
176
 
    if (ec->shape_knot_holder) { // desktroy knotholder
177
 
        sp_knot_holder_destroy (ec->shape_knot_holder);
178
 
        ec->shape_knot_holder = NULL;
179
 
    }
180
 
 
181
 
    if (ec->shape_repr) { // remove old listener
182
 
        sp_repr_remove_listener_by_data (ec->shape_repr, ec);
183
 
        Inkscape::GC::release(ec->shape_repr);
184
 
        ec->shape_repr = 0;
185
 
    }
186
 
 
 
157
    ec->shape_editor->unset_item(SH_KNOTHOLDER);
187
158
    SPItem *item = selection->singleItem();
188
 
    if (item) {
189
 
        ec->shape_knot_holder = sp_item_knot_holder (item, ec->desktop);
190
 
        Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR (item);
191
 
        if (shape_repr) {
192
 
            ec->shape_repr = shape_repr;
193
 
            Inkscape::GC::anchor(shape_repr);
194
 
            sp_repr_add_listener (shape_repr, &ec_shape_repr_events, ec);
195
 
        }
196
 
    }
 
159
    ec->shape_editor->set_item(item, SH_KNOTHOLDER);
197
160
}
198
161
 
199
162
static void
210
173
    sp_event_context_read (ec, "rounded");
211
174
    sp_event_context_read (ec, "randomized");
212
175
 
 
176
    ec->shape_editor = new ShapeEditor(ec->desktop);
 
177
 
 
178
    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
 
179
    if (item) {
 
180
        ec->shape_editor->set_item(item, SH_KNOTHOLDER);
 
181
    }
 
182
 
213
183
    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
214
 
 
215
 
    SPItem *item = selection->singleItem();
216
 
        if (item) {
217
 
            ec->shape_knot_holder = sp_item_knot_holder (item, ec->desktop);
218
 
            Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR (item);
219
 
            if (shape_repr) {
220
 
                ec->shape_repr = shape_repr;
221
 
                Inkscape::GC::anchor(shape_repr);
222
 
                sp_repr_add_listener (shape_repr, &ec_shape_repr_events, ec);
223
 
            }
224
 
        }
225
 
 
226
184
    sc->sel_changed_connection.disconnect();
227
185
    sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_star_context_selection_changed), (gpointer)sc));
228
186
 
229
 
    if (prefs_get_int_attribute("tools.shapes", "selcue", 0) != 0) {
 
187
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
188
    if (prefs->getBool("/tools/shapes/selcue")) {
230
189
        ec->enableSelectionCue();
231
190
    }
232
191
 
233
 
    if (prefs_get_int_attribute("tools.shapes", "gradientdrag", 0) != 0) {
 
192
    if (prefs->getBool("/tools/shapes/gradientdrag")) {
234
193
        ec->enableGrDrag();
235
194
    }
236
195
 
238
197
}
239
198
 
240
199
static void
241
 
sp_star_context_set (SPEventContext *ec, const gchar *key, const gchar *val)
 
200
sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val)
242
201
{
243
202
    SPStarContext *sc = SP_STAR_CONTEXT (ec);
244
 
    if (!strcmp (key, "magnitude")) {
245
 
        sc->magnitude = (val) ? atoi (val) : 5;
246
 
        sc->magnitude = CLAMP (sc->magnitude, 3, 1024);
247
 
    } else if (!strcmp (key, "proportion")) {
248
 
        sc->proportion = (val) ? g_ascii_strtod (val, NULL) : 0.5;
249
 
        sc->proportion = CLAMP (sc->proportion, 0.01, 2.0);
250
 
    } else if (!strcmp (key, "isflatsided")) {
251
 
        if (val && !strcmp(val, "true"))
252
 
            sc->isflatsided = true;
253
 
        else
254
 
            sc->isflatsided = false;
255
 
    } else if (!strcmp (key, "rounded")) {
256
 
        sc->rounded = (val) ? g_ascii_strtod (val, NULL) : 0.0;
257
 
    } else if (!strcmp (key, "randomized")) {
258
 
        sc->randomized = (val) ? g_ascii_strtod (val, NULL) : 0.0;
 
203
    Glib::ustring path = val->getEntryName();
 
204
 
 
205
    if (path == "magnitude") {
 
206
        sc->magnitude = CLAMP (val->getInt(5), 3, 1024);
 
207
    } else if (path == "proportion") {
 
208
        sc->proportion = CLAMP (val->getDouble(0.5), 0.01, 2.0);
 
209
    } else if (path == "isflatsided") {
 
210
        sc->isflatsided = val->getBool();
 
211
    } else if (path == "rounded") {
 
212
        sc->rounded = val->getDouble();
 
213
    } else if (path == "randomized") {
 
214
        sc->randomized = val->getDouble();
259
215
    }
260
216
}
261
217
 
265
221
 
266
222
    SPDesktop *desktop = event_context->desktop;
267
223
    Inkscape::Selection *selection = sp_desktop_selection (desktop);
 
224
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
268
225
 
269
226
    SPStarContext *sc = SP_STAR_CONTEXT (event_context);
270
227
 
271
 
    event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100);
 
228
    event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
272
229
 
273
230
    gint ret = FALSE;
274
231
 
277
234
        if (event->button.button == 1 && !event_context->space_panning) {
278
235
 
279
236
            dragging = TRUE;
 
237
            sp_event_context_snap_window_open(event_context);
280
238
 
281
239
            sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
282
240
 
283
 
            SnapManager const &m = desktop->namedview->snap_manager;
284
 
            sc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, sc->center, sc->item).getPoint();
 
241
            /* Snap center */
 
242
            SnapManager &m = desktop->namedview->snap_manager;
 
243
            m.setup(desktop, true);
 
244
            Geom::Point pt2g = to_2geom(sc->center);
 
245
            m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g, Inkscape::SNAPSOURCE_HANDLE);
 
246
            sc->center = from_2geom(pt2g);
285
247
 
286
248
            sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
287
249
                                GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
288
 
                                GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK,
 
250
                                GDK_POINTER_MOTION_MASK |
 
251
                                GDK_POINTER_MOTION_HINT_MASK |
 
252
                                GDK_BUTTON_PRESS_MASK,
289
253
                                NULL, event->button.time);
290
254
            ret = TRUE;
291
255
        }
303
267
            // motion notify coordinates as given (no snapping back to origin)
304
268
            event_context->within_tolerance = false;
305
269
 
306
 
            NR::Point const motion_w(event->motion.x, event->motion.y);
307
 
            NR::Point motion_dt(event_context->desktop->w2d(motion_w));
308
 
            
309
 
            SnapManager const &m = desktop->namedview->snap_manager;
310
 
            motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, sc->item).getPoint();
311
 
            
 
270
            Geom::Point const motion_w(event->motion.x, event->motion.y);
 
271
            Geom::Point motion_dt(desktop->w2d(motion_w));
 
272
 
312
273
            sp_star_drag (sc, motion_dt, event->motion.state);
313
274
 
314
275
            gobble_motion_events(GDK_BUTTON1_MASK);
320
281
        event_context->xp = event_context->yp = 0;
321
282
        if (event->button.button == 1 && !event_context->space_panning) {
322
283
            dragging = FALSE;
 
284
            sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings
323
285
            if (!event_context->within_tolerance) {
324
286
                // we've been dragging, finish the star
325
287
                sp_star_finish (sc);
379
341
                sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
380
342
                                      event->button.time);
381
343
                dragging = false;
 
344
                sp_event_context_snap_window_closed(event_context);
382
345
                if (!event_context->within_tolerance) {
383
346
                    // we've been dragging, finish the rect
384
347
                    sp_star_finish(sc);
419
382
    return ret;
420
383
}
421
384
 
422
 
static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
 
385
static void sp_star_drag(SPStarContext *sc, Geom::Point p, guint state)
423
386
{
424
387
    SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop;
425
388
 
426
 
    int const snaps = prefs_get_int_attribute ("options.rotationsnapsperpi", "value", 12);
 
389
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
390
    int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
427
391
 
428
392
    if (!sc->item) {
429
393
 
437
401
        repr->setAttribute("sodipodi:type", "star");
438
402
 
439
403
        /* Set style */
440
 
        sp_desktop_apply_style_tool(desktop, repr, "tools.shapes.star", false);
 
404
        sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/star", false);
441
405
 
442
406
        sc->item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
443
407
        Inkscape::GC::release(repr);
444
 
        sc->item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
 
408
        sc->item->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
445
409
        sc->item->updateRepr();
446
410
 
447
411
        sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
448
412
    }
449
413
 
450
 
    NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center);
451
 
    NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p);
452
 
 
453
414
    /* Snap corner point with no constraints */
454
 
    SnapManager const &m = desktop->namedview->snap_manager;
455
 
    p1 = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1, sc->item).getPoint();
 
415
    SnapManager &m = desktop->namedview->snap_manager;
 
416
    m.setup(desktop, true, sc->item);
 
417
    Geom::Point pt2g = to_2geom(p);
 
418
    m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g, Inkscape::SNAPSOURCE_HANDLE);
 
419
 
 
420
    Geom::Point const p0 = desktop->dt2doc(sc->center);
 
421
    Geom::Point const p1 = desktop->dt2doc(pt2g);
456
422
 
457
423
    SPStar *star = SP_STAR(sc->item);
458
424
 
459
425
    double const sides = (gdouble) sc->magnitude;
460
 
    NR::Point const d = p1 - p0;
461
 
    NR::Coord const r1 = NR::L2(d);
462
 
    double arg1 = atan2(d);
 
426
    Geom::Point const d = p1 - p0;
 
427
    Geom::Coord const r1 = Geom::L2(d);
 
428
    double arg1 = atan2(from_2geom(d));
463
429
 
464
430
    if (state & GDK_CONTROL_MASK) {
465
431
        /* Snap angle */
466
432
        arg1 = sp_round(arg1, M_PI / snaps);
467
433
    }
468
434
 
469
 
    sp_star_position_set(star, sc->magnitude, p0, r1, r1 * sc->proportion,
 
435
    sp_star_position_set(star, sc->magnitude, from_2geom(p0), r1, r1 * sc->proportion,
470
436
                         arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized);
471
437
 
472
438
    /* status text */
496
462
        sp_canvas_end_forced_full_redraws(desktop->canvas);
497
463
 
498
464
        sp_desktop_selection(desktop)->set(sc->item);
499
 
        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, 
 
465
        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
500
466
                         _("Create star"));
501
467
 
502
468
        sc->item = NULL;