From fc019a949710e73a59042475a14d8d741e187b5e Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Thu, 25 Oct 2012 23:19:23 +0700 Subject: [PATCH] The Big Commit (tm): Remove Cairo.Color and most of Gdk.Color usage from libprolooks --- demos/DisplayDemo.vala | 4 +- demos/GaussianBlurDemo.vala | 1 - demos/GlossGradientDemo.vala | 13 +- demos/HelpersTest.vala | 136 +++++++++++---------- demos/KnobDemo.vala | 6 +- src/Curve.vala | 10 +- src/Display.vala | 112 ++++++++--------- src/GlossGradient.vala | 26 ++-- src/Helpers.vala | 259 +++++++++++++++------------------------- src/Keyboard.vala | 12 +- src/Knob.vala | 2 +- src/Led.vala | 91 +++++++------- src/LineGraph.vala | 22 ++-- src/SimpleKnobImageSource.vala | 10 +- src/SmallButton.vala | 106 ++++++++-------- src/ThorwilKnobImageSource.vala | 12 +- src/TransportButton.vala | 38 +++--- src/VuMeter.vala | 9 +- 18 files changed, 399 insertions(+), 470 deletions(-) diff --git a/demos/DisplayDemo.vala b/demos/DisplayDemo.vala index 659db80..7b9d528 100644 --- a/demos/DisplayDemo.vala +++ b/demos/DisplayDemo.vala @@ -19,8 +19,8 @@ public class TestDisplay : DisplayBase { Cairo.TextExtents ext = Cairo.TextExtents(); cr.text_extents (str, out ext); - Color line_color; - Color.parse (text_color_default, out line_color); + RGBA line_color = RGBA(); + line_color.parse (text_color_default); set_source_color (cr, line_color, 0.5); cr.move_to (20, 20 + ext.y_bearing); diff --git a/demos/GaussianBlurDemo.vala b/demos/GaussianBlurDemo.vala index 6f3c757..4a6662f 100644 --- a/demos/GaussianBlurDemo.vala +++ b/demos/GaussianBlurDemo.vala @@ -42,7 +42,6 @@ namespace Prolooks { } static int main (string[] args) { - int i, j; Gtk.init (ref args); var window = new Window (WindowType.TOPLEVEL); diff --git a/demos/GlossGradientDemo.vala b/demos/GlossGradientDemo.vala index 7589565..3ff4616 100644 --- a/demos/GlossGradientDemo.vala +++ b/demos/GlossGradientDemo.vala @@ -22,7 +22,7 @@ namespace Prolooks { get_allocation(out allocation); set_source_color_string(cr, "#EDEDED"); - set_source_color(cr, style.bg[(int)Gtk.StateType.NORMAL]); + set_source_color(cr, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL])); cr.rectangle(0, 0, allocation.width, allocation.height); cr.fill(); @@ -30,11 +30,11 @@ namespace Prolooks { double glossbar_height = allocation.height - 2 * padding; double glossbar_width = (allocation.width - 2 * padding) / 5.0 ; - Cairo.Pattern gloss_red = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, cairo_color_from_string("#D84212"), 50); - Cairo.Pattern gloss_green = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, cairo_color_from_string("#237000"), 50); - Cairo.Pattern gloss_blue = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, cairo_color_from_string("#0081FF"), 50); - Cairo.Pattern gloss_violet = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, cairo_color_from_string("#9331AB"), 50); - Cairo.Pattern gloss_gray = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, cairo_color_from_string("#5B5B57"), 50); + Cairo.Pattern gloss_red = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#D84212"), 50); + Cairo.Pattern gloss_green = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#237000"), 50); + Cairo.Pattern gloss_blue = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#0081FF"), 50); + Cairo.Pattern gloss_violet = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#9331AB"), 50); + Cairo.Pattern gloss_gray = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#5B5B57"), 50); cr.rectangle(padding, padding, glossbar_width, glossbar_height); cr.set_source(gloss_blue); @@ -61,7 +61,6 @@ namespace Prolooks { } static int main (string[] args) { - int i, j; Gtk.init (ref args); var window = new Window (WindowType.TOPLEVEL); diff --git a/demos/HelpersTest.vala b/demos/HelpersTest.vala index 10c0a60..b8a4ec6 100644 --- a/demos/HelpersTest.vala +++ b/demos/HelpersTest.vala @@ -8,139 +8,137 @@ using Gdk; namespace Prolooks { public static void helpers_unit_tests () { - Test.add_func ("/prolooks/helpers/color_from_string", () => { - Color red = color_from_string("#ff0000"); - assert (red.red == 65535); + Test.add_func ("/prolooks/helpers/rgba_from_string", () => { + RGBA red = rgba_from_string("#ff0000"); + assert (red.red == 1.0); assert (red.green == 0); assert (red.blue == 0); } ); Test.add_func ("/prolooks/helpers/color_to_string", () => { - string original = "#abcdef"; - Color color = color_from_string(original); - string result = color_to_string(color); - stdout.printf(result); + string original = "rgb(99,111,222)"; + RGBA color = rgba_from_string(original); + string result = color.to_string(); + stdout.printf(result); assert (result == original); - original = "#0a1005"; - color = color_from_string(original); - result = color_to_string(color); - stdout.printf(result); + original = "rgb(10,16,5)"; + color = rgba_from_string(original); + result = color.to_string(); + stdout.printf(result); assert (result == original); } ); Test.add_func ("/prolooks/helpers/rgb2hsv <-> hsv2rgb", () => { - Color color = color_from_string ("#ff0000"); + RGBA color = rgba_from_string ("rgb(255, 0, 0)"); HSV hsv = new HSV (); - hsv.from_gdk_color (color); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 0.0); assert (hsv.saturation == 1.0); assert (hsv.value == 1.0); - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); - assert (color.red == 65535); + assert (color.red == 1.0); assert (color.green == 0); assert (color.blue == 0); - color = color_from_string ("#00ff00"); - hsv.from_gdk_color (color); + color = rgba_from_string ("#00ff00"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 120.0); assert (hsv.saturation == 1.0); assert (hsv.value == 1.0); - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); assert (color.red == 0); - assert (color.green == 65535); + assert (color.green == 1.0); assert (color.blue == 0); - color = color_from_string ("#0000ff"); - hsv.from_gdk_color (color); + color = rgba_from_string ("#0000ff"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 240.0); assert (hsv.saturation == 1.0); assert (hsv.value == 1.0); - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); assert (color.red == 0); assert (color.green == 0); - assert (color.blue == 65535); + assert (color.blue == 1.0); - color = color_from_string ("#ff00ff"); - hsv.from_gdk_color (color); + color = rgba_from_string ("#ff00ff"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 300.0); assert (hsv.saturation == 1.0); assert (hsv.value == 1.0); - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); - assert (color.red == 65535); + assert (color.red == 1.0); assert (color.green == 0); - assert (color.blue == 65535); + assert (color.blue == 1.0); - color = color_from_string ("#800080"); - hsv.from_gdk_color (color); + color = rgba_from_string ("#800080"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 300.0); assert (hsv.saturation == 1.0); assert (Math.floor(hsv.value * 10.0) / 10.0 == 0.5); - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); - assert (color.red == 32895); - assert (color.green == 0); - assert (color.blue == 32895); + assert (color.to_string() == "rgb(128,0,128)"); - color = color_from_string ("#ffff00"); - hsv.from_gdk_color (color); + color = rgba_from_string ("#ffff00"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 60.0); assert (hsv.saturation == 1.0); assert (hsv.value == 1.0); - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); - assert (color.red == 65535); - assert (color.green == 65535); + assert (color.red == 1.0); + assert (color.green == 1.0); assert (color.blue == 0); - color = color_from_string ("#00ffff"); - hsv.from_gdk_color (color); + color = rgba_from_string ("#00ffff"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 180.0); assert (hsv.saturation == 1.0); assert (hsv.value == 1.0); - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); assert (color.red == 0); - assert (color.green == 65535); - assert (color.blue == 65535); + assert (color.green == 1.0); + assert (color.blue == 1.0); - color = color_from_string ("#00ECFF"); - hsv.from_gdk_color (color); + color = rgba_from_string ("#00ECFF"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (Math.floor(hsv.hue) == 184); assert (hsv.saturation == 1.0); assert (hsv.value == 1.0); /* rounding errors here - color = hsv.to_gdk_color (); + color = hsv.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); assert (color.red == 0); assert (color.green == 61016); - assert (color.blue == 65535); + assert (color.blue == 1.0); */ - color = color_from_string("#ffffff"); - hsv.from_gdk_color (color); + color = rgba_from_string("#ffffff"); + hsv.from_rgba (color); stdout.printf ("\ncolor %s is in hsv: %s\n", color.to_string(), hsv.to_string()); assert (hsv.hue == 0.0); assert (hsv.saturation == 0.0); @@ -150,49 +148,49 @@ namespace Prolooks { ); Test.add_func ("/prolooks/helpers/rgb2hsl <-> hsl2rgb", () => { - Color color = color_from_string ("#ff0000"); + RGBA color = rgba_from_string ("#ff0000"); HSL hsl = new HSL (); - hsl.from_gdk_color (color); + hsl.from_rgba (color); stdout.printf ("\ncolor %s is in hsl: %s\n", color.to_string(), hsl.to_string()); assert (hsl.hue == 0.0); assert (hsl.saturation == 1.0); assert (hsl.lightness == 0.5); - color = hsl.to_gdk_color (); + color = hsl.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); - assert (color.red == 65535); + assert (color.red == 1.0); assert (color.green == 0); assert (color.blue == 0); - color = color_from_string ("#00ff00"); - hsl.from_gdk_color (color); + color = rgba_from_string ("#00ff00"); + hsl.from_rgba (color); stdout.printf ("\ncolor %s is in hsl: %s\n", color.to_string(), hsl.to_string()); assert (hsl.hue == 120.0); assert (hsl.saturation == 1.0); assert (hsl.lightness == 0.5); - color = hsl.to_gdk_color (); + color = hsl.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); assert (color.red == 0); - assert (color.green == 65535); + assert (color.green == 1.0); assert (color.blue == 0); - color = color_from_string ("#0000ff"); - hsl.from_gdk_color (color); + color = rgba_from_string ("#0000ff"); + hsl.from_rgba (color); stdout.printf ("\ncolor %s is in hsl: %s\n", color.to_string(), hsl.to_string()); assert (hsl.hue == 240.0); assert (hsl.saturation == 1.0); assert (hsl.lightness == 0.5); - color = hsl.to_gdk_color (); + color = hsl.to_rgba (); stdout.printf ("Converting back to RGB yields: %s\n", color.to_string()); assert (color.red == 0); assert (color.green == 0); - assert (color.blue == 65535); + assert (color.blue == 1.0); - color = color_from_string("#ffffff"); - hsl.from_gdk_color (color); + color = rgba_from_string("#ffffff"); + hsl.from_rgba (color); stdout.printf ("\ncolor %s is in hsl: %s\n", color.to_string(), hsl.to_string()); assert (hsl.hue == 0.0); assert (hsl.saturation == 0.0); @@ -202,16 +200,16 @@ namespace Prolooks { ); Test.add_func ("/prolooks/helpers/shade", () => { - Color gray = color_from_string("#0a0a0a"); - Color shaded = shade_color (gray, 1.0); + RGBA gray = rgba_from_string("#0a0a0a"); + RGBA shaded = rgba_shade (gray, 1.0); stdout.printf ("\noriginal color: %s\n", gray.to_string()); stdout.printf ("shaded color: %s\n", shaded.to_string()); - assert (strcmp(shaded.to_string(), "#0a090a090a09") == 0); + assert (strcmp(shaded.to_string(), "rgb(10,10,10)") == 0); - shaded = shade_color (gray, 0.5); + shaded = rgba_shade (gray, 0.5); stdout.printf ("\noriginal color: %s\n", gray.to_string()); stdout.printf ("shaded color: %s\n", shaded.to_string()); - assert (strcmp(shaded.to_string(), "#050405040504") == 0); + assert (strcmp(shaded.to_string(), "rgb(5,5,5)") == 0); } ); } diff --git a/demos/KnobDemo.vala b/demos/KnobDemo.vala index 71fcc37..af09c24 100644 --- a/demos/KnobDemo.vala +++ b/demos/KnobDemo.vala @@ -17,9 +17,9 @@ namespace Prolooks { if (i < 2) { var isource = new SimpleKnobImageSource (); if (i == 0) - isource.led_color = color_from_string ("#ff0000"); + isource.led_color = rgba_from_string ("#ff0000"); else - isource.led_color = color_from_string ("#ffff00"); + isource.led_color = rgba_from_string ("#ffff00"); knob.image_source = isource; } hbox.pack_start (knob); @@ -27,7 +27,7 @@ namespace Prolooks { Knob thorwil_knob = new Knob (); var isource = new ThorwilKnobImageSource (); - isource.lamp_color = color_from_string ("#9fc717"); + isource.lamp_color = rgba_from_string ("#9fc717"); thorwil_knob.image_source = isource; hbox.pack_start (thorwil_knob); diff --git a/src/Curve.vala b/src/Curve.vala index f44abda..3e2f408 100644 --- a/src/Curve.vala +++ b/src/Curve.vala @@ -128,13 +128,13 @@ public class Curve : DrawingArea { /* Widget is asked to draw itself */ public bool on_draw (Cairo.Context c) { - Gdk.Color scHot = { 0, 65535, 0, 0 }; - Gdk.Color scPoint = { 0, 65535, 65535, 65535 }; - Gdk.Color scLine = { 0, 32767, 32767, 32767 }; + Gdk.RGBA scHot = { 1.0, 0.0, 0.0, 1.0 }; + Gdk.RGBA scPoint = { 1.0, 1.0, 1.0, 1.0 }; + Gdk.RGBA scLine = { 0.5, 0.5, 0.5, 1.0 }; if (points.length () > 0) { - Gdk.cairo_set_source_color (c, scLine); + Gdk.cairo_set_source_rgba (c, scLine); for (size_t i = 0; i < points.length (); i++) { @@ -166,7 +166,7 @@ public class Curve : DrawingArea { CurvePoint pt = points.nth_data(i); float x = pt.x, y = pt.y; log2phys (ref x, ref y); - Gdk.cairo_set_source_color (c, (i == (size_t)cur_pt) ? scHot : scPoint); + Gdk.cairo_set_source_rgba (c, (i == (size_t)cur_pt) ? scHot : scPoint); c.rectangle (x - 2, y - 2, 5, 5); c.fill (); } diff --git a/src/Display.vala b/src/Display.vala index 7891293..2574399 100644 --- a/src/Display.vala +++ b/src/Display.vala @@ -78,16 +78,16 @@ public abstract class DisplayBase : DrawingArea { draw.connect(on_draw); } - public static void outer_rim_for_display(Cairo.Context cr, double x, double y, double w, double h, Color outside, double rounded_corner_radius = 5.0) { - Color inside; - Color inside_left; - Color inside_top; - Color inside_right; - Color inside_bottom; + public static void outer_rim_for_display(Cairo.Context cr, double x, double y, double w, double h, RGBA outside, double rounded_corner_radius = 5.0) { + RGBA inside = RGBA(); + RGBA inside_left = RGBA(); + RGBA inside_top = RGBA(); + RGBA inside_right = RGBA(); + RGBA inside_bottom = RGBA(); - Color.parse("#010101", out inside); - Color.parse("#525357", out inside_left); - Color.parse("#444444", out inside_top); + inside.parse("#010101"); + inside_left.parse("#525357"); + inside_top.parse("#444444"); inside_right = outside; inside_bottom = outside; @@ -103,42 +103,42 @@ public abstract class DisplayBase : DrawingArea { // inside background rounded_rect (cr, 1, 1, w - 2, h - 2, rounded_corner_radius, rounded_corner_radius); - set_source_color(cr, inside); + cairo_set_source_rgba(cr, inside); cr.fill (); // top rim cr.move_to (horiz_rim_left_x, top_rim_y); cr.line_to (horiz_rim_right_x, top_rim_y); - set_source_color(cr, inside_top); + cairo_set_source_rgba(cr, inside_top); cr.stroke (); // right rim cr.move_to (right_rim_x, vert_rim_top_y); cr.line_to (right_rim_x, vert_rim_bottom_y); - set_source_color (cr, inside_right); + cairo_set_source_rgba (cr, inside_right); cr.stroke (); // bottom rim cr.move_to (horiz_rim_right_x, bottom_rim_y); cr.line_to (horiz_rim_left_x, bottom_rim_y); - set_source_color (cr, inside_bottom); + cairo_set_source_rgba (cr, inside_bottom); cr.stroke(); // left rim cr.move_to (left_rim_x, vert_rim_bottom_y); cr.line_to (left_rim_x, vert_rim_top_y); - set_source_color (cr, inside_left); + cairo_set_source_rgba (cr, inside_left); cr.stroke(); } public static const string matrix_dot_base_color = "#41403e"; - public static Gdk.Color matrix_dot_color () { - return shade_color (color_from_string (matrix_dot_base_color), 0.5); + public static Gdk.RGBA matrix_dot_color () { + return rgba_shade (rgba_from_string (matrix_dot_base_color), 0.5); } - public static void dot_matrix(Cairo.Context cr, double x, double y, double w, double h, Gdk.Color color) { + public static void dot_matrix(Cairo.Context cr, double x, double y, double w, double h, Gdk.RGBA color) { cr.save(); - set_source_color (cr, color); + cairo_set_source_rgba (cr, color); for (double i = x + 1; i < x + w; i++) { for (double j = y + 1; j < y + h; j++) { if (((long)i % 2) == 0 && ((long)j % 2) == 1) { @@ -152,28 +152,28 @@ public abstract class DisplayBase : DrawingArea { } public static void inner_glass_rim(Cairo.Context cr, double x, double y, double w, double h, double radius = 4.0) { - Color rim_left_top1; - Color rim_left_bottom1; - Color rim_left_top2; - Color rim_left_bottom2; - Color rim_right_top; - Color rim_right_bottom; - Color rim_top1; - Color rim_top2; - Color rim_bottom; + RGBA rim_left_top1 = RGBA(); + RGBA rim_left_bottom1 = RGBA(); + RGBA rim_left_top2 = RGBA(); + RGBA rim_left_bottom2 = RGBA(); + RGBA rim_right_top = RGBA(); + RGBA rim_right_bottom = RGBA(); + RGBA rim_top1 = RGBA(); + RGBA rim_top2 = RGBA(); + RGBA rim_bottom = RGBA(); - Color.parse("#2a282d", out rim_left_top1); - Color.parse("#2b2c2e", out rim_left_bottom1); - Color.parse("#1b191c", out rim_left_top2); - Color.parse("#1d181f", out rim_left_bottom2); - Color.parse("#3d3b3c", out rim_right_top); - Color.parse("#3a4036", out rim_right_bottom); - Color.parse("#605b5f", out rim_top1); - Color.parse("#2f2e33", out rim_top2); - Color.parse("#3e403d", out rim_bottom); + rim_left_top1.parse("#2a282d"); + rim_left_bottom1.parse("#2b2c2e"); + rim_left_top2.parse("#1b191c"); + rim_left_bottom2.parse("#1d181f"); + rim_right_top.parse("#3d3b3c"); + rim_right_bottom.parse("#3a4036"); + rim_top1.parse("#605b5f"); + rim_top2.parse("#2f2e33"); + rim_bottom.parse("#3e403d"); - Color test; - Color.parse("#ff0000", out test); + RGBA test = RGBA(); + test.parse("#ff0000"); double ARC_TO_BEZIER = 0.55228475; @@ -190,19 +190,19 @@ public abstract class DisplayBase : DrawingArea { // rim_top1 cr.move_to ( x + radius, y); cr.rel_line_to ( w - 2 * radius, 0.0); - set_source_color (cr, rim_top1); + cairo_set_source_rgba (cr, rim_top1); cr.stroke (); // rim top2 cr.move_to ( x + radius, y + 1); cr.rel_line_to ( w - 2 * radius, 0.0); - set_source_color(cr, rim_top2); + cairo_set_source_rgba(cr, rim_top2); cr.stroke (); // right top corner cr.move_to (x + w - radius, y); cr.rel_curve_to ( c, 0.0, radius, c, radius, radius); - set_source_color (cr, rim_top1); + cairo_set_source_rgba (cr, rim_top1); cr.stroke (); // rim right @@ -215,19 +215,19 @@ public abstract class DisplayBase : DrawingArea { // right bottom corner cr.move_to (x + w, y + h - radius); cr.rel_curve_to ( 0.0, c, c - radius, radius, -radius, radius); - set_source_color (cr, rim_right_bottom); + cairo_set_source_rgba (cr, rim_right_bottom); cr.stroke (); // bottom line cr.move_to (x + w - radius, y + h); cr.rel_line_to (-w + 2 * radius, 0); - set_source_color (cr, rim_bottom); + cairo_set_source_rgba (cr, rim_bottom); cr.stroke (); // bottom left corner cr.move_to (x + radius, y + h); cr.rel_curve_to ( -c, 0, -radius, -c, -radius, -radius); - set_source_color (cr, rim_left_bottom1); + cairo_set_source_rgba (cr, rim_left_bottom1); cr.stroke (); // rim left @@ -245,13 +245,13 @@ public abstract class DisplayBase : DrawingArea { // top left corner cr.move_to (x, y + radius); cr.rel_curve_to (0.0, -c, radius - c, -radius, radius, -radius); - set_source_color (cr, rim_top1); + cairo_set_source_rgba (cr, rim_top1); cr.stroke (); // top left corner (adding thickness) cr.move_to (x + 1, y + radius); cr.rel_curve_to (0.0, -c, radius - c, -radius, radius, -radius + 1); - set_source_color (cr, rim_top1); + cairo_set_source_rgba (cr, rim_top1); cr.stroke (); } @@ -270,9 +270,9 @@ public abstract class DisplayBase : DrawingArea { } public static void text (Cairo.Context cr, string text, double x, double y, double size, string color = text_color_default) { - Color text_color; - Color.parse (color, out text_color); - set_source_color (cr, text_color); + RGBA text_color = RGBA(); + text_color.parse (color); + cairo_set_source_rgba (cr, text_color); set_font (cr, size); cr.move_to (x, y); @@ -280,10 +280,10 @@ public abstract class DisplayBase : DrawingArea { } public static void lcd(Cairo.Context cr, double w, double h, double radius = 5.0) { - Color green_rim_top; - Color green_rim_bottom; - Color.parse ("#2c4329", out green_rim_top); - Color.parse ("#101d09", out green_rim_bottom); + RGBA green_rim_top = RGBA(); + RGBA green_rim_bottom = RGBA(); + green_rim_top.parse ("#2c4329"); + green_rim_bottom.parse ("#101d09"); cr.set_source (create_gradient (0.0, 0.0, 0.0, h, green_rim_top, green_rim_bottom, 1.0, 1.0)); rounded_rect (cr, 0.0, 0.0, w, h, radius, radius); cr.stroke (); @@ -310,7 +310,7 @@ public abstract class DisplayBase : DrawingArea { /* Widget is asked to draw itself */ public bool on_draw (Cairo.Context c) { - //Color test_color = color_from_string ("#ff0000"); + //RGBA test_color = RGBA.parse ("#ff0000"); Gtk.Allocation allocation; get_allocation(out allocation); @@ -335,13 +335,13 @@ public abstract class DisplayBase : DrawingArea { set_line_width_from_device (cache_cr); - DisplayBase.outer_rim_for_display (cache_cr, 0, 0, _width, _height, style.bg[(int)Gtk.StateType.NORMAL]); + DisplayBase.outer_rim_for_display (cache_cr, 0, 0, _width, _height, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL])); if (show_glass_rim) { cache_cr.translate (4.5, 3.5); inner_glass_rim (cache_cr, 0, 0, _width - 8, _height - 9, 2); } - + cache_cr.translate (3.0, 3.0); lcd(cache_cr, inner_width, inner_height, _height > 30 ? 5.0 : 3.0); diff --git a/src/GlossGradient.vala b/src/GlossGradient.vala index 0903bfb..e110513 100644 --- a/src/GlossGradient.vala +++ b/src/GlossGradient.vala @@ -6,7 +6,7 @@ using Gdk; namespace Prolooks { - private static double perceptualGlossFractionForColor(Cairo.Color color) { + private static double perceptualGlossFractionForColor(RGBA color) { double REFLECTION_SCALE_NUMBER = 0.2; double NTSC_RED_FRACTION = 0.299; double NTSC_GREEN_FRACTION = 0.587; @@ -22,17 +22,17 @@ namespace Prolooks { return glossScale; } - private static Cairo.Color perceptualCausticColorForColor(Cairo.Color input) { + private static RGBA perceptualCausticColorForColor(RGBA input) { double CAUSTIC_FRACTION = 0.60; double COSINE_ANGLE_SCALE = 1.4; double MIN_RED_THRESHOLD = 0.95; double MAX_BLUE_THRESHOLD = 0.7; double GRAYSCALE_CAUSTIC_SATURATION = 0.2; - Cairo.Color source = input; + RGBA source = input; HSV source_hsv = new HSV(); - source_hsv.from_cairo_color(source); + source_hsv.from_rgba(source); double hue = source_hsv.hue; double saturation = source_hsv.saturation; @@ -40,7 +40,7 @@ namespace Prolooks { double alpha = input.alpha; HSV target_hsv = new HSV(); - target_hsv.from_cairo_color(new Cairo.Color(1.0, 1.0, 0.0)); + target_hsv.from_rgba(rgba_new(1.0, 1.0, 0.0)); double targetHue = target_hsv.hue; double targetSaturation = target_hsv.saturation; @@ -54,7 +54,7 @@ namespace Prolooks { if (hue > MIN_RED_THRESHOLD) { hue -= 1.0; } else if (hue > MAX_BLUE_THRESHOLD) { - target_hsv.from_cairo_color(new Cairo.Color(1.0, 0.0, 1.0)); + target_hsv.from_rgba(rgba_new(1.0, 0.0, 1.0)); targetHue = target_hsv.hue; targetSaturation = target_hsv.saturation; @@ -67,15 +67,15 @@ namespace Prolooks { target_hsv.saturation = saturation; target_hsv.value = value * (1.0 - scaledCaustic) + targetValue * scaledCaustic; - Cairo.Color target_color = target_hsv.to_cairo_color(); + RGBA target_color = target_hsv.to_rgba(); target_color.alpha = alpha; return target_color; } private struct GlossParameters { - Cairo.Color color; - Cairo.Color caustic; + RGBA color; + RGBA caustic; double expCoefficient; double expScale; double expOffset; @@ -83,8 +83,8 @@ namespace Prolooks { double finalWhite; } - private static Cairo.Color glossInterpolation(double progress, ref GlossParameters params) { - Cairo.Color output = new Cairo.Color(); + private static RGBA glossInterpolation(double progress, ref GlossParameters params) { + RGBA output = RGBA(); if (progress < 0.5) { @@ -117,7 +117,7 @@ namespace Prolooks { return output; } - public static Cairo.Pattern gloss_gradient_pattern(double x0, double y0, double x1, double y1, Cairo.Color color, int no_steps = 100) { + public static Cairo.Pattern gloss_gradient_pattern(double x0, double y0, double x1, double y1, RGBA color, int no_steps = 100) { double EXP_COEFFICIENT = 1.2; double REFLECTION_MAX = 0.60; double REFLECTION_MIN = 0.20; @@ -140,7 +140,7 @@ namespace Prolooks { Cairo.Pattern result = new Cairo.Pattern.linear(x0, y0, x1, y1); for (double offset = 0; offset <= 1.0; offset += 1.0 / (double) no_steps) { - Cairo.Color stop = glossInterpolation(offset, ref params); + RGBA stop = glossInterpolation(offset, ref params); result.add_color_stop_rgba(offset, stop.red, stop.green, stop.blue, stop.alpha); } diff --git a/src/Helpers.vala b/src/Helpers.vala index 0b595c8..f2185d3 100644 --- a/src/Helpers.vala +++ b/src/Helpers.vala @@ -6,62 +6,7 @@ using Gtk; using Gdk; -namespace Cairo { - - public class Color { - public double red { get; set; } - public double green { get; set; } - public double blue { get; set; } - public double alpha { get; set; } - - public Color (double red = 0.0, double green = 0.0, double blue = 0.0, double alpha = 1.0) { - this.red = red; this.green = green; this.blue = blue; this.alpha = alpha; - } - - public Cairo.Color copy () { - return new Cairo.Color (red, green, blue, alpha); - } - - public Color.from_string (string webcolor) { - set_from_string(webcolor); - } - - public Cairo.Color shade (double shade_factor) { - Prolooks.HSL hsl = new Prolooks.HSL (); - hsl.from_cairo_color (this); - - hsl.lightness = Math.fmin (hsl.lightness * shade_factor, 1.0); - hsl.lightness = Math.fmax (hsl.lightness, 0.0); - - hsl.saturation = Math.fmin (hsl.saturation * shade_factor, 1.0); - hsl.saturation = Math.fmax (hsl.saturation, 0.0); - - return hsl.to_cairo_color (); - } - - public void set_to (Cairo.Color a_color) { - red = a_color.red; - green = a_color.green; - blue = a_color.blue; - alpha = a_color.alpha; - } - - public void set_as_source_in (Cairo.Context cr) { - cr.set_source_rgba (red, green, blue, alpha); - } - - public void add_color_stop_to (Cairo.Pattern p, double offset) { - p.add_color_stop_rgba (offset, red, green, blue, alpha); - } - - public void set_from_string (string webcolor) { - set_to(Prolooks.gdk_color_to_cairo(Prolooks.color_from_string(webcolor))); - } - } -} - namespace Prolooks { - public enum ButtonState { NORMAL, PRESSED; @@ -71,6 +16,34 @@ namespace Prolooks { PRESS_BUTTON, TOGGLE_BUTTON; } + + public static Gdk.RGBA rgba_new (double red, double green, double blue, double alpha = 1.0) { + Gdk.RGBA color = RGBA(); + color.red = red; + color.green = green; + color.blue = blue; + color.alpha = alpha; + return color; + } + + public static Gdk.RGBA rgba_from_string (string s) { + Gdk.RGBA color = RGBA(); + color.parse(s); + color.alpha = 1.0; + return color; + } + + public static Gdk.RGBA gdk_color_to_rgba (Gdk.Color color) { + Gdk.RGBA rgba = RGBA(); + rgba.red = (double)color.red / (double)uint16.MAX; + rgba.green = (double)color.green / (double)uint16.MAX; + rgba.blue = (double)color.blue / (double)uint16.MAX; + return rgba; + } + + public static void add_color_stop_to (Cairo.Pattern p, double offset, Gdk.RGBA color) { + p.add_color_stop_rgba (offset, color.red, color.green, color.blue, color.alpha); + } public static void set_line_width_from_device (Cairo.Context cr) { double ux=1, uy=1; @@ -80,61 +53,26 @@ namespace Prolooks { } cr.set_line_width (ux); } - - public static Gdk.Color color_from_string (string webcolor) { - Gdk.Color color; - Gdk.Color.parse(webcolor, out color); - return color; - } - public static string color_to_string (Gdk.Color color) { - var scale = uint16.MAX / uint8.MAX; - return "#%02x%02x%02x".printf (color.red / scale, color.green / scale, color.blue / scale); - } - - public static Cairo.Color cairo_color_from_string (string webcolor) { - return gdk_color_to_cairo(color_from_string(webcolor)); - } - - public static void set_source_color (Cairo.Context cr, Gdk.Color color, double alpha = 1.0) { - cr.set_source_rgba((double)color.red / (double)uint16.MAX, (double)color.green / (double)uint16.MAX, (double)color.blue / (double)uint16.MAX, alpha); - } - - public static void gdk_color_to_cairo_color (Gdk.Color color, ref double red, ref double green, ref double blue) { - red = (double)color.red / (double)uint16.MAX; - green = (double)color.green / (double)uint16.MAX; - blue = (double)color.blue / (double)uint16.MAX; - } - - public static Cairo.Color gdk_color_to_cairo (Gdk.Color color) { - double r = 0, g = 0, b = 0; - gdk_color_to_cairo_color (color, ref r, ref g, ref b); - return new Cairo.Color (r, g, b); - } - - public static Gdk.Color cairo_color_to_gdk (Cairo.Color cairo_color) { - Gdk.Color color = Gdk.Color(); - - color.red = (uint16) (cairo_color.red * (double)uint16.MAX); - color.green = (uint16) (cairo_color.green * (double)uint16.MAX); - color.blue = (uint16) (cairo_color.blue * (double)uint16.MAX); - - return color; + public static void set_source_color (Cairo.Context cr, Gdk.RGBA color, double alpha = 1.0) { + cr.set_source_rgba(color.red, color.green, color.blue, alpha); } - + public static void set_source_color_string (Cairo.Context cr, string color, double alpha = 1.0) { - set_source_color (cr, color_from_string (color), alpha); + Gdk.RGBA c = rgba_from_string(color); + c.alpha = alpha; + Gdk.cairo_set_source_rgba (cr, c); } - public static void add_color_stop (Cairo.Pattern p, double offset, Gdk.Color color, double alpha = 1.0) { - p.add_color_stop_rgba (offset, (double)color.red / (double)uint16.MAX, (double)color.green / (double)uint16.MAX, (double)color.blue / (double)uint16.MAX, alpha); + public static void add_color_stop (Cairo.Pattern p, double offset, Gdk.RGBA color, double alpha = 1.0) { + p.add_color_stop_rgba (offset, color.red, color.green, color.blue, alpha); } public static void add_color_stop_str (Cairo.Pattern p, double offset, string color, double alpha = 1.0) { - add_color_stop (p, offset, color_from_string (color), alpha); + add_color_stop (p, offset, rgba_from_string (color), alpha); } - public static Cairo.Pattern create_gradient (double x1, double y1, double x2, double y2, Gdk.Color start, Gdk.Color stop, double alpha_start = 1.0, double alpha_stop = 1.0) { + public static Cairo.Pattern create_gradient (double x1, double y1, double x2, double y2, Gdk.RGBA start, Gdk.RGBA stop, double alpha_start = 1.0, double alpha_stop = 1.0) { Cairo.Pattern gradient = new Cairo.Pattern.linear(x1, y1, x2, y2); add_color_stop(gradient, 0, start, alpha_start); add_color_stop(gradient, 1, stop, alpha_stop); @@ -142,7 +80,7 @@ namespace Prolooks { } public static Cairo.Pattern create_gradient_str (double x1, double y1, double x2, double y2, string start, string stop, double alpha_start = 1.0, double alpha_stop = 1.0) { - return create_gradient (x1, y1, x2, y2, color_from_string (start), color_from_string (stop), alpha_start, alpha_stop); + return create_gradient (x1, y1, x2, y2, rgba_from_string (start), rgba_from_string (stop), alpha_start, alpha_stop); } public static void rounded_rect (Cairo.Context cr, double x, double y, double w, double h, double radius_x=5, double radius_y=5) { @@ -175,10 +113,10 @@ namespace Prolooks { public static void background_gradient(Cairo.Context cr, double w, double h) { // outside background - Color background_gradient_start; - Color background_gradient_stop; - Color.parse("#bebdc2", out background_gradient_start); - Color.parse("#b1b4b9", out background_gradient_stop); + Gdk.RGBA background_gradient_start = RGBA(); + Gdk.RGBA background_gradient_stop = RGBA(); + background_gradient_start.parse("#bebdc2"); + background_gradient_stop.parse("#b1b4b9"); cr.rectangle (0, 0, w, h); Cairo.Pattern background_gradient = new Cairo.Pattern.linear(0, 0, 0, h); @@ -196,12 +134,17 @@ namespace Prolooks { public double hue {get; set;} public double saturation {get; set;} public double lightness {get; set;} + public double alpha {get; set;} + public HSL() { + alpha = 1.0; + } + public string to_string() { return "HSL (%f, %f, %f)".printf (hue, saturation, lightness); } - public Cairo.Color to_cairo_color() { + public Gdk.RGBA to_rgba() { int i; var hue_shift = new double[3]; var color_shift = new double[3]; @@ -243,25 +186,18 @@ namespace Prolooks { color_shift[i] = m1; } - Cairo.Color color = new Cairo.Color(color_shift[0], color_shift[1], color_shift[2]); + Gdk.RGBA color = { color_shift[0], color_shift[1], color_shift[2], alpha}; return color; } - - public Gdk.Color to_gdk_color() { - return cairo_color_to_gdk(to_cairo_color()); - } - - public void from_gdk_color(Gdk.Color color) { - from_cairo_color(gdk_color_to_cairo(color)); - } - - public void from_cairo_color(Cairo.Color color) { + + public void from_rgba(Gdk.RGBA color) { double min, max, delta; double red = color.red; double green = color.green; double blue = color.blue; + this.alpha = color.alpha; if (red > green) { if (red > blue) @@ -316,60 +252,54 @@ namespace Prolooks { public double hue {get; set;} public double saturation {get; set;} public double value {get; set;} + public double alpha {get; set;} + public HSV() { + alpha = 1.0; + } + public string to_string() { return "HSV (%f, %f, %f)".printf (hue, saturation, value); } - public HSV.for_gdk_color (Gdk.Color color) { - from_gdk_color (color); - } - - public HSV.for_cairo_color (Cairo.Color color) { - from_cairo_color (color); - } + public HSV.for_rgba (Gdk.RGBA color) { + from_rgba (color); + } - public Cairo.Color to_cairo_color() { - double r = 0.0, g = 0.0, b = 0.0; - double v = value; - int hi; - double f, p, q, t; + public Gdk.RGBA to_rgba() { + double r = 0.0, g = 0.0, b = 0.0; + double v = value; + int hi; + double f, p, q, t; - hi = (int) modula(Math.floor(hue / 60.0), 6); - f = hue / 60.0 - Math.floor(hue / 60.0); - p = value * (1.0 - saturation); - q = value * (1.0 - f * saturation); - t = value * (1.0 - (1.0 - f) * saturation); - - switch (hi) { - case 0: r = value; g = t; b = p; break; - case 1: r = q; g = value; b = p; break; - case 2: r = p; g = value; b = t; break; - case 3: r = p; g = q; b = value; break; - case 4: r = t; g = p; b = value; break; - case 5: r = value; g = p; b = q; break; - default: break; - } + hi = (int) modula(Math.floor(hue / 60.0), 6); + f = hue / 60.0 - Math.floor(hue / 60.0); + p = value * (1.0 - saturation); + q = value * (1.0 - f * saturation); + t = value * (1.0 - (1.0 - f) * saturation); + + switch (hi) { + case 0: r = value; g = t; b = p; break; + case 1: r = q; g = value; b = p; break; + case 2: r = p; g = value; b = t; break; + case 3: r = p; g = q; b = value; break; + case 4: r = t; g = p; b = value; break; + case 5: r = value; g = p; b = q; break; + default: break; + } - Cairo.Color color = new Cairo.Color(r, g, b); + Gdk.RGBA color = {r, g, b, alpha }; - return color; + return color; } - public Gdk.Color to_gdk_color() { - return cairo_color_to_gdk(to_cairo_color()); - } - - public void from_gdk_color(Gdk.Color color) { - from_cairo_color(gdk_color_to_cairo(color)); - } - - public void from_cairo_color(Cairo.Color color) { + public void from_rgba(Gdk.RGBA color) { double min, max, delta; double red = color.red; double green = color.green; double blue = color.blue; + this.alpha = color.alpha; if (red > green) { if (red > blue) @@ -423,19 +353,18 @@ namespace Prolooks { } } - public static Gdk.Color shade_color(Gdk.Color orig, double shade_ratio) { - HSL HSL = new HSL (); - HSL.from_gdk_color (orig); + public static Gdk.RGBA rgba_shade(Gdk.RGBA orig, double shade_ratio) { + HSL HSL = new HSL (); + HSL.from_rgba (orig); - HSL.lightness = Math.fmin (HSL.lightness * shade_ratio, 1.0); - HSL.lightness = Math.fmax (HSL.lightness, 0.0); + HSL.lightness = Math.fmin (HSL.lightness * shade_ratio, 1.0); + HSL.lightness = Math.fmax (HSL.lightness, 0.0); - HSL.saturation = Math.fmin (HSL.saturation * shade_ratio, 1.0); - HSL.saturation = Math.fmax (HSL.saturation, 0.0); + HSL.saturation = Math.fmin (HSL.saturation * shade_ratio, 1.0); + HSL.saturation = Math.fmax (HSL.saturation, 0.0); - Gdk.Color result = HSL.to_gdk_color (); - - return result; + Gdk.RGBA result = HSL.to_rgba (); + return result; } public static Gdk.Pixbuf cairo_image_surface_to_pixbuf (Cairo.ImageSurface surface) { diff --git a/src/Keyboard.vala b/src/Keyboard.vala index 7f908ec..aa00995 100644 --- a/src/Keyboard.vala +++ b/src/Keyboard.vala @@ -69,9 +69,9 @@ public class Keyboard : DrawingArea { Gtk.Allocation allocation; get_allocation(out allocation); - Gdk.Color scWhiteKey = { 0, 65535, 65535, 65535 }; - Gdk.Color scBlackKey = { 0, 0, 0, 0 }; - Gdk.Color scOutline = { 0, 0, 0, 0 }; + Gdk.RGBA scWhiteKey = { 1, 1, 1, 1 }; + Gdk.RGBA scBlackKey = { 0, 0, 0, 1 }; + Gdk.RGBA scOutline = { 0, 0, 0, 1 }; int sy = allocation.height - 1; c.set_line_join (Cairo.LineJoin.MITER); @@ -81,12 +81,12 @@ public class Keyboard : DrawingArea { { KeyInfo ki = { 0.5 + 12 * i, 0.5, 12, sy, 12 * (i / 7) + semitones_w[i % 7], false }; c.new_path (); - Gdk.cairo_set_source_color (c, scWhiteKey); + Gdk.cairo_set_source_rgba (c, scWhiteKey); if (!pre_draw (c, ref ki)) { c.rectangle (ki.x, ki.y, ki.width, ki.height); c.fill_preserve (); - Gdk.cairo_set_source_color (c, scOutline); + Gdk.cairo_set_source_rgba (c, scOutline); if (!pre_draw_outline (c, ref ki)) c.stroke (); else @@ -102,7 +102,7 @@ public class Keyboard : DrawingArea { KeyInfo ki = { 8.5 + 12 * i, 0.5, 8, sy * 3 / 5, 12 * (i / 7) + semitones_b[i % 7], true }; c.new_path (); c.rectangle (ki.x, ki.y, ki.width, ki.height); - Gdk.cairo_set_source_color (c, scBlackKey); + Gdk.cairo_set_source_rgba (c, scBlackKey); if (!pre_draw (c, ref ki)) { c.fill (); diff --git a/src/Knob.vala b/src/Knob.vala index 264f5a7..3841214 100644 --- a/src/Knob.vala +++ b/src/Knob.vala @@ -34,7 +34,7 @@ public class Knob : Range { get { if (_image_source == null) { var isource = new SimpleKnobImageSource (); - isource.led_color = color_from_string ("#9fc717"); + isource.led_color = rgba_from_string ("#9fc717"); _image_source = isource; set_size_request((int)image_source.get_knob_width (), (int)image_source.get_knob_height ()); } diff --git a/src/Led.vala b/src/Led.vala index 30cbefb..415bdc0 100644 --- a/src/Led.vala +++ b/src/Led.vala @@ -11,9 +11,24 @@ public class Led : DrawingArea { private bool _led_state = false; - private double r = 1; - private double g = 0; - private double b = 0; + Gdk.RGBA base_color = Gdk.RGBA(); + + public void set_rgb(double _r, double _g, double _b) + { + base_color.red = _r; + base_color.green = _g; + base_color.blue = _b; + base_color.alpha = 1.0; + queue_draw(); + } + + public void get_rgb(ref double _r, ref double _g, ref double _b) + { + _r = base_color.red; + _g = base_color.green; + _b = base_color.blue; + } + [Description(nick="LED is on", blurb="Whether the LED is on or off")] public bool led_state { @@ -29,12 +44,12 @@ public class Led : DrawingArea { public Led () { // Set favored widget size set_size_request (20, 20); - draw.connect(on_draw); + draw.connect(on_draw); } public new virtual void get_preferred_width (out int minimum_width, out int natural_width) { - minimum_width = 20; - natural_width = 20; + minimum_width = 20; + natural_width = 20; } public new virtual void get_preferred_height_for_width (int width, out int minimum_height, out int natural_height) { @@ -52,36 +67,22 @@ public class Led : DrawingArea { natural_width = 20; } - [Description(nick="LED color", blurb="color as a string as accepted by gdk_color_parse (), eg: #a0b1c2")] + [Description(nick="LED color", blurb="color as a string as accepted by gdk_rgba_parse (), eg: #a0b1c2")] public string color { set { if (value != null & value != "") { - gdk_color_to_cairo_color (color_from_string (value), ref r, ref g, ref b); - queue_draw (); + base_color.parse(value); + base_color.alpha = 1.0; } else { - r = 1; g = 0; b = 0; + base_color.parse("rgb(1,0,0)"); + base_color.alpha = 1.0; } } } - - public void set_rgb(double _r, double _g, double _b) - { - r = _r; - g = _g; - b = _b; - queue_draw(); - } - public void get_rgb(ref double _r, ref double _g, ref double _b) - { - _r = r; - _g = g; - _b = b; - } - - public static void paint_led (Cairo.Context cr, Cairo.Color led_color, int width, int height, bool led_state) { + public static void paint_led (Cairo.Context cr, Gdk.RGBA led_color, int width, int height, bool led_state) { HSV hsv = new HSV(); - hsv.from_cairo_color (led_color); + hsv.from_rgba (led_color); if (led_state) { hsv.saturation = 0.76; hsv.value = 0.87; @@ -89,7 +90,7 @@ public class Led : DrawingArea { hsv.saturation = 0.74; hsv.value = 0.78; } - Cairo.Color base_color = hsv.to_cairo_color (); + Gdk.RGBA base_color = hsv.to_rgba (); if (led_state) { hsv.saturation = 0.89; @@ -98,7 +99,7 @@ public class Led : DrawingArea { hsv.saturation = 0.97; hsv.value = 0.76; } - Cairo.Color border_color = hsv.to_cairo_color (); + Gdk.RGBA border_color = hsv.to_rgba (); if (led_state) { hsv.saturation = 0.38; @@ -107,7 +108,7 @@ public class Led : DrawingArea { hsv.saturation = 0.33; hsv.value = 0.88; } - Cairo.Color bottom_gloss_color = hsv.to_cairo_color (); + Gdk.RGBA bottom_gloss_color = hsv.to_rgba (); bottom_gloss_color.alpha = 0.7; if (led_state) { @@ -117,10 +118,10 @@ public class Led : DrawingArea { hsv.saturation = 0.60; hsv.value = 0.96; } - Cairo.Color bottom_gloss_color2 = hsv.to_cairo_color(); + Gdk.RGBA bottom_gloss_color2 = hsv.to_rgba(); bottom_gloss_color2.alpha = 0.7; - Cairo.Color rim_color = new Cairo.Color.from_string ("#898573"); + Gdk.RGBA rim_color = rgba_from_string ("#898573"); rim_color.alpha = 0.7; int xc = width / 2; @@ -131,10 +132,10 @@ public class Led : DrawingArea { double inner_diameter = 10 * parts; Cairo.Pattern upper_shine = new Cairo.Pattern.radial(xc - 1.6 * parts, yc - 2.2 * parts, 0.8 * parts, xc, yc, inner_diameter / 2 - 0.5 * parts); - base_color.shade (2.5).add_color_stop_to (upper_shine, 0); - base_color.shade (1.5).add_color_stop_to (upper_shine, 0.2); - base_color.shade (1.0).add_color_stop_to (upper_shine, 0.5); - border_color.add_color_stop_to (upper_shine, 1.0); + add_color_stop_to (upper_shine, 0, rgba_shade (base_color, 2.5)); + add_color_stop_to (upper_shine, 0.2, rgba_shade (base_color, 1.5)); + add_color_stop_to (upper_shine, 0.5, rgba_shade (base_color, 1.0)); + add_color_stop_to (upper_shine, 1.0, border_color); cr.arc (xc, yc, inner_diameter / 2 - 0.5 * parts, 0, 2 * Math.PI); cr.set_source (upper_shine); @@ -146,9 +147,9 @@ public class Led : DrawingArea { cr.clip (); Cairo.Pattern bottom_gloss = new Cairo.Pattern.radial(xc + 0.68 * 5 * parts, yc + 0.68 * 5 * parts, 1 * parts, xc + 0.68 * 5 * parts, yc + 0.68 * 5 * parts, 4 * parts); - bottom_gloss_color.add_color_stop_to (bottom_gloss, 0); - bottom_gloss_color2.add_color_stop_to (bottom_gloss, 0.3); - border_color.add_color_stop_to (bottom_gloss, 1.0); + add_color_stop_to (bottom_gloss, 0, bottom_gloss_color); + add_color_stop_to (bottom_gloss, 0.3, bottom_gloss_color2); + add_color_stop_to (bottom_gloss, 1.0, border_color); cr.set_source (bottom_gloss); cr.arc (xc + 0.68 * 5 * parts, yc + 0.68 * 5 * parts, 3*parts, 0, 2 * Math.PI); cr.fill (); @@ -157,18 +158,18 @@ public class Led : DrawingArea { cr.arc(xc, yc, inner_diameter / 2 - 0.2 * parts, 0, 2 * Math.PI); cr.set_line_width (0.7 * parts); - rim_color.set_as_source_in (cr); + Gdk.cairo_set_source_rgba (cr, rim_color); cr.stroke(); if (led_state) { Cairo.Pattern flare = new Cairo.Pattern.radial(xc, yc, inner_diameter / 2, xc, yc, inner_diameter); hsv.saturation = 96; hsv.value = 90; - Cairo.Color flare_color = hsv.to_cairo_color (); + Gdk.RGBA flare_color = hsv.to_rgba (); flare_color.alpha = 0.3; - flare_color.add_color_stop_to (flare, 0.1); + add_color_stop_to (flare, 0.1, flare_color); flare_color.alpha = 0.0; - flare_color.add_color_stop_to (flare, 1.0); + add_color_stop_to (flare, 1.0, flare_color); cr.set_source (flare); cr.arc (xc, yc, inner_diameter, 0, 2 * Math.PI); @@ -181,9 +182,7 @@ public class Led : DrawingArea { Gtk.Allocation allocation; get_allocation(out allocation); - Cairo.Color base_color = new Cairo.Color (r, g, b); //new Cairo.Color.from_string ("#c73734"); - - set_source_color(cr, style.bg[(int)Gtk.StateType.NORMAL]); + set_source_color(cr, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL])); cr.rectangle(0, 0, allocation.width, allocation.height); cr.fill(); diff --git a/src/LineGraph.vala b/src/LineGraph.vala index edaf74a..9443ec9 100644 --- a/src/LineGraph.vala +++ b/src/LineGraph.vala @@ -83,7 +83,7 @@ public class DefaultGraphSource : GLib.Object, IGraphSource { public virtual void set_subindex_look (ILineProperties line_props, int subindex) { if ((subindex & 1) != 0) { - Cairo.Color c = new Cairo.Color.from_string (DisplayBase.text_color_default); + RGBA c = rgba_from_string (DisplayBase.text_color_default); line_props.set_line_color ((float) c.red, (float) c.green, (float) c.blue); } else { line_props.set_line_color (0.62f, 0.78f, 0.09f); @@ -326,7 +326,7 @@ public class LineGraph : DrawingArea { int ox = 1, oy = 1; int sx = allocation.width - 2, sy = allocation.height - 2; - Gdk.Color sc = { 0, 0, 0, 0 }; + Gdk.RGBA sc = { 0, 0, 0 }; bool cache_dirty = false; @@ -349,7 +349,7 @@ public class LineGraph : DrawingArea { c.select_font_face ("Bitstream Vera Sans", FontSlant.NORMAL, FontWeight.NORMAL); c.set_font_size (9); - cairo_set_source_color (c, sc); + cairo_set_source_rgba (c, sc); c.rectangle (ox, oy, sx, sy); c.clip (); @@ -362,10 +362,10 @@ public class LineGraph : DrawingArea { bool vertical = false; string legend; float[] data = new float[2 * sx]; - Gdk.Color sc2 = { 0, 0, 65535, 0 }; + Gdk.RGBA sc2 = { 0, 1.0, 0 }; float x = 0, y = 0; int size = 0; - Gdk.Color sc3 = { 0, 32767, 65535, 0 }; + Gdk.RGBA sc3 = { 0.5, 1.0, 0.0 }; int graph_n = 0, grid_n = 0, dot_n = 0, grid_n_save = 0; @@ -377,7 +377,7 @@ public class LineGraph : DrawingArea { cache_cr.select_font_face ("Bitstream Vera Sans", FontSlant.NORMAL, FontWeight.NORMAL); cache_cr.set_font_size (9); - cairo_set_source_color (cache_cr, sc); + cairo_set_source_rgba (cache_cr, sc); cache_cr.rectangle (ox, oy, sx, sy); cache_cr.clip_preserve (); cache_cr.fill (); @@ -391,7 +391,7 @@ public class LineGraph : DrawingArea { set_line_width_from_device (cache_cr); - DisplayBase.outer_rim_for_display (cache_cr, 0, 0, sx, sy, style.bg[(int)Gtk.StateType.NORMAL]); + DisplayBase.outer_rim_for_display (cache_cr, 0, 0, sx, sy, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL])); if (show_glass_rim) { cache_cr.translate (4.5, 3.5); @@ -436,7 +436,7 @@ public class LineGraph : DrawingArea { } grid_n_save = grid_n; - cairo_set_source_color (cache_cr, sc2); + cairo_set_source_rgba (cache_cr, sc2); cache_cr.set_line_join (LineJoin.MITER); cache_cr.set_line_width (1); @@ -448,7 +448,7 @@ public class LineGraph : DrawingArea { draw_graph (cache_cr, ref data, sx, sy); } - cairo_set_source_color (cache_cr, sc3); + cairo_set_source_rgba (cache_cr, sc3); for (dot_n = 0;; dot_n++) { @@ -490,7 +490,7 @@ public class LineGraph : DrawingArea { } } - cairo_set_source_color (c, sc2); + cairo_set_source_rgba (c, sc2); c.set_line_join (LineJoin.MITER); c.set_line_width (1); @@ -502,7 +502,7 @@ public class LineGraph : DrawingArea { draw_graph (c, ref data, sx, sy); } - cairo_set_source_color (c, sc3); + cairo_set_source_rgba (c, sc3); for (int gn = dot_n;; gn++) { size = 3; diff --git a/src/SimpleKnobImageSource.vala b/src/SimpleKnobImageSource.vala index b6b8030..432fcbe 100644 --- a/src/SimpleKnobImageSource.vala +++ b/src/SimpleKnobImageSource.vala @@ -7,7 +7,7 @@ namespace Prolooks { public double knob_height { get; set; } public double x { get; set; } public double y { get; set; } - public Gdk.Color led_color { get; set; } + public Gdk.RGBA led_color { get; set; } public double get_knob_width () { return knob_width; @@ -31,7 +31,7 @@ namespace Prolooks { get_knob_height (), get_line_width (), get_radius (), - Prolooks.color_to_string(led_color)); + led_color.to_string()); } construct { @@ -40,7 +40,7 @@ namespace Prolooks { x = knob_width / 2; y = knob_height / 2; set_size_request (phases * (int)knob_width, variants * (int)knob_height); - led_color = color_from_string ("#ff7f00"); + led_color = rgba_from_string ("#ff7f00"); draw.connect(on_draw); } @@ -149,13 +149,13 @@ namespace Prolooks { if (!glowlit) { cr.set_source_rgb(0, 0, 0); } else { - set_source_color(cr, shade_color (led_color, glowval)); + Gdk.cairo_set_source_rgba(cr, rgba_shade (led_color, glowval)); } } else { if (hilite) { cr.set_source_rgb(1, 1, 0); } else { - set_source_color(cr, led_color); + Gdk.cairo_set_source_rgba(cr, led_color); } } diff --git a/src/SmallButton.vala b/src/SmallButton.vala index efe403f..5bd97d9 100644 --- a/src/SmallButton.vala +++ b/src/SmallButton.vala @@ -11,16 +11,16 @@ using Gdk; namespace Prolooks { public class SmallButton : ButtonBase { - private Color base_color; + private RGBA base_color; [Description(nick="button color", blurb="color as a string as accepted by gdk_color_parse (), eg: #a0b1c2")] public string color { set { lock (base_color) { if (value != null & value != "") { - base_color = color_from_string (value); + base_color = rgba_from_string (value); } else { - base_color = style.bg[(int)Gtk.StateType.NORMAL]; + base_color = gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL]); } } } @@ -35,7 +35,7 @@ public class SmallButton : ButtonBase { | Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK); - base_color = style.bg[(int)Gtk.StateType.NORMAL]; + base_color = gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL]); // Set favored widget size set_size_request (20, 20); @@ -64,48 +64,48 @@ public class SmallButton : ButtonBase { } - public static void button_bg (Cairo.Context cr, Gdk.Color base_color, Gdk.Color outside_color, double width, double height, double shade_inside = 1.0) { - Gdk.Color color; + public static void button_bg (Cairo.Context cr, Gdk.RGBA base_color, Gdk.RGBA outside_color, double width, double height, double shade_inside = 1.0) { + Gdk.RGBA color; // line - color = outside_color; color = shade_color (color, 1.06); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.06); set_source_color (cr, color); cr.move_to (2, 0); cr.line_to (width - 3, 0); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.05); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.05); set_source_color (cr, color); cr.move_to (1, 1); cr.line_to (width - 2, 1); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.05); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.05); set_source_color (cr, color); cr.move_to (0, 2); cr.line_to (width - 1, 2); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.04); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.04); set_source_color (cr, color); cr.move_to (3, 0); cr.line_to (width - 4, 0); cr.stroke (); // line - color = outside_color; color = shade_color (color, 0.97); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 0.97); set_source_color (cr, color); cr.move_to (2, 1); cr.line_to (width - 3, 1); cr.stroke (); // line - color = outside_color; color = shade_color (color, 0.96); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 0.96); set_source_color (cr, color); cr.move_to (1, 2); cr.line_to (width - 2, 2); cr.stroke (); // missing line - color = outside_color; color = shade_color (color, 0.96); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 0.96); set_source_color (cr, color); cr.move_to (0, 3); cr.line_to (width - 1, 3); cr.stroke (); @@ -113,75 +113,75 @@ public class SmallButton : ButtonBase { // line - color = outside_color; color = shade_color (color, 1.13); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.13); set_source_color (cr, color); cr.move_to (2, height - 1); cr.line_to (width - 3, height - 1); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.09); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.09); set_source_color (cr, color); cr.move_to (1, height - 2); cr.line_to (width - 2, height - 2); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.10); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.10); set_source_color (cr, color); cr.move_to (0, height - 3); cr.line_to (width - 1, height - 3); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.15); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.15); set_source_color (cr, color); cr.move_to (3, height - 1); cr.line_to (width - 4, height - 1); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.12); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.12); set_source_color (cr, color); cr.move_to (2, height - 2); cr.line_to (width - 3, height - 2); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.13); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.13); set_source_color (cr, color); cr.move_to (1, height - 3); cr.line_to (width - 2, height - 3); cr.stroke (); /////////////////////////// border outline // line - color = base_color; color = shade_color (color, 0.6); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.6); set_source_color (cr, color); cr.move_to (3, 1); cr.line_to (width - 4, 1); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.6); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.6); set_source_color (cr, color); cr.move_to (3, height - 2); cr.line_to (width - 4, height - 2); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.6); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.6); set_source_color (cr, color); cr.move_to (1, 3); cr.line_to (1, height - 4); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.6); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.6); set_source_color (cr, color); cr.move_to (width - 2, 3); cr.line_to (width - 2, height - 4); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.6); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.6); set_source_color (cr, color); cr.move_to (2, 2); cr.line_to (width - 3, 2); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.6); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.6); set_source_color (cr, color); cr.move_to (2, height - 3); cr.line_to (width - 3, height - 3); cr.stroke (); @@ -189,19 +189,19 @@ public class SmallButton : ButtonBase { /////////////////////////// border smooth effect // line - color = base_color; color = shade_color (color, 1.02); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 1.02); set_source_color (cr, color); cr.move_to (3, 2); cr.line_to (width - 4, 2); cr.stroke (); // line - color = base_color; color = shade_color (color, 1.00); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 1.00); set_source_color (cr, color); cr.move_to (2, 3); cr.line_to (2, height - 4); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.94); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.94); set_source_color (cr, color); cr.move_to (width - 3, 3); cr.line_to (width - 3, height - 4); cr.stroke (); @@ -209,20 +209,20 @@ public class SmallButton : ButtonBase { /////////////////////////// inside highlight // line - color = base_color; color = shade_color (color, 1.2); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 1.2); set_source_color (cr, color); cr.move_to (4, 2); cr.line_to (width - 5, 2); cr.stroke (); // line - color = base_color; color = shade_color (color, 1.1); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 1.1); set_source_color (cr, color); cr.move_to (2, 4); cr.line_to (2, height - 5); cr.stroke (); /////////////////////////// inside shadow // line - color = base_color; color = shade_color (color, 1.04); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 1.04); set_source_color (cr, color); cr.move_to (width - 3, 4); cr.line_to (width - 3, height - 5); cr.stroke (); @@ -230,7 +230,7 @@ public class SmallButton : ButtonBase { /////////////////////////// fill gradient // gradient - Cairo.Pattern gloss_gradient = gloss_gradient_pattern(0.0, 0.0, 0.0, height, gdk_color_to_cairo(shade_color(base_color, shade_inside))); + Cairo.Pattern gloss_gradient = gloss_gradient_pattern(0.0, 0.0, 0.0, height, rgba_shade(base_color, shade_inside)); cr.set_source (gloss_gradient); cr.rectangle (1.0, 2, width - 4, height - 5); @@ -240,26 +240,26 @@ public class SmallButton : ButtonBase { /////////////////////////// bottom border smooth effect // line - color = base_color; color = shade_color (color, 1.00); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 1.00); set_source_color (cr, color); cr.move_to (3, height - 3); cr.line_to (width - 4, height - 3); cr.stroke (); // line - color = base_color; color = shade_color (color, 1.1); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 1.1); set_source_color (cr, color); cr.move_to (4, height - 3); cr.line_to (width - 5, height - 3); cr.stroke (); } - public static void button_bg_pressed (Cairo.Context cr, Gdk.Color base_color, Gdk.Color outside_color, double width, double height) { + public static void button_bg_pressed (Cairo.Context cr, Gdk.RGBA base_color, Gdk.RGBA outside_color, double width, double height) { Cairo.Pattern gradient; - Gdk.Color color; - //Gdk.Color test_color = color_from_string ("#ff0000"); + Gdk.RGBA color; + //Gdk.RGBA test_color = RGBA.parse ("#ff0000"); /////////////////////////// outside highlight // gradient - gradient = create_gradient (0, 0, 0, height - 4, shade_color (outside_color, 1.2), shade_color (outside_color, 1.0)); + gradient = create_gradient (0, 0, 0, height - 4, rgba_shade (outside_color, 1.2), rgba_shade (outside_color, 1.0)); cr.set_source (gradient); cr.rectangle (width - 2 - 0.5, 2, 1, height - 4); @@ -267,7 +267,7 @@ public class SmallButton : ButtonBase { // gradient - gradient = create_gradient (0, 0, 0, height - 6, shade_color (outside_color, 1.2), shade_color (outside_color, 1.0)); + gradient = create_gradient (0, 0, 0, height - 6, rgba_shade (outside_color, 1.2), rgba_shade (outside_color, 1.0)); cr.set_source (gradient); cr.rectangle (width - 1 - 0.5, 3, 1, height - 6); @@ -276,51 +276,51 @@ public class SmallButton : ButtonBase { // line - color = outside_color; color = shade_color (color, 1.0); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.0); set_source_color (cr, color); cr.move_to (2, height - 2); cr.line_to (width - 3, height - 2); cr.stroke (); // line - color = outside_color; color = shade_color (color, 1.0); set_source_color (cr, color); + color = outside_color; color = rgba_shade (color, 1.0); set_source_color (cr, color); cr.move_to (3, height - 1); cr.line_to (width - 4, height - 1); cr.stroke (); /////////////////////////// border outline // line - color = base_color; color = shade_color (color, 0.55); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.55); set_source_color (cr, color); cr.move_to (3, 1); cr.line_to (width - 4, 1); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.55); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.55); set_source_color (cr, color); cr.move_to (3, height - 2); cr.line_to (width - 4, height - 2); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.55); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.55); set_source_color (cr, color); cr.move_to (1, 3); cr.line_to (1, height - 4); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.55); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.55); set_source_color (cr, color); cr.move_to (width - 2, 3); cr.line_to (width - 2, height - 4); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.55); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.55); set_source_color (cr, color); cr.move_to (2, 2); cr.line_to (width - 3, 2); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.55); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.55); set_source_color (cr, color); cr.move_to (2, height - 3); cr.line_to (width - 3, height - 3); cr.stroke (); @@ -328,13 +328,13 @@ public class SmallButton : ButtonBase { /////////////////////////// inside shadow // line - color = base_color; color = shade_color (color, 0.9); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.9); set_source_color (cr, color); cr.move_to (3, 2); cr.line_to (width - 4, 2); cr.stroke (); // line - color = base_color; color = shade_color (color, 0.85); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.85); set_source_color (cr, color); cr.move_to (2, 3); cr.line_to (2, height - 4); cr.stroke (); @@ -342,14 +342,14 @@ public class SmallButton : ButtonBase { /////////////////////////// fill gradient // gradient - gradient = create_gradient (0, 0, 0, height - 6, shade_color (base_color, 0.95), shade_color (base_color, 0.9)); + gradient = create_gradient (0, 0, 0, height - 6, rgba_shade (base_color, 0.95), rgba_shade (base_color, 0.9)); cr.set_source (gradient); cr.rectangle (3 - 0.5, 2, width - 5, height - 5.5); cr.fill (); // line - color = base_color; color = shade_color (color, 0.9); set_source_color (cr, color); + color = base_color; color = rgba_shade (color, 0.9); set_source_color (cr, color); cr.move_to (3, height - 3); cr.line_to (width - 5, height - 3); cr.stroke (); @@ -371,11 +371,11 @@ public class SmallButton : ButtonBase { if (button_state == ButtonState.PRESSED) { lock (base_color) { - button_bg_pressed (cr, base_color, style.bg[(int)Gtk.StateType.NORMAL], width, height); + button_bg_pressed (cr, base_color, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL]), width, height); } } else { lock (base_color) { - button_bg (cr, base_color, style.bg[(int)Gtk.StateType.NORMAL], width, height, prelighted ? 1.1 : 1.0); + button_bg (cr, base_color, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL]), width, height, prelighted ? 1.1 : 1.0); } } return false; diff --git a/src/ThorwilKnobImageSource.vala b/src/ThorwilKnobImageSource.vala index fa97dc0..45957c6 100644 --- a/src/ThorwilKnobImageSource.vala +++ b/src/ThorwilKnobImageSource.vala @@ -7,16 +7,16 @@ namespace Prolooks { public double knob_height { get; set; } private HSV lamp_hsv; - private Gdk.Color _lamp_color; + private Gdk.RGBA _lamp_color; - public Gdk.Color lamp_color { + public Gdk.RGBA lamp_color { get { return _lamp_color; } set { _lamp_color = value; - lamp_hsv = new HSV.for_gdk_color (value); + lamp_hsv = new HSV.for_rgba (value); } } @@ -48,7 +48,7 @@ namespace Prolooks { knob_width = 40; knob_height = 40; set_size_request ((int)(phases * knob_width), (int) (knob_height)); - lamp_color = color_from_string ("#b9feff"); + lamp_color = rgba_from_string ("#b9feff"); draw.connect(on_draw); } @@ -124,10 +124,10 @@ namespace Prolooks { // ProgressLamp lamp_hsv.saturation = 0.27; lamp_hsv.value = 1.0; - var lamp_bright = lamp_hsv.to_gdk_color (); + var lamp_bright = lamp_hsv.to_rgba (); lamp_hsv.saturation = 0.66; lamp_hsv.value = 0.67; - var lamp_dark = lamp_hsv.to_gdk_color (); + var lamp_dark = lamp_hsv.to_rgba (); cr.set_source (create_gradient (20, 20, 89, 87, lamp_bright, lamp_dark)); cr.set_line_width (progress_width); diff --git a/src/TransportButton.vala b/src/TransportButton.vala index 8e14f90..228f66b 100644 --- a/src/TransportButton.vala +++ b/src/TransportButton.vala @@ -53,7 +53,7 @@ public class TransportButton : ButtonBase { case IconType.FAST_BACKWARD: width = 11; height = 12; break; case IconType.TO_END: case IconType.TO_START: width = 10; height = 12; break; - default: GLib.assert_not_reached (); break; + default: GLib.assert_not_reached (); } } @@ -67,8 +67,8 @@ public class TransportButton : ButtonBase { } public static void paint_stop_icon (Cairo.Context cr) { - Color stop_icon_color_center = shade_color(color_from_string ("#184b6a"), 1.4); - Color stop_icon_color_outside = shade_color(color_from_string ("#050f2a"), 1.4); + RGBA stop_icon_color_center = rgba_shade(rgba_from_string ("#184b6a"), 1.4); + RGBA stop_icon_color_outside = rgba_shade(rgba_from_string ("#050f2a"), 1.4); Cairo.Pattern pt = new Cairo.Pattern.radial (4.5, 4.5, 0, 4.5, 4.5, 3); add_color_stop (pt, 0, stop_icon_color_center); @@ -80,8 +80,8 @@ public class TransportButton : ButtonBase { } public static void paint_play_icon (Cairo.Context cr) { - Color play_icon_color_middle = color_from_string ("#4b9a0d"); - Color play_icon_color_outside = color_from_string ("#2e4f18"); + RGBA play_icon_color_middle = rgba_from_string ("#4b9a0d"); + RGBA play_icon_color_outside = rgba_from_string ("#2e4f18"); Cairo.Pattern pt = new Cairo.Pattern.radial (3.5, 7.5, 3, 3.5, 7.5, 10); add_color_stop(pt, 0, play_icon_color_middle); @@ -98,8 +98,8 @@ public class TransportButton : ButtonBase { } public static void paint_rec_icon (Cairo.Context cr) { - Color rec_icon_color_middle = shade_color(color_from_string ("#8b2f20"), 1.4); - Color rec_icon_color_outside = shade_color(color_from_string ("#47090a"), 1.4); + RGBA rec_icon_color_middle = rgba_shade(rgba_from_string ("#8b2f20"), 1.4); + RGBA rec_icon_color_outside = rgba_shade(rgba_from_string ("#47090a"), 1.4); Cairo.Pattern pt = new Cairo.Pattern.radial (5.0, 5.0, 0, 5.0, 5.0, 10); add_color_stop(pt, 0, rec_icon_color_middle); @@ -110,7 +110,7 @@ public class TransportButton : ButtonBase { cr.fill (); } - public static Color ff_icons_color = color_from_string ("#212121"); + public static RGBA ff_icons_color = rgba_from_string ("#212121"); public static void paint_fast_forward_icon (Cairo.Context cr) { set_source_color (cr, ff_icons_color); @@ -192,16 +192,16 @@ public class TransportButton : ButtonBase { cr.restore (); } - private Color pressed_color () { - Color pressed_color = color_from_string ("#c2c2c2"); + private RGBA pressed_color () { + RGBA pressed_color = rgba_from_string ("#c2c2c2"); switch (icon_type) { - case IconType.STOP: pressed_color = color_from_string ("#2d73a2"); break; - case IconType.REC: pressed_color = color_from_string ("#d46552"); break; - case IconType.PLAY: pressed_color = color_from_string ("#87bb36"); break; + case IconType.STOP: pressed_color = rgba_from_string ("#2d73a2"); break; + case IconType.REC: pressed_color = rgba_from_string ("#d46552"); break; + case IconType.PLAY: pressed_color = rgba_from_string ("#87bb36"); break; case IconType.FAST_FORWARD: case IconType.FAST_BACKWARD: case IconType.TO_END: - case IconType.TO_START: pressed_color = color_from_string ("#636363"); break; + case IconType.TO_START: pressed_color = rgba_from_string ("#636363"); break; default: GLib.assert_not_reached (); break; } return pressed_color; @@ -218,7 +218,7 @@ public class TransportButton : ButtonBase { cr.rectangle (0.0, 0.0, allocation.width, allocation.height); cr.fill (); - set_source_color (cr, style.bg[(int)Gtk.StateType.NORMAL]); + set_source_color (cr, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL])); cr.rectangle (0, 0, allocation.width, allocation.height); cr.fill (); @@ -271,8 +271,8 @@ public class TransportButton : ButtonBase { // draw shine // upper shine - Color shine_upper_gradient1 = color_from_string ("#ffffff"); - Color shine_upper_gradient2 = color_from_string ("#c0c0c0"); + RGBA shine_upper_gradient1 = rgba_from_string ("#ffffff"); + RGBA shine_upper_gradient2 = rgba_from_string ("#c0c0c0"); Cairo.Pattern shine_upper = create_gradient (0, 0, 0, allocation.height / 2.0, shine_upper_gradient1, shine_upper_gradient2, shine_alpha_start, shine_alpha_stop); cr.set_source (shine_upper); cr.rectangle (0, 0, allocation.width, allocation.height / 2.0); @@ -287,8 +287,8 @@ public class TransportButton : ButtonBase { } // lower shine - Color shine_lower_gradient1 = color_from_string ("#a0a0a0"); - Color shine_lower_gradient2 = color_from_string ("#a0a0a0"); + RGBA shine_lower_gradient1 = rgba_from_string ("#a0a0a0"); + RGBA shine_lower_gradient2 = rgba_from_string ("#a0a0a0"); Cairo.Pattern shine_lower = create_gradient (0, allocation.height / 2.0, 0, allocation.height, shine_lower_gradient1, shine_lower_gradient2, shine_alpha_stop, shine_alpha_start); cr.set_source (shine_lower); cr.rectangle (2, allocation.height / 2.0, allocation.width - 3, allocation.height / 2.0 - 2); diff --git a/src/VuMeter.vala b/src/VuMeter.vala index 793ab89..97706c6 100644 --- a/src/VuMeter.vala +++ b/src/VuMeter.vala @@ -35,11 +35,16 @@ public class VuMeter : DrawingArea { private double g = 1; private double b = 0; - [Description(nick="monochrome color", blurb="sets the meter color in monochrome color mode, can contain a string as accepted by gdk_color_parse (), eg: #a0b1c2")] + [Description(nick="monochrome color", blurb="sets the meter color in monochrome color mode, can contain a string as accepted by gdk_rgba_parse (), eg: #a0b1c2")] public string color { set { if (value != null & value != "") { - gdk_color_to_cairo_color (color_from_string (value), ref r, ref g, ref b); + Gdk.RGBA rgba = Gdk.RGBA(); + rgba.parse(value); + r = rgba.red; + g = rgba.green; + b = rgba.blue; + cache_surface = null; queue_draw (); } else { -- 2.11.4.GIT