summaryrefslogtreecommitdiff
path: root/plugins/shotwell-transitions/SquaresEffect.vala
blob: b397419da4072a161b2736201d199505b9b54313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
76
77
78
79
80
81
82
83
84
85
86
/* Copyright 2013 Jens Bav
 * Copyright 2016 Software Freedom Conservancy Inc.
 *
 * 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 SquaresEffectDescriptor : ShotwellTransitionDescriptor {
    public SquaresEffectDescriptor(GLib.File resource_directory) {
        base(resource_directory);
    }

    public override unowned string get_id() {
        return "org.yorba.shotwell.transitions.squares";
    }

    public override unowned string get_pluggable_name() {
        return _("Squares");
    }

    public override Transitions.Effect create(HostInterface host) {
        return new SquaresEffect();
    }
}

private class SquaresEffect : Object, Transitions.Effect {
    private const int DESIRED_FPS = 25;
    private const int MIN_FPS = 10;
    private const int SQUARE_SIZE = 100;
    private double square_count_x;
    private double square_count_y;

    public SquaresEffect() {
    }

    public void get_fps(out int desired_fps, out int min_fps) {
        desired_fps = SquaresEffect.DESIRED_FPS;
        min_fps = SquaresEffect.MIN_FPS;
    }

    public void start(Transitions.Visuals visuals, Transitions.Motion motion) {
      square_count_x = visuals.to_pos.width/SQUARE_SIZE + 1;
      square_count_y = visuals.to_pos.height/SQUARE_SIZE + 1;
    }

    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) {
            Gdk.cairo_set_source_pixbuf(ctx, visuals.from_pixbuf, visuals.from_pos.x,
                visuals.from_pos.y);
            ctx.paint_with_alpha(1 - alpha);
        }
        
        if (visuals.to_pixbuf != null) {
            Gdk.cairo_set_source_pixbuf(ctx, visuals.to_pixbuf,visuals.to_pos.x, visuals.to_pos.y);
            for (double y = 0; y<=square_count_y; y++) {
                for (double x = 0; x <=square_count_x; x++) {
                    double size = SQUARE_SIZE * (Math.fmin(1, alpha + ((square_count_x - x)
                        / square_count_x + (square_count_y - y)/square_count_y)/2.5));

                    ctx.rectangle(visuals.to_pos.x + x * SQUARE_SIZE, visuals.to_pos.y + y
                        * SQUARE_SIZE, size, size);

                    ctx.fill();
                }
            }
            
            ctx.clip();
            ctx.paint_with_alpha(alpha);
        }
    }

    public void advance(Transitions.Visuals visuals, Transitions.Motion motion, int frame_number) {
    }

    public void cancel() {
    }
}