Code

Nicer symbol for guide anchor
authorcilix42 <cilix42@users.sourceforge.net>
Mon, 26 Jan 2009 16:39:07 +0000 (16:39 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Mon, 26 Jan 2009 16:39:07 +0000 (16:39 +0000)
src/display/Makefile_insert
src/display/guideline.cpp
src/display/guideline.h
src/display/sp-ctrlpoint.cpp [new file with mode: 0644]
src/display/sp-ctrlpoint.h [new file with mode: 0644]

index 33adbb3086a5899108988a927daf0f19910f5e98..06d8c29ef1683f93f8b50379b5d8cd0fb5106d4c 100644 (file)
@@ -68,6 +68,8 @@ display_libspdisplay_a_SOURCES = \
        display/sp-canvas.h     \
        display/sp-ctrlline.cpp \
        display/sp-ctrlline.h \
+       display/sp-ctrlpoint.cpp        \
+       display/sp-ctrlpoint.h \
        display/sp-ctrlquadr.cpp \
        display/sp-ctrlquadr.h \
        display/nr-filter.cpp           \
index 5380eec45f849e4aa8d99a015a406218c495a3fe..f1b85b556b7f5188ffc3f0891ab25ac054202357 100644 (file)
@@ -20,7 +20,7 @@
 #include <2geom/transforms.h>
 #include "display-forward.h"
 #include "sp-canvas-util.h"
-#include "sp-ctrlquadr.h"
+#include "sp-ctrlpoint.h"
 #include "guideline.h"
 
 static void sp_guideline_class_init(SPGuideLineClass *c);
@@ -35,7 +35,6 @@ static double sp_guideline_point(SPCanvasItem *item, Geom::Point p, SPCanvasItem
 static void sp_guideline_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba);
 
 static SPCanvasItemClass *parent_class;
-static const double radius = 7.0;
 
 GType sp_guideline_get_type()
 {
@@ -89,13 +88,13 @@ static void sp_guideline_destroy(GtkObject *object)
     g_return_if_fail (object != NULL);
     g_return_if_fail (SP_IS_GUIDELINE (object));
     //g_return_if_fail (SP_GUIDELINE(object)->origin != NULL);
-    //g_return_if_fail (SP_IS_CTRLQUADR(SP_GUIDELINE(object)->origin));
+    //g_return_if_fail (SP_IS_CTRLPOINT(SP_GUIDELINE(object)->origin));
     
-    if (SP_GUIDELINE(object)->origin != NULL && SP_IS_CTRLQUADR(SP_GUIDELINE(object)->origin)) {
+    if (SP_GUIDELINE(object)->origin != NULL && SP_IS_CTRLPOINT(SP_GUIDELINE(object)->origin)) {
         gtk_object_destroy(GTK_OBJECT(SP_GUIDELINE(object)->origin));
     } else {
         // FIXME: This branch shouldn't be reached (although it seems to be harmless).
-        //g_error("Why can it be that gl->origin is not a valid SPCtrlQuadr?\n");
+        //g_error("Why can it be that gl->origin is not a valid SPCtrlPoint?\n");
     }
 
     GTK_OBJECT_CLASS(parent_class)->destroy(object);
@@ -187,16 +186,6 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
     }
 }
 
-static void set_origin_coords(SPCtrlQuadr *quadr, Geom::Point const &center, double const r)
-{
-    sp_ctrlquadr_set_coords(quadr,
-                            center + Geom::Point(-r,-r),
-                            center + Geom::Point(-r, r),
-                            center + Geom::Point( r, r),
-                            center + Geom::Point( r,-r));
-    
-}
-
 static void sp_guideline_update(SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
 {
     SPGuideLine *gl = SP_GUIDELINE(item);
@@ -208,7 +197,7 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Matrix const &affine,
     gl->point_on_line[Geom::X] = affine[4];
     gl->point_on_line[Geom::Y] = affine[5];
 
-    set_origin_coords(gl->origin, gl->point_on_line * affine.inverse(), radius);
+    sp_ctrlpoint_set_coords(gl->origin, gl->point_on_line * affine.inverse());
     sp_canvas_item_request_update(SP_CANVAS_ITEM (gl->origin));
 
     if (gl->is_horizontal()) {
@@ -239,10 +228,10 @@ static double sp_guideline_point(SPCanvasItem *item, Geom::Point p, SPCanvasItem
 SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal)
 {
     SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL);
-    SPCanvasItem *origin = sp_canvas_item_new(parent, SP_TYPE_CTRLQUADR, NULL);
+    SPCanvasItem *origin = sp_canvas_item_new(parent, SP_TYPE_CTRLPOINT, NULL);
 
     SPGuideLine *gl = SP_GUIDELINE(item);
-    SPCtrlQuadr *cp = SP_CTRLQUADR(origin);
+    SPCtrlPoint *cp = SP_CTRLPOINT(origin);
     gl->origin = cp;
 
     normal.normalize();
@@ -250,7 +239,7 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line,
     gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]);
     sp_guideline_set_position(gl, point_on_line);
 
-    set_origin_coords(cp, point_on_line, radius);
+    sp_ctrlpoint_set_coords(cp, point_on_line);
 
     return item;
 }
@@ -272,7 +261,7 @@ void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line)
 void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba)
 {
     gl->rgba = rgba;
-    sp_ctrlquadr_set_rgba32(gl->origin, rgba);
+    sp_ctrlpoint_set_color(gl->origin, rgba);
 
     sp_canvas_item_request_update(SP_CANVAS_ITEM(gl));
 }
