[niepce] npc_fwk: added gdkutils



commit 201987f7b19008a8ead0c08fdfb37e7660713d4e
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Feb 1 19:53:58 2020 -0500

    npc_fwk: added gdkutils

 crates/npc-fwk/src/toolkit/gdk_utils.rs | 43 +++++++++++++++++++++++++++++++++
 crates/npc-fwk/src/toolkit/mod.rs       |  1 +
 src/Makefile.am                         |  1 +
 3 files changed, 45 insertions(+)
---
diff --git a/crates/npc-fwk/src/toolkit/gdk_utils.rs b/crates/npc-fwk/src/toolkit/gdk_utils.rs
new file mode 100644
index 0000000..2ff9da6
--- /dev/null
+++ b/crates/npc-fwk/src/toolkit/gdk_utils.rs
@@ -0,0 +1,43 @@
+/*
+ * niepce - npc-fwk/toolkit/gdk_utils.rs
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+use std::cmp;
+
+use gdk_pixbuf;
+
+pub fn gdkpixbuf_scale_to_fit(
+    pix: Option<&gdk_pixbuf::Pixbuf>,
+    dim: i32,
+) -> Option<gdk_pixbuf::Pixbuf> {
+    if let Some(pix) = pix {
+        let orig_h = pix.get_height();
+        let orig_w = pix.get_width();
+        let orig_dim = cmp::max(orig_h, orig_w);
+        let ratio: f64 = dim as f64 / orig_dim as f64;
+        let width = ratio * orig_w as f64;
+        let height = ratio * orig_h as f64;
+        pix.scale_simple(
+            width as i32,
+            height as i32,
+            gdk_pixbuf::InterpType::Bilinear,
+        )
+    } else {
+        None
+    }
+}
diff --git a/crates/npc-fwk/src/toolkit/mod.rs b/crates/npc-fwk/src/toolkit/mod.rs
index 659d60b..fa78c5d 100644
--- a/crates/npc-fwk/src/toolkit/mod.rs
+++ b/crates/npc-fwk/src/toolkit/mod.rs
@@ -18,6 +18,7 @@
  */
 
 pub mod clickable_cell_renderer;
+pub mod gdk_utils;
 pub mod mimetype;
 pub mod widgets;
 
diff --git a/src/Makefile.am b/src/Makefile.am
index b029abd..04e156a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,6 +36,7 @@ RUST_SOURCES = \
        @top_srcdir@/crates/npc-fwk/src/base/propertyvalue.rs \
        @top_srcdir@/crates/npc-fwk/src/base/rgbcolour.rs \
        @top_srcdir@/crates/npc-fwk/src/lib.rs \
+       @top_srcdir@/crates/npc-fwk/src/toolkit/gdk_utils.rs \
        @top_srcdir@/crates/npc-fwk/src/toolkit/mimetype.rs \
        @top_srcdir@/crates/npc-fwk/src/toolkit/mod.rs \
        @top_srcdir@/crates/npc-fwk/src/toolkit/widgets/mod.rs \


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