[aseprite] 42/196: she/gtk: add a simple image preview

Tobias Hansen thansen at moszumanska.debian.org
Wed Apr 20 18:49:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 29eaaea1fdeb98e89777feb67120d98737b30cf3
Author: Gabriel Rauter <rauter.gabriel at gmail.com>
Date:   Mon Mar 7 15:46:08 2016 +0100

    she/gtk: add a simple image preview
    
    This adds a simple image preview for image formats supported by
    Gdk::Pixbuf.
---
 src/she/gtk/native_dialogs.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/she/gtk/native_dialogs.cpp b/src/she/gtk/native_dialogs.cpp
index 573c020..37ce7b1 100644
--- a/src/she/gtk/native_dialogs.cpp
+++ b/src/she/gtk/native_dialogs.cpp
@@ -21,6 +21,8 @@
 #include <gtkmm/filechooserdialog.h>
 #include <gtkmm/button.h>
 #include <gtkmm/filefilter.h>
+#include <gtkmm/image.h>
+#include <gdkmm/pixbuf.h>
 #include <glibmm/refptr.h>
 #include <glibmm/miscutils.h>
 #include <glibmm/fileutils.h>
@@ -47,6 +49,9 @@ public:
        FileDialogGTK3::lastUsedDir() = Glib::get_user_special_dir(Glib::USER_DIRECTORY_DOCUMENTS);
     #endif
     }
+    this->set_use_preview_label(false);
+    this->set_preview_widget(m_preview);
+    this->signal_update_preview().connect(sigc::mem_fun(this, &FileDialogGTK3::updatePreview));
   }
 
   void on_show() override {
@@ -125,6 +130,18 @@ public:
     m_file_name = filename;
   }
 
+  void updatePreview() {
+    this->set_preview_widget_active(false);
+    std::string fileName = this->get_filename();
+    try {
+      if (!Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
+          auto previewPixbuf = Gdk::Pixbuf::create_from_file(fileName, 256, 256, true);
+          m_preview.set(previewPixbuf);
+          this->set_preview_widget_active();
+      }
+    } catch(Glib::Error e) {}
+  }
+
   bool show(Display* parent) override {
     //keep pointer on parent display to get information later
     m_display = parent;
@@ -156,6 +173,7 @@ private:
   std::map<std::string, Glib::RefPtr<Gtk::FileFilter>> m_filters;
   Gtk::Button* m_ok_button;
   Glib::RefPtr<Gtk::Application> m_app;
+  Gtk::Image m_preview;
   Display* m_display;
   bool m_cancel;
   static std::string& lastUsedDir() { static std::string lastUsedDir; return lastUsedDir; }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list