[gnome-games/wip/exalm/ds: 2/13] retro-runner: Use savestate aspect ratio for pixbufs



commit 017e110663237bf5c550ac3c5740b032864eb8c5
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Aug 14 00:43:53 2019 +0500

    retro-runner: Use savestate aspect ratio for pixbufs
    
    Explicitly rewrite "x-dpi" and "y-dpi" options for pixbufs
    used in Retro.CoreView.set_pixbuf(). This will allow retro-gtk
    to display them with correct aspect ratio.
    
    If no aspect ratio is present, do nothing, falling back to the
    previous behavior.

 src/retro/retro-runner.vala | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index fd81b851..405815e8 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -2,6 +2,7 @@
 
 public class Games.RetroRunner : Object, Runner {
        private const int MAX_AUTOSAVES = 5;
+       private const float Y_DPI = 1000000.0f;
 
        public signal void game_init ();
        public signal void game_deinit ();
@@ -172,6 +173,21 @@ public class Games.RetroRunner : Object, Runner {
                view.set_pixbuf (current_state_pixbuf);
        }
 
+       private void set_pixbuf_aspect_ratio (Gdk.Pixbuf pixbuf, float aspect_ratio) {
+               if (aspect_ratio == 0)
+                       return;
+
+               var x_dpi = "%g".printf (aspect_ratio * Y_DPI);
+               var y_dpi = "%g".printf (Y_DPI);
+
+               // FIXME: We shouldn't be saving it in the first place, since it doesn't work
+               pixbuf.remove_option ("x-dpi");
+               pixbuf.remove_option ("y-dpi");
+
+               pixbuf.set_option ("x-dpi", x_dpi);
+               pixbuf.set_option ("y-dpi", y_dpi);
+       }
+
        public void preview_savestate (Savestate savestate) {
                previewed_savestate = savestate;
 
@@ -182,6 +198,10 @@ public class Games.RetroRunner : Object, Runner {
                // a critical operation
                try {
                        pixbuf = new Gdk.Pixbuf.from_file (screenshot_path);
+
+                       var aspect_ratio = savestate.get_screenshot_aspect_ratio ();
+
+                       set_pixbuf_aspect_ratio (pixbuf, (float) aspect_ratio);
                }
                catch (Error e) {
                        warning ("Couldn't load %s: %s", screenshot_path, e.message);


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