SlideEffect.vala 2.43 KB
Newer Older
1
/* Copyright 2010 Maxim Kartashev
2
 * Copyright 2011-2013 Yorba Foundation
3 4
 *
 * This software is licensed under the GNU Lesser General Public License
5
 * (version 2.1 or later).  See the COPYING file in this distribution.
6 7 8 9 10
 */

using Spit;

private class SlideEffectDescriptor : ShotwellTransitionDescriptor {
11 12 13 14
    public SlideEffectDescriptor(GLib.File resource_directory) {
        base(resource_directory);
    }

15
    public override unowned string get_id() {
16 17 18
        return "org.yorba.shotwell.transitions.slide";
    }
    
19
    public override unowned string get_pluggable_name() {
20
        return _("Slide");
21 22
    }
    
23
    public override Transitions.Effect create(Spit.HostInterface host) {
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        return new SlideEffect();
    }
}

private class SlideEffect : Object, Transitions.Effect {
    private const int DESIRED_FPS = 25;
    private const int MIN_FPS = 15;
    
    public SlideEffect() {
    }
    
    public void get_fps(out int desired_fps, out int min_fps) {
        desired_fps = SlideEffect.DESIRED_FPS;
        min_fps = SlideEffect.MIN_FPS;
    }
    
    public void start(Transitions.Visuals visuals, Transitions.Motion motion) {
    }
    
    public bool needs_clear_background() {
        return true;
    }
    
    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);
        
        if (visuals.from_pixbuf != null) {
            int from_target_x = (motion.direction == Transitions.Direction.FORWARD) 
                ? -visuals.from_pixbuf.width : width;
            int from_current_x = (int) (visuals.from_pos.x * (1 - alpha) + from_target_x * alpha);
            Gdk.cairo_set_source_pixbuf(ctx, visuals.from_pixbuf, from_current_x, visuals.from_pos.y);
            ctx.paint();
        }

        if (visuals.to_pixbuf != null) {
            int to_target_x = (width - visuals.to_pixbuf.width) / 2;
            int from_x = (motion.direction == Transitions.Direction.FORWARD) 
                ? width : -visuals.to_pixbuf.width;
            int to_current_x = (int) (from_x * (1 - alpha) + to_target_x * alpha);
            Gdk.cairo_set_source_pixbuf(ctx, visuals.to_pixbuf, to_current_x, visuals.to_pos.y);
            ctx.paint();
        }
    }
    
    public void advance(Transitions.Visuals visuals, Transitions.Motion motion, int frame_number) {
    }
    
    public void cancel() {
    }
}