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



commit 6b2a666383ef96145c64779f95b3c78ed4f81e26
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 "aspect-ratio" option 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 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 49535ec7..d4787a7f 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -172,6 +172,18 @@ 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 aspect_ratio_str = "%g".printf (aspect_ratio);
+
+               // set_option() fails if the option is already present
+               pixbuf.remove_option ("aspect-ratio");
+
+               pixbuf.set_option ("aspect-ratio", aspect_ratio_str);
+       }
+
        public void preview_savestate (Savestate savestate) {
                previewed_savestate = savestate;
 
@@ -182,6 +194,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]