51
51
static void sp_star_context_dispose (GObject *object);
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);
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);
60
60
static SPEventContextClass * parent_class;
108
108
event_context->within_tolerance = false;
109
109
event_context->item_to_select = NULL;
111
event_context->shape_repr = NULL;
112
event_context->shape_knot_holder = NULL;
114
111
star_context->item = NULL;
116
113
star_context->magnitude = 5;
131
128
sc->sel_changed_connection.disconnect();
132
129
sc->sel_changed_connection.~connection();
134
if (ec->shape_knot_holder) {
135
sp_knot_holder_destroy (ec->shape_knot_holder);
136
ec->shape_knot_holder = NULL;
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);
131
delete ec->shape_editor;
132
ec->shape_editor = NULL;
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);
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 */
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);
176
if (ec->shape_knot_holder) { // desktroy knotholder
177
sp_knot_holder_destroy (ec->shape_knot_holder);
178
ec->shape_knot_holder = NULL;
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);
157
ec->shape_editor->unset_item(SH_KNOTHOLDER);
187
158
SPItem *item = selection->singleItem();
189
ec->shape_knot_holder = sp_item_knot_holder (item, ec->desktop);
190
Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR (item);
192
ec->shape_repr = shape_repr;
193
Inkscape::GC::anchor(shape_repr);
194
sp_repr_add_listener (shape_repr, &ec_shape_repr_events, ec);
159
ec->shape_editor->set_item(item, SH_KNOTHOLDER);
210
173
sp_event_context_read (ec, "rounded");
211
174
sp_event_context_read (ec, "randomized");
176
ec->shape_editor = new ShapeEditor(ec->desktop);
178
SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
180
ec->shape_editor->set_item(item, SH_KNOTHOLDER);
213
183
Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
215
SPItem *item = selection->singleItem();
217
ec->shape_knot_holder = sp_item_knot_holder (item, ec->desktop);
218
Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR (item);
220
ec->shape_repr = shape_repr;
221
Inkscape::GC::anchor(shape_repr);
222
sp_repr_add_listener (shape_repr, &ec_shape_repr_events, ec);
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));
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();
233
if (prefs_get_int_attribute("tools.shapes", "gradientdrag", 0) != 0) {
192
if (prefs->getBool("/tools/shapes/gradientdrag")) {
234
193
ec->enableGrDrag();
241
sp_star_context_set (SPEventContext *ec, const gchar *key, const gchar *val)
200
sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val)
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;
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();
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();
266
222
SPDesktop *desktop = event_context->desktop;
267
223
Inkscape::Selection *selection = sp_desktop_selection (desktop);
224
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
269
226
SPStarContext *sc = SP_STAR_CONTEXT (event_context);
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);
273
230
gint ret = FALSE;
277
234
if (event->button.button == 1 && !event_context->space_panning) {
237
sp_event_context_snap_window_open(event_context);
281
239
sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
283
SnapManager const &m = desktop->namedview->snap_manager;
284
sc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, sc->center, sc->item).getPoint();
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);
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);
303
267
// motion notify coordinates as given (no snapping back to origin)
304
268
event_context->within_tolerance = false;
306
NR::Point const motion_w(event->motion.x, event->motion.y);
307
NR::Point motion_dt(event_context->desktop->w2d(motion_w));
309
SnapManager const &m = desktop->namedview->snap_manager;
310
motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, sc->item).getPoint();
270
Geom::Point const motion_w(event->motion.x, event->motion.y);
271
Geom::Point motion_dt(desktop->w2d(motion_w));
312
273
sp_star_drag (sc, motion_dt, event->motion.state);
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);
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)
424
387
SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop;
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);
437
401
repr->setAttribute("sodipodi:type", "star");
440
sp_desktop_apply_style_tool(desktop, repr, "tools.shapes.star", false);
404
sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/star", false);
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();
447
411
sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
450
NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center);
451
NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p);
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);
420
Geom::Point const p0 = desktop->dt2doc(sc->center);
421
Geom::Point const p1 = desktop->dt2doc(pt2g);
457
423
SPStar *star = SP_STAR(sc->item);
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));
464
430
if (state & GDK_CONTROL_MASK) {
466
432
arg1 = sp_round(arg1, M_PI / snaps);
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);
472
438
/* status text */
496
462
sp_canvas_end_forced_full_redraws(desktop->canvas);
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"));