[Tomoe-cvs 847] CVS update: libtomoe-gtk/src

Back to archive index

Hiroyuki Ikezoe ikezo****@users*****
2006年 11月 22日 (水) 15:04:55 JST


Index: libtomoe-gtk/src/tomoe-canvas.c
diff -u libtomoe-gtk/src/tomoe-canvas.c:1.10 libtomoe-gtk/src/tomoe-canvas.c:1.11
--- libtomoe-gtk/src/tomoe-canvas.c:1.10	Tue Nov 21 20:17:22 2006
+++ libtomoe-gtk/src/tomoe-canvas.c	Wed Nov 22 15:04:55 2006
@@ -48,13 +48,16 @@
     GdkGC           *annotate_gc;
     GdkGC           *axis_gc;
     GdkPixmap       *pixmap;
+#if 0
     GList           *stroke;
     GList           *stroke_list;
+#endif
     GList           *candidates;
     gint             auto_find_time;
     guint            auto_find_id;
     TomoeContext    *context;
     TomoeGlyph      *preview;
+    TomoeGlyph      *glyph;
     gboolean         locked;
 };
 
@@ -82,8 +85,8 @@
                                                  gint               x,
                                                  gint               y);
 static void   tomoe_canvas_draw_line            (TomoeCanvas       *canvas,
-                                                 TomoePoint        *p1,
-                                                 TomoePoint        *p2,
+                                                 TomoePoint        *point1,
+                                                 TomoePoint        *point2,
                                                  gboolean           draw,
                                                  GdkColor          *color);
 static void   tomoe_canvas_draw_background      (TomoeCanvas       *canvas,
@@ -92,7 +95,7 @@
 static void   tomoe_canvas_resize               (TomoeCanvas       *canvas,
                                                  gdouble            x_rate,
                                                  gdouble            y_rate);
-static void   tomoe_canvas_position             (TomoeCanvas       *canvas,
+static void   tomoe_canvas_move_position        (TomoeCanvas       *canvas,
                                                  gint               dx,
                                                  gint               dy);
 
@@ -102,20 +105,24 @@
                                                  GList            **most_node);
 static GList *get_vertex                        (GList             *first_node,
                                                  GList             *last_node);
-static void   draw_stroke                       (GList             *stroke,
+static void   draw_stroke                       (GList             *points,
                                                  TomoeCanvas       *canvas,
-                                                 guint             *index);
+                                                 guint              index);
+#if 0
 static void   draw_preview_stroke               (TomoeCanvas       *canvas,
                                                  TomoeStroke       *stroke,
                                                  guint             *index);
-static void   draw_annotate                     (GList             *stroke,
+#endif
+static void   draw_annotate                     (GList             *points,
                                                  TomoeCanvas       *canvas,
                                                  guint              index,
                                                  GdkColor          *color);
+#if 0
 static void   draw_preview_annotate             (TomoeCanvas       *canvas,
                                                  TomoeStroke       *stroke,
                                                  guint              inde,
                                                  GdkColor          *color);
+#endif
 static void   on_size_allocate                  (GtkWidget         *widget,
                                                  GtkAllocation     *allocation,
                                                  gpointer           user_data);
@@ -221,12 +228,11 @@
     priv->annotate_gc       = NULL;
     priv->axis_gc           = NULL;
     priv->pixmap            = NULL;
-    priv->stroke            = NULL;
-    priv->stroke_list       = NULL;
     priv->candidates        = NULL;
     priv->auto_find_time    = 0;
     priv->auto_find_id      = 0;
     priv->preview           = NULL;
+    priv->glyph             = tomoe_glyph_new ();
     priv->locked            = FALSE;
 
     gtk_widget_get_size_request(GTK_WIDGET (canvas), &width, &height);
@@ -241,6 +247,7 @@
     instance_list = g_list_append (instance_list, (gpointer) canvas);
 }
 
+#if 0
 static void
 tomoe_canvas_free_stroke_list (TomoeCanvas *canvas)
 {
@@ -261,6 +268,7 @@
         priv->stroke_list = NULL;
     }
 }
+#endif
 
 static void
 tomoe_canvas_dispose (GObject *object)
