ported to Cairo drawing.

2007-11-06  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpblobeditor.c: ported to Cairo drawing.


svn path=/trunk/; revision=24073
This commit is contained in:
Sven Neumann
2007-11-06 09:01:24 +00:00
committed by Sven Neumann
parent 36e1fa8d29
commit 5d229df1f2
2 changed files with 57 additions and 26 deletions

View File

@ -1,3 +1,7 @@
2007-11-06 Sven Neumann <sven@gimp.org>
* app/widgets/gimpblobeditor.c: ported to Cairo drawing.
2007-11-05 Michael Natterer <mitch@gimp.org> 2007-11-05 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcurveview.c (gimp_curve_view_expose): translate * app/widgets/gimpcurveview.c (gimp_curve_view_expose): translate

View File

@ -59,6 +59,7 @@ static gboolean gimp_blob_editor_motion_notify (GtkWidget *widget,
static void gimp_blob_editor_get_handle (GimpBlobEditor *editor, static void gimp_blob_editor_get_handle (GimpBlobEditor *editor,
GdkRectangle *rect); GdkRectangle *rect);
static void gimp_blob_editor_draw_blob (GimpBlobEditor *editor, static void gimp_blob_editor_draw_blob (GimpBlobEditor *editor,
cairo_t *cr,
gdouble xc, gdouble xc,
gdouble yc, gdouble yc,
gdouble radius); gdouble radius);
@ -187,6 +188,7 @@ gimp_blob_editor_expose (GtkWidget *widget,
GdkEventExpose *event) GdkEventExpose *event)
{ {
GimpBlobEditor *editor = GIMP_BLOB_EDITOR (widget); GimpBlobEditor *editor = GIMP_BLOB_EDITOR (widget);
cairo_t *cr;
GdkRectangle rect; GdkRectangle rect;
gint r0; gint r0;
@ -195,23 +197,25 @@ gimp_blob_editor_expose (GtkWidget *widget,
if (r0 < 2) if (r0 < 2)
return TRUE; return TRUE;
gimp_blob_editor_draw_blob (editor, cr = gdk_cairo_create (widget->window);
widget->allocation.width / 2,
widget->allocation.height / 2, gimp_blob_editor_draw_blob (editor, cr,
widget->allocation.width / 2.0,
widget->allocation.height / 2.0,
0.9 * r0); 0.9 * r0);
gimp_blob_editor_get_handle (editor, &rect); gimp_blob_editor_get_handle (editor, &rect);
gdk_draw_rectangle (widget->window, cairo_rectangle (cr,
widget->style->bg_gc[widget->state], rect.x + 0.5, rect.y + 0.5, rect.width - 1, rect.width - 1);
TRUE, /* filled */ gdk_cairo_set_source_color (cr, &widget->style->light[widget->state]);
rect.x, rect.y, cairo_fill_preserve (cr);
rect.width, rect.height);
gtk_paint_shadow (widget->style, widget->window, widget->state, gdk_cairo_set_source_color (cr, &widget->style->dark[widget->state]);
GTK_SHADOW_OUT, cairo_set_line_width (cr, 1);
NULL, widget, NULL, cairo_stroke (cr);
rect.x, rect.y,
rect.width, rect.height); cairo_destroy (cr);
return TRUE; return TRUE;
} }
@ -225,8 +229,8 @@ gimp_blob_editor_button_press (GtkWidget *widget,
gimp_blob_editor_get_handle (editor, &rect); gimp_blob_editor_get_handle (editor, &rect);
if ((event->x >= rect.x) && (event->x-rect.x < rect.width) && if ((event->x >= rect.x) && (event->x - rect.x < rect.width) &&
(event->y >= rect.y) && (event->y-rect.y < rect.height)) (event->y >= rect.y) && (event->y - rect.y < rect.height))
{ {
editor->active = TRUE; editor->active = TRUE;
} }
@ -309,14 +313,15 @@ gimp_blob_editor_get_handle (GimpBlobEditor *editor,
static void static void
gimp_blob_editor_draw_blob (GimpBlobEditor *editor, gimp_blob_editor_draw_blob (GimpBlobEditor *editor,
cairo_t *cr,
gdouble xc, gdouble xc,
gdouble yc, gdouble yc,
gdouble radius) gdouble radius)
{ {
GtkWidget *widget = GTK_WIDGET (editor); GtkWidget *widget = GTK_WIDGET (editor);
Blob *blob; Blob *blob;
BlobFunc function = blob_ellipse; BlobFunc function = blob_ellipse;
gint i; gint i;
switch (editor->type) switch (editor->type)
{ {
@ -333,18 +338,40 @@ gimp_blob_editor_draw_blob (GimpBlobEditor *editor,
break; break;
} }
blob = function (xc, yc, /* to get a nice antialiased outline, render the blob at double size */
radius * cos (editor->angle), blob = function (2.0 * xc, 2.0 * yc,
radius * sin (editor->angle), 2.0 * radius * cos (editor->angle),
2.0 * radius * sin (editor->angle),
(- (radius / editor->aspect) * sin (editor->angle)), (- (radius / editor->aspect) * sin (editor->angle)),
( (radius / editor->aspect) * cos (editor->angle))); ( (radius / editor->aspect) * cos (editor->angle)));
for (i = 0; i < blob->height; i++) for (i = 0; i < blob->height; i++)
if (blob->data[i].left <= blob->data[i].right) if (blob->data[i].left <= blob->data[i].right)
gdk_draw_line (widget->window, {
widget->style->fg_gc[widget->state], cairo_move_to (cr, blob->data[i].left / 2.0, (blob->y + i) / 2.0);
blob->data[i].left, i + blob->y, break;
blob->data[i].right + 1, i + blob->y); }
for (i = i + 1; i < blob->height; i++)
{
if (blob->data[i].left > blob->data[i].right)
break;
cairo_line_to (cr, blob->data[i].left / 2.0, (blob->y + i) / 2.0);
}
for (i = i - 1; i >= 0; i--)
{
if (blob->data[i].left > blob->data[i].right)
break;
cairo_line_to (cr, blob->data[i].right / 2.0, (blob->y + i) / 2.0);
}
cairo_close_path (cr);
g_free (blob); g_free (blob);
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
cairo_fill (cr);
} }