diff --git a/src/star-context.cpp b/src/star-context.cpp
index 74b252860ee13c083eec82d085e8abb5f9573f9b..97577bcbae0b0bc053c790fa54a8952bc9eb7d79 100644 (file)
--- a/src/star-context.cpp
+++ b/src/star-context.cpp
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <cstring>
+#include <string>
#include <gdk/gdkkeysyms.h>
#include "desktop-style.h"
#include "message-context.h"
#include "pixmaps/cursor-star.xpm"
-#include "pixmaps/cursor-star.pixbuf"
#include "sp-metrics.h"
#include <glibmm/i18n.h>
#include "prefs-utils.h"
SPEventContext *event_context = SP_EVENT_CONTEXT (star_context);
event_context->cursor_shape = cursor_star_xpm;
- event_context->cursor_pixbuf = gdk_pixbuf_new_from_inline(
- -1,
- cursor_star_pixbuf,
- FALSE,
- NULL);
event_context->hot_x = 4;
event_context->hot_y = 4;
event_context->xp = 0;
sc->sel_changed_connection.~connection();
if (ec->shape_knot_holder) {
- sp_knot_holder_destroy (ec->shape_knot_holder);
+ delete ec->shape_knot_holder;
ec->shape_knot_holder = NULL;
}
@@ -175,7 +174,7 @@ sp_star_context_selection_changed (Inkscape::Selection * selection, gpointer dat
SPEventContext *ec = SP_EVENT_CONTEXT (sc);
if (ec->shape_knot_holder) { // desktroy knotholder
- sp_knot_holder_destroy (ec->shape_knot_holder);
+ delete ec->shape_knot_holder;
ec->shape_knot_holder = NULL;
}
@@ -275,24 +274,30 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
switch (event->type) {
case GDK_BUTTON_PRESS:
- if (event->button.button == 1) {
+ if (event->button.button == 1 && !event_context->space_panning) {
dragging = TRUE;
sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
-
- SnapManager const &m = desktop->namedview->snap_manager;
- sc->center = m.freeSnap(Inkscape::Snapper::SNAP_POINT, sc->center, sc->item).getPoint();
+
+ /* Snap center */
+ SnapManager &m = desktop->namedview->snap_manager;
+ m.setup(desktop, true);
+ Geom::Point pt2g = to_2geom(sc->center);
+ m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g);
+ sc->center = from_2geom(pt2g);
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
- GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK,
+ GDK_POINTER_MOTION_MASK |
+ GDK_POINTER_MOTION_HINT_MASK |
+ GDK_BUTTON_PRESS_MASK,
NULL, event->button.time);
ret = TRUE;
}
break;
case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ if (dragging && (event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) {
if ( event_context->within_tolerance
&& ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
@@ -305,14 +310,18 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
event_context->within_tolerance = false;
NR::Point const motion_w(event->motion.x, event->motion.y);
- NR::Point const motion_dt(event_context->desktop->w2d(motion_w));
+ NR::Point motion_dt(desktop->w2d(motion_w));
+
sp_star_drag (sc, motion_dt, event->motion.state);
+
+ gobble_motion_events(GDK_BUTTON1_MASK);
+
ret = TRUE;
}
break;
case GDK_BUTTON_RELEASE:
event_context->xp = event_context->yp = 0;
- if (event->button.button == 1) {
+ if (event->button.button == 1 && !event_context->space_panning) {
dragging = FALSE;
if (!event_context->within_tolerance) {
// we've been dragging, finish the star
@@ -366,6 +375,21 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
case GDK_Escape:
sp_desktop_selection(desktop)->clear();
//TODO: make dragging escapable by Esc
+ break;
+
+ case GDK_space:
+ if (dragging) {
+ sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
+ event->button.time);
+ dragging = false;
+ if (!event_context->within_tolerance) {
+ // we've been dragging, finish the rect
+ sp_star_finish(sc);
+ }
+ // do not return true, so that space would work switching to selector
+ }
+ break;
+
default:
break;
}
}
/* Create object */
- Inkscape::XML::Node *repr = sp_repr_new("svg:path");
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(sc));
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
repr->setAttribute("sodipodi:type", "star");
/* Set style */
Inkscape::GC::release(repr);
sc->item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
sc->item->updateRepr();
- }
- NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center);
- NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p);
+ sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
+ }
/* Snap corner point with no constraints */
- SnapManager const &m = desktop->namedview->snap_manager;
- p1 = m.freeSnap(Inkscape::Snapper::SNAP_POINT, p1, sc->item).getPoint();
-
+ SnapManager &m = desktop->namedview->snap_manager;
+ m.setup(desktop, true, sc->item);
+ Geom::Point pt2g = to_2geom(p);
+ m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g);
+
+ Geom::Point const p0 = to_2geom(sp_desktop_dt2root_xy_point(desktop, sc->center));
+ Geom::Point const p1 = to_2geom(sp_desktop_dt2root_xy_point(desktop, from_2geom(pt2g)));
+
SPStar *star = SP_STAR(sc->item);
double const sides = (gdouble) sc->magnitude;
- NR::Point const d = p1 - p0;
- NR::Coord const r1 = NR::L2(d);
- double arg1 = atan2(d);
+ Geom::Point const d = p1 - p0;
+ Geom::Coord const r1 = Geom::L2(d);
+ double arg1 = atan2(from_2geom(d));
if (state & GDK_CONTROL_MASK) {
/* Snap angle */
arg1 = sp_round(arg1, M_PI / snaps);
}
- sp_star_position_set(star, sc->magnitude, p0, r1, r1 * sc->proportion,
+ sp_star_position_set(star, sc->magnitude, from_2geom(p0), r1, r1 * sc->proportion,
arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized);
/* status text */
GString *rads = SP_PX_TO_METRIC_STRING(r1, desktop->namedview->getDefaultMetric());
- sc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
+ sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE,
( sc->isflatsided?
_("<b>Polygon</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle")
: _("<b>Star</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle") ),
sp_shape_set_shape(SP_SHAPE(sc->item));
- object->updateRepr(NULL, SP_OBJECT_WRITE_EXT);
+ object->updateRepr(SP_OBJECT_WRITE_EXT);
+
+ sp_canvas_end_forced_full_redraws(desktop->canvas);
sp_desktop_selection(desktop)->set(sc->item);
sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
- /* TODO: annotate */ "star-context.cpp:474");
+ _("Create star"));
sc->item = NULL;
}