@@ -300,12 +308,17 @@
         priv->candidates     = NULL;
     }
 
+    if (priv->glyph) {
+        g_object_unref (priv->glyph);
+        priv->glyph = NULL;
+    }
+
     if (priv->auto_find_id) {
         g_source_remove (priv->auto_find_id);
         priv->auto_find_id = 0;
     }
 
-    tomoe_canvas_free_stroke_list (canvas);
+    /* tomoe_canvas_free_stroke_list (canvas); */
 
     if (G_OBJECT_CLASS(tomoe_canvas_parent_class)->dispose)
         G_OBJECT_CLASS(tomoe_canvas_parent_class)->dispose(object);
@@ -398,25 +411,16 @@
     TomoeCanvas *canvas = TOMOE_CANVAS (widget);
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
     gboolean retval = FALSE;
-    GdkColor color;
-    color.red   = 0x8000;
-    color.green = 0x0000;
-    color.blue  = 0x0000;
+    //GdkColor color = { 0, 0x8000, 0x0000, 0x0000};
 
     if (priv->locked) return retval;
 
     if (event->button != 1)
         return retval;
-
-    if (!priv->stroke)
-        return retval;
-
-    draw_annotate (priv->stroke, canvas, g_list_length (priv->stroke_list) + 1, &color);
-
-    priv->stroke_list = g_list_append(priv->stroke_list,
-                                      priv->stroke);
-    priv->stroke = NULL;
-
+#if 0
+    tomoe_glyph_line_to (priv->glyph);
+    draw_annotate (canvas, tomoe_glyph_get_number_of_strokes (priv->glyph) + 1, &color);
+#endif
     g_signal_emit (G_OBJECT (widget), canvas_signals[STROKE_ADDED_SIGNAL], 0);
 
     if (priv->auto_find_id) {
@@ -445,9 +449,6 @@
 
     if (priv->locked) return retval;
 
-    if (!priv->stroke)
-        return retval;
-
     if (event->is_hint) {
         gdk_window_get_pointer(event->window, &x, &y, &state);
     } else {
@@ -457,79 +458,91 @@
     }
     
     if (state & GDK_BUTTON1_MASK && priv->pixmap) {
-        tomoe_canvas_append_point (canvas, x, y);
+        tomoe_glyph_line_to (priv->glyph, x, y);
+        /* tomoe_canvas_append_point (canvas, x, y); */
     }
 
     return retval;
 }
 
