[niepce] npc-fwk: Add Into<gdk::RGBA> for RgbColour



commit 3aaa68713de925a3a567e643892473ffc354eef6
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Jan 11 17:36:14 2020 -0500

    npc-fwk: Add Into<gdk::RGBA> for RgbColour

 Cargo.lock                           |  1 +
 crates/npc-fwk/Cargo.toml            |  1 +
 crates/npc-fwk/src/base/rgbcolour.rs | 16 +++++++++++++++-
 crates/npc-fwk/src/lib.rs            |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 211fc18..10d4e83 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -601,6 +601,7 @@ dependencies = [
  "cbindgen 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "exempi 2.5.0 (git+https://github.com/hfiguiere/exempi-rs.git?rev=53cfc05)",
+ "gdk 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "gio 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "gio-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "glib 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/crates/npc-fwk/Cargo.toml b/crates/npc-fwk/Cargo.toml
index d4cff6b..9835d49 100644
--- a/crates/npc-fwk/Cargo.toml
+++ b/crates/npc-fwk/Cargo.toml
@@ -14,6 +14,7 @@ gio-sys = "*"
 gio = "^0.8.0"
 glib-sys = "*"
 glib = { version = "^0.9.0" }
+gdk = "^0.12.0"
 lazy_static = "^1.2.0"
 libc = "0.2.39"
 multimap = "0.4.0"
diff --git a/crates/npc-fwk/src/base/rgbcolour.rs b/crates/npc-fwk/src/base/rgbcolour.rs
index 797fb0a..4745a57 100644
--- a/crates/npc-fwk/src/base/rgbcolour.rs
+++ b/crates/npc-fwk/src/base/rgbcolour.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/base/rgbcolour.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2020 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,10 +18,13 @@
  */
 
 use libc::c_char;
+use std::convert::Into;
 use std::ffi::CString;
 use std::num::ParseIntError;
 use std::str::FromStr;
 
+use gdk;
+
 #[repr(C)]
 #[derive(Clone, Default)]
 pub struct RgbColour {
@@ -73,6 +76,17 @@ impl ToString for RgbColour {
     }
 }
 
+impl Into<gdk::RGBA> for RgbColour {
+    fn into(self) -> gdk::RGBA {
+        gdk::RGBA {
+            red: self.r as f64 / 65535_f64,
+            green: self.g as f64 / 65535_f64,
+            blue: self.b as f64 / 65535_f64,
+            alpha: 1.0,
+        }
+    }
+}
+
 #[no_mangle]
 pub extern "C" fn fwk_rgbcolour_to_string(c: &RgbColour) -> *mut c_char {
     CString::new(c.to_string().as_bytes()).unwrap().into_raw()
diff --git a/crates/npc-fwk/src/lib.rs b/crates/npc-fwk/src/lib.rs
index 9042c12..c2af9a1 100644
--- a/crates/npc-fwk/src/lib.rs
+++ b/crates/npc-fwk/src/lib.rs
@@ -19,6 +19,7 @@
 
 extern crate chrono;
 extern crate exempi;
+extern crate gdk;
 extern crate gio;
 extern crate gio_sys;
 extern crate glib;


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