1/* 2* Copyright (c) 2011-2013 Yorba Foundation 3* 2010 Maxim Kartashev 4* 5* This program is free software; you can redistribute it and/or 6* modify it under the terms of the GNU Lesser General Public 7* License as published by the Free Software Foundation; either 8* version 2.1 of the License, or (at your option) any later version. 9* 10* This program is distributed in the hope that it will be useful, 11* but WITHOUT ANY WARRANTY; without even the implied warranty of 12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13* General Public License for more details. 14* 15* You should have received a copy of the GNU General Public 16* License along with this program; if not, write to the 17* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18* Boston, MA 02110-1301 USA 19*/ 20 21using Spit; 22 23private class SlideEffectDescriptor : ShotwellTransitionDescriptor { 24 public SlideEffectDescriptor (GLib.File resource_directory) { 25 base (resource_directory); 26 } 27 28 public override unowned string get_id () { 29 return "io.elementary.photos.transitions.slide"; 30 } 31 32 public override unowned string get_pluggable_name () { 33 return _ ("Slide"); 34 } 35 36 public override Transitions.Effect create (Spit.HostInterface host) { 37 return new SlideEffect (); 38 } 39} 40 41private class SlideEffect : Object, Transitions.Effect { 42 private const int DESIRED_FPS = 25; 43 private const int MIN_FPS = 15; 44 45 public SlideEffect () { 46 } 47 48 public void get_fps (out int desired_fps, out int min_fps) { 49 desired_fps = SlideEffect.DESIRED_FPS; 50 min_fps = SlideEffect.MIN_FPS; 51 } 52 53 public void start (Transitions.Visuals visuals, Transitions.Motion motion) { 54 } 55 56 public bool needs_clear_background () { 57 return true; 58 } 59 60 public void paint (Transitions.Visuals visuals, Transitions.Motion motion, Cairo.Context ctx, 61 int width, int height, int frame_number) { 62 double alpha = motion.get_alpha (frame_number); 63 64 if (visuals.from_pixbuf != null) { 65 int from_target_x = (motion.direction == Transitions.Direction.FORWARD) 66 ? -visuals.from_pixbuf.width : width; 67 int from_current_x = (int) (visuals.from_pos.x * (1 - alpha) + from_target_x * alpha); 68 Gdk.cairo_set_source_pixbuf (ctx, visuals.from_pixbuf, from_current_x, visuals.from_pos.y); 69 ctx.paint (); 70 } 71 72 if (visuals.to_pixbuf != null) { 73 int to_target_x = (width - visuals.to_pixbuf.width) / 2; 74 int from_x = (motion.direction == Transitions.Direction.FORWARD) 75 ? width : -visuals.to_pixbuf.width; 76 int to_current_x = (int) (from_x * (1 - alpha) + to_target_x * alpha); 77 Gdk.cairo_set_source_pixbuf (ctx, visuals.to_pixbuf, to_current_x, visuals.to_pos.y); 78 ctx.paint (); 79 } 80 } 81 82 public void advance (Transitions.Visuals visuals, Transitions.Motion motion, int frame_number) { 83 } 84 85 public void cancel () { 86 } 87} 88