+static TomoeGlyph *
+create_sparse_glyph (TomoeCanvas *canvas)
+{
+    TomoeGlyph *g;
+    TomoeCanvasPriv *priv;
+    const GList *strokes, *list;
+
+    g_return_val_if_fail (TOMOE_IS_CANVAS (canvas), NULL);
+
+    priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
+    g = tomoe_glyph_new ();
+
+    strokes = tomoe_glyph_get_strokes (priv->glyph);
+    for (list = strokes; list; list = g_list_next (list)) {
+        GList *points = (GList *) list->data;
+        GList *point, *new_points;
+        TomoePoint *start_point = (TomoePoint *) points->data;
+
+        tomoe_glyph_move_to (g, start_point->x, start_point->y);
+    
+        new_points = g_list_prepend (get_vertex(points, g_list_last(points)),
+                                     points->data);
+    
+        for (point = new_points; point; point = g_list_next (point)) {
+            TomoePoint *p = (TomoePoint *) point->data;
+            gint x, y;
+            x = p->x * ((gdouble)TOMOE_CANVAS_DEFAULT_SIZE / priv->size);
+            y = p->y * ((gdouble)TOMOE_CANVAS_DEFAULT_SIZE / priv->size);
+            tomoe_glyph_line_to (g, x, y);
+        }
+    }
+
+    return g;
+}
+
 static void
 tomoe_canvas_real_find (TomoeCanvas *canvas)
 {
     TomoeCanvasPriv *priv;
     GtkWidget *widget = GTK_WIDGET (canvas);
-    GList *line;
-    TomoeGlyph g;
-    guint i, j;
-    GdkColor color;
-    color.red   = 0x8000;
-    color.green = 0x0000;
-    color.blue  = 0x0000;
+    const GList *strokes, *list;
+    TomoeGlyph *g;
+    GdkColor color = { 0, 0x8000, 0x0000, 0x0000};
 
     g_return_if_fail (TOMOE_IS_CANVAS (canvas));
 
     _init_gc (canvas);
     priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
 
-    g.stroke_num = g_list_length (priv->stroke_list);
-    g.strokes    = g_new0 (TomoeStroke, g.stroke_num);
+    /* create a new glyph which has more sparse points */
+    g = create_sparse_glyph (canvas);
 
-    for (i = 0, line = priv->stroke_list;
-         line;
-         i++, line = line->next)
-    {
-        GList *dots, *dot;
-        gint x, y, px, py;
-
-        dots = g_list_prepend (
-            get_vertex((GList*)line->data,
-                       (GList*)g_list_last((GList*)line->data)),
-            ((GList*)(line->data))->data);
-        px = py = -1;
-
-        g.strokes[i].point_num = g_list_length (dots);
-        g.strokes[i].points = g_new0 (TomoePoint, g.strokes[i].point_num);
-
-        for (j = 0, dot = dots; dot; j++, dot = dot->next) {
-            x = ((TomoePoint *)(dot->data))->x;
-            y = ((TomoePoint *)(dot->data))->y;
-
-            g.strokes[i].points[j].x = x
-                * ((gdouble)TOMOE_CANVAS_DEFAULT_SIZE / priv->size);
-            g.strokes[i].points[j].y = y
-                * ((gdouble)TOMOE_CANVAS_DEFAULT_SIZE / priv->size);
-
-            if (px != -1) {
-
-                gdk_draw_line(priv->pixmap,
-                              priv->adjust_line_gc,
-                              px, py, x, y);
+    /* draw thin red lines and annotations for sparse points */
+    strokes = tomoe_glyph_get_strokes (g);
+    for (list = strokes; list; list = g_list_next (list)) {
+        GList *points = (GList *) list->data;
+        GList *point;
+        guint i;
+        TomoePoint *pp = NULL;
+    
+        for (point = points, i = 0; point; point = g_list_next (point), i++) {
+            TomoePoint *p = (TomoePoint *) point->data;
+            if (pp) {
+                tomoe_canvas_draw_line (canvas, pp, p, FALSE, &color);
+            } else {
+                draw_annotate (points, canvas, i, &color);
             }
-            px = x;
-            py = y;
+            pp = p;
         }
-
-        g_list_free (dots);
     }
 
     if (priv->candidates) {
         _g_list_free_all (priv->candidates, g_object_unref);
         priv->candidates     = NULL;
     }
-    priv->candidates = tomoe_context_search_by_strokes (priv->context, &g);
-    for (i = 0; i < g.stroke_num; i++)
-        g_free (g.strokes[i].points);
-    g_free (g.strokes);
+    priv->candidates = tomoe_context_search_by_strokes (priv->context, g);
+
+    g_object_unref (g);
 
     gdk_draw_drawable(widget->window,
                       widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
@@ -549,7 +562,6 @@
     _init_gc (canvas);
     priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
 
-    tomoe_canvas_free_stroke_list (canvas);
     tomoe_canvas_draw_background (canvas, TRUE);
 
     if (priv->candidates) {
@@ -564,49 +576,29 @@
 tomoe_canvas_get_glyph (TomoeCanvas *canvas)
 {
     TomoeCanvasPriv *priv;
-    GList *line;
-    TomoeGlyph *g = (TomoeGlyph*)calloc(1, sizeof (TomoeGlyph));
-    int i, j;
+    TomoeGlyph *g;
 
     g_return_val_if_fail (TOMOE_IS_CANVAS (canvas), NULL);
 
     priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
 
-    g->stroke_num = g_list_length (priv->stroke_list);
-    g->strokes    = g_new0 (TomoeStroke, g->stroke_num);
+    g = create_sparse_glyph (canvas);
 
-    for (i = 0, line = priv->stroke_list;
-         line;
-         i++, line = line->next)
-    {
-        GList *dots, *dot;
-        gint x, y, px, py;
-
-        dots = g_list_prepend (
-            get_vertex((GList*)line->data,
-                       (GList*)g_list_last((GList*)line->data)),
-            ((GList*)(line->data))->data);
-        px = py = -1;
-
-        g->strokes[i].point_num = g_list_length (dots);
-        g->strokes[i].points = g_new0 (TomoePoint, g->strokes[i].point_num);
-
-        for (j = 0, dot = dots; dot; j++, dot = dot->next) {
-            x = ((TomoePoint *)(dot->data))->x;
-            y = ((TomoePoint *)(dot->data))->y;
-
-            g->strokes[i].points[j].x = x
-                * ((gdouble)TOMOE_CANVAS_DEFAULT_SIZE / priv->size);
-            g->strokes[i].points[j].y = y
-                * ((gdouble)TOMOE_CANVAS_DEFAULT_SIZE / priv->size);
-            px = x;
-            py = y;
-        }
+    return g;
+}
 
-        g_list_free (dots);
-    }
+void
+tomoe_canvas_set_glyph (TomoeCanvas *canvas, TomoeGlyph *glyph)
+{
+    TomoeCanvasPriv *priv;
 
-    return g;
+    g_return_if_fail (TOMOE_IS_CANVAS (canvas));
+
+    priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
+
+    if (priv->glyph)
+        g_object_unref (priv->glyph);
+    priv->glyph = glyph;
 }
 
 void 
@@ -637,90 +629,132 @@
 };
 
 static void
-get_char_size (TomoeCanvas *canvas, CharSize *char_size)
+get_rectangle_for_stroke (GList *points, GdkRectangle *rect)
 {
-    TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
-    GList *node0, *node;
+    GList *list;
 
-    GList *base_stroke = ((GList*)(priv->stroke_list))->data;
-    gint base_x = ((TomoePoint*)(base_stroke->data))->x;
-    gint base_y = ((TomoePoint*)(base_stroke->data))->y;
+    for (list = points; list; list = g_list_next (list)) {
+        gint x = ((TomoePoint*)(list->data))->x;
+        gint y = ((TomoePoint*)(list->data))->y;
 
-    char_size->x0 = base_x;
-    char_size->y0 = base_y;
-    char_size->x1 = base_x;
-    char_size->y1 = base_y;
+        rect->x = MIN (rect->x, x);
+        rect->y = MIN (rect->y, y);
+        rect->width  = MAX (rect->width, x - rect->x);
+        rect->height = MAX (rect->height, y - rect->y);
+    }
+}
 
-    for (node0 = priv->stroke_list; node0; node0 = g_list_next (node0)) {
-        GList *stroke = (GList*) node0->data;
+static void
+get_char_size (TomoeCanvas *canvas, GdkRectangle *rect)
+{
+    TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
+    const GList *strokes, *list;
+    TomoeGlyph *g = priv->glyph;
 
-        for (node = stroke; node; node = g_list_next (node)) {
-            gint x = ((TomoePoint*)(node->data))->x;
-            gint y = ((TomoePoint*)(node->data))->y;
+    rect->x = G_MAXINT;
+    rect->y = G_MAXINT;
+    rect->width = 0;
+    rect->height = 0;
 
-            char_size->x0 = MIN (char_size->x0, x);
-            char_size->y0 = MIN (char_size->y0, y);
-            char_size->x1 = MAX (char_size->x1, x);
-            char_size->y1 = MAX (char_size->y1, y);
+    strokes = tomoe_glyph_get_strokes (g);
+    for (list= strokes; list; list = g_list_next (list)) {
+        GList *points = (GList *) list->data;
+        GList *point;
+        for (point = points; point; point = g_list_next (point)) {
+            get_rectangle_for_stroke (points, rect);
         }
     }
 }
 
+static TomoeGlyph *
+_tomoe_glyph_new_scale_glyph (TomoeGlyph *glyph, gdouble sx, gdouble sy)
+{
+    const GList *strokes, *list;
+    TomoeGlyph *new = tomoe_glyph_new ();
+
+    strokes = tomoe_glyph_get_strokes (glyph);
+    for (list= strokes; list; list = g_list_next (list)) {
+        GList *points = (GList *) list->data;
+        GList *point;
+        gboolean first = TRUE;
+        for ( point = points; point; point = g_list_next (point)) {
+            TomoePoint *cp = (TomoePoint *) point->data;
+            if (first)
+                tomoe_glyph_line_to (new, cp->x * sx, cp->y * sy);
+            else
+                tomoe_glyph_move_to (new, cp->x * sx, cp->y * sy);
+            first = FALSE;
+        }
+    }
+    return new;
+}
+
 static void
 tomoe_canvas_resize (TomoeCanvas *canvas, gdouble x_rate, gdouble y_rate)
 {
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
-    GList *node0;
+    TomoeGlyph *new_glyph;
 
-    for (node0 = priv->stroke_list; node0; node0 = g_list_next (node0)) {
-        GList *stroke = (GList*) node0->data;
-        GList *node1;
-
-        for (node1 = stroke; node1; node1 = g_list_next (node1)) {
-            ((TomoePoint*)(node1->data))->x *= x_rate;
-            ((TomoePoint*)(node1->data))->y *= y_rate;
+    new_glyph = _tomoe_glyph_new_scale_glyph (priv->glyph, x_rate, y_rate);
+
+    tomoe_canvas_set_glyph (canvas, new_glyph);
+}
+
+static TomoeGlyph *
+_tomoe_glyph_new_move_glyph (TomoeGlyph *glyph, gint dx, gint dy)
+{
+    const GList *strokes, *list;
+    TomoeGlyph *new = tomoe_glyph_new ();
+
+    strokes = tomoe_glyph_get_strokes (glyph);
+    for (list= strokes; list; list = g_list_next (list)) {
+        GList *points = (GList *) list->data;
+        GList *point;
+        gboolean first = TRUE;
+        for ( point = points; point; point = g_list_next (point)) {
+            TomoePoint *cp = (TomoePoint *) point->data;
+            if (first)
+                tomoe_glyph_line_to (new, cp->x + dx, cp->y + dy);
+            else
+                tomoe_glyph_move_to (new, cp->x + dx, cp->y + dy);
+            first = FALSE;
         }
     }
+    return new;
 }
 
 static void
-tomoe_canvas_position (TomoeCanvas *canvas, gint dx, gint dy)
+tomoe_canvas_move_position (TomoeCanvas *canvas, gint dx, gint dy)
 {
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
-    GList *node0;
+    TomoeGlyph *new_glyph;
 
-    for (node0 = priv->stroke_list; node0; node0 = g_list_next (node0)) {
-        GList *stroke = (GList*) node0->data;
-        GList *node1;
+    new_glyph = _tomoe_glyph_new_move_glyph (priv->glyph, dx, dy);
 
-        for (node1 = stroke; node1; node1 = g_list_next (node1)) {
-            ((TomoePoint*)(node1->data))->x += dx;
-            ((TomoePoint*)(node1->data))->y += dy;
-        }
-    }
+    tomoe_canvas_set_glyph (canvas, new_glyph);
 }
 
 static void
 tomoe_canvas_real_normalize (TomoeCanvas *canvas)
 {
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
-    CharSize char_size;
+    GdkRectangle char_size;
     gdouble x_rate, y_rate;
     gint dx, dy;
 
     get_char_size (canvas, &char_size);
     x_rate = (priv->size * TOMOE_CANVAS_DEFAULT_RATE)
-           / (char_size.x1 - char_size.x0);
+           / char_size.width;
     y_rate = (priv->size * TOMOE_CANVAS_DEFAULT_RATE)
-           / (char_size.y1 - char_size.y0);
+           / char_size.height;
 
     tomoe_canvas_resize (canvas, x_rate, y_rate);
 
     get_char_size (canvas, &char_size);
-    dx = ((priv->size - (char_size.x1 - char_size.x0)) / 2) - char_size.x0;
-    dy = ((priv->size - (char_size.y1 - char_size.y0)) / 2) - char_size.y0;
+    dx = ((priv->size - char_size.width)  / 2) - char_size.x;
+    dy = ((priv->size - char_size.height) / 2) - char_size.y;
 
-    tomoe_canvas_position (canvas, dx, dy);
+    tomoe_canvas_move_position (canvas, dx, dy);
 
     tomoe_canvas_refresh (canvas);
     tomoe_canvas_find (canvas);
@@ -768,8 +802,8 @@
 {
     TomoeCanvasPriv *priv;
     GtkWidget *widget;
-    guint index = 1;
-    GList *node;
+    guint i;
+    const GList *strokes, *list;
 
     g_return_if_fail (TOMOE_IS_CANVAS (canvas));
 
@@ -786,18 +820,21 @@
                         widget->allocation.height);
 
     tomoe_canvas_draw_axis (canvas);
-
+#if 0
     if (priv->preview) {
         guint i;
         index = 1;
         for (i = 0; i < priv->preview->stroke_num; i++)
             draw_preview_stroke (canvas, &priv->preview->strokes[i], &index);
     }
+#endif
 
-    index = 1;
-    for (node = priv->stroke_list; node; node = g_list_next (node)) {
-        draw_stroke (node->data, canvas, &index);
+    strokes = tomoe_glyph_get_strokes (priv->glyph);
+    for (list = strokes, i = 1; list; list = g_list_next (list), i++) {
+        GList *points = (GList *) list->data;
+        draw_stroke (points, canvas, i);
     }
+
     gdk_draw_drawable(widget->window,
                       widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                       priv->pixmap,
@@ -810,28 +847,24 @@
 tomoe_canvas_revert (TomoeCanvas *canvas)
 {
     TomoeCanvasPriv *priv;
-    GList *last;
+    gboolean reverted = TRUE;
 
     g_return_if_fail (TOMOE_IS_CANVAS (canvas));
 
     priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
 
     /* remove last line */
-    last = g_list_last (priv->stroke_list);
-    if (last) {
-        GList *stroke = (GList*) last->data;
-
-        priv->stroke_list = g_list_remove (priv->stroke_list, stroke);
-        g_list_foreach (stroke, (GFunc) g_free, NULL);
-        g_list_free (stroke);
-
+    tomoe_glyph_remove_last_stroke (priv->glyph);
+    /* reverted = tomoe_glyph_remove_last_stroke (priv->glyph); */
+    if (reverted) {
         tomoe_canvas_refresh (canvas);
 
         g_signal_emit (G_OBJECT (canvas),
                        canvas_signals[STROKE_REVERTED_SIGNAL], 0);
-
+#if 0
         if (!priv->stroke_list)
             g_signal_emit (G_OBJECT (canvas), canvas_signals[CLEAR_SIGNAL], 0);
+#endif
     }
 }
 
@@ -856,10 +889,7 @@
 
     g_return_val_if_fail (TOMOE_IS_CANVAS (canvas), FALSE);
 
-    if (priv->stroke || priv->stroke_list)
-        return TRUE;
-
-    return FALSE;
+    return (tomoe_glyph_get_number_of_strokes (priv->glyph) > 0);
 }
 
 void
@@ -977,21 +1007,12 @@
 {
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
     GList *last;
-    TomoePoint *p1, *p2 = g_new0 (TomoePoint, 1);
-    GdkColor color;
-    color.red   = 0x0000;
-    color.green = 0x0000;
-    color.blue  = 0x0000;
-
-    p2->x = x;
-    p2->y = y;
+    GdkColor color = { 0, 0x0000, 0x0000, 0x0000};
 
-    last = g_list_last (priv->stroke);
-    priv->stroke = g_list_append (priv->stroke, p2);
-    p1 = last ? (TomoePoint*) last->data : p2;
+    tomoe_glyph_move_to (priv->glyph, x, y);
 
     _init_gc (canvas);
-    tomoe_canvas_draw_line (canvas, p1, p2, TRUE, &color);
+    /* tomoe_canvas_draw_line (canvas, pp, p, &color); */
 }
 
 static void
@@ -1179,31 +1200,28 @@
 }
 
 static void
-draw_stroke (GList *stroke, TomoeCanvas *canvas, guint *index)
+draw_stroke (GList *points, TomoeCanvas *canvas, guint index)
 {
     GList *node;
-    GdkColor color;
-    color.red   = 0x8000;
-    color.green = 0x0000;
-    color.blue  = 0x0000;
+    GdkColor color = { 0, 0x8000, 0x0000, 0x0000 };
 
     _init_gc (canvas);
 
-    for (node = stroke; node; node = g_list_next (node)) {
+    for (node = points; node; node = g_list_next (node)) {
         GList *next = g_list_next (node);
         TomoePoint *p1, *p2;
 
         if (!next) break;
 
-        p1 = (TomoePoint*) node->data;
-        p2 = (TomoePoint*) next->data;
+        p1 = (TomoePoint *) node->data;
+        p2 = (TomoePoint *) next->data;
 
         tomoe_canvas_draw_line (canvas, p1, p2, FALSE, &color);
     }
-    draw_annotate (stroke, canvas, *index, &color);
-    (*index)++;
+    draw_annotate (points, canvas, index, &color);
 }
 
+#if 0
 static void
 draw_preview_stroke (TomoeCanvas *canvas, TomoeStroke* stroke, guint *index)
 {
@@ -1229,13 +1247,12 @@
     /* draw_preview_annotate (canvas, stroke, *index, &color); */
     (*index)++;
 }
-
+#endif
 static void
-draw_annotate (GList *stroke, TomoeCanvas *canvas, guint index, GdkColor *color)
+draw_annotate (GList *points, TomoeCanvas *canvas, guint index, GdkColor *color)
 {
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
     GtkWidget *widget = GTK_WIDGET (canvas);
-
     gchar *buffer; 
     PangoLayout *layout;
     gint width, height;
@@ -1246,17 +1263,17 @@
     gint sign;
 
     gdouble factor = 1.0 / ((gdouble)TOMOE_CANVAS_DEFAULT_SIZE / (gdouble)priv->size);
+    x = ((TomoePoint*)(points->data))->x * factor;
+    y = ((TomoePoint*)(points->data))->y * factor;
 
-    x = ((TomoePoint*)((g_list_first (stroke))->data))->x * factor;
-    y = ((TomoePoint*)((g_list_first (stroke))->data))->y * factor;
-
-    if (g_list_length (stroke) == 1) {
+    if (g_list_length (points) == 1) {
         dx = x;
         dy = y;
     } else {
-        dx = ((TomoePoint*)((g_list_last (stroke))->data))->x * factor - x;
-        dy = ((TomoePoint*)((g_list_last (stroke))->data))->y * factor - y;
+        dx = 0;
+        dy = 0;
     }
+
     dl = sqrt (dx*dx + dy*dy);
     sign = (dy <= dx) ? 1 : -1;
 
@@ -1278,6 +1295,7 @@
     g_object_unref (layout);
 }
 
+#if 0
 static void
 draw_preview_annotate (TomoeCanvas *canvas, TomoeStroke *stroke, guint index, GdkColor *color)
 {
@@ -1325,7 +1343,7 @@
     g_free (buffer);
     g_object_unref (layout);
 }
-
+#endif
 static void
 on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
 {
Index: libtomoe-gtk/src/tomoe-canvas.h
diff -u libtomoe-gtk/src/tomoe-canvas.h:1.4 libtomoe-gtk/src/tomoe-canvas.h:1.5
--- libtomoe-gtk/src/tomoe-canvas.h:1.4	Fri Nov 17 10:14:28 2006
+++ libtomoe-gtk/src/tomoe-canvas.h	Wed Nov 22 15:04:55 2006
@@ -88,6 +88,8 @@
 void          tomoe_canvas_set_context        (TomoeCanvas  *canvas,
                                                TomoeContext *context);
 TomoeGlyph   *tomoe_canvas_get_glyph          (TomoeCanvas  *canvas);
+void          tomoe_canvas_set_glyph          (TomoeCanvas  *canvas,
+                                               TomoeGlyph   *glyph);
 void          tomoe_canvas_set_preview_glyph  (TomoeCanvas  *canvas,
                                                TomoeGlyph   *glyph);
 void          tomoe_canvas_lock               (TomoeCanvas  *canvas,


tomoe-cvs メーリングリストの案内
Back to archive index