[gimp/metadata-browser] Bug 642728: Use cairo to draw Gfig
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] Bug 642728: Use cairo to draw Gfig
- Date: Wed, 12 Sep 2012 22:52:03 +0000 (UTC)
commit 08b9a33f92b43a009d40f82c37af75bb993bf2b0
Author: Massimo Valentini <mvalentini src gnome org>
Date: Thu Feb 16 17:56:52 2012 +0100
Bug 642728: Use cairo to draw Gfig
plug-ins/gfig/gfig-arc.c | 58 ++++---------
plug-ins/gfig/gfig-bezier.c | 63 +++------------
plug-ins/gfig/gfig-bezier.h | 3 +-
plug-ins/gfig/gfig-circle.c | 52 +++---------
plug-ins/gfig/gfig-dialog.c | 132 ++++++++++++++---------------
plug-ins/gfig/gfig-dobject.c | 63 ++++-----------
plug-ins/gfig/gfig-dobject.h | 6 +-
plug-ins/gfig/gfig-ellipse.c | 89 +++-----------------
plug-ins/gfig/gfig-grid.c | 177 ++++++++++++++--------------------------
plug-ins/gfig/gfig-grid.h | 6 +-
plug-ins/gfig/gfig-line.c | 46 ++--------
plug-ins/gfig/gfig-poly.c | 59 +++-----------
plug-ins/gfig/gfig-preview.c | 37 +++++---
plug-ins/gfig/gfig-preview.h | 3 -
plug-ins/gfig/gfig-rectangle.c | 77 +++--------------
plug-ins/gfig/gfig-spiral.c | 42 ++-------
plug-ins/gfig/gfig-star.c | 60 ++++----------
plug-ins/gfig/gfig.c | 1 -
plug-ins/gfig/gfig.h | 17 +++-
19 files changed, 301 insertions(+), 690 deletions(-)
---
diff --git a/plug-ins/gfig/gfig-arc.c b/plug-ins/gfig/gfig-arc.c
index ce27faf..8c432f9 100644
--- a/plug-ins/gfig/gfig-arc.c
+++ b/plug-ins/gfig/gfig-arc.c
@@ -27,7 +27,6 @@
#include <math.h>
#include <stdlib.h>
-#undef GDK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
@@ -83,7 +82,8 @@ static void arc_drawing_details (GfigObject *obj,
gboolean draw_cnts,
gboolean do_scale);
-static void d_draw_arc (GfigObject *obj);
+static void d_draw_arc (GfigObject *obj,
+ cairo_t *cr);
static void d_paint_arc (GfigObject *obj);
@@ -380,13 +380,6 @@ arc_drawing_details (GfigObject *obj,
if (!pnt3)
return; /* Still not fully drawn */
- if (draw_cnts)
- {
- draw_sqr (&pnt1->pnt, obj == gfig_context->selected_obj);
- draw_sqr (&pnt2->pnt, obj == gfig_context->selected_obj);
- draw_sqr (&pnt3->pnt, obj == gfig_context->selected_obj);
- }
-
if (do_scale)
{
/* Adjust pnts for scaling */
@@ -441,8 +434,10 @@ arc_drawing_details (GfigObject *obj,
}
static void
-d_draw_arc (GfigObject *obj)
+d_draw_arc (GfigObject *obj,
+ cairo_t *cr)
{
+ DobjPoints *pnt1, *pnt2, *pnt3;
GdkPoint center_pnt;
gdouble radius, minang, arcang;
@@ -451,9 +446,20 @@ d_draw_arc (GfigObject *obj)
if (!obj)
return;
+ pnt1 = obj->points;
+ pnt2 = pnt1 ? pnt1->next : NULL;
+ pnt3 = pnt2 ? pnt2->next : NULL;
+
+ if (! pnt3)
+ return;
+
+ draw_sqr (&pnt1->pnt, obj == gfig_context->selected_obj, cr);
+ draw_sqr (&pnt2->pnt, obj == gfig_context->selected_obj, cr);
+ draw_sqr (&pnt3->pnt, obj == gfig_context->selected_obj, cr);
+
arc_drawing_details (obj, &minang, ¢er_pnt, &arcang, &radius,
TRUE, FALSE);
- gfig_draw_arc (center_pnt.x, center_pnt.y, radius, radius, minang, arcang);
+ gfig_draw_arc (center_pnt.x, center_pnt.y, radius, radius, -minang, -(minang + arcang), cr);
}
static void
@@ -587,33 +593,10 @@ d_update_arc_line (GdkPoint *pnt)
if ((epnt = spnt->next))
{
- /* undraw current */
- /* Draw square on point */
- draw_circle (&epnt->pnt, TRUE);
-
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- /*gfig_context->preview->style->bg_gc[GTK_STATE_NORMAL],*/
- gfig_gc,
- spnt->pnt.x,
- spnt->pnt.y,
- epnt->pnt.x,
- epnt->pnt.y);
g_free (epnt);
}
- /* draw new */
- /* Draw circle on point */
- draw_circle (pnt, TRUE);
-
epnt = new_dobjpoint (pnt->x, pnt->y);
-
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- /*gfig_context->preview->style->bg_gc[GTK_STATE_NORMAL],*/
- gfig_gc,
- spnt->pnt.x,
- spnt->pnt.y,
- epnt->pnt.x,
- epnt->pnt.y);
spnt->next = epnt;
}
@@ -648,7 +631,6 @@ d_arc_line_start (GdkPoint *pnt,
{
if (!obj_creating || !shift_down)
{
- /* Draw square on point */
/* Must delete obj_creating if we have one */
obj_creating = d_new_object (LINE, pnt->x, pnt->y);
}
@@ -664,8 +646,6 @@ d_arc_start (GdkPoint *pnt,
gboolean shift_down)
{
/* Draw lines to start with -- then convert to an arc */
- if (!tmp_line)
- draw_sqr (pnt, TRUE);
d_arc_line_start (pnt, TRUE); /* TRUE means multiple pointed line */
}
@@ -673,9 +653,6 @@ static void
d_arc_line_end (GdkPoint *pnt,
gboolean shift_down)
{
- /* Undraw the last circle */
- draw_circle (pnt, TRUE);
-
if (shift_down)
{
if (tmp_line)
@@ -749,7 +726,6 @@ d_arc_end (GdkPoint *pnt,
{
selvals.scaletoimage = 0;
}
- /*d_draw_arc (newarc);*/
gtk_widget_queue_draw (gfig_context->preview);
if (need_to_scale)
{
diff --git a/plug-ins/gfig/gfig-bezier.c b/plug-ins/gfig/gfig-bezier.c
index f9c283d..2890562 100644
--- a/plug-ins/gfig/gfig-bezier.c
+++ b/plug-ins/gfig/gfig-bezier.c
@@ -53,7 +53,7 @@ static void fp_pnt_add (gdouble p1,
gdouble p3,
gdouble p4);
static gdouble *d_bz_get_array (gint *sz);
-static void d_bz_line (void);
+static void d_bz_line (cairo_t *cr);
static void DrawBezier (fp_pnt points,
gint np,
gdouble mid,
@@ -102,7 +102,7 @@ d_bz_get_array (gint *sz)
}
static void
-d_bz_line (void)
+d_bz_line (cairo_t *cr)
{
gint i, x0, y0, x1, y1;
@@ -115,7 +115,7 @@ d_bz_line (void)
x1 = fp_pnt_pnts[i + 2];
y1 = fp_pnt_pnts[i + 3];
- gfig_draw_line (x0, y0, x1, y1);
+ gfig_draw_line (x0, y0, x1, y1, cr);
}
}
@@ -179,7 +179,8 @@ DrawBezier (fp_pnt points,
}
void
-d_draw_bezier (GfigObject *obj)
+d_draw_bezier (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *spnt;
gint seg_count = 0;
@@ -200,7 +201,10 @@ d_draw_bezier (GfigObject *obj)
/* Go around all the points drawing a line from one to the next */
for (spnt = obj->points; spnt; spnt = spnt->next)
{
- draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj);
+ if (! spnt->next && obj == obj_creating)
+ draw_circle (&spnt->pnt, TRUE, cr);
+ else
+ draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj, cr);
line_pnts[i][0] = spnt->pnt.x;
line_pnts[i][1] = spnt->pnt.y;
i++;
@@ -212,13 +216,12 @@ d_draw_bezier (GfigObject *obj)
{
fp_pnt_start ();
DrawBezier (line_pnts, seg_count, 0.5, 0);
- d_bz_line ();
+ d_bz_line (cr);
}
fp_pnt_start ();
DrawBezier (line_pnts, seg_count, 0.5, 3);
- d_bz_line ();
- /*bezier4 (line_pnts, seg_count, 20);*/
+ d_bz_line (cr);
g_free (line_pnts);
}
@@ -302,30 +305,21 @@ static void
d_update_bezier (GdkPoint *pnt)
{
DobjPoints *s_pnt, *l_pnt;
- gint saved_cnt_pnt = selvals.opts.showcontrol;
g_assert (tmp_bezier != NULL);
- /* Undraw last one then draw new one */
s_pnt = tmp_bezier->points;
if (!s_pnt)
return; /* No points */
- /* Hack - turn off cnt points in draw routine
- */
-
if ((l_pnt = s_pnt->next))
{
- /* Undraw */
while (l_pnt->next)
{
l_pnt = l_pnt->next;
}
- draw_circle (&l_pnt->pnt, TRUE);
- selvals.opts.showcontrol = 0;
- d_draw_bezier (tmp_bezier);
l_pnt->pnt = *pnt;
}
else
@@ -333,16 +327,7 @@ d_update_bezier (GdkPoint *pnt)
/* Radius is a few pixels away */
/* First edge point */
d_pnt_add_line (tmp_bezier, pnt->x, pnt->y,-1);
- l_pnt = s_pnt->next;
}
-
- /* draw it */
- selvals.opts.showcontrol = 0;
- d_draw_bezier (tmp_bezier);
- selvals.opts.showcontrol = saved_cnt_pnt;
-
- /* Realy draw the control points */
- draw_circle (&l_pnt->pnt, TRUE);
}
void
@@ -374,7 +359,6 @@ d_bezier_end (GdkPoint *pnt,
if (shift_down)
{
- /* Undraw circle on last pnt */
while (l_pnt->next)
{
l_pnt = l_pnt->next;
@@ -382,29 +366,12 @@ d_bezier_end (GdkPoint *pnt,
if (l_pnt)
{
- draw_circle (&l_pnt->pnt, TRUE);
- draw_sqr (&l_pnt->pnt, TRUE);
-
if (bezier_closed)
{
- gboolean tmp_frame = bezier_line_frame;
/* if closed then add first point */
- d_draw_bezier (tmp_bezier);
d_pnt_add_line (tmp_bezier,
tmp_bezier->points->pnt.x,
tmp_bezier->points->pnt.y, -1);
- /* Final has no frame */
- bezier_line_frame = FALSE;
- d_draw_bezier (tmp_bezier);
- bezier_line_frame = tmp_frame; /* What is was */
- }
- else if (bezier_line_frame)
- {
- gboolean tmp_frame = bezier_line_frame;
- d_draw_bezier (tmp_bezier);
- bezier_line_frame = FALSE;
- d_draw_bezier (tmp_bezier);
- bezier_line_frame = tmp_frame; /* What is was */
}
add_to_all_obj (gfig_context->current_obj, obj_creating);
@@ -416,15 +383,7 @@ d_bezier_end (GdkPoint *pnt,
}
else
{
- if (!tmp_bezier->points->next)
- {
- draw_circle (&tmp_bezier->points->pnt, TRUE);
- draw_sqr (&tmp_bezier->points->pnt, TRUE);
- }
-
- d_draw_bezier (tmp_bezier);
d_pnt_add_line (tmp_bezier, pnt->x, pnt->y,-1);
- d_draw_bezier (tmp_bezier);
}
}
diff --git a/plug-ins/gfig/gfig-bezier.h b/plug-ins/gfig/gfig-bezier.h
index 1cda9cb..954e2ed 100644
--- a/plug-ins/gfig/gfig-bezier.h
+++ b/plug-ins/gfig/gfig-bezier.h
@@ -27,7 +27,8 @@
extern GfigObject *tmp_bezier;
-void d_draw_bezier (GfigObject *obj);
+void d_draw_bezier (GfigObject *obj,
+ cairo_t *cr);
void d_bezier_object_class_init (void);
diff --git a/plug-ins/gfig/gfig-circle.c b/plug-ins/gfig/gfig-circle.c
index f21dcb2..0b58524 100644
--- a/plug-ins/gfig/gfig-circle.c
+++ b/plug-ins/gfig/gfig-circle.c
@@ -25,7 +25,6 @@
#include "config.h"
#include <libgimp/gimp.h>
-#undef GDK_DISABLE_DEPRECATED
#include <libgimp/gimpui.h>
#include "gfig.h"
@@ -37,7 +36,8 @@
static gint calc_radius (GdkPoint *center,
GdkPoint *edge);
-static void d_draw_circle (GfigObject *obj);
+static void d_draw_circle (GfigObject *obj,
+ cairo_t *cr);
static void d_paint_circle (GfigObject *obj);
static GfigObject *d_copy_circle (GfigObject *obj);
@@ -53,7 +53,8 @@ calc_radius (GdkPoint *center, GdkPoint *edge)
}
static void
-d_draw_circle (GfigObject *obj)
+d_draw_circle (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *center_pnt;
DobjPoints *edge_pnt;
@@ -64,19 +65,22 @@ d_draw_circle (GfigObject *obj)
if (!center_pnt)
return; /* End-of-line */
+ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr);
+
edge_pnt = center_pnt->next;
if (!edge_pnt)
- {
- g_warning ("Internal error - circle no edge pnt");
- }
+ return;
radius = calc_radius (¢er_pnt->pnt, &edge_pnt->pnt);
- draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj);
- draw_sqr (&edge_pnt->pnt, obj == gfig_context->selected_obj);
+
+ if (obj_creating == obj)
+ draw_circle (&edge_pnt->pnt, TRUE, cr);
+ else
+ draw_sqr (&edge_pnt->pnt, obj == gfig_context->selected_obj, cr);
gfig_draw_arc (center_pnt->pnt.x, center_pnt->pnt.y,
- radius, radius, 0, 360);
+ radius, radius, 0, 360, cr);
}
static void
@@ -166,9 +170,7 @@ static void
d_update_circle (GdkPoint *pnt)
{
DobjPoints *center_pnt, *edge_pnt;
- gint radius;
- /* Undraw last one then draw new one */
center_pnt = obj_creating->points;
if (!center_pnt)
@@ -176,19 +178,6 @@ d_update_circle (GdkPoint *pnt)
if ((edge_pnt = center_pnt->next))
{
- /* Undraw current */
- draw_circle (&edge_pnt->pnt, TRUE);
- radius = calc_radius (¢er_pnt->pnt, &edge_pnt->pnt);
-
- gdk_draw_arc (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- 0,
- center_pnt->pnt.x - (gint) RINT (radius),
- center_pnt->pnt.y - (gint) RINT (radius),
- (gint) RINT (radius) * 2,
- (gint) RINT (radius) * 2,
- 0,
- 360 * 64);
edge_pnt->pnt = *pnt;
}
else
@@ -196,20 +185,6 @@ d_update_circle (GdkPoint *pnt)
edge_pnt = new_dobjpoint (pnt->x, pnt->y);
center_pnt->next = edge_pnt;
}
-
- draw_circle (&edge_pnt->pnt, TRUE);
-
- radius = calc_radius (¢er_pnt->pnt, &edge_pnt->pnt);
-
- gdk_draw_arc (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- 0,
- center_pnt->pnt.x - (gint) RINT (radius),
- center_pnt->pnt.y - (gint) RINT (radius),
- (gint) RINT (radius) * 2,
- (gint) RINT (radius) * 2,
- 0,
- 360 * 64);
}
void
@@ -231,7 +206,6 @@ d_circle_end (GdkPoint *pnt,
}
else
{
- draw_circle (pnt, TRUE);
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
diff --git a/plug-ins/gfig/gfig-dialog.c b/plug-ins/gfig/gfig-dialog.c
index 488ab56..757cf68 100644
--- a/plug-ins/gfig/gfig-dialog.c
+++ b/plug-ins/gfig/gfig-dialog.c
@@ -38,7 +38,6 @@
#endif
#include <libgimp/gimp.h>
-#undef GDK_DISABLE_DEPRECATED
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
@@ -160,8 +159,6 @@ static void gfig_grid_action_callback (GtkAction *action,
gpointer data);
static void gfig_prefs_action_callback (GtkAction *action,
gpointer data);
-static gint gfig_scale_x (gint x);
-static gint gfig_scale_y (gint y);
static void toggle_show_image (void);
static void gridtype_combo_callback (GtkWidget *widget,
gpointer data);
@@ -191,7 +188,6 @@ static void lower_selected_obj (GtkWidget *widget,
static void toggle_obj_type (GtkRadioAction *action,
GtkRadioAction *current,
gpointer data);
-static void gfig_new_gc (void);
static GtkUIManager *create_ui_manager (GtkWidget *window);
@@ -486,9 +482,9 @@ gfig_dialog (void)
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&gfig_context->show_background);
- g_signal_connect (toggle, "toggled",
- G_CALLBACK (gfig_preview_expose),
- NULL);
+ g_signal_connect_swapped (toggle, "toggled",
+ G_CALLBACK (gtk_widget_queue_draw),
+ gfig_context->preview);
gtk_widget_show (toggle);
/* "snap to grid" checkbutton at bottom of style frame */
@@ -523,8 +519,6 @@ gfig_dialog (void)
gtk_widget_show (top_level_dlg);
- gfig_new_gc (); /* Need this for drawing */
-
gfig = gfig_load_from_parasite ();
if (gfig)
{
@@ -782,41 +776,60 @@ gfig_clear_action_callback (GtkWidget *widget,
gfig_paint_callback ();
}
+void
+draw_item (cairo_t *cr, gboolean fill)
+{
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
+
+ if (fill)
+ {
+ cairo_fill_preserve (cr);
+ }
+ else
+ {
+ cairo_set_line_width (cr, 3.0);
+ cairo_stroke_preserve (cr);
+ }
+
+ cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
+ cairo_set_line_width (cr, 1.0);
+ cairo_stroke (cr);
+}
/* Given a point x, y draw a circle */
void
draw_circle (GdkPoint *p,
- gboolean selected)
+ gboolean selected,
+ cairo_t *cr)
{
if (!selvals.opts.showcontrol)
return;
- gdk_draw_arc (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- selected,
- p->x - SQ_SIZE/2,
- p->y - SQ_SIZE/2,
- SQ_SIZE,
- SQ_SIZE,
- 0,
- 360*64);
+ cairo_arc (cr,
+ gfig_scale_x (p->x) + .5,
+ gfig_scale_y (p->y) + .5,
+ SQ_SIZE / 2,
+ 0, 2 * G_PI);
+
+ draw_item (cr, selected);
}
/* Given a point x, y draw a square around it */
void
draw_sqr (GdkPoint *p,
- gboolean selected)
+ gboolean selected,
+ cairo_t *cr)
{
if (!selvals.opts.showcontrol)
return;
- gdk_draw_rectangle (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- selected,
- gfig_scale_x (p->x) - SQ_SIZE / 2,
- gfig_scale_y (p->y) - SQ_SIZE / 2,
- SQ_SIZE,
- SQ_SIZE);
+ cairo_rectangle (cr,
+ gfig_scale_x (p->x) + .5 - SQ_SIZE / 2,
+ gfig_scale_y (p->y) + .5 - SQ_SIZE / 2,
+ SQ_SIZE,
+ SQ_SIZE);
+
+ draw_item (cr, selected);
}
static void
@@ -1480,13 +1493,13 @@ gfig_grid_action_callback (GtkAction *action,
g_object_add_weak_pointer (G_OBJECT (gfig_opt_widget.gridtypemenu),
(gpointer) &gfig_opt_widget.gridtypemenu);
- combo = gimp_int_combo_box_new (_("Normal"), GTK_STATE_NORMAL,
+ combo = gimp_int_combo_box_new (_("Normal"), GFIG_NORMAL_GC,
_("Black"), GFIG_BLACK_GC,
_("White"), GFIG_WHITE_GC,
_("Grey"), GFIG_GREY_GC,
- _("Darker"), GTK_STATE_ACTIVE,
- _("Lighter"), GTK_STATE_PRELIGHT,
- _("Very dark"), GTK_STATE_SELECTED,
+ _("Darker"), GFIG_DARKER_GC,
+ _("Lighter"), GFIG_LIGHTER_GC,
+ _("Very dark"), GFIG_VERY_DARK_GC,
NULL);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), 0);
@@ -2013,7 +2026,7 @@ gfig_paint_callback (void)
back_pixbuf = NULL;
}
- gfig_preview_expose (gfig_context->preview, NULL);
+ gtk_widget_queue_draw (gfig_context->preview);
}
/* Draw the grid on the screen
@@ -2112,7 +2125,7 @@ scale_to_orginal_x (gdouble *list)
*list *= scale_x_factor;
}
-static gint
+gint
gfig_scale_x (gint x)
{
if (!selvals.scaletoimage)
@@ -2127,7 +2140,7 @@ scale_to_orginal_y (gdouble *list)
*list *= scale_y_factor;
}
-static gint
+gint
gfig_scale_y (gint y)
{
if (!selvals.scaletoimage)
@@ -2166,45 +2179,28 @@ scale_to_xy (gdouble *list,
void
gfig_draw_arc (gint x, gint y, gint width, gint height, gint angle1,
- gint angle2)
+ gint angle2, cairo_t *cr)
{
- gdk_draw_arc (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- FALSE,
- gfig_scale_x (x - width),
- gfig_scale_y (y - height),
- gfig_scale_x (2 * width),
- gfig_scale_y (2 * height),
- angle1 * 64,
- angle2 * 64);
-}
+ cairo_save (cr);
-void
-gfig_draw_line (gint x0, gint y0, gint x1, gint y1)
-{
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- gfig_scale_x (x0),
- gfig_scale_y (y0),
- gfig_scale_x (x1),
- gfig_scale_y (y1));
-}
+ cairo_translate (cr, gfig_scale_x (x), gfig_scale_y (y));
+ cairo_scale (cr, gfig_scale_x (width), gfig_scale_y (height));
-static void
-gfig_new_gc (void)
-{
- GdkColor fg, bg;
+ if (angle1 < angle2)
+ cairo_arc (cr, 0., 0., 1., angle1 * G_PI / 180, angle2 * G_PI / 180);
+ else
+ cairo_arc_negative (cr, 0., 0., 1., angle1 * G_PI / 180, angle2 * G_PI / 180);
- /* create a new graphics context */
- gfig_gc = gdk_gc_new (gtk_widget_get_window (gfig_context->preview));
+ cairo_restore (cr);
- gdk_gc_set_function (gfig_gc, GDK_INVERT);
+ draw_item (cr, FALSE);
+}
- fg.pixel = 0xFFFFFFFF;
- bg.pixel = 0x00000000;
- gdk_gc_set_foreground (gfig_gc, &fg);
- gdk_gc_set_background (gfig_gc, &bg);
+void
+gfig_draw_line (gint x0, gint y0, gint x1, gint y1, cairo_t *cr)
+{
+ cairo_move_to (cr, gfig_scale_x (x0) + .5, gfig_scale_y (y0) + .5);
+ cairo_line_to (cr, gfig_scale_x (x1) + .5, gfig_scale_y (y1) + .5);
- gdk_gc_set_line_attributes (gfig_gc, 1,
- GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
+ draw_item (cr, FALSE);
}
diff --git a/plug-ins/gfig/gfig-dobject.c b/plug-ins/gfig/gfig-dobject.c
index 0c2699c..1cb7655 100644
--- a/plug-ins/gfig/gfig-dobject.c
+++ b/plug-ins/gfig/gfig-dobject.c
@@ -49,7 +49,8 @@ static GfigObject *operation_obj = NULL;
static GdkPoint *move_all_pnt; /* Point moving all from */
-static void draw_one_obj (GfigObject *obj);
+static void draw_one_obj (GfigObject *obj,
+ cairo_t *cr);
static void do_move_obj (GfigObject *obj,
GdkPoint *to_pnt);
static void do_move_all_obj (GdkPoint *to_pnt);
@@ -370,18 +371,14 @@ object_operation_start (GdkPoint *pnt,
case MOVE_OBJ:
if (operation_obj->type == BEZIER)
{
- d_draw_bezier (operation_obj);
tmp_bezier = operation_obj;
- d_draw_bezier (operation_obj);
}
break;
case MOVE_POINT:
if (operation_obj->type == BEZIER)
{
- d_draw_bezier (operation_obj);
tmp_bezier = operation_obj;
- d_draw_bezier (operation_obj);
}
/* If shift is down the break into sep lines */
if ((operation_obj->type == POLY
@@ -401,6 +398,7 @@ object_operation_start (GdkPoint *pnt,
}
/* Re calc which object point we are lookin at */
scan_obj_points (operation_obj->points, pnt);
+ gtk_widget_queue_draw (gfig_context->preview);
}
break;
@@ -416,7 +414,7 @@ object_operation_start (GdkPoint *pnt,
add_to_all_obj (gfig_context->current_obj, new_obj);
operation_obj = new_obj;
selvals.otype = MOVE_COPY_OBJ;
- new_obj->class->drawfunc (new_obj);
+ gtk_widget_queue_draw (gfig_context->preview);
}
break;
@@ -443,9 +441,7 @@ object_operation_end (GdkPoint *pnt,
if (selvals.otype != DEL_OBJ && operation_obj &&
operation_obj->type == BEZIER)
{
- d_draw_bezier (operation_obj);
tmp_bezier = NULL; /* use as switch */
- d_draw_bezier (operation_obj);
}
if (operation_obj && selvals.otype != DEL_OBJ)
@@ -562,8 +558,6 @@ remove_obj_from_list (GFigObj *obj,
if (g_list_find (obj->obj_list, del_obj))
{
- del_obj->class->drawfunc (del_obj);
-
obj->obj_list = g_list_remove (obj->obj_list, del_obj);
free_one_obj (del_obj);
@@ -579,6 +573,8 @@ remove_obj_from_list (GFigObj *obj,
draw_grid_clear ();
obj_show_single = -1; /* Show entry again */
}
+
+ gtk_widget_queue_draw (gfig_context->preview);
}
else
g_warning (_("Hey where has the object gone ?"));
@@ -600,16 +596,12 @@ do_move_all_obj (GdkPoint *to_pnt)
{
GfigObject *obj = all->data;
- /* undraw ! */
- draw_one_obj (obj);
-
update_pnts (obj, xdiff, ydiff);
-
- /* Draw in new pos */
- draw_one_obj (obj);
}
*move_all_pnt = *to_pnt;
+
+ gtk_widget_queue_draw (gfig_context->preview);
}
}
@@ -638,13 +630,9 @@ do_move_obj (GfigObject *obj,
if (xdiff || ydiff)
{
- /* undraw ! */
- draw_one_obj (obj);
-
update_pnts (obj, xdiff, ydiff);
- /* Draw in new pos */
- draw_one_obj (obj);
+ gtk_widget_queue_draw (gfig_context->preview);
}
}
@@ -663,14 +651,11 @@ do_move_obj_pnt (GfigObject *obj,
if ((!xdiff && !ydiff) || !spnt)
return;
- /* undraw ! */
- draw_one_obj (obj);
-
spnt->pnt.x = spnt->pnt.x - xdiff;
spnt->pnt.y = spnt->pnt.y - ydiff;
/* Draw in new pos */
- draw_one_obj (obj);
+ gtk_widget_queue_draw (gfig_context->preview);
}
/* copy objs */
@@ -697,14 +682,16 @@ copy_all_objs (GList *objs)
/* Screen refresh */
static void
-draw_one_obj (GfigObject * obj)
+draw_one_obj (GfigObject *obj,
+ cairo_t *cr)
{
- obj->class->drawfunc (obj);
+ obj->class->drawfunc (obj, cr);
}
void
draw_objects (GList *objs,
- gboolean show_single)
+ gboolean show_single,
+ cairo_t *cr)
{
/* Show_single - only one object to draw Unless shift
* is down in which case show all.
@@ -715,7 +702,7 @@ draw_objects (GList *objs,
while (objs)
{
if (!show_single || count == obj_show_single || obj_show_single == -1)
- draw_one_obj (objs->data);
+ draw_one_obj (objs->data, cr);
objs = g_list_next (objs);
count++;
@@ -788,40 +775,30 @@ object_start (GdkPoint *pnt,
{
case LINE:
/* Shift means we are still drawing */
- if (!shift_down || !obj_creating)
- draw_sqr (pnt, TRUE);
d_line_start (pnt, shift_down);
break;
case RECTANGLE:
- draw_sqr (pnt, TRUE);
d_rectangle_start (pnt, shift_down);
break;
case CIRCLE:
- draw_sqr (pnt, TRUE);
d_circle_start (pnt, shift_down);
break;
case ELLIPSE:
- draw_sqr (pnt, TRUE);
d_ellipse_start (pnt, shift_down);
break;
case POLY:
- draw_sqr (pnt, TRUE);
d_poly_start (pnt, shift_down);
break;
case ARC:
d_arc_start (pnt, shift_down);
break;
case STAR:
- draw_sqr (pnt, TRUE);
d_star_start (pnt, shift_down);
break;
case SPIRAL:
- draw_sqr (pnt, TRUE);
d_spiral_start (pnt, shift_down);
break;
case BEZIER:
- if (!tmp_bezier)
- draw_sqr (pnt, TRUE);
d_bezier_start (pnt, shift_down);
break;
default:
@@ -850,34 +827,26 @@ object_end (GdkPoint *pnt,
{
case LINE:
d_line_end (pnt, shift_down);
- draw_sqr (pnt, TRUE);
break;
case RECTANGLE:
d_rectangle_end (pnt, shift_down);
- draw_sqr (pnt, TRUE);
break;
case CIRCLE:
- draw_sqr (pnt, TRUE);
d_circle_end (pnt, shift_down);
break;
case ELLIPSE:
- draw_sqr (pnt, TRUE);
d_ellipse_end (pnt, shift_down);
break;
case POLY:
- draw_sqr (pnt, TRUE);
d_poly_end (pnt, shift_down);
break;
case STAR:
- draw_sqr (pnt, TRUE);
d_star_end (pnt, shift_down);
break;
case ARC:
- draw_sqr (pnt, TRUE);
d_arc_end (pnt, shift_down);
break;
case SPIRAL:
- draw_sqr (pnt, TRUE);
d_spiral_end (pnt, shift_down);
break;
case BEZIER:
diff --git a/plug-ins/gfig/gfig-dobject.h b/plug-ins/gfig/gfig-dobject.h
index 2315273..87eb393 100644
--- a/plug-ins/gfig/gfig-dobject.h
+++ b/plug-ins/gfig/gfig-dobject.h
@@ -27,6 +27,7 @@
#include "gfig-types.h"
#include "gfig-style.h"
+typedef void (*DobjDrawFunc) (GfigObject *, cairo_t *);
typedef void (*DobjFunc) (GfigObject *);
typedef GfigObject *(*DobjGenFunc) (GfigObject *);
@@ -43,7 +44,7 @@ typedef struct
const gchar *name;
/* virtuals */
- DobjFunc drawfunc; /* How do I draw myself */
+ DobjDrawFunc drawfunc; /* How do I draw myself */
DobjFunc paintfunc; /* Draw me on canvas */
DobjGenFunc copyfunc; /* copy */
void (*update) (GdkPoint *pnt);
@@ -82,7 +83,8 @@ void d_delete_dobjpoints (DobjPoints *pnts);
void object_update (GdkPoint *pnt);
GList *copy_all_objs (GList *objs);
void draw_objects (GList *objs,
- gboolean show_single);
+ gboolean show_single,
+ cairo_t *cr);
GfigObject *d_load_object (gchar *desc,
FILE *fp);
diff --git a/plug-ins/gfig/gfig-ellipse.c b/plug-ins/gfig/gfig-ellipse.c
index 65584ee..1e9dd81 100644
--- a/plug-ins/gfig/gfig-ellipse.c
+++ b/plug-ins/gfig/gfig-ellipse.c
@@ -27,7 +27,6 @@
#include <stdlib.h>
#include <libgimp/gimp.h>
-#undef GDK_DISABLE_DEPRECATED
#include <libgimp/gimpui.h>
#include "gfig.h"
@@ -37,51 +36,43 @@
#include "libgimp/stdplugins-intl.h"
-static void d_draw_ellipse (GfigObject *obj);
+static void d_draw_ellipse (GfigObject *obj,
+ cairo_t *cr);
static void d_paint_ellipse (GfigObject *obj);
static GfigObject *d_copy_ellipse (GfigObject *obj);
static void d_update_ellipse (GdkPoint *pnt);
static void
-d_draw_ellipse (GfigObject * obj)
+d_draw_ellipse (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *center_pnt;
DobjPoints *edge_pnt;
gint bound_wx;
gint bound_wy;
- gint top_x;
- gint top_y;
center_pnt = obj->points;
if (!center_pnt)
return; /* End-of-line */
+ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr);
+
edge_pnt = center_pnt->next;
if (!edge_pnt)
- {
- g_warning ("Internal error - ellipse no edge pnt");
- }
+ return;
- draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj);
- draw_sqr (&edge_pnt->pnt, obj == gfig_context->selected_obj);
+ if (obj == obj_creating)
+ draw_circle (&edge_pnt->pnt, TRUE, cr);
+ else
+ draw_sqr (&edge_pnt->pnt, obj == gfig_context->selected_obj, cr);
bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x);
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y);
- if (edge_pnt->pnt.x > center_pnt->pnt.x)
- top_x = 2 * center_pnt->pnt.x - edge_pnt->pnt.x;
- else
- top_x = edge_pnt->pnt.x;
-
- if (edge_pnt->pnt.y > center_pnt->pnt.y)
- top_y = 2 * center_pnt->pnt.y - edge_pnt->pnt.y;
- else
- top_y = edge_pnt->pnt.y;
-
- gfig_draw_arc (center_pnt->pnt.x, center_pnt->pnt.y, bound_wx, bound_wy, 0, 360);
+ gfig_draw_arc (center_pnt->pnt.x, center_pnt->pnt.y, bound_wx, bound_wy, 0, 360, cr);
}
static void
@@ -184,12 +175,7 @@ static void
d_update_ellipse (GdkPoint *pnt)
{
DobjPoints *center_pnt, *edge_pnt;
- gint bound_wx;
- gint bound_wy;
- gint top_x;
- gint top_y;
- /* Undraw last one then draw new one */
center_pnt = obj_creating->points;
if (!center_pnt)
@@ -197,31 +183,6 @@ d_update_ellipse (GdkPoint *pnt)
if ((edge_pnt = center_pnt->next))
{
- /* Undraw current */
- bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x) * 2;
- bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y) * 2;
-
- if (edge_pnt->pnt.x > center_pnt->pnt.x)
- top_x = 2 * center_pnt->pnt.x - edge_pnt->pnt.x;
- else
- top_x = edge_pnt->pnt.x;
-
- if (edge_pnt->pnt.y > center_pnt->pnt.y)
- top_y = 2 * center_pnt->pnt.y - edge_pnt->pnt.y;
- else
- top_y = edge_pnt->pnt.y;
-
- draw_circle (&edge_pnt->pnt, TRUE);
-
- gdk_draw_arc (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- 0,
- top_x,
- top_y,
- bound_wx,
- bound_wy,
- 0,
- 360 * 64);
edge_pnt->pnt = *pnt;
}
else
@@ -229,31 +190,6 @@ d_update_ellipse (GdkPoint *pnt)
edge_pnt = new_dobjpoint (pnt->x, pnt->y);
center_pnt->next = edge_pnt;
}
-
- draw_circle (&edge_pnt->pnt, TRUE);
-
- bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x) * 2;
- bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y) * 2;
-
- if (edge_pnt->pnt.x > center_pnt->pnt.x)
- top_x = 2 * center_pnt->pnt.x - edge_pnt->pnt.x;
- else
- top_x = edge_pnt->pnt.x;
-
- if (edge_pnt->pnt.y > center_pnt->pnt.y)
- top_y = 2 * center_pnt->pnt.y - edge_pnt->pnt.y;
- else
- top_y = edge_pnt->pnt.y;
-
- gdk_draw_arc (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- 0,
- top_x,
- top_y,
- bound_wx,
- bound_wy,
- 0,
- 360 * 64);
}
void
@@ -275,7 +211,6 @@ d_ellipse_end (GdkPoint *pnt,
}
else
{
- draw_circle (pnt, TRUE);
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
diff --git a/plug-ins/gfig/gfig-grid.c b/plug-ins/gfig/gfig-grid.c
index 8486c99..8f9605c 100644
--- a/plug-ins/gfig/gfig-grid.c
+++ b/plug-ins/gfig/gfig-grid.c
@@ -26,7 +26,6 @@
#include <stdlib.h>
#include <libgimp/gimp.h>
-#undef GDK_DISABLE_DEPRECATED
#include <libgimp/gimpui.h>
#include "gfig.h"
@@ -42,14 +41,14 @@
#define TAN_1o6PI_RAD 1 / SQRT3 /* Tangent 1/6 Pi Radians == SIN / COS */
#define RECIP_TAN_1o6PI_RAD SQRT3 /* Reciprocal of Tangent 1/6 Pi Radians */
-static GdkGC *grid_hightlight_drawgc = NULL;
gint grid_gc_type = GTK_STATE_NORMAL;
-static void draw_grid_polar (GdkGC *drawgc);
-static void draw_grid_sq (GdkGC *drawgc);
-static void draw_grid_iso (GdkGC *drawgc);
+static void draw_grid_polar (cairo_t *drawgc);
+static void draw_grid_sq (cairo_t *drawgc);
+static void draw_grid_iso (cairo_t *drawgc);
-static GdkGC * gfig_get_grid_gc (GtkWidget *widget,
+static cairo_t * gfig_get_grid_gc (cairo_t *cr,
+ GtkWidget *widget,
gint gctype);
static void find_grid_pos_polar (GdkPoint *p,
@@ -190,41 +189,6 @@ find_grid_pos_polar (GdkPoint *p,
void
gfig_grid_colours (GtkWidget *widget)
{
- GdkColormap *colormap;
- GdkGCValues values;
- GdkColor col1;
- GdkColor col2;
- guchar stipple[8] =
- {
- 0xAA, /* ####---- */
- 0x55, /* ###----# */
- 0xAA, /* ##----## */
- 0x55, /* #----### */
- 0xAA, /* ----#### */
- 0x55, /* ---####- */
- 0xAA, /* --####-- */
- 0x55, /* -####--- */
- };
-
- colormap = gdk_screen_get_rgb_colormap (gtk_widget_get_screen (widget));
-
- gdk_color_parse ("gray50", &col1);
- gdk_colormap_alloc_color (colormap, &col1, FALSE, TRUE);
-
- gdk_color_parse ("gray80", &col2);
- gdk_colormap_alloc_color (colormap, &col2, FALSE, TRUE);
-
- values.background.pixel = col1.pixel;
- values.foreground.pixel = col2.pixel;
- values.fill = GDK_OPAQUE_STIPPLED;
- values.stipple = gdk_bitmap_create_from_data (gtk_widget_get_window (widget),
- (gchar *) stipple, 4, 4);
- grid_hightlight_drawgc = gdk_gc_new_with_values (gtk_widget_get_window (widget),
- &values,
- GDK_GC_FOREGROUND |
- GDK_GC_BACKGROUND |
- GDK_GC_FILL |
- GDK_GC_STIPPLE);
}
void
@@ -395,7 +359,7 @@ find_grid_pos (GdkPoint *p,
}
static void
-draw_grid_polar (GdkGC *drawgc)
+draw_grid_polar (cairo_t *cr)
{
gdouble inner_radius;
gdouble outer_radius;
@@ -408,16 +372,11 @@ draw_grid_polar (GdkGC *drawgc)
{
gdouble t;
gdouble sector_size = 2 * G_PI / current_sectors;
-
- gdk_draw_arc (gtk_widget_get_window (gfig_context->preview),
- drawgc,
- 0,
- 0.5 + (preview_width / 2 - outer_radius),
- 0.5 + (preview_height / 2 - outer_radius),
- 0.5 + (outer_radius * 2),
- 0.5 + (outer_radius * 2),
- 0,
- 360 * 64);
+ cairo_arc (cr,
+ 0.5 + preview_width / 2,
+ 0.5 + preview_height / 2,
+ outer_radius, 0, 2 * G_PI);
+ cairo_stroke (cr);
while ((current_sectors < selvals.opts.grid_sectors_desired)
&& (inner_radius * sector_size
@@ -431,13 +390,13 @@ draw_grid_polar (GdkGC *drawgc)
{
gdouble normal_x = cos (selvals.opts.grid_rotation+t);
gdouble normal_y = sin (selvals.opts.grid_rotation+t);
-
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- drawgc,
+ cairo_move_to (cr,
0.5 + (preview_width / 2 + inner_radius * normal_x),
- 0.5 + (preview_height / 2 - inner_radius * normal_y),
+ 0.5 + (preview_height / 2 - inner_radius * normal_y));
+ cairo_line_to (cr,
0.5 + (preview_width / 2 + outer_radius * normal_x),
- 0.5 + (preview_height / 2 - outer_radius * normal_y) );
+ 0.5 + (preview_height / 2 - outer_radius * normal_y));
+ cairo_stroke (cr);
}
}
@@ -446,7 +405,7 @@ draw_grid_polar (GdkGC *drawgc)
static void
-draw_grid_sq (GdkGC *drawgc)
+draw_grid_sq (cairo_t *cr)
{
gint step;
gint loop;
@@ -456,29 +415,22 @@ draw_grid_sq (GdkGC *drawgc)
for (loop = 0 ; loop < preview_height ; loop += step)
{
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- drawgc,
- 0,
- loop,
- preview_width,
- loop);
+ cairo_move_to (cr, 0, loop);
+ cairo_line_to (cr, preview_width, loop);
}
/* Draw the vertical lines */
for (loop = 0 ; loop < preview_width ; loop += step)
{
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- drawgc,
- loop,
- 0,
- loop,
- preview_height);
+ cairo_move_to (cr, loop, 0);
+ cairo_line_to (cr, loop, preview_height);
}
+ cairo_stroke (cr);
}
static void
-draw_grid_iso (GdkGC *drawgc)
+draw_grid_iso (cairo_t *cr)
{
/* vstep is an int since it's defined from grid size */
gint vstep;
@@ -496,13 +448,10 @@ draw_grid_iso (GdkGC *drawgc)
/* Draw the vertical lines - These are easy */
for (loop = 0 ; loop < preview_width ; loop += hstep)
{
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- drawgc,
- (gint)loop,
- (gint)0,
- (gint)loop,
- (gint)preview_height);
+ cairo_move_to (cr, loop, 0);
+ cairo_line_to (cr, loop, preview_height);
}
+ cairo_stroke (cr);
/* draw diag lines at a Theta of +/- 1/6 Pi Rad */
@@ -517,55 +466,50 @@ draw_grid_iso (GdkGC *drawgc)
/* Draw diag lines */
for (loop = diagonal_start ; loop < diagonal_end ; loop += vstep)
{
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- drawgc,
- (gint)0,
- (gint)loop,
- (gint)diagonal_width,
- (gint)loop + diagonal_height);
-
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- drawgc,
- (gint)0,
- (gint)loop,
- (gint)diagonal_width,
- (gint)loop - diagonal_height);
+ cairo_move_to (cr, 0, loop);
+ cairo_line_to (cr, diagonal_width, loop + diagonal_height);
+
+ cairo_move_to (cr, 0, loop);
+ cairo_line_to (cr, diagonal_width, loop - diagonal_height);
}
+ cairo_stroke (cr);
}
-static GdkGC *
-gfig_get_grid_gc (GtkWidget *w, gint gctype)
+static cairo_t *
+gfig_get_grid_gc (cairo_t *cr, GtkWidget *w, gint gctype)
{
- GtkStyle *style = gtk_widget_get_style (w);
switch (gctype)
{
+ default:
+ case GFIG_NORMAL_GC:
+ cairo_set_source_rgb (cr, .92, .92, .92);
+ break;
case GFIG_BLACK_GC:
- return style->black_gc;
+ cairo_set_source_rgb (cr, 0., 0., 0.);
+ break;
case GFIG_WHITE_GC:
- return style->white_gc;
+ cairo_set_source_rgb (cr, 1., 1., 1.);
+ break;
case GFIG_GREY_GC:
- return grid_hightlight_drawgc;
- case GTK_STATE_NORMAL:
- return style->bg_gc[GTK_STATE_NORMAL];
- case GTK_STATE_ACTIVE:
- return style->bg_gc[GTK_STATE_ACTIVE];
- case GTK_STATE_PRELIGHT:
- return style->bg_gc[GTK_STATE_PRELIGHT];
- case GTK_STATE_SELECTED:
- return style->bg_gc[GTK_STATE_SELECTED];
- case GTK_STATE_INSENSITIVE:
- return style->bg_gc[GTK_STATE_INSENSITIVE];
- default:
- g_warning ("Unknown type for grid colouring\n");
- return style->bg_gc[GTK_STATE_PRELIGHT];
+ cairo_set_source_rgb (cr, .5, .5, .5);
+ break;
+ case GFIG_DARKER_GC:
+ cairo_set_source_rgb (cr, .25, .25, .25);
+ break;
+ case GFIG_LIGHTER_GC:
+ cairo_set_source_rgb (cr, .75, .75, .75);
+ break;
+ case GFIG_VERY_DARK_GC:
+ cairo_set_source_rgb (cr, .125, .125, .125);
+ break;
}
+
+ return cr;
}
void
-draw_grid (void)
+draw_grid (cairo_t *cr)
{
- GdkGC *drawgc;
-
/* Get the size of the preview and calc where the lines go */
/* Draw in prelight to start with... */
/* Always start in the upper left corner for rect.
@@ -579,16 +523,17 @@ draw_grid (void)
}
if (selvals.opts.drawgrid)
- drawgc = gfig_get_grid_gc (gfig_context->preview, grid_gc_type);
+ gfig_get_grid_gc (cr, gfig_context->preview, grid_gc_type);
else
return;
+ cairo_set_line_width (cr, 1.);
if (selvals.opts.gridtype == RECT_GRID)
- draw_grid_sq (drawgc);
+ draw_grid_sq (cr);
else if (selvals.opts.gridtype == POLAR_GRID)
- draw_grid_polar (drawgc);
+ draw_grid_polar (cr);
else if (selvals.opts.gridtype == ISO_GRID)
- draw_grid_iso (drawgc);
+ draw_grid_iso (cr);
}
diff --git a/plug-ins/gfig/gfig-grid.h b/plug-ins/gfig/gfig-grid.h
index eba78f1..79fc6e4 100644
--- a/plug-ins/gfig/gfig-grid.h
+++ b/plug-ins/gfig/gfig-grid.h
@@ -25,9 +25,13 @@
#ifndef __GFIG_GRID_H__
#define __GFIG_GRID_H__
+#define GFIG_NORMAL_GC -1
#define GFIG_BLACK_GC -2
#define GFIG_WHITE_GC -3
#define GFIG_GREY_GC -4
+#define GFIG_DARKER_GC -5
+#define GFIG_LIGHTER_GC -6
+#define GFIG_VERY_DARK_GC -7
#define MIN_GRID 10
#define MAX_GRID 50
@@ -38,6 +42,6 @@ void gfig_grid_colours (GtkWidget *widget);
void find_grid_pos (GdkPoint *p,
GdkPoint *gp,
guint state);
-void draw_grid (void);
+void draw_grid (cairo_t *cr);
#endif /* __GFIG_GRID_H__ */
diff --git a/plug-ins/gfig/gfig-line.c b/plug-ins/gfig/gfig-line.c
index 4a8970c..2b81912 100644
--- a/plug-ins/gfig/gfig-line.c
+++ b/plug-ins/gfig/gfig-line.c
@@ -25,7 +25,6 @@
#include "config.h"
#include <libgimp/gimp.h>
-#undef GDK_DISABLE_DEPRECATED
#include <libgimp/gimpui.h>
#include "gfig.h"
@@ -36,7 +35,8 @@
static GfigObject *d_copy_line (GfigObject *obj);
-static void d_draw_line (GfigObject *obj);
+static void d_draw_line (GfigObject *obj,
+ cairo_t *cr);
static void d_paint_line (GfigObject *obj);
static void d_update_line (GdkPoint *pnt);
@@ -55,7 +55,8 @@ d_copy_line (GfigObject *obj)
}
static void
-d_draw_line (GfigObject *obj)
+d_draw_line (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *spnt;
DobjPoints *epnt;
@@ -69,13 +70,16 @@ d_draw_line (GfigObject *obj)
while (spnt && epnt)
{
- draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj);
+ draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj, cr);
/* Go around all the points drawing a line from one to the next */
- gfig_draw_line (spnt->pnt.x, spnt->pnt.y, epnt->pnt.x, epnt->pnt.y);
+ gfig_draw_line (spnt->pnt.x, spnt->pnt.y, epnt->pnt.x, epnt->pnt.y, cr);
spnt = epnt;
epnt = epnt->next;
}
- draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj);
+ if (obj_creating == obj)
+ draw_circle (&spnt->pnt, TRUE, cr);
+ else
+ draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj, cr);
}
static void
@@ -131,15 +135,10 @@ d_line_object_class_init (void)
class->update = d_update_line;
}
-/* Update end point of line */
static void
d_update_line (GdkPoint *pnt)
{
DobjPoints *spnt, *epnt;
- /* Get last but one segment and undraw it -
- * Then draw new segment in.
- * always dealing with the static object.
- */
/* Get start of segments */
spnt = obj_creating->points;
@@ -149,31 +148,10 @@ d_update_line (GdkPoint *pnt)
if ((epnt = spnt->next))
{
- /* undraw current */
- /* Draw square on point */
- draw_circle (&epnt->pnt, TRUE);
-
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- spnt->pnt.x,
- spnt->pnt.y,
- epnt->pnt.x,
- epnt->pnt.y);
g_free (epnt);
}
- /* draw new */
- /* Draw circle on point */
- draw_circle (pnt, TRUE);
-
epnt = new_dobjpoint (pnt->x, pnt->y);
-
- gdk_draw_line (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- spnt->pnt.x,
- spnt->pnt.y,
- epnt->pnt.x,
- epnt->pnt.y);
spnt->next = epnt;
}
@@ -183,7 +161,6 @@ d_line_start (GdkPoint *pnt,
{
if (!obj_creating || !shift_down)
{
- /* Draw square on point */
/* Must delete obj_creating if we have one */
obj_creating = d_new_object (LINE, pnt->x, pnt->y);
}
@@ -198,9 +175,6 @@ void
d_line_end (GdkPoint *pnt,
gboolean shift_down)
{
- /* Undraw the last circle */
- draw_circle (pnt, TRUE);
-
if (shift_down)
{
if (tmp_line)
diff --git a/plug-ins/gfig/gfig-poly.c b/plug-ins/gfig/gfig-poly.c
index 2db2905..ae74a4e 100644
--- a/plug-ins/gfig/gfig-poly.c
+++ b/plug-ins/gfig/gfig-poly.c
@@ -37,7 +37,8 @@
static gint poly_num_sides = 3; /* Default to three sided object */
-static void d_draw_poly (GfigObject *obj);
+static void d_draw_poly (GfigObject *obj,
+ cairo_t *cr);
static GfigObject *d_copy_poly (GfigObject *obj);
static void d_update_poly (GdkPoint *pnt);
@@ -53,7 +54,8 @@ tool_options_poly (GtkWidget *notebook)
}
static void
-d_draw_poly (GfigObject *obj)
+d_draw_poly (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *center_pnt;
DobjPoints *radius_pnt;
@@ -76,7 +78,7 @@ d_draw_poly (GfigObject *obj)
/* First point is the center */
/* Just draw a control point around it */
- draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj);
+ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr);
/* Next point defines the radius */
radius_pnt = center_pnt->next; /* this defines the vertices */
@@ -90,7 +92,10 @@ d_draw_poly (GfigObject *obj)
}
/* Other control point */
- draw_sqr (&radius_pnt->pnt, obj == gfig_context->selected_obj);
+ if (obj == obj_creating)
+ draw_circle (&radius_pnt->pnt, TRUE, cr);
+ else
+ draw_sqr (&radius_pnt->pnt, obj == gfig_context->selected_obj, cr);
/* Have center and radius - draw polygon */
@@ -123,7 +128,7 @@ d_draw_poly (GfigObject *obj)
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
- gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
+ gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y, cr);
}
else
{
@@ -133,7 +138,7 @@ d_draw_poly (GfigObject *obj)
start_pnt = calc_pnt;
}
- gfig_draw_line (first_pnt.x, first_pnt.y, start_pnt.x, start_pnt.y);
+ gfig_draw_line (first_pnt.x, first_pnt.y, start_pnt.x, start_pnt.y, cr);
}
void
@@ -290,9 +295,6 @@ d_poly2lines (GfigObject *obj)
if (!center_pnt)
return; /* no-line */
- /* Undraw it to start with - removes control points */
- obj->class->drawfunc (obj);
-
/* NULL out these points free later */
obj->points = NULL;
@@ -349,9 +351,6 @@ d_poly2lines (GfigObject *obj)
/* hey we're a line now */
obj->type = LINE;
obj->class = &dobj_class[LINE];
-
- /* draw it + control pnts */
- obj->class->drawfunc (obj);
}
void
@@ -385,9 +384,6 @@ d_star2lines (GfigObject *obj)
if (!center_pnt)
return; /* no-line */
- /* Undraw it to start with - removes control points */
- obj->class->drawfunc (obj);
-
/* NULL out these points free later */
obj->points = NULL;
@@ -474,9 +470,6 @@ d_star2lines (GfigObject *obj)
/* hey we're a line now */
obj->type = LINE;
obj->class = &dobj_class[LINE];
-
- /* draw it + control pnts */
- obj->class->drawfunc (obj);
}
static GfigObject *
@@ -511,49 +504,20 @@ d_update_poly (GdkPoint *pnt)
{
DobjPoints *center_pnt;
DobjPoints *edge_pnt;
- gint saved_cnt_pnt = selvals.opts.showcontrol;
- /* Undraw last one then draw new one */
center_pnt = obj_creating->points;
if (!center_pnt)
return; /* No points */
- /* Leave the first pnt alone -
- * Edge point defines "radius"
- * Only undraw if already have edge point.
- */
-
- /* Hack - turn off cnt points in draw routine
- * Looking back over the other update routines I could
- * use this trick again and cut down on code size!
- */
-
-
if ((edge_pnt = center_pnt->next))
{
- /* Undraw */
- draw_circle (&edge_pnt->pnt, TRUE);
- selvals.opts.showcontrol = 0;
- d_draw_poly (obj_creating);
-
edge_pnt->pnt = *pnt;
}
else
{
- /* Radius is a few pixels away */
- /* First edge point */
d_pnt_add_line (obj_creating, pnt->x, pnt->y, -1);
- edge_pnt = center_pnt->next;
}
-
- /* draw it */
- selvals.opts.showcontrol = 0;
- d_draw_poly (obj_creating);
- selvals.opts.showcontrol = saved_cnt_pnt;
-
- /* Realy draw the control points */
- draw_circle (&edge_pnt->pnt, TRUE);
}
void
@@ -568,7 +532,6 @@ void
d_poly_end (GdkPoint *pnt,
gboolean shift_down)
{
- draw_circle (pnt, TRUE);
add_to_all_obj (gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}
diff --git a/plug-ins/gfig/gfig-preview.c b/plug-ins/gfig/gfig-preview.c
index 4090f5e..5b349d1 100644
--- a/plug-ins/gfig/gfig-preview.c
+++ b/plug-ins/gfig/gfig-preview.c
@@ -24,7 +24,6 @@
#include "config.h"
#include <libgimp/gimp.h>
-#undef GDK_DISABLE_DEPRECATED
#include <libgimp/gimpui.h>
#include "gfig.h"
@@ -53,6 +52,8 @@ static GtkWidget *pos_label; /* XY pos marker */
static void gfig_preview_realize (GtkWidget *widget);
static gboolean gfig_preview_events (GtkWidget *widget,
GdkEvent *event);
+static gboolean gfig_preview_expose (GtkWidget *widget,
+ GdkEvent *event);
static gint gfig_invscale_x (gint x);
static gint gfig_invscale_y (gint y);
@@ -145,7 +146,7 @@ gfig_preview_realize (GtkWidget *widget)
}
static void
-draw_background (void)
+draw_background (cairo_t *cr)
{
if (! back_pixbuf)
back_pixbuf = gimp_image_get_thumbnail (gfig_context->image_id,
@@ -153,27 +154,32 @@ draw_background (void)
GIMP_PIXBUF_LARGE_CHECKS);
if (back_pixbuf)
- gdk_draw_pixbuf (gtk_widget_get_window (gfig_context->preview),
- gtk_widget_get_style (gfig_context->preview)->fg_gc[GTK_STATE_NORMAL],
- back_pixbuf, 0, 0,
- 0, 0,
- gdk_pixbuf_get_width (back_pixbuf),
- gdk_pixbuf_get_height (back_pixbuf),
- GDK_RGB_DITHER_NONE, 0, 0);
+ {
+ gdk_cairo_set_source_pixbuf (cr, back_pixbuf, 0, 0);
+ cairo_paint (cr);
+ }
}
-gboolean
+static gboolean
gfig_preview_expose (GtkWidget *widget,
GdkEvent *event)
{
- gdk_window_clear (gtk_widget_get_window (gfig_context->preview));
+ cairo_t *cr = gdk_cairo_create (event->expose.window);
if (gfig_context->show_background)
- draw_background ();
+ draw_background (cr);
- draw_grid ();
- draw_objects (gfig_context->current_obj->obj_list, TRUE);
+ draw_grid (cr);
+ draw_objects (gfig_context->current_obj->obj_list, TRUE, cr);
+ if (obj_creating)
+ {
+ GList *single = g_list_prepend (NULL, obj_creating);
+ draw_objects (single, TRUE, cr);
+ g_list_free (single);
+ }
+
+ cairo_destroy (cr);
return FALSE;
}
@@ -232,6 +238,8 @@ gfig_preview_events (GtkWidget *widget,
}
}
object_start (&point, bevent->state & GDK_SHIFT_MASK);
+
+ gtk_widget_queue_draw (widget);
}
break;
@@ -291,6 +299,7 @@ gfig_preview_events (GtkWidget *widget,
if (obj_creating)
{
obj_creating->class->update (&point);
+ gtk_widget_queue_draw (widget);
}
gfig_pos_update (point.x, point.y);
break;
diff --git a/plug-ins/gfig/gfig-preview.h b/plug-ins/gfig/gfig-preview.h
index 64442b4..527d3dc 100644
--- a/plug-ins/gfig/gfig-preview.h
+++ b/plug-ins/gfig/gfig-preview.h
@@ -29,9 +29,6 @@
GtkWidget *make_preview (void);
-gboolean gfig_preview_expose (GtkWidget *widget,
- GdkEvent *event);
-
void gfig_pos_enable (GtkWidget *widget,
gpointer data);
diff --git a/plug-ins/gfig/gfig-rectangle.c b/plug-ins/gfig/gfig-rectangle.c
index 6559086..2178638 100644
--- a/plug-ins/gfig/gfig-rectangle.c
+++ b/plug-ins/gfig/gfig-rectangle.c
@@ -25,7 +25,6 @@
#include "config.h"
#include <libgimp/gimp.h>
-#undef GDK_DISABLE_DEPRECATED
#include <libgimp/gimpui.h>
#include "gfig.h"
@@ -34,32 +33,16 @@
#include "libgimp/stdplugins-intl.h"
-static void d_draw_rectangle (GfigObject *obj);
+static void d_draw_rectangle (GfigObject *obj,
+ cairo_t *cr);
static void d_paint_rectangle (GfigObject *obj);
static GfigObject *d_copy_rectangle (GfigObject *obj);
static void d_update_rectangle (GdkPoint *pnt);
-static gint
-gfig_scale_x (gint x)
-{
- if (!selvals.scaletoimage)
- return (gint) (x * (1 / scale_x_factor));
- else
- return x;
-}
-
-static gint
-gfig_scale_y (gint y)
-{
- if (!selvals.scaletoimage)
- return (gint) (y * (1 / scale_y_factor));
- else
- return y;
-}
-
static void
-d_draw_rectangle (GfigObject *obj)
+d_draw_rectangle (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *first_pnt;
DobjPoints *second_pnt;
@@ -71,15 +54,17 @@ d_draw_rectangle (GfigObject *obj)
if (!first_pnt)
return; /* End-of-line */
+ draw_sqr (&first_pnt->pnt, obj == gfig_context->selected_obj, cr);
+
second_pnt = first_pnt->next;
if (!second_pnt)
- {
- g_warning ("Internal error - rectangle no edge pnt");
- }
+ return;
- draw_sqr (&first_pnt->pnt, obj == gfig_context->selected_obj);
- draw_sqr (&second_pnt->pnt, obj == gfig_context->selected_obj);
+ if (obj == obj_creating)
+ draw_circle (&second_pnt->pnt, TRUE, cr);
+ else
+ draw_sqr (&second_pnt->pnt, obj == gfig_context->selected_obj, cr);
xmin = MIN (gfig_scale_x (first_pnt->pnt.x),
gfig_scale_x (second_pnt->pnt.x));
@@ -90,11 +75,8 @@ d_draw_rectangle (GfigObject *obj)
ymax = MAX (gfig_scale_y (first_pnt->pnt.y),
gfig_scale_y (second_pnt->pnt.y));
- gdk_draw_rectangle (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- FALSE,
- xmin, ymin,
- xmax - xmin, ymax - ymin);
+ cairo_rectangle (cr, xmin + .5, ymin + .5, xmax - xmin, ymax - ymin);
+ draw_item (cr, FALSE);
}
static void
@@ -181,10 +163,7 @@ d_update_rectangle (GdkPoint *pnt)
{
DobjPoints *first_pnt;
DobjPoints *second_pnt;
- gint xmin, ymin;
- gint xmax, ymax;
- /* Undraw last one then draw new one */
first_pnt = obj_creating->points;
if (!first_pnt)
@@ -192,21 +171,6 @@ d_update_rectangle (GdkPoint *pnt)
if ((second_pnt = first_pnt->next))
{
- /* Undraw current */
- draw_circle (&second_pnt->pnt, TRUE);
-
- xmin = MIN (gfig_scale_x (first_pnt->pnt.x),
- gfig_scale_x (second_pnt->pnt.x));
- ymin = MIN (gfig_scale_y (first_pnt->pnt.y),
- gfig_scale_y (second_pnt->pnt.y));
- xmax = MAX (gfig_scale_x (first_pnt->pnt.x),
- gfig_scale_x (second_pnt->pnt.x));
- ymax = MAX (gfig_scale_y (first_pnt->pnt.y),
- gfig_scale_y (second_pnt->pnt.y));
- gdk_draw_rectangle (gtk_widget_get_window (gfig_context->preview),
- gfig_gc,
- FALSE,
- xmin, ymin, xmax - xmin, ymax - ymin);
second_pnt->pnt.x = pnt->x;
second_pnt->pnt.y = pnt->y;
}
@@ -215,20 +179,6 @@ d_update_rectangle (GdkPoint *pnt)
second_pnt = new_dobjpoint (pnt->x, pnt->y);
first_pnt->next = second_pnt;
}
-
- draw_circle (&second_pnt->pnt, TRUE);
-
- xmin = MIN (gfig_scale_x (first_pnt->pnt.x),
- gfig_scale_x (second_pnt->pnt.x));
- ymin = MIN (gfig_scale_y (first_pnt->pnt.y),
- gfig_scale_y (second_pnt->pnt.y));
- xmax = MAX (gfig_scale_x (first_pnt->pnt.x),
- gfig_scale_x (second_pnt->pnt.x));
- ymax = MAX (gfig_scale_y (first_pnt->pnt.y),
- gfig_scale_y (second_pnt->pnt.y));
- gdk_draw_rectangle (gtk_widget_get_window (gfig_context->preview),
- gfig_gc, FALSE,
- xmin, ymin, xmax - xmin, ymax - ymin);
}
void
@@ -250,7 +200,6 @@ d_rectangle_end (GdkPoint *pnt,
}
else
{
- draw_circle (pnt, TRUE);
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
diff --git a/plug-ins/gfig/gfig-spiral.c b/plug-ins/gfig/gfig-spiral.c
index f3573ae..2d461b0 100644
--- a/plug-ins/gfig/gfig-spiral.c
+++ b/plug-ins/gfig/gfig-spiral.c
@@ -37,7 +37,8 @@
#include "libgimp/stdplugins-intl.h"
-static void d_draw_spiral (GfigObject *obj);
+static void d_draw_spiral (GfigObject *obj,
+ cairo_t *cr);
static void d_paint_spiral (GfigObject *obj);
static GfigObject *d_copy_spiral (GfigObject *obj);
@@ -57,7 +58,8 @@ tool_options_spiral (GtkWidget *notebook)
}
static void
-d_draw_spiral (GfigObject *obj)
+d_draw_spiral (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *center_pnt;
DobjPoints *radius_pnt;
@@ -82,7 +84,7 @@ d_draw_spiral (GfigObject *obj)
/* First point is the center */
/* Just draw a control point around it */
- draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj);
+ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr);
/* Next point defines the radius */
radius_pnt = center_pnt->next; /* this defines the vetices */
@@ -96,7 +98,10 @@ d_draw_spiral (GfigObject *obj)
}
/* Other control point */
- draw_sqr (&radius_pnt->pnt, obj == gfig_context->selected_obj);
+ if (obj_creating == obj)
+ draw_circle (&radius_pnt->pnt, TRUE, cr);
+ else
+ draw_sqr (&radius_pnt->pnt, obj == gfig_context->selected_obj, cr);
/* Have center and radius - draw spiral */
@@ -137,7 +142,7 @@ d_draw_spiral (GfigObject *obj)
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
- gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
+ gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y, cr);
}
else
{
@@ -278,31 +283,14 @@ d_update_spiral (GdkPoint *pnt)
{
DobjPoints *center_pnt;
DobjPoints *edge_pnt;
- gint saved_cnt_pnt = selvals.opts.showcontrol;
- /* Undraw last one then draw new one */
center_pnt = obj_creating->points;
if (!center_pnt)
return; /* No points */
- /* Leave the first pnt alone -
- * Edge point defines "radius"
- * Only undraw if already have edge point.
- */
-
- /* Hack - turn off cnt points in draw routine
- * Looking back over the other update routines I could
- * use this trick again and cut down on code size!
- */
-
if ((edge_pnt = center_pnt->next))
{
- /* Undraw */
- draw_circle (&edge_pnt->pnt, TRUE);
- selvals.opts.showcontrol = 0;
- d_draw_spiral (obj_creating);
-
edge_pnt->pnt = *pnt;
}
else
@@ -310,16 +298,7 @@ d_update_spiral (GdkPoint *pnt)
/* Radius is a few pixels away */
/* First edge point */
d_pnt_add_line (obj_creating, pnt->x, pnt->y, -1);
- edge_pnt = center_pnt->next;
}
-
- /* draw it */
- selvals.opts.showcontrol = 0;
- d_draw_spiral (obj_creating);
- selvals.opts.showcontrol = saved_cnt_pnt;
-
- /* Realy draw the control points */
- draw_circle (&edge_pnt->pnt, TRUE);
}
void
@@ -334,7 +313,6 @@ void
d_spiral_end (GdkPoint *pnt,
gboolean shift_down)
{
- draw_circle (pnt, TRUE);
add_to_all_obj (gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}
diff --git a/plug-ins/gfig/gfig-star.c b/plug-ins/gfig/gfig-star.c
index ca37372..feb1f5a 100644
--- a/plug-ins/gfig/gfig-star.c
+++ b/plug-ins/gfig/gfig-star.c
@@ -37,7 +37,8 @@
static gint star_num_sides = 3; /* Default to three sided object */
-static void d_draw_star (GfigObject *obj);
+static void d_draw_star (GfigObject *obj,
+ cairo_t *cr);
static void d_paint_star (GfigObject *obj);
static GfigObject *d_copy_star (GfigObject *obj);
@@ -54,7 +55,8 @@ tool_options_star (GtkWidget *notebook)
}
static void
-d_draw_star (GfigObject *obj)
+d_draw_star (GfigObject *obj,
+ cairo_t *cr)
{
DobjPoints *center_pnt;
DobjPoints *outer_radius_pnt;
@@ -79,16 +81,13 @@ d_draw_star (GfigObject *obj)
/* First point is the center */
/* Just draw a control point around it */
- draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj);
+ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr);
/* Next point defines the radius */
outer_radius_pnt = center_pnt->next; /* this defines the vertices */
if (!outer_radius_pnt)
{
-#ifdef DEBUG
- g_warning ("Internal error in star - no outer vertice point \n");
-#endif /* DEBUG */
return;
}
@@ -96,15 +95,20 @@ d_draw_star (GfigObject *obj)
if (!inner_radius_pnt)
{
-#ifdef DEBUG
- g_warning ("Internal error in star - no inner vertice point \n");
-#endif /* DEBUG */
return;
}
/* Other control points */
- draw_sqr (&outer_radius_pnt->pnt, obj == gfig_context->selected_obj);
- draw_sqr (&inner_radius_pnt->pnt, obj == gfig_context->selected_obj);
+ if (obj == obj_creating)
+ {
+ draw_circle (&outer_radius_pnt->pnt, TRUE, cr);
+ draw_circle (&inner_radius_pnt->pnt, TRUE, cr);
+ }
+ else
+ {
+ draw_sqr (&outer_radius_pnt->pnt, obj == gfig_context->selected_obj, cr);
+ draw_sqr (&inner_radius_pnt->pnt, obj == gfig_context->selected_obj, cr);
+ }
/* Have center and radius - draw star */
@@ -150,7 +154,7 @@ d_draw_star (GfigObject *obj)
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
- gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
+ gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y, cr);
}
else
{
@@ -160,7 +164,7 @@ d_draw_star (GfigObject *obj)
start_pnt = calc_pnt;
}
- gfig_draw_line (first_pnt.x, first_pnt.y, start_pnt.x, start_pnt.y);
+ gfig_draw_line (first_pnt.x, first_pnt.y, start_pnt.x, start_pnt.y, cr);
}
static void
@@ -354,33 +358,15 @@ static void
d_update_star (GdkPoint *pnt)
{
DobjPoints *center_pnt, *inner_pnt, *outer_pnt;
- gint saved_cnt_pnt = selvals.opts.showcontrol;
- /* Undraw last one then draw new one */
center_pnt = obj_creating->points;
if (!center_pnt)
return; /* No points */
- /* Leave the first pnt alone -
- * Edge point defines "radius"
- * Only undraw if already have edge point.
- */
-
- /* Hack - turn off cnt points in draw routine
- * Looking back over the other update routines I could
- * use this trick again and cut down on code size!
- */
-
-
if ((outer_pnt = center_pnt->next))
{
- /* Undraw */
inner_pnt = outer_pnt->next;
- draw_circle (&inner_pnt->pnt, TRUE);
- draw_circle (&outer_pnt->pnt, TRUE);
- selvals.opts.showcontrol = 0;
- d_draw_star (obj_creating);
outer_pnt->pnt = *pnt;
inner_pnt->pnt.x = pnt->x + (2 * (center_pnt->pnt.x - pnt->x)) / 3;
inner_pnt->pnt.y = pnt->y + (2 * (center_pnt->pnt.y - pnt->y)) / 3;
@@ -390,23 +376,12 @@ d_update_star (GdkPoint *pnt)
/* Radius is a few pixels away */
/* First edge point */
d_pnt_add_line (obj_creating, pnt->x, pnt->y,-1);
- outer_pnt = center_pnt->next;
/* Inner radius */
d_pnt_add_line (obj_creating,
pnt->x + (2 * (center_pnt->pnt.x - pnt->x)) / 3,
pnt->y + (2 * (center_pnt->pnt.y - pnt->y)) / 3,
-1);
- inner_pnt = outer_pnt->next;
}
-
- /* draw it */
- selvals.opts.showcontrol = 0;
- d_draw_star (obj_creating);
- selvals.opts.showcontrol = saved_cnt_pnt;
-
- /* Realy draw the control points */
- draw_circle (&outer_pnt->pnt, TRUE);
- draw_circle (&inner_pnt->pnt, TRUE);
}
void
@@ -421,7 +396,6 @@ void
d_star_end (GdkPoint *pnt,
gboolean shift_down)
{
- draw_circle (pnt, TRUE);
add_to_all_obj (gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}
diff --git a/plug-ins/gfig/gfig.c b/plug-ins/gfig/gfig.c
index d106d2c..23088e9 100644
--- a/plug-ins/gfig/gfig.c
+++ b/plug-ins/gfig/gfig.c
@@ -90,7 +90,6 @@ static gint load_options (GFigObj *gfig,
FILE *fp);
/* globals */
-GdkGC *gfig_gc;
GfigObjectClass dobj_class[10];
GFigContext *gfig_context;
GtkWidget *top_level_dlg;
diff --git a/plug-ins/gfig/gfig.h b/plug-ins/gfig/gfig.h
index dd298cd..8567203 100644
--- a/plug-ins/gfig/gfig.h
+++ b/plug-ins/gfig/gfig.h
@@ -73,7 +73,6 @@ void object_end (GdkPoint *pnt, gint shift_down);
extern gint line_no;
extern gint preview_width, preview_height;
extern gint need_to_scale;
-extern GdkGC *gfig_gc;
extern gdouble scale_x_factor, scale_y_factor;
extern GdkPixbuf *back_pixbuf;
@@ -165,6 +164,8 @@ gchar *get_line (gchar *buf,
FILE *from,
gint init);
+gint gfig_scale_x (gint x);
+gint gfig_scale_y (gint y);
void scale_to_xy (gdouble *list,
gint size);
void scale_to_original_xy (gdouble *list,
@@ -175,10 +176,14 @@ void gfig_paint (BrushType brush_type,
gint seg_count,
gdouble line_pnts[]);
+void draw_item (cairo_t *cr,
+ gboolean fill);
void draw_circle (GdkPoint *p,
- gboolean selected);
+ gboolean selected,
+ cairo_t *cr);
void draw_sqr (GdkPoint *p,
- gboolean selected);
+ gboolean selected,
+ cairo_t *cr);
void list_button_update (GFigObj *obj);
@@ -198,12 +203,14 @@ void gfig_draw_arc (gint x,
gint width,
gint height,
gint angle1,
- gint angle2);
+ gint angle2,
+ cairo_t *cr);
void gfig_draw_line (gint x0,
gint y0,
gint x1,
- gint y1);
+ gint y1,
+ cairo_t *cr);
void gfig_paint_callback (void);
GFigObj *gfig_load (const gchar *filename,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]