[gtkmm/wip/dboles/rgba-construct-doubles-4] Gdk::RGBA: Add constructor taking doubles r, g, b, a



commit fa758097aae26f026cc232897d50a935611afeff
Author: Daniel Boles <dboles src gmail com>
Date:   Sun Dec 16 20:17:03 2018 +0000

    Gdk::RGBA: Add constructor taking doubles r,g,b,a
    
    Enable constructing `Gdk::RGBA`s directly with the desired components as
    fractions, sparing the user from having to do a verbose and error-prone
    2-step 'construction' and also making it far nicer to declare e.g. a
    `std::vector<Gdk::RGBA>` to be used as a palette of colours in an app.
    
    notes:
    
     * I first delegated to `RGBA()` then did `set_rgba()`, but Kjell and I
       agreed initialising directly was better than redundantly reassigning.
    
     * GdkRGBA only has 4 fields, but we included a trailing `,` in RGBA()
       initialising them to 0, which is meaningless, I just do that here too
    
    https://gitlab.gnome.org/GNOME/gtkmm/issues/40

 gdk/src/rgba.ccg | 6 ++++++
 gdk/src/rgba.hg  | 8 ++++++++
 2 files changed, 14 insertions(+)
---
diff --git a/gdk/src/rgba.ccg b/gdk/src/rgba.ccg
index e8bede6b..af781c91 100644
--- a/gdk/src/rgba.ccg
+++ b/gdk/src/rgba.ccg
@@ -35,6 +35,12 @@ RGBA::RGBA(const Glib::ustring& value)
   set(value);
 }
 
+RGBA::RGBA(double red_, double green_, double blue_, double alpha_)
+{
+  GdkRGBA tmp = { red_, green_, blue_, alpha_, };
+  gobject_ = gdk_rgba_copy(&tmp);
+}
+
 void RGBA::set_grey_u(gushort value, gushort alpha)
 {
   gobject_->red = gobject_->green = gobject_->blue = (value / MULTIPLIER);
diff --git a/gdk/src/rgba.hg b/gdk/src/rgba.hg
index 1668e480..e9f8c8fd 100644
--- a/gdk/src/rgba.hg
+++ b/gdk/src/rgba.hg
@@ -68,6 +68,14 @@ public:
   explicit RGBA(const Glib::ustring& value);
   _IGNORE(gdk_rgba_parse)
 
+  /** Construct a Gdk::RGBA, by specifying red, green, and blue color component values, as fractions.
+   * @param red_ The red component of the color, as a fraction.
+   * @param green_ The green component of the color, as a fraction.
+   * @param blue_ The blue component of the color, as a fraction.
+   * @param alpha_ The alpha component of the color, as a fraction.
+   */
+  RGBA(double red_, double green_, double blue_, double alpha_ = 1.0);
+
   /** Set a grey color, by using the same value for all color components.
    * @param value The value to be used for the red, green, and blue components, in the range 0..65535.
    * @param alpha The alpha component of the color, in the range 0..65535.


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