/***********************************************
* ge_hsb_from_color -
- *
+ *
* Get HSB values from RGB values.
*
* Modified from Smooth but originated in GTK+
***********************************************/
void
-ge_hsb_from_color (const CairoColor *color,
- gdouble *hue,
+ge_hsb_from_color (const CairoColor *color,
+ gdouble *hue,
gdouble *saturation,
- gdouble *brightness)
+ gdouble *brightness)
{
gdouble min, max, delta;
gdouble red, green, blue;
red = color->r;
green = color->g;
blue = color->b;
-
+
if (red > green)
{
max = MAX(red, blue);
max = MAX(green, blue);
min = MIN(red, blue);
}
-
+
*brightness = (max + min) / 2;
-
+
if (fabs(max - min) < 0.0001)
{
*hue = 0;
*saturation = 0;
- }
+ }
else
{
if (*brightness <= 0.5)
*saturation = (max - min) / (max + min);
else
*saturation = (max - min) / (2 - max - min);
-
+
delta = max -min;
-
+
if (red == max)
*hue = (green - blue) / delta;
else if (green == max)
*hue = 2 + (blue - red) / delta;
else if (blue == max)
*hue = 4 + (red - green) / delta;
-
+
*hue *= 60;
if (*hue < 0.0)
*hue += 360;
}
}
-
+
/***********************************************
* ge_color_from_hsb -
- *
+ *
* Get RGB values from HSB values.
*
* Modified from Smooth but originated in GTK+
***********************************************/
#define MODULA(number, divisor) (((gint)number % divisor) + (number - (gint)number))
void
-ge_color_from_hsb (gdouble hue,
+ge_color_from_hsb (gdouble hue,
gdouble saturation,
- gdouble brightness,
+ gdouble brightness,
CairoColor *color)
{
gint i;
gdouble m1, m2, m3;
if (!color) return;
-
+
if (brightness <= 0.5)
m2 = brightness * (1 + saturation);
else
m2 = brightness + saturation - brightness * saturation;
-
+
m1 = 2 * brightness - m2;
-
+
hue_shift[0] = hue + 120;
hue_shift[1] = hue;
hue_shift[2] = hue - 120;
-
- color_shift[0] = color_shift[1] = color_shift[2] = brightness;
-
+
+ color_shift[0] = color_shift[1] = color_shift[2] = brightness;
+
i = (saturation == 0)?3:0;
-
+
for (; i < 3; i++)
{
m3 = hue_shift[i];
-
+
if (m3 > 360)
m3 = MODULA(m3, 360);
else if (m3 < 0)
m3 = 360 - MODULA(ABS(m3), 360);
-
+
if (m3 < 60)
color_shift[i] = m1 + (m2 - m1) * m3 / 60;
else if (m3 < 180)
color_shift[i] = m1 + (m2 - m1) * (240 - m3) / 60;
else
color_shift[i] = m1;
- }
-
+ }
+
color->r = color_shift[0];
color->g = color_shift[1];
- color->b = color_shift[2];
- color->a = 1.0;
+ color->b = color_shift[2];
+ color->a = 1.0;
}
void
c->blue = b;
}
-void
+void
ge_gtk_style_to_cairo_color_cube (GtkStyle * style, CairoColorCube *cube)
{
int i;
g_return_if_fail (style && cube);
for (i = 0; i < 5; i++)
- {
+ {
ge_gdk_color_to_cairo (&style->bg[i], &cube->bg[i]);
ge_gdk_color_to_cairo (&style->fg[i], &cube->fg[i]);
gdouble hue = 0;
gdouble saturation = 0;
gdouble brightness = 0;
-
+
g_return_if_fail (base && composite);
ge_hsb_from_color (base, &hue, &saturation, &brightness);
-
+
brightness = MIN(brightness*shade_ratio, 1.0);
brightness = MAX(brightness, 0.0);
-
+
saturation = MIN(saturation*shade_ratio, 1.0);
saturation = MAX(saturation, 0.0);
-
+
ge_color_from_hsb (hue, saturation, brightness, composite);
- composite->a = base->a;
+ composite->a = base->a;
}
void
gdouble hue = 0;
gdouble saturation = 0;
gdouble brightness = 0;
-
+
g_return_if_fail (base && composite);
ge_hsb_from_color (base, &hue, &saturation, &brightness);
saturation = MAX(saturation, 0.0);
ge_color_from_hsb (hue, saturation, brightness, composite);
- composite->a = base->a;
+ composite->a = base->a;
}
void
-ge_mix_color (const CairoColor *color1, const CairoColor *color2,
+ge_mix_color (const CairoColor *color1, const CairoColor *color2,
gdouble mix_factor, CairoColor *composite)
{
g_return_if_fail (color1 && color2 && composite);
composite->a = 1.0;
}
-cairo_t *
+cairo_t *
ge_gdk_drawable_to_cairo (GdkDrawable *window, GdkRectangle *area)
{
cairo_t *cr;
cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
- if (area)
+ if (area)
{
cairo_rectangle (cr, area->x, area->y, area->width, area->height);
cairo_clip_preserve (cr);
return cr;
}
-void
+void
ge_cairo_set_color (cairo_t *cr, const CairoColor *color)
{
g_return_if_fail (cr && color);
- cairo_set_source_rgba (cr, color->r, color->g, color->b, color->a);
+ cairo_set_source_rgba (cr, color->r, color->g, color->b, color->a);
}
void
alpha);
}
-void
-ge_cairo_pattern_add_color_stop_color (cairo_pattern_t *pattern,
- gfloat offset,
+void
+ge_cairo_pattern_add_color_stop_color (cairo_pattern_t *pattern,
+ gfloat offset,
const CairoColor *color)
{
g_return_if_fail (pattern && color);
- cairo_pattern_add_color_stop_rgba (pattern, offset, color->r, color->g, color->b, color->a);
+ cairo_pattern_add_color_stop_rgba (pattern, offset, color->r, color->g, color->b, color->a);
}
void
-ge_cairo_pattern_add_color_stop_shade(cairo_pattern_t *pattern,
- gdouble offset,
- const CairoColor *color,
+ge_cairo_pattern_add_color_stop_shade(cairo_pattern_t *pattern,
+ gdouble offset,
+ const CairoColor *color,
gdouble shade)
{
CairoColor shaded;
ge_shade_color(color, shade, &shaded);
}
- ge_cairo_pattern_add_color_stop_color(pattern, offset, &shaded);
+ ge_cairo_pattern_add_color_stop_color(pattern, offset, &shaded);
}
/* This function will draw a rounded corner at position x,y. If the radius
cairo_move_to (cr, x+radius, y);
else
cairo_move_to (cr, x, y);
-
+
if (corners & CR_CORNER_TOPRIGHT)
cairo_arc (cr, x+w-radius, y+radius, radius, G_PI * 1.5, G_PI * 2);
else
cairo_line_to (cr, x+w, y);
-
+
if (corners & CR_CORNER_BOTTOMRIGHT)
cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, G_PI * 0.5);
else
cairo_line_to (cr, x+w, y+h);
-
+
if (corners & CR_CORNER_BOTTOMLEFT)
cairo_arc (cr, x+radius, y+h-radius, radius, G_PI * 0.5, G_PI);
else
cairo_line_to (cr, x, y+h);
-
+
if (corners & CR_CORNER_TOPLEFT)
cairo_arc (cr, x+radius, y+radius, radius, G_PI, G_PI * 1.5);
else
/***********************************************
* ge_cairo_simple_border -
- *
+ *
* A simple routine to draw thin squared
* borders with a topleft and bottomright color.
- *
+ *
* It originated in Smooth-Engine.
***********************************************/
void
ge_cairo_simple_border (cairo_t *cr,
const CairoColor * tl, const CairoColor * br,
- gint x, gint y, gint width, gint height,
+ gint x, gint y, gint width, gint height,
gboolean topleft_overlap)
{
gboolean solid_color;
g_return_if_fail (cr != NULL);
g_return_if_fail (tl != NULL);
g_return_if_fail (br != NULL);
-
+
solid_color = (tl == br) || ((tl->r == br->r) && (tl->g == br->g) && (tl->b == br->b) && (tl->a == br->a));
if (topleft_overlap)
{
- ge_cairo_set_color(cr, br);
+ ge_cairo_set_color(cr, br);
cairo_move_to(cr, x + 0.5, y + height - 0.5);
cairo_line_to(cr, x + width - 0.5, y + height - 0.5);
cairo_line_to(cr, x + width - 0.5, y + 0.5);
-
+
cairo_stroke (cr);
}
-
- ge_cairo_set_color(cr, tl);
+
+ ge_cairo_set_color(cr, tl);
cairo_move_to(cr, x + 0.5, y + height - 0.5);
cairo_line_to(cr, x + 0.5, y + 0.5);
if (!solid_color)
{
cairo_stroke(cr);
- ge_cairo_set_color(cr, br);
+ ge_cairo_set_color(cr, br);
}
cairo_move_to(cr, x + 0.5, y + height - 0.5);
cairo_save(cr);
- ge_cairo_set_color(cr, color);
+ ge_cairo_set_color(cr, color);
cairo_move_to(cr, points[0].x, points[0].y);
for (i = 1; i < npoints; i++)
{
if (!((points[i].x == points[i + 1].x) &&
- (points[i].y == points[i + 1].y)))
+ (points[i].y == points[i + 1].y)))
{
cairo_line_to(cr, points[i].x, points[i].y);
}
}
-
- if ((points[npoints-1].x != points[0].y) ||
+
+ if ((points[npoints-1].x != points[0].x) ||
(points[npoints-1].y != points[0].y))
{
cairo_line_to(cr, points[0].x, points[0].y);
gint y1,
gint x2,
gint y2)
-{
+{
cairo_save(cr);
- ge_cairo_set_color(cr, color);
+ ge_cairo_set_color(cr, color);
cairo_set_line_width (cr, 1);
cairo_move_to(cr, x1 + 0.5, y1 + 0.5);
gint *height)
{
cairo_matrix_t matrix;
-
+
cairo_matrix_init_identity (&matrix);
-
+
cairo_translate (cr, *x, *y);
*x = 0;
*y = 0;
-
+
if (mirror & CR_MIRROR_HORIZONTAL)
{
cairo_matrix_scale (&matrix, -1, 1);
cairo_matrix_init (&matrix, 0, 1, 1, 0, 0, 0);
cairo_transform (cr, &matrix);
-
+
/* swap width/height */
tmp = *width;
*x = 0;
/***********************************************
* ge_cairo_pattern_fill -
- *
+ *
* Fill an area with some pattern
* Scaling or tiling if needed
***********************************************/
-void
+void
ge_cairo_pattern_fill(cairo_t *canvas,
CairoPattern *pattern,
gint x,
/***********************************************
* ge_cairo_color_pattern -
- *
+ *
* Create A Solid Color Pattern
***********************************************/
CairoPattern*
ge_cairo_color_pattern(CairoColor *base)
-{
+{
CairoPattern * result = g_new0(CairoPattern, 1);
#if ((CAIRO_VERSION_MAJOR < 1) || ((CAIRO_VERSION_MAJOR == 1) && (CAIRO_VERSION_MINOR < 2)))
result->scale = GE_DIRECTION_NONE;
result->translate = GE_DIRECTION_NONE;
- result->handle = cairo_pattern_create_rgba(base->r,
- base->g,
- base->b,
+ result->handle = cairo_pattern_create_rgba(base->r,
+ base->g,
+ base->b,
base->a);
result->operator = CAIRO_OPERATOR_SOURCE;
-
+
return result;
}
/***********************************************
* ge_cairo_pixbuf_pattern -
- *
+ *
* Create A Tiled Pixbuf Pattern
***********************************************/
CairoPattern*
ge_cairo_pixbuf_pattern(GdkPixbuf *pixbuf)
-{
+{
CairoPattern * result = g_new0(CairoPattern, 1);
cairo_t *canvas;
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
-
+
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
canvas = cairo_create(surface);
/***********************************************
* ge_cairo_pixmap_pattern -
- *
+ *
* Create A Tiled Pixmap Pattern
***********************************************/
CairoPattern*
ge_cairo_pixmap_pattern(GdkPixmap *pixmap)
-{
+{
CairoPattern * result = NULL;
GdkPixbuf * pixbuf;
gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
- pixbuf = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE (pixmap),
- gdk_drawable_get_colormap(GDK_DRAWABLE (pixmap)),
+ pixbuf = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE (pixmap),
+ gdk_drawable_get_colormap(GDK_DRAWABLE (pixmap)),
0, 0, 0, 0, width, height);
result = ge_cairo_pixbuf_pattern(pixbuf);
-
+
g_object_unref (pixbuf);
return result;
}
/***********************************************
- * ge_cairo_linear_shade_gradient_pattern -
- *
+ * ge_cairo_linear_shade_gradient_pattern -
+ *
* Create A Linear Shade Gradient Pattern
* Aka Smooth Shade Gradient, from/to gradient
* With End points defined as shades of the
* base color
***********************************************/
CairoPattern *
-ge_cairo_linear_shade_gradient_pattern(CairoColor *base,
- gdouble shade1,
- gdouble shade2,
+ge_cairo_linear_shade_gradient_pattern(CairoColor *base,
+ gdouble shade1,
+ gdouble shade2,
gboolean vertical)
{
CairoPattern * result = g_new0(CairoPattern, 1);
-
+
#if ((CAIRO_VERSION_MAJOR < 1) || ((CAIRO_VERSION_MAJOR == 1) && (CAIRO_VERSION_MINOR < 2)))
result->type = CAIRO_PATTERN_TYPE_LINEAR;
#endif
{
if (pattern->handle)
cairo_pattern_destroy(pattern->handle);
-
+
g_free(pattern);
}
}
const gchar*
g_module_check_init (GModule *module)
{
- return gtk_check_version (GTK_MAJOR_VERSION,
- GTK_MINOR_VERSION,
- GTK_MICRO_VERSION - GTK_INTERFACE_AGE);
+ (void) module;
+
+ return gtk_check_version (GTK_MAJOR_VERSION,
+ GTK_MINOR_VERSION,
+ GTK_MICRO_VERSION - GTK_INTERFACE_AGE);
}