Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / display / sodipodi-ctrl.cpp
index db199d3a51e2421a0d6a72fe1414689506f2420f..a63f570cf12457876b17eb66226d788a6bc62b72 100644 (file)
@@ -8,9 +8,10 @@
  *
  */
 
+#include <2geom/transforms.h>
 #include "sp-canvas-util.h"
-#include "display-forward.h"
 #include "sodipodi-ctrl.h"
+#include "libnr/nr-pixops.h"
 
 enum {
     ARG_0,
@@ -31,10 +32,10 @@ static void sp_ctrl_init (SPCtrl *ctrl);
 static void sp_ctrl_destroy (GtkObject *object);
 static void sp_ctrl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id);
 
-static void sp_ctrl_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
+static void sp_ctrl_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
 static void sp_ctrl_render (SPCanvasItem *item, SPCanvasBuf *buf);
 
-static double sp_ctrl_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
+static double sp_ctrl_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item);
 
 
 static SPCanvasItemClass *parent_class;
@@ -109,6 +110,8 @@ sp_ctrl_init (SPCtrl *ctrl)
     ctrl->box.x0 = ctrl->box.y0 = ctrl->box.x1 = ctrl->box.y1 = 0;
     ctrl->cache = NULL;
     ctrl->pixbuf = NULL;
+
+    ctrl->_point = Geom::Point(0,0);
 }
 
 static void
@@ -121,6 +124,11 @@ sp_ctrl_destroy (GtkObject *object)
 
     ctrl = SP_CTRL (object);
 
+    if (ctrl->cache) {
+        g_free(ctrl->cache);
+        ctrl->cache = NULL;
+    }
+
     if (GTK_OBJECT_CLASS (parent_class)->destroy)
         (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 }
@@ -202,7 +210,7 @@ sp_ctrl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
 }
 
 static void
-sp_ctrl_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
+sp_ctrl_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
 {
     SPCtrl *ctrl;
     gint x, y;
@@ -272,14 +280,14 @@ sp_ctrl_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags
 }
 
 static double
-sp_ctrl_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item)
+sp_ctrl_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item)
 {
     SPCtrl *ctrl = SP_CTRL (item);
 
     *actual_item = item;
 
-    double const x = p[NR::X];
-    double const y = p[NR::Y];
+    double const x = p[Geom::X];
+    double const y = p[Geom::Y];
 
     if ((x >= ctrl->box.x0) && (x <= ctrl->box.x1) && (y >= ctrl->box.y0) && (y <= ctrl->box.y1)) return 0.0;
 
@@ -313,11 +321,13 @@ sp_ctrl_build_cache (SPCtrl *ctrl)
 
     side = (ctrl->span * 2 +1);
     c = ctrl->span ;
-    g_free (ctrl->cache);
     size = (side) * (side) * 4;
-    ctrl->cache = (guchar*)g_malloc (size);
     if (side < 2) return;
 
+    if (ctrl->cache)
+        g_free (ctrl->cache);
+    ctrl->cache = (guchar*)g_malloc (size);
+
     switch (ctrl->shape) {
         case SP_CTRL_SHAPE_SQUARE:
             p = ctrl->cache;
@@ -481,9 +491,9 @@ sp_ctrl_build_cache (SPCtrl *ctrl)
 }
 
 // composite background, foreground, alpha for xor mode
-#define COMPOSE_X(b,f,a) ( ( ((guchar) b) * ((guchar) (0xff - a)) + ((guchar) ((b ^ ~f) + b/4 - (b>127? 63 : 0))) * ((guchar) a) ) / 0xff )
+#define COMPOSE_X(b,f,a) ( FAST_DIVIDE<255>( ((guchar) b) * ((guchar) (0xff - a)) + ((guchar) ((b ^ ~f) + b/4 - (b>127? 63 : 0))) * ((guchar) a) ) )
 // composite background, foreground, alpha for color mode
-#define COMPOSE_N(b,f,a) ( ( ((guchar) b) * ((guchar) (0xff - a)) + ((guchar) f) * ((guchar) a) ) / 0xff )
+#define COMPOSE_N(b,f,a) ( FAST_DIVIDE<255>( ((guchar) b) * ((guchar) (0xff - a)) + ((guchar) f) * ((guchar) a) ) )
 
 static void
 sp_ctrl_render (SPCanvasItem *item, SPCanvasBuf *buf)
@@ -540,9 +550,12 @@ sp_ctrl_render (SPCanvasItem *item, SPCanvasBuf *buf)
     ctrl->shown = TRUE;
 }
 
-void SPCtrl::moveto (NR::Point const p) {
-    sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (this), NR::Matrix(NR::translate (p)));
-    _moved = true;
+void SPCtrl::moveto (Geom::Point const p) {
+    if (p != _point) {
+        sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (this), Geom::Matrix(Geom::Translate (p)));
+        _moved = true;
+    }
+    _point = p;
 }
 
 
@@ -555,4 +568,4 @@ void SPCtrl::moveto (NR::Point const p) {
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :