Code

changes to use RegisteredTransformedPoint as widget for LPE point. not complete
[inkscape.git] / src / star-context.cpp
index 74b252860ee13c083eec82d085e8abb5f9573f9b..cee03b4b1fbea8906f704cb7b470ab38631d9dea 100644 (file)
  * 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>
 
@@ -31,7 +36,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 +100,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 +274,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 +291,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 +304,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 +372,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 +432,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 */
@@ -421,6 +443,8 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
         Inkscape::GC::release(repr);
         sc->item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
         sc->item->updateRepr();
+
+        sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
     }
 
     NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center);
@@ -428,7 +452,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);
 
@@ -447,7 +471,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") ),
@@ -467,11 +491,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;
     }