[gimp] plug-ins: port ifs-compose drawing to cairo
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port ifs-compose drawing to cairo
- Date: Fri, 10 Sep 2010 12:45:05 +0000 (UTC)
commit 9b440396e1c9212f07382dfdd595285e8d2a64dc
Author: Michael Natterer <mitch gimp org>
Date: Fri Sep 10 14:44:41 2010 +0200
plug-ins: port ifs-compose drawing to cairo
plug-ins/ifs-compose/ifs-compose-utils.c | 58 +++++++++++++++++++--------
plug-ins/ifs-compose/ifs-compose.c | 63 +++++++++++++++---------------
plug-ins/ifs-compose/ifs-compose.h | 9 ++--
3 files changed, 76 insertions(+), 54 deletions(-)
---
diff --git a/plug-ins/ifs-compose/ifs-compose-utils.c b/plug-ins/ifs-compose/ifs-compose-utils.c
index e03f657..4e2a355 100644
--- a/plug-ins/ifs-compose/ifs-compose-utils.c
+++ b/plug-ins/ifs-compose/ifs-compose-utils.c
@@ -716,33 +716,57 @@ aff_element_draw (AffElement *elem,
gboolean selected,
gint width,
gint height,
- GdkDrawable *win,
- GdkGC *normal_gc,
- GdkGC *selected_gc,
+ cairo_t *cr,
+ GdkColor *color,
PangoLayout *layout)
{
- PangoRectangle rect;
- GdkGC *gc;
+ PangoRectangle rect;
+ gint i;
pango_layout_set_text (layout, elem->name, -1);
pango_layout_get_pixel_extents (layout, NULL, &rect);
- if (selected)
- gc = selected_gc;
- else
- gc = normal_gc;
+ gdk_cairo_set_source_color (cr, color);
- gdk_draw_layout (win, gc,
- elem->v.x * width - rect.width / 2,
- elem->v.y * width + rect.height / 2,
- layout);
+ cairo_move_to (cr,
+ elem->v.x * width - rect.width / 2,
+ elem->v.y * width + rect.height / 2);
+ pango_cairo_show_layout (cr, layout);
+ cairo_fill (cr);
+
+ cairo_set_line_width (cr, 1.0);
if (elem->click_boundary != elem->draw_boundary)
- gdk_draw_polygon (win, normal_gc, FALSE, elem->click_boundary->points,
- elem->click_boundary->npoints);
+ {
+ cairo_move_to (cr,
+ elem->click_boundary->points[0].x,
+ elem->click_boundary->points[0].y);
+
+ for (i = 1; i < elem->click_boundary->npoints; i++)
+ cairo_line_to (cr,
+ elem->click_boundary->points[i].x,
+ elem->click_boundary->points[i].y);
+
+ cairo_close_path (cr);
+
+ cairo_stroke (cr);
+ }
+
+ if (selected)
+ cairo_set_line_width (cr, 3.0);
+
+ cairo_move_to (cr,
+ elem->draw_boundary->points[0].x,
+ elem->draw_boundary->points[0].y);
+
+ for (i = 1; i < elem->draw_boundary->npoints; i++)
+ cairo_line_to (cr,
+ elem->draw_boundary->points[i].x,
+ elem->draw_boundary->points[i].y);
+
+ cairo_close_path (cr);
- gdk_draw_polygon (win, gc, FALSE, elem->draw_boundary->points,
- elem->draw_boundary->npoints);
+ cairo_stroke (cr);
}
AffElement *
diff --git a/plug-ins/ifs-compose/ifs-compose.c b/plug-ins/ifs-compose/ifs-compose.c
index 7228366..722fc76 100644
--- a/plug-ins/ifs-compose/ifs-compose.c
+++ b/plug-ins/ifs-compose/ifs-compose.c
@@ -126,8 +126,6 @@ typedef struct
gdouble op_center_y;
guint button_state;
gint num_selected;
-
- GdkGC *selected_gc;
} IfsDesignArea;
typedef struct
@@ -983,8 +981,6 @@ ifs_compose_dialog (GimpDrawable *drawable)
gdk_flush ();
- g_object_unref (ifsDesign->selected_gc);
-
g_free (ifsD);
return ifscint.run;
@@ -1500,6 +1496,7 @@ design_area_expose (GtkWidget *widget,
{
GtkStyle *style = gtk_widget_get_style (widget);
GtkStateType state = gtk_widget_get_state (widget);
+ cairo_t *cr;
GtkAllocation allocation;
PangoLayout *layout;
gint i;
@@ -1507,31 +1504,29 @@ design_area_expose (GtkWidget *widget,
gtk_widget_get_allocation (widget, &allocation);
- if (!ifsDesign->selected_gc)
- {
- ifsDesign->selected_gc = gdk_gc_new (gtk_widget_get_window (ifsDesign->area));
- gdk_gc_set_line_attributes (ifsDesign->selected_gc, 2,
- GDK_LINE_SOLID, GDK_CAP_ROUND,
- GDK_JOIN_ROUND);
- }
+ cr = gdk_cairo_create (ifsDesign->pixmap);
+
+ gdk_cairo_set_source_color (cr, &style->bg[state]);
+ cairo_paint (cr);
- gdk_draw_rectangle (ifsDesign->pixmap,
- style->bg_gc[state],
- TRUE,
- event->area.x,
- event->area.y,
- event->area.width, event->area.height);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_translate (cr, 0.5, 0.5);
/* draw an indicator for the center */
cx = ifsvals.center_x * allocation.width;
cy = ifsvals.center_y * allocation.width;
- gdk_draw_line (ifsDesign->pixmap,
- style->fg_gc[state],
- cx - 10, cy, cx + 10, cy);
- gdk_draw_line (ifsDesign->pixmap,
- style->fg_gc[state],
- cx, cy - 10, cx, cy + 10);
+
+ cairo_move_to (cr, cx - 10, cy);
+ cairo_line_to (cr, cx + 10, cy);
+
+ cairo_move_to (cr, cx, cy - 10);
+ cairo_line_to (cr, cx, cy + 10);
+
+ gdk_cairo_set_source_color (cr, &style->fg[state]);
+ cairo_set_line_width (cr, 1.0);
+ cairo_stroke (cr);
layout = gtk_widget_create_pango_layout (widget, NULL);
@@ -1540,20 +1535,24 @@ design_area_expose (GtkWidget *widget,
aff_element_draw (elements[i], element_selected[i],
allocation.width,
allocation.height,
- ifsDesign->pixmap,
- style->fg_gc[state],
- ifsDesign->selected_gc,
+ cr,
+ &style->fg[state],
layout);
}
g_object_unref (layout);
- gdk_draw_drawable (gtk_widget_get_window (widget),
- style->fg_gc[state],
- ifsDesign->pixmap,
- event->area.x, event->area.y,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
+ cairo_destroy (cr);
+
+ cr = gdk_cairo_create (gtk_widget_get_window (widget));
+
+ gdk_cairo_region (cr, event->region);
+ cairo_clip (cr);
+
+ gdk_cairo_set_source_pixmap (cr, ifsDesign->pixmap, 0.0, 0.0);
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
return FALSE;
}
diff --git a/plug-ins/ifs-compose/ifs-compose.h b/plug-ins/ifs-compose/ifs-compose.h
index 0e35d1c..ce4d092 100644
--- a/plug-ins/ifs-compose/ifs-compose.h
+++ b/plug-ins/ifs-compose/ifs-compose.h
@@ -153,12 +153,11 @@ void aff_element_compute_boundary (AffElement *elem,
gint num_elements);
void aff_element_draw (AffElement *elem,
gint selected,
- gint width,
+ gint width,
gint height,
- GdkDrawable *win,
- GdkGC *normal_gc,
- GdkGC *selected_gc,
- PangoLayout *layout);
+ cairo_t *cr,
+ GdkColor *color,
+ PangoLayout *layout);
void ifs_render (AffElement **elements,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]