[gnome-games] snapshot-row: Switch to SnapshotThumbnail
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] snapshot-row: Switch to SnapshotThumbnail
- Date: Wed, 24 Jun 2020 15:31:20 +0000 (UTC)
commit 57a02cc41deb6251383fec3284edc841d72b688f
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Jun 24 15:42:59 2020 +0500
snapshot-row: Switch to SnapshotThumbnail
data/ui/snapshot-row.ui | 9 +---
data/ui/snapshots-list.ui | 4 +-
src/ui/snapshot-row.vala | 103 +---------------------------------------------
3 files changed, 5 insertions(+), 111 deletions(-)
---
diff --git a/data/ui/snapshot-row.ui b/data/ui/snapshot-row.ui
index da81b1b8..500fed94 100644
--- a/data/ui/snapshot-row.ui
+++ b/data/ui/snapshot-row.ui
@@ -3,7 +3,6 @@
<requires lib="gtk+" version="3.24"/>
<template class="GamesSnapshotRow" parent="GtkListBoxRow">
<property name="visible">true</property>
- <signal name="notify::scale-factor" handler="on_scale_factor_changed"/>
<style>
<class name="snapshot-row"/>
</style>
@@ -16,16 +15,10 @@
<property name="visible">true</property>
<property name="margin">2</property>
<child>
- <object class="GtkDrawingArea" id="image">
+ <object class="GamesSnapshotThumbnail" id="thumbnail">
<property name="visible">true</property>
<property name="valign">start</property>
- <property name="width-request">66</property>
- <property name="height-request">66</property>
<property name="margin">6</property>
- <signal name="draw" handler="on_draw_image"/>
- <style>
- <class name="snapshot-thumbnail"/>
- </style>
</object>
</child>
<child>
diff --git a/data/ui/snapshots-list.ui b/data/ui/snapshots-list.ui
index c4d38dc1..80b2609a 100644
--- a/data/ui/snapshots-list.ui
+++ b/data/ui/snapshots-list.ui
@@ -46,8 +46,8 @@
<property name="visible">True</property>
<property name="icon-name">list-add-symbolic</property>
<property name="pixel-size">32</property>
- <property name="width-request">66</property>
- <property name="height-request">66</property>
+ <property name="width-request">64</property>
+ <property name="height-request">64</property>
<property name="margin">6</property>
<style>
<class name="snapshot-thumbnail"/>
diff --git a/src/ui/snapshot-row.vala b/src/ui/snapshot-row.vala
index c42ae99e..2bf065cf 100644
--- a/src/ui/snapshot-row.vala
+++ b/src/ui/snapshot-row.vala
@@ -2,10 +2,8 @@
[GtkTemplate (ui = "/org/gnome/Games/ui/snapshot-row.ui")]
private class Games.SnapshotRow : Gtk.ListBoxRow {
- public const int THUMBNAIL_SIZE = 64;
-
[GtkChild]
- private Gtk.DrawingArea image;
+ private SnapshotThumbnail thumbnail;
[GtkChild]
private Gtk.Label name_label;
[GtkChild]
@@ -28,63 +26,14 @@ private class Games.SnapshotRow : Gtk.ListBoxRow {
var date_format = get_date_format (creation_date);
date_label.label = creation_date.format (date_format);
- load_thumbnail ();
+ thumbnail.snapshot = snapshot;
}
}
- private Gdk.Pixbuf pixbuf;
-
public SnapshotRow (Snapshot snapshot) {
Object (snapshot: snapshot);
}
- private void load_thumbnail () {
- if (snapshot == null)
- return;
-
- var screenshot_path = snapshot.get_screenshot_path ();
- var screenshot_width = 0;
- var screenshot_height = 0;
-
- Gdk.Pixbuf.get_file_info (screenshot_path, out screenshot_width, out screenshot_height);
-
- var aspect_ratio = snapshot.screenshot_aspect_ratio;
-
- // A fallback for migrated snapshots
- if (aspect_ratio == 0)
- aspect_ratio = (double) screenshot_width / screenshot_height;
-
- var thumbnail_width = screenshot_width;
- var thumbnail_height = (int) (screenshot_width / aspect_ratio);
-
- if (thumbnail_width > thumbnail_height) {
- thumbnail_width = THUMBNAIL_SIZE;
- thumbnail_height = (int) (THUMBNAIL_SIZE / aspect_ratio);
- }
- else {
- thumbnail_height = THUMBNAIL_SIZE;
- thumbnail_width = (int) (THUMBNAIL_SIZE * aspect_ratio);
- }
-
- thumbnail_width *= scale_factor;
- thumbnail_height *= scale_factor;
-
- try {
- pixbuf = new Gdk.Pixbuf.from_file_at_scale (screenshot_path,
- thumbnail_width,
- thumbnail_height,
- false);
- }
- catch (Error e) {
- warning ("Failed to load snapshot thumbnail: %s", e.message);
- }
- }
-
- [GtkCallback]
- private void on_scale_factor_changed () {
- load_thumbnail ();
- }
-
public void set_name (string name) {
name_label.label = name;
snapshot.name = name;
@@ -109,54 +58,6 @@ private class Games.SnapshotRow : Gtk.ListBoxRow {
revealer.reveal_child = false;
}
- [GtkCallback]
- private bool on_draw_image (Cairo.Context cr) {
- var width = image.get_allocated_width ();
- var height = image.get_allocated_height ();
-
- var style = image.get_style_context ();
- style.render_background (cr, 0.0, 0.0, width, height);
- style.render_frame (cr, 0.0, 0.0, width, height);
-
- if (pixbuf == null)
- return Gdk.EVENT_PROPAGATE;
-
- var flags = image.get_state_flags ();
- var border_radius = (int) style.get_property (Gtk.STYLE_PROPERTY_BORDER_RADIUS, flags);
- border_radius = border_radius.clamp (0, int.max (width / 2, height / 2));
-
- rounded_rectangle (cr, 0.5, 0.5, width - 1, height - 1, border_radius);
- cr.clip ();
-
- cr.save ();
- cr.scale (1.0 / scale_factor, 1.0 / scale_factor);
-
- var x_offset = (width * scale_factor - pixbuf.width) / 2;
- var y_offset = (height * scale_factor - pixbuf.height) / 2;
-
- Gdk.cairo_set_source_pixbuf (cr, pixbuf, x_offset, y_offset);
- cr.paint ();
-
- cr.restore ();
-
- return Gdk.EVENT_PROPAGATE;
- }
-
- // TODO: Share this with GameThumbnail
- private void rounded_rectangle (Cairo.Context cr, double x, double y, double width, double height,
double radius) {
- const double ARC_0 = 0;
- const double ARC_1 = Math.PI * 0.5;
- const double ARC_2 = Math.PI;
- const double ARC_3 = Math.PI * 1.5;
-
- cr.new_sub_path ();
- cr.arc (x + width - radius, y + radius, radius, ARC_3, ARC_0);
- cr.arc (x + width - radius, y + height - radius, radius, ARC_0, ARC_1);
- cr.arc (x + radius, y + height - radius, radius, ARC_1, ARC_2);
- cr.arc (x + radius, y + radius, radius, ARC_2, ARC_3);
- cr.close_path ();
- }
-
// Adapted from nautilus-file.c, nautilus_file_get_date_as_string()
private string get_date_format (DateTime date) {
var date_midnight = new DateTime.local (date.get_year (),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]