app: port GimpFgBgView rendering to cairo

This commit is contained in:
Michael Natterer 2010-07-29 14:05:51 +02:00
parent 06488d03fe
commit 8d67b5b69b
2 changed files with 22 additions and 73 deletions

View File

@ -139,68 +139,9 @@ gimp_fg_bg_view_destroy (GtkObject *object)
if (view->context) if (view->context)
gimp_fg_bg_view_set_context (view, NULL); gimp_fg_bg_view_set_context (view, NULL);
if (view->render_buf)
{
g_free (view->render_buf);
view->render_buf = NULL;
view->render_buf_size = 0;
}
GTK_OBJECT_CLASS (parent_class)->destroy (object); GTK_OBJECT_CLASS (parent_class)->destroy (object);
} }
static void
gimp_fg_bg_view_draw_rect (GimpFgBgView *view,
GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
const GimpRGB *color)
{
gint rowstride;
guchar r, g, b;
gint xx, yy;
guchar *bp;
if (! (width > 0 && height > 0))
return;
gimp_rgb_get_uchar (color, &r, &g, &b);
rowstride = 3 * ((width + 3) & -4);
if (! view->render_buf || view->render_buf_size < height * rowstride)
{
view->render_buf_size = rowstride * height;
g_free (view->render_buf);
view->render_buf = g_malloc (view->render_buf_size);
}
bp = view->render_buf;
for (xx = 0; xx < width; xx++)
{
*bp++ = r;
*bp++ = g;
*bp++ = b;
}
bp = view->render_buf;
for (yy = 1; yy < height; yy++)
{
bp += rowstride;
memcpy (bp, view->render_buf, rowstride);
}
gdk_draw_rgb_image (drawable, gc, x, y, width, height,
GDK_RGB_DITHER_MAX,
view->render_buf,
rowstride);
}
static gboolean static gboolean
gimp_fg_bg_view_expose (GtkWidget *widget, gimp_fg_bg_view_expose (GtkWidget *widget,
GdkEventExpose *eevent) GdkEventExpose *eevent)
@ -208,6 +149,7 @@ gimp_fg_bg_view_expose (GtkWidget *widget,
GimpFgBgView *view = GIMP_FG_BG_VIEW (widget); GimpFgBgView *view = GIMP_FG_BG_VIEW (widget);
GtkStyle *style = gtk_widget_get_style (widget); GtkStyle *style = gtk_widget_get_style (widget);
GdkWindow *window = gtk_widget_get_window (widget); GdkWindow *window = gtk_widget_get_window (widget);
cairo_t *cr;
GtkAllocation allocation; GtkAllocation allocation;
gint x, y; gint x, y;
gint width, height; gint width, height;
@ -217,6 +159,11 @@ gimp_fg_bg_view_expose (GtkWidget *widget,
if (! gtk_widget_is_drawable (widget)) if (! gtk_widget_is_drawable (widget))
return FALSE; return FALSE;
cr = gdk_cairo_create (eevent->window);
gdk_cairo_region (cr, eevent->region);
cairo_clip (cr);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
x = allocation.x; x = allocation.x;
@ -232,12 +179,14 @@ gimp_fg_bg_view_expose (GtkWidget *widget,
if (view->context) if (view->context)
{ {
gimp_context_get_background (view->context, &color); gimp_context_get_background (view->context, &color);
gimp_fg_bg_view_draw_rect (view, window, gimp_cairo_set_source_rgb (cr, &color);
style->fg_gc[0],
cairo_rectangle (cr,
x + width - rect_w + 1, x + width - rect_w + 1,
y + height - rect_h + 1, y + height - rect_h + 1,
rect_w - 2, rect_h - 2, rect_w - 2,
&color); rect_h - 2);
cairo_fill (cr);
} }
gtk_paint_shadow (style, window, GTK_STATE_NORMAL, gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
@ -250,11 +199,14 @@ gimp_fg_bg_view_expose (GtkWidget *widget,
if (view->context) if (view->context)
{ {
gimp_context_get_foreground (view->context, &color); gimp_context_get_foreground (view->context, &color);
gimp_fg_bg_view_draw_rect (view, window, gimp_cairo_set_source_rgb (cr, &color);
style->fg_gc[0],
x + 1, y + 1, cairo_rectangle (cr,
rect_w - 2, rect_h - 2, x + 1,
&color); y + 1,
rect_w - 2,
rect_h - 2);
cairo_fill (cr);
} }
gtk_paint_shadow (style, window, GTK_STATE_NORMAL, gtk_paint_shadow (style, window, GTK_STATE_NORMAL,

View File

@ -37,9 +37,6 @@ struct _GimpFgBgView
GtkWidget parent_instance; GtkWidget parent_instance;
GimpContext *context; GimpContext *context;
guchar *render_buf;
gint render_buf_size;
}; };
struct _GimpFgBgViewClass struct _GimpFgBgViewClass