index e1d5ecab2ec387223134d8bde0f02488e9f003f0..a6ce57113815dc0a2020aaa7440ccd263aa24de0 100644 (file)
 #define SP_GUIDELINE(o) (GTK_CHECK_CAST((o), SP_TYPE_GUIDELINE, SPGuideLine))
 #define SP_IS_GUIDELINE(o) (GTK_CHECK_TYPE((o), SP_TYPE_GUIDELINE))
 
-class SPCtrlQuadr;
+class SPCtrlPoint;
 
 struct SPGuideLine {
     SPCanvasItem item;
-    SPCtrlQuadr *origin; // unlike 'item', this is only held locally
+    SPCtrlPoint *origin; // unlike 'item', this is only held locally
 
     guint32 rgba;
 
diff --git a/src/display/sp-ctrlpoint.cpp b/src/display/sp-ctrlpoint.cpp
new file mode 100644 (file)
index 0000000..279d3f7
--- /dev/null
@@ -0,0 +1,190 @@
+#define __INKSCAPE_CTRLPOINT_C__
+
+/*
+ * Simple point
+ *
+ * Author:
+ *   Maximilian Albert <maximilian.albert@gmail.com>
+ *
+ * Copyright (C) 2008 Maximilian Albert
+ *
+ * Released under GNU GPL
+ */
+
+#include "display-forward.h"
+#include "sp-canvas-util.h"
+#include "sp-ctrlpoint.h"
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <color.h>
+#include "display/inkscape-cairo.h"
+
+
+static void sp_ctrlpoint_class_init (SPCtrlPointClass *klass);
+static void sp_ctrlpoint_init (SPCtrlPoint *ctrlpoint);
+static void sp_ctrlpoint_destroy (GtkObject *object);
+
+static void sp_ctrlpoint_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
+static void sp_ctrlpoint_render (SPCanvasItem *item, SPCanvasBuf *buf);
+
+static SPCanvasItemClass *parent_class;
+
+GType
+sp_ctrlpoint_get_type (void)
+{
+    static GType type = 0;
+    if (!type) {
+        GTypeInfo info = {
+            sizeof(SPCtrlPointClass),
+            NULL, NULL,
+            (GClassInitFunc) sp_ctrlpoint_class_init,
+            NULL, NULL,
+            sizeof(SPCtrlPoint),
+            0,
+            (GInstanceInitFunc) sp_ctrlpoint_init,
+            NULL
+        };
+        type = g_type_register_static(SP_TYPE_CANVAS_ITEM, "SPCtrlPoint", &info, (GTypeFlags)0);
+    }
+    return type;
+}
+
+static void
+sp_ctrlpoint_class_init (SPCtrlPointClass *klass)
+{
+    GtkObjectClass *object_class = (GtkObjectClass *) klass;
+    SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass;
+
+    parent_class = (SPCanvasItemClass*)gtk_type_class (SP_TYPE_CANVAS_ITEM);
+
+    object_class->destroy = sp_ctrlpoint_destroy;
+
+    item_class->update = sp_ctrlpoint_update;
+    item_class->render = sp_ctrlpoint_render;
+}
+
+static void
+sp_ctrlpoint_init (SPCtrlPoint *ctrlpoint)
+{
+    ctrlpoint->rgba = 0x0000ff7f;
+    ctrlpoint->pt[Geom::X] = ctrlpoint->pt[Geom::Y] = 0.0;
+    ctrlpoint->item=NULL;
+    ctrlpoint->radius = 2;
+}
+
+static void
+sp_ctrlpoint_destroy (GtkObject *object)
+{
+    g_return_if_fail (object != NULL);
+    g_return_if_fail (SP_IS_CTRLPOINT (object));
+
+    SPCtrlPoint *ctrlpoint = SP_CTRLPOINT (object);
+
+    ctrlpoint->item=NULL;
+
+    if (GTK_OBJECT_CLASS (parent_class)->destroy)
+        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+
+static void
+sp_ctrlpoint_render (SPCanvasItem *item, SPCanvasBuf *buf)
+{
+    SPCtrlPoint *cp = SP_CTRLPOINT (item);
+
+    if (!buf->ct)
+        return;
+
+    sp_canvas_prepare_buffer (buf);
+
+    guint32 rgba = cp->rgba;
+    cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
+
+    cairo_set_line_width(buf->ct, 1);
+    cairo_new_path(buf->ct);
+
+    Geom::Point pt = cp->pt * cp->affine;
+
+    cairo_arc(buf->ct, pt[Geom::X] - buf->rect.x0, pt[Geom::Y] - buf->rect.y0, cp->radius, 0.0, 2 * M_PI);
+    cairo_stroke(buf->ct);
+}
+
+static void
+sp_ctrlpoint_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
+{
+    SPCtrlPoint *cp = SP_CTRLPOINT (item);
+
+    sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
+
+    if (parent_class->update)
+        (* parent_class->update) (item, affine, flags);
+
+    sp_canvas_item_reset_bounds (item);
+
+    cp->affine = affine;
+
+    Geom::Point pt = cp->pt * affine;
+
+    item->x1 = pt[Geom::X] - cp->radius;
+    item->y1 = pt[Geom::Y] - cp->radius;
+    item->x2 = pt[Geom::X] + cp->radius;
+    item->y2 = pt[Geom::Y] + cp->radius;
+
+    sp_canvas_request_redraw (item->canvas,
+                              (int)item->x1 - 15, (int)item->y1 - 15,
+                              (int)item->x1 + 15, (int)item->y1 + 15);
+}
+
+void
+sp_ctrlpoint_set_color (SPCtrlPoint *cp, guint32 rgba)
+{
+    g_return_if_fail (cp != NULL);
+    g_return_if_fail (SP_IS_CTRLPOINT (cp));
+
+    if (rgba != cp->rgba) {
+        SPCanvasItem *item;
+        cp->rgba = rgba;
+        item = SP_CANVAS_ITEM (cp);
+        sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
+    }
+}
+
+#define EPSILON 1e-6
+#define DIFFER(a,b) (fabs ((a) - (b)) > EPSILON)
+
+void
+sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const gdouble x, const gdouble y)
+{
+    g_return_if_fail (cp != NULL);
+    g_return_if_fail (SP_IS_CTRLPOINT (cp));
+
+    if (DIFFER (x, cp->pt[Geom::X]) || DIFFER (y, cp->pt[Geom::Y])) {
+        cp->pt[Geom::X] = x;
+        cp->pt[Geom::Y] = y;
+        sp_canvas_item_request_update (SP_CANVAS_ITEM (cp));
+    }
+}
+
+void
+sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const Geom::Point pt)
+{
+    sp_ctrlpoint_set_coords(cp, pt[Geom::X], pt[Geom::Y]);
+}
+
+void
+sp_ctrlpoint_set_radius (SPCtrlPoint *cp, const double r)
+{
+    cp->radius = r;
+}
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/display/sp-ctrlpoint.h b/src/display/sp-ctrlpoint.h
new file mode 100644 (file)
index 0000000..67440c4
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef __INKSCAPE_CTRLPOINT_H__
+#define __INKSCAPE_CTRLPOINT_H__
+
+/*
+ * A simple point
+ *
+ * Author:
+ *   Maximilian Albert <maximilian.albert@gmail.com>
+ *
+ * Copyright (C) 2008 Maximilian Albert
+ *
+ * Released under GNU GPL
+ */
+
+#include "sp-canvas.h"
+
+struct SPItem;
+
+#define SP_TYPE_CTRLPOINT (sp_ctrlpoint_get_type ())
+#define SP_CTRLPOINT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_CTRLPOINT, SPCtrlPoint))
+#define SP_IS_CTRLPOINT(obj) (GTK_CHECK_TYPE ((obj), SP_TYPE_CTRLPOINT))
+
+struct SPCtrlPoint : public SPCanvasItem{
+    SPItem *item;  // the item to which this line belongs in some sense; may be NULL for some users
+    guint32 rgba;
+    Geom::Point pt;
+    Geom::Matrix affine;
+    double radius;
+};
+struct SPCtrlPointClass : public SPCanvasItemClass{};
+
+GType sp_ctrlpoint_get_type (void);
+
+void sp_ctrlpoint_set_color (SPCtrlPoint *cp, guint32 rgba);
+void sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const gdouble x, const gdouble y);
+void sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const Geom::Point pt);
+void sp_ctrlpoint_set_radius (SPCtrlPoint *cp, const double r);
+
+
+
+#endif
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :