summaryrefslogtreecommitdiff
path: root/plugins/shotwell-transitions/BlindsEffect.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
commit4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d (patch)
treed2e54377d14d604356c86862a326f64ae64dadd6 /plugins/shotwell-transitions/BlindsEffect.vala
Imported Upstream version 0.18.1upstream/0.18.1
Diffstat (limited to 'plugins/shotwell-transitions/BlindsEffect.vala')
-rw-r--r--plugins/shotwell-transitions/BlindsEffect.vala96
1 files changed, 96 insertions, 0 deletions
diff --git a/plugins/shotwell-transitions/BlindsEffect.vala b/plugins/shotwell-transitions/BlindsEffect.vala
new file mode 100644
index 0000000..6fdcf18
--- /dev/null
+++ b/plugins/shotwell-transitions/BlindsEffect.vala
@@ -0,0 +1,96 @@
+/* Copyright 2013 Jens Bav
+ * Copyright 2011-2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+using Spit;
+
+private class BlindsEffectDescriptor : ShotwellTransitionDescriptor {
+ public BlindsEffectDescriptor(GLib.File resource_directory) {
+ base(resource_directory);
+ }
+
+ public override unowned string get_id() {
+ return "org.yorba.shotwell.transitions.blinds";
+ }
+
+ public override unowned string get_pluggable_name() {
+ return _("Blinds");
+ }
+
+ public override Transitions.Effect create(HostInterface host) {
+ return new BlindsEffect();
+ }
+}
+
+private class BlindsEffect : Object, Transitions.Effect {
+ private const int DESIRED_FPS = 30;
+ private const int MIN_FPS = 15;
+
+ private const int BLIND_WIDTH = 50;
+ private int current_blind_width;
+
+ private Cairo.ImageSurface[] to_blinds;
+ private int blind_count;
+
+ public BlindsEffect() {
+ }
+
+ public void get_fps(out int desired_fps, out int min_fps) {
+ desired_fps = BlindsEffect.DESIRED_FPS;
+ min_fps = BlindsEffect.MIN_FPS;
+ }
+
+ public bool needs_clear_background() {
+ return true;
+ }
+
+ public void start(Transitions.Visuals visuals, Transitions.Motion motion) {
+ if (visuals.from_pixbuf != null) {
+ blind_count = visuals.to_pixbuf.width / BLIND_WIDTH;
+ current_blind_width =
+ (int) Math.ceil((double) visuals.to_pixbuf.width / (double) blind_count);
+
+ to_blinds = new Cairo.ImageSurface[blind_count];
+
+ for (int i = 0; i < blind_count; ++i) {
+ to_blinds[i] = new Cairo.ImageSurface(Cairo.Format.RGB24, current_blind_width,
+ visuals.to_pixbuf.height);
+ Cairo.Context ctx = new Cairo.Context(to_blinds[i]);
+ Gdk.cairo_set_source_pixbuf(ctx, visuals.to_pixbuf, -i * current_blind_width, 0);
+ ctx.paint();
+ }
+ }
+ }
+
+ public void paint(Transitions.Visuals visuals, Transitions.Motion motion, Cairo.Context ctx,
+ int width, int height, int frame_number) {
+ double alpha = motion.get_alpha(frame_number);
+ int y = visuals.to_pos.y;
+ int x = visuals.to_pos.x;
+
+ if (visuals.from_pixbuf != null){
+ Gdk.cairo_set_source_pixbuf(ctx, visuals.from_pixbuf, visuals.from_pos.x,
+ visuals.from_pos.y);
+ ctx.paint_with_alpha(1 - alpha * 2);
+ }
+
+ for (int i = 0; i < blind_count; ++i) {
+ ctx.set_source_surface(to_blinds[i], x + i * current_blind_width, y);
+ ctx.rectangle(x + i * current_blind_width, y, current_blind_width * (alpha + 0.5),
+ visuals.to_pixbuf.height);
+ ctx.fill();
+ }
+
+ ctx.clip();
+ ctx.paint();
+ }
+
+ public void advance(Transitions.Visuals visuals, Transitions.Motion motion, int frame_number) {
+ }
+
+ public void cancel() {
+ }
+}