Mackie control: non-existent controls zero pot ring fix.
[ardour.git] / libs / clearlooks-newer / cairo-support.c
index dbe6fd3d346454633671984f5bab748bd44d9569..e221a0d8e8cc8ac94c5f2fb280b81743ddac0423 100644 (file)
@@ -4,16 +4,16 @@
 
 /***********************************************
  * 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;
@@ -21,7 +21,7 @@ ge_hsb_from_color (const CairoColor *color,
        red = color->r;
        green = color->g;
        blue = color->b;
-  
+
        if (red > green)
        {
                max = MAX(red, blue);
@@ -32,48 +32,48 @@ ge_hsb_from_color (const CairoColor *color,
                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;
@@ -81,31 +81,31 @@ ge_color_from_hsb (gdouble hue,
        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)
@@ -114,12 +114,12 @@ ge_color_from_hsb (gdouble hue,
                        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
@@ -155,7 +155,7 @@ ge_cairo_color_to_gtk (const CairoColor *cc, GdkColor *c)
        c->blue = b;
 }
 
-void 
+void
 ge_gtk_style_to_cairo_color_cube (GtkStyle * style, CairoColorCube *cube)
 {
        int i;
@@ -163,7 +163,7 @@ ge_gtk_style_to_cairo_color_cube (GtkStyle * style, CairoColorCube *cube)
        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]);
 
@@ -189,19 +189,19 @@ ge_shade_color(const CairoColor *base, gdouble shade_ratio, CairoColor *composit
        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
@@ -210,7 +210,7 @@ ge_saturate_color (const CairoColor *base, gdouble saturate_level, CairoColor *c
        gdouble hue = 0;
        gdouble saturation = 0;
        gdouble brightness = 0;
+
        g_return_if_fail (base && composite);
 
        ge_hsb_from_color (base, &hue, &saturation, &brightness);
@@ -219,11 +219,11 @@ ge_saturate_color (const CairoColor *base, gdouble saturate_level, CairoColor *c
        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);
@@ -234,7 +234,7 @@ ge_mix_color (const CairoColor *color1, const CairoColor *color2,
        composite->a = 1.0;
 }
 
-cairo_t * 
+cairo_t *
 ge_gdk_drawable_to_cairo (GdkDrawable  *window, GdkRectangle *area)
 {
        cairo_t *cr;
@@ -246,7 +246,7 @@ ge_gdk_drawable_to_cairo (GdkDrawable  *window, GdkRectangle *area)
        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);
@@ -256,12 +256,12 @@ ge_gdk_drawable_to_cairo (GdkDrawable  *window, GdkRectangle *area)
        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
@@ -275,20 +275,20 @@ ge_cairo_set_gdk_color_with_alpha (cairo_t *cr, const GdkColor *color, gdouble a
                                   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;
@@ -302,7 +302,7 @@ ge_cairo_pattern_add_color_stop_shade(cairo_pattern_t *pattern,
                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
@@ -370,22 +370,22 @@ ge_cairo_rounded_rectangle (cairo_t *cr,
                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
@@ -408,16 +408,16 @@ ge_cairo_stroke_rectangle (cairo_t *cr, double x, double y, double w, double h)
 
 /***********************************************
  * 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;
@@ -425,7 +425,7 @@ ge_cairo_simple_border (cairo_t *cr,
        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));
 
@@ -437,16 +437,16 @@ ge_cairo_simple_border (cairo_t *cr,
 
        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);
@@ -457,7 +457,7 @@ ge_cairo_simple_border (cairo_t *cr,
                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);
@@ -479,19 +479,19 @@ void ge_cairo_polygon (cairo_t *cr,
 
        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);
@@ -508,10 +508,10 @@ void ge_cairo_line (cairo_t *cr,
                        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);
@@ -531,13 +531,13 @@ ge_cairo_mirror (cairo_t     *cr,
                  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);
@@ -566,7 +566,7 @@ ge_cairo_exchange_axis (cairo_t  *cr,
        cairo_matrix_init (&matrix, 0, 1, 1, 0, 0, 0);
 
        cairo_transform (cr, &matrix);
-       
+
        /* swap width/height */
        tmp = *width;
        *x = 0;
@@ -578,11 +578,11 @@ ge_cairo_exchange_axis (cairo_t  *cr,
 
 /***********************************************
  * 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,
@@ -653,12 +653,12 @@ ge_cairo_pattern_fill(cairo_t *canvas,
 
 /***********************************************
  * 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)))
@@ -668,24 +668,24 @@ ge_cairo_color_pattern(CairoColor *base)
        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;
@@ -701,7 +701,7 @@ ge_cairo_pixbuf_pattern(GdkPixbuf *pixbuf)
 
        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);
@@ -723,12 +723,12 @@ ge_cairo_pixbuf_pattern(GdkPixbuf *pixbuf)
 
 /***********************************************
  * ge_cairo_pixmap_pattern -
- *  
+ *
  *   Create A Tiled Pixmap Pattern
  ***********************************************/
 CairoPattern*
 ge_cairo_pixmap_pattern(GdkPixmap *pixmap)
-{      
+{
        CairoPattern * result = NULL;
 
        GdkPixbuf * pixbuf;
@@ -736,33 +736,33 @@ ge_cairo_pixmap_pattern(GdkPixmap *pixmap)
 
        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
@@ -796,7 +796,7 @@ ge_cairo_pattern_destroy(CairoPattern *pattern)
        {
                if (pattern->handle)
                        cairo_pattern_destroy(pattern->handle);
-                       
+
                g_free(pattern);
        }
 }
@@ -809,7 +809,9 @@ GE_EXPORT const gchar* g_module_check_init (GModule *module);
 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);
 }