mirror of https://github.com/GNOME/gimp.git
app: port GimpColorBar drawing to cairo
This commit is contained in:
parent
ac80163771
commit
208096bc7c
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
@ -153,14 +155,20 @@ static gboolean
|
|||
gimp_color_bar_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event)
|
||||
{
|
||||
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
|
||||
GtkStyle *style = gtk_widget_get_style (widget);
|
||||
GtkAllocation allocation;
|
||||
guchar *buf;
|
||||
guchar *b;
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
gint i, j;
|
||||
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
|
||||
cairo_t *cr;
|
||||
GtkAllocation allocation;
|
||||
cairo_surface_t *surface;
|
||||
cairo_pattern_t *pattern;
|
||||
guchar *b;
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
gint i;
|
||||
|
||||
cr = gdk_cairo_create (event->window);
|
||||
|
||||
gdk_cairo_region (cr, event->region);
|
||||
cairo_clip (cr);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
|
@ -172,46 +180,42 @@ gimp_color_bar_expose (GtkWidget *widget,
|
|||
if (width < 1 || height < 1)
|
||||
return TRUE;
|
||||
|
||||
buf = g_alloca (width * height * 3);
|
||||
cairo_translate (cr, allocation.x + x, allocation.y + y);
|
||||
cairo_rectangle (cr, 0, 0, width, height);
|
||||
cairo_clip (cr);
|
||||
|
||||
switch (bar->orientation)
|
||||
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 1);
|
||||
|
||||
for (i = 0, b = cairo_image_surface_get_data (surface);
|
||||
i < 256;
|
||||
i++, b += 4)
|
||||
{
|
||||
case GTK_ORIENTATION_HORIZONTAL:
|
||||
for (i = 0, b = buf; i < width; i++, b += 3)
|
||||
{
|
||||
const guchar *src = bar->buf + 3 * ((i * 256) / width);
|
||||
const guchar *src = bar->buf + 3 * i;
|
||||
|
||||
b[0] = src[0];
|
||||
b[1] = src[1];
|
||||
b[2] = src[2];
|
||||
}
|
||||
|
||||
for (i = 1; i < height; i++)
|
||||
memcpy (buf + i * width * 3, buf, width * 3);
|
||||
|
||||
break;
|
||||
|
||||
case GTK_ORIENTATION_VERTICAL:
|
||||
for (i = 0, b = buf; i < height; i++, b += 3 * width)
|
||||
{
|
||||
const guchar *src = bar->buf + 3 * (255 - ((i * 256) / height));
|
||||
guchar *dest = b;
|
||||
|
||||
for (j = 0; j < width; j++, dest += 3)
|
||||
{
|
||||
dest[0] = src[0];
|
||||
dest[1] = src[1];
|
||||
dest[2] = src[2];
|
||||
}
|
||||
}
|
||||
break;
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL(b, src[0], src[1], src[2]);
|
||||
}
|
||||
|
||||
gdk_draw_rgb_image (gtk_widget_get_window (widget), style->black_gc,
|
||||
allocation.x + x, allocation.y + y,
|
||||
width, height,
|
||||
GDK_RGB_DITHER_NORMAL,
|
||||
buf, 3 * width);
|
||||
pattern = cairo_pattern_create_for_surface (surface);
|
||||
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
if (bar->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
cairo_scale (cr, (gdouble) width / 256.0, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cairo_translate (cr, 0, height);
|
||||
cairo_scale (cr, 1.0, (gdouble) height / 256.0);
|
||||
cairo_rotate (cr, - G_PI / 2);
|
||||
}
|
||||
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_pattern_destroy (pattern);
|
||||
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_destroy (cr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue