[california] Remove Gdk.Color references: Bug #731295



commit f4b4d08939214eef95d26ddaf86ec052d5bab244
Author: Jim Nelson <jim yorba org>
Date:   Thu Jun 5 14:16:44 2014 -0700

    Remove Gdk.Color references: Bug #731295

 src/activator/webcal/activator-webcal-pane.vala |    5 +-
 src/backing/backing-source.vala                 |   11 +---
 src/manager/manager-calendar-list-item.vala     |    4 +-
 src/util/util-gfx.vala                          |   92 +++-------------------
 src/view/week/week-day-pane.vala                |    2 +-
 5 files changed, 18 insertions(+), 96 deletions(-)
---
diff --git a/src/activator/webcal/activator-webcal-pane.vala b/src/activator/webcal/activator-webcal-pane.vala
index 493bf28..047304f 100644
--- a/src/activator/webcal/activator-webcal-pane.vala
+++ b/src/activator/webcal/activator-webcal-pane.vala
@@ -71,12 +71,9 @@ internal class WebCalActivatorPane : Gtk.Grid, Toolkit.Card {
     }
     
     private async void subscribe_async() {
-        Gdk.Color color;
-        color_button.get_color(out color);
-        
         try {
             yield store.subscribe_webcal_async(name_entry.text, URI.parse(url_entry.text),
-                null, Gfx.rgb_to_uint8_rgb_string(color), null);
+                null, Gfx.rgba_to_uint8_rgb_string(color_button.rgba), null);
             notify_success();
         } catch (Error err) {
             notify_failure(_("Unable to subscribe to Web calendar at %s: %s").printf(url_entry.text,
diff --git a/src/backing/backing-source.vala b/src/backing/backing-source.vala
index b907d7f..c2a0dbc 100644
--- a/src/backing/backing-source.vala
+++ b/src/backing/backing-source.vala
@@ -91,15 +91,6 @@ public abstract class Source : BaseObject, Gee.Comparable<Source> {
     }
     
     /**
-     * Returns the current { link color} setting as a Gdk.Color.
-     *
-     * If the color string is unparseable, returns a Gdk.Color that corresponds to "dressy-black".
-     */
-    public Gdk.Color color_as_rgb() {
-        return Gfx.rgb_string_to_rgb(color, Gdk.Color() { red = 0, green = 0, blue = 0 }, null);
-    }
-    
-    /**
      * Returns the current { link color} setting as a Gdk.RGBA.
      *
      * If the color string is unparseable, returns a Gdk.RGBA that corresponds to "dressy-black".
@@ -113,7 +104,7 @@ public abstract class Source : BaseObject, Gee.Comparable<Source> {
      * Set the { link color} property to the string representation of the Gdk.RGBA structure.
      */
     public void set_color_to_rgba(Gdk.RGBA rgba) {
-        color = Gfx.rgb_to_uint8_rgb_string(Gfx.rgba_to_rgb(rgba));
+        color = Gfx.rgba_to_uint8_rgb_string(rgba);
     }
     
     /**
diff --git a/src/manager/manager-calendar-list-item.vala b/src/manager/manager-calendar-list-item.vala
index 29d2fdf..ca6a2a6 100644
--- a/src/manager/manager-calendar-list-item.vala
+++ b/src/manager/manager-calendar-list-item.vala
@@ -102,13 +102,13 @@ internal class CalendarListItem : Gtk.Grid, Toolkit.MutableWidget {
     
     private bool source_to_color(Binding binding, Value source_value, ref Value target_value) {
         bool used_default;
-        target_value = Gfx.rgb_string_to_rgba(source.color, Gfx.RGBA_BLACK, out used_default);
+        target_value = Gfx.rgb_string_to_rgba(source.color, Gfx.BLACK, out used_default);
         
         return !used_default;
     }
     
     private bool color_to_source(Binding binding, Value source_value, ref Value target_value) {
-        target_value = Gfx.rgb_to_uint8_rgb_string(Gfx.rgba_to_rgb(color_button.rgba));
+        target_value = Gfx.rgba_to_uint8_rgb_string(color_button.rgba);
         
         return true;
     }
diff --git a/src/util/util-gfx.vala b/src/util/util-gfx.vala
index 72bab00..b9bfb3d 100644
--- a/src/util/util-gfx.vala
+++ b/src/util/util-gfx.vala
@@ -6,43 +6,13 @@
 
 namespace California.Gfx {
 
-public const Gdk.Color RGB_BLACK = { 0, 0, 0 };
-public const Gdk.Color RGB_WHITE = { 255, 255, 255 };
-
-public const Gdk.RGBA RGBA_BLACK = { 0.0, 0.0, 0.0, 1.0 };
-public const Gdk.RGBA RGBA_WHITE = { 1.0, 1.0, 1.0, 1.0 };
-
-/**
- * Convert an RGB string into an RGB structure.
- *
- * The string can be in any of the forms that Gdk.Color.parse accepts.  If unable to parse the
- * string, the { link default_rgb} is returned and { link used_default} is set to true.
- */
-public Gdk.Color rgb_string_to_rgb(string? rgb_string, Gdk.Color default_rgb, out bool used_default) {
-    if (String.is_empty(rgb_string)) {
-        used_default = true;
-        
-        return default_rgb;
-    }
-    
-    Gdk.Color rgb;
-    if (!Gdk.Color.parse(rgb_string, out rgb)) {
-        debug("Unable to parse RGB color \"%s\"", rgb_string);
-        
-        used_default = true;
-        
-        return default_rgb;
-    }
-    
-    used_default = false;
-    
-    return rgb;
-}
+public const Gdk.RGBA BLACK = { 0.0, 0.0, 0.0, 1.0 };
+public const Gdk.RGBA WHITE = { 1.0, 1.0, 1.0, 1.0 };
 
 /**
- * Convert an RGB string into an RGBA structure.
+ * Convert an RGBA string into an RGBA structure.
  *
- * The string can be in any of the forms that Gdk.Color.parse accepts.  If unable to parse the
+ * The string can be in any of the forms that Gdk.RGBA.parse accepts.  If unable to parse the
  * string, the { link default_rgba} is returned and { link used_default} is set to true.
  */
 public Gdk.RGBA rgb_string_to_rgba(string? rgb_string, Gdk.RGBA default_rgba, out bool used_default) {
@@ -52,31 +22,20 @@ public Gdk.RGBA rgb_string_to_rgba(string? rgb_string, Gdk.RGBA default_rgba, ou
         return default_rgba;
     }
     
-    Gdk.Color rgb;
-    if (!Gdk.Color.parse(rgb_string, out rgb)) {
-        debug("Unable to parse RGB color \"%s\"", rgb_string);
+    Gdk.RGBA rgba = Gdk.RGBA();
+    if (!rgba.parse(rgb_string)) {
+        debug("Unable to parse RGBA color \"%s\"", rgb_string);
         
         used_default = true;
         
         return default_rgba;
     }
     
-    Gdk.RGBA rgba = Gdk.RGBA();
-    rgba.red = uint16_to_fp(rgb.red);
-    rgba.green = uint16_to_fp(rgb.green);
-    rgba.blue = uint16_to_fp(rgb.blue);
-    rgba.alpha = 1.0;
-    
     used_default = false;
     
     return rgba;
 }
 
-// compiler error if this calculation is done inline when initializing struct
-private inline double uint16_to_fp(uint16 value) {
-    return (double) value / (double) uint16.MAX;
-}
-
 /**
  * Converts the Gdk.RGBA into a 32-bit pixel representation.
  */
@@ -92,41 +51,16 @@ private inline uint8 fp_to_uint8(double value) {
 }
 
 /**
- * Converts a Gdk.RGBA structure into an RGB (Gdk.Color) structure.
+ * Converts the Gdk.RGBA into an RGB string representation ("#ad12c3")
  *
- * The alpha channel is necessarily stripped in this conversion.
+ * Note that alpha channel information is lost in this conversion.
  */
-public Gdk.Color rgba_to_rgb(Gdk.RGBA rgba) {
-    Gdk.Color rgb = Gdk.Color();
-    rgb.red = fp_to_uint16(rgba.red);
-    rgb.green = fp_to_uint16(rgba.green);
-    rgb.blue = fp_to_uint16(rgba.blue);
-    
-    return rgb;
-}
-
-private inline uint16 fp_to_uint16(double value) {
-    return (uint16) Math.round(value * (double) uint16.MAX);
-}
-
-public string rgb_to_uint8_rgb_string(Gdk.Color rgb) {
+public string rgba_to_uint8_rgb_string(Gdk.RGBA rgba) {
     return "#%02x%02x%02x".printf(
-        uint16_to_uint8(rgb.red),
-        uint16_to_uint8(rgb.green),
-        uint16_to_uint8(rgb.blue)
+        fp_to_uint8(rgba.red),
+        fp_to_uint8(rgba.green),
+        fp_to_uint8(rgba.blue)
     );
 }
 
-private inline uint8 uint16_to_uint8(uint16 value) {
-    return (uint8) (value / (uint8.MAX + 1));
-}
-
-public string rgb_to_string(Gdk.Color rgb) {
-    return "(%d,%d,%d)".printf(rgb.red, rgb.green, rgb.blue);
-}
-
-public string rgba_to_string(Gdk.RGBA rgba) {
-    return "(%lf,%lf,%lf,%lf)".printf(rgba.red, rgba.green, rgba.blue, rgba.alpha);
-}
-
 }
diff --git a/src/view/week/week-day-pane.vala b/src/view/week/week-day-pane.vala
index 4dbb13c..f579c67 100644
--- a/src/view/week/week-day-pane.vala
+++ b/src/view/week/week-day-pane.vala
@@ -227,7 +227,7 @@ internal class DayPane : Pane, Common.InstanceContainer {
             ctx.rectangle(0, start_y, rect_width, end_y - start_y);
             
             // background rectangle (to prevent hour lines from showing when using alpha, below)
-            Gdk.cairo_set_source_rgba(ctx, Gfx.RGBA_WHITE);
+            Gdk.cairo_set_source_rgba(ctx, Gfx.WHITE);
             ctx.fill_preserve();
             
             // interior rectangle (use alpha to mute colors)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]