[shotwell] Remove video sprockets
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell] Remove video sprockets
- Date: Mon, 16 Jul 2018 08:36:39 +0000 (UTC)
commit 69dca690b212654ea4513874c4f0eb23aa29b9a8
Author: Jens Georg <mail jensge org>
Date: Mon Jul 16 10:34:41 2018 +0200
Remove video sprockets
Replace with a trinket to show it's a video.
icons/sprocket.png | Bin 231 -> 0 bytes
org.gnome.Shotwell.gresource.xml | 1 -
src/MediaPage.vala | 81 ---------------------------------------
src/Resources.vala | 28 ++++++++++++++
src/Thumbnail.vala | 7 +++-
src/camera/ImportPage.vala | 10 ++---
6 files changed, 38 insertions(+), 89 deletions(-)
---
diff --git a/org.gnome.Shotwell.gresource.xml b/org.gnome.Shotwell.gresource.xml
index a27b52e1..237a5e3f 100644
--- a/org.gnome.Shotwell.gresource.xml
+++ b/org.gnome.Shotwell.gresource.xml
@@ -61,7 +61,6 @@
<file preprocess="xml-stripblanks">icons/shotwell.svg</file>
<file>icons/shotwell-street.jpg</file>
<file>icons/slideshow-extension-point.png</file>
- <file>icons/sprocket.png</file>
<file>icons/straighten-symbolic.svg</file>
<file>misc/org.gnome.Shotwell.css</file>
</gresource>
diff --git a/src/MediaPage.vala b/src/MediaPage.vala
index 7241c9ae..83169064 100644
--- a/src/MediaPage.vala
+++ b/src/MediaPage.vala
@@ -5,10 +5,6 @@
*/
public class MediaSourceItem : CheckerboardItem {
- private static Gdk.Pixbuf basis_sprocket_pixbuf = null;
- private static Gdk.Pixbuf current_sprocket_pixbuf = null;
-
- private bool enable_sprockets = false;
private string? natural_collation_key = null;
// preserve the same constructor arguments and semantics as CheckerboardItem so that we're
@@ -16,85 +12,8 @@ public class MediaSourceItem : CheckerboardItem {
public MediaSourceItem(ThumbnailSource source, Dimensions initial_pixbuf_dim, string title,
string? comment, bool marked_up = false, Pango.Alignment alignment = Pango.Alignment.LEFT) {
base(source, initial_pixbuf_dim, title, comment, marked_up, alignment);
- if (basis_sprocket_pixbuf == null)
- basis_sprocket_pixbuf = Resources.load_icon("sprocket.png", 0);
- }
-
- protected override void paint_image(Cairo.Context ctx, Gdk.Pixbuf pixbuf,
- Gdk.Point origin) {
- Dimensions pixbuf_dim = Dimensions.for_pixbuf(pixbuf);
- // sprocket geometry calculation (and possible adjustment) has to occur before we call
- // base.paint_image( ) because the base-class method needs the correct trinket horizontal
- // offset
-
- if (!enable_sprockets) {
- set_horizontal_trinket_offset(0);
- } else {
- double reduction_factor = ((double) pixbuf_dim.major_axis()) /
- ((double) ThumbnailCache.Size.LARGEST);
- int reduced_size = (int) (reduction_factor * basis_sprocket_pixbuf.width);
-
- if (current_sprocket_pixbuf == null || reduced_size != current_sprocket_pixbuf.width) {
- current_sprocket_pixbuf = basis_sprocket_pixbuf.scale_simple(reduced_size,
- reduced_size, Gdk.InterpType.HYPER);
- }
-
- set_horizontal_trinket_offset(current_sprocket_pixbuf.width);
- }
-
- base.paint_image(ctx, pixbuf, origin);
-
- if (enable_sprockets) {
- paint_sprockets(ctx, origin, pixbuf_dim);
- }
- }
-
- protected void paint_one_sprocket(Cairo.Context ctx, Gdk.Point origin) {
- ctx.save();
- Gdk.cairo_set_source_pixbuf(ctx, current_sprocket_pixbuf, origin.x, origin.y);
- ctx.paint();
- ctx.restore();
}
- protected void paint_sprockets(Cairo.Context ctx, Gdk.Point item_origin,
- Dimensions item_dimensions) {
- int num_sprockets = item_dimensions.height / current_sprocket_pixbuf.height;
-
- Gdk.Point left_paint_location = item_origin;
- Gdk.Point right_paint_location = item_origin;
- right_paint_location.x += (item_dimensions.width - current_sprocket_pixbuf.width);
- for (int i = 0; i < num_sprockets; i++) {
- paint_one_sprocket(ctx, left_paint_location);
- paint_one_sprocket(ctx, right_paint_location);
-
- left_paint_location.y += current_sprocket_pixbuf.height;
- right_paint_location.y += current_sprocket_pixbuf.height;
- }
-
- int straggler_pixels = item_dimensions.height % current_sprocket_pixbuf.height;
- if (straggler_pixels > 0) {
- ctx.save();
-
- Gdk.cairo_set_source_pixbuf(ctx, current_sprocket_pixbuf, left_paint_location.x,
- left_paint_location.y);
- ctx.rectangle(left_paint_location.x, left_paint_location.y,
- current_sprocket_pixbuf.get_width(), straggler_pixels);
- ctx.fill();
-
- Gdk.cairo_set_source_pixbuf(ctx, current_sprocket_pixbuf, right_paint_location.x,
- right_paint_location.y);
- ctx.rectangle(right_paint_location.x, right_paint_location.y,
- current_sprocket_pixbuf.get_width(), straggler_pixels);
- ctx.fill();
-
- ctx.restore();
- }
- }
-
- public void set_enable_sprockets(bool enable_sprockets) {
- this.enable_sprockets = enable_sprockets;
- }
-
public new void set_title(string text, bool marked_up = false,
Pango.Alignment alignment = Pango.Alignment.LEFT) {
base.set_title(text, marked_up, alignment);
diff --git a/src/Resources.vala b/src/Resources.vala
index 295288b9..ff364132 100644
--- a/src/Resources.vala
+++ b/src/Resources.vala
@@ -562,6 +562,34 @@ along with Shotwell; if not, write to the Free Software Foundation, Inc.,
return null;
}
+ public Gdk.Pixbuf? get_video_trinket(int scale) {
+ int cache_key = scale << 18;
+ var cached_pixbuf = get_cached_trinket(cache_key);
+
+ if (cached_pixbuf != null)
+ return cached_pixbuf;
+
+ try {
+ var theme = Gtk.IconTheme.get_default();
+ var info = theme.lookup_icon ("filter-videos-symbolic", (int)(scale * 2),
Gtk.IconLookupFlags.GENERIC_FALLBACK);
+ var icon = info.load_symbolic({0.8, 0.8, 0.8, 1.0}, null, null, null);
+ var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, icon.width, icon.height);
+ var ctx = new Cairo.Context(surface);
+ ctx.set_source_rgba(0.0, 0.0, 0.0, 0.35);
+ ctx.rectangle(0, 0, icon.width, icon.height);
+ ctx.fill();
+ Gdk.cairo_set_source_pixbuf(ctx, icon, 0, 0);
+ ctx.paint();
+
+ trinket_cache[cache_key] = Gdk.pixbuf_get_from_surface(surface, 0, 0, icon.width, icon.height);
+ return trinket_cache[cache_key];
+ } catch (Error err) {
+ critical ("%s", err.message);
+
+ return null;
+ }
+ }
+
public Gdk.Pixbuf? get_flagged_trinket(int scale) {
int cache_key = scale << 16;
var cached_pixbuf = get_cached_trinket(cache_key);
diff --git a/src/Thumbnail.vala b/src/Thumbnail.vala
index d5766813..f47fc698 100644
--- a/src/Thumbnail.vala
+++ b/src/Thumbnail.vala
@@ -57,8 +57,7 @@ public class Thumbnail : MediaSourceItem {
Tag.global.items_altered.connect(on_tags_altered);
assert((media is LibraryPhoto) || (media is Video));
- set_enable_sprockets(media is Video);
-
+
original_dim = media.get_dimensions();
dim = original_dim.get_scaled(scale, true);
@@ -396,4 +395,8 @@ public class Thumbnail : MediaSourceItem {
return (rating != Rating.UNRATED && show_ratings)
? Resources.get_rating_trinket(rating, scale) : null;
}
+
+ protected override Gdk.Pixbuf? get_top_left_trinket(int scale) {
+ return (media is Video) ? Resources.get_video_trinket (scale) : null;
+ }
}
diff --git a/src/camera/ImportPage.vala b/src/camera/ImportPage.vala
index cf6e1007..08395908 100644
--- a/src/camera/ImportPage.vala
+++ b/src/camera/ImportPage.vala
@@ -272,11 +272,7 @@ class ImportPreview : MediaSourceItem {
base(source, Dimensions(), source.get_name(), null);
this.duplicated_file = null;
-
- // draw sprocket holes as visual indications on video previews
- if (source is VideoImportSource)
- set_enable_sprockets(true);
-
+
// scale down pixbuf if necessary
Gdk.Pixbuf pixbuf = null;
try {
@@ -394,6 +390,10 @@ class ImportPreview : MediaSourceItem {
public ImportSource get_import_source() {
return (ImportSource) get_source();
}
+
+ protected override Gdk.Pixbuf? get_top_left_trinket(int scale) {
+ return (get_import_source() is VideoImportSource) ? Resources.get_video_trinket (scale) : null;
+ }
}
public class CameraViewTracker : Core.ViewTracker {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]