Code

angled guidelines: create angled line when dragging from edge of rulers
[inkscape.git] / src / star-context.cpp
index 3147dd213fc8d596657b070da5d088e6b3665942..73e230deb57610193b1045f07ba73da3b11a7cc7 100644 (file)
@@ -31,7 +31,6 @@
 #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"
@@ -96,11 +95,6 @@ sp_star_context_init (SPStarContext * star_context)
     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;
@@ -275,14 +269,14 @@ 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();
+            sc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, sc->center, sc->item).getPoint();
 
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                 GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -292,7 +286,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
         }
         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 +299,21 @@ 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(event_context->desktop->w2d(motion_w));
+            
+            SnapManager const &m = desktop->namedview->snap_manager;
+            motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, sc->item).getPoint();
+            
             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 +367,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;
         }
@@ -411,7 +427,8 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
         }
 
         /* 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 */
@@ -430,7 +447,7 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
 
     /* Snap corner point with no constraints */
     SnapManager const &m = desktop->namedview->snap_manager;
-    p1 = m.freeSnap(Inkscape::Snapper::SNAP_POINT, p1, sc->item).getPoint();
+    p1 = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1, sc->item).getPoint();
 
     SPStar *star = SP_STAR(sc->item);
 
@@ -449,7 +466,7 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
 
     /* 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&#176;; with <b>Ctrl</b> to snap angle")
                                  : _("<b>Star</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle") ),
@@ -469,13 +486,13 @@ sp_star_finish (SPStarContext * sc)
 
         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;
     }