~elementary-apps/pantheon-photos/master

« back to all changes in this revision

Viewing changes to plugins/pantheon-photos-transitions/CirclesEffect.vala

  • Committer: RabbitBot
  • Author(s): Corentin Noël
  • Date: 2016-01-14 14:48:54 UTC
  • mfrom: (2879.1.3)
  • Revision ID: git-v1:938bcfdd68fed20a4d47ccfceeaa15f75f7eff12
Ported to CMake. Removed very old retro-compatibility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2013 Jens Bav
 
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
using Spit;
 
9
 
 
10
private class CirclesEffectDescriptor : ShotwellTransitionDescriptor {
 
11
    public CirclesEffectDescriptor (GLib.File resource_directory) {
 
12
        base (resource_directory);
 
13
    }
 
14
 
 
15
    public override unowned string get_id () {
 
16
        return "org.pantheon.photos.transitions.circles";
 
17
    }
 
18
 
 
19
    public override unowned string get_pluggable_name () {
 
20
        return _ ("Circles");
 
21
    }
 
22
 
 
23
    public override Transitions.Effect create (HostInterface host) {
 
24
        return new CirclesEffect ();
 
25
    }
 
26
}
 
27
 
 
28
private class CirclesEffect : Object, Transitions.Effect {
 
29
    private const int DESIRED_FPS = 25;
 
30
    private const int MIN_FPS = 15;
 
31
    private const double SPEED = 2.5;
 
32
 
 
33
    public CirclesEffect () {
 
34
    }
 
35
 
 
36
    public void get_fps (out int desired_fps, out int min_fps) {
 
37
        desired_fps = CirclesEffect.DESIRED_FPS;
 
38
        min_fps = CirclesEffect.MIN_FPS;
 
39
    }
 
40
 
 
41
    public void start (Transitions.Visuals visuals, Transitions.Motion motion) {
 
42
    }
 
43
 
 
44
    public bool needs_clear_background () {
 
45
        return true;
 
46
    }
 
47
 
 
48
    public void paint (Transitions.Visuals visuals, Transitions.Motion motion, Cairo.Context ctx,
 
49
                       int width, int height, int frame_number) {
 
50
        double alpha = motion.get_alpha (frame_number);
 
51
        int distance = 60, radius;
 
52
        int circleCountX = width / (2 * distance);
 
53
        int circleCountY = height / distance;
 
54
        double maxRadius = SPEED * distance;
 
55
 
 
56
        if (visuals.from_pixbuf != null) {
 
57
            Gdk.cairo_set_source_pixbuf (ctx, visuals.from_pixbuf, visuals.from_pos.x,
 
58
                                         visuals.from_pos.y);
 
59
            ctx.paint_with_alpha (1 - alpha);
 
60
        }
 
61
 
 
62
        if (visuals.to_pixbuf != null) {
 
63
            Gdk.cairo_set_source_pixbuf (ctx, visuals.to_pixbuf, visuals.to_pos.x, visuals.to_pos.y);
 
64
 
 
65
            for (int y = 0; y <= circleCountY; y++) {
 
66
                for (int x = 0; x <= circleCountX; x++) {
 
67
                    radius = (int) (Math.fmax (0, Math.fmin (1, alpha - ((double) (x + y) / (double)
 
68
                                               ((circleCountY + circleCountX) * SPEED)))) * maxRadius);
 
69
                    ctx.arc (2 * distance * x, 2 * distance * y, radius, 0, 2 * Math.PI);
 
70
                    ctx.fill ();
 
71
                }
 
72
            }
 
73
 
 
74
            ctx.clip ();
 
75
            ctx.paint_with_alpha (alpha);
 
76
        }
 
77
 
 
78
 
 
79
    }
 
80
 
 
81
    public void advance (Transitions.Visuals visuals, Transitions.Motion motion, int frame_number) {
 
82
    }
 
83
 
 
84
    public void cancel () {
 
85
    }
 
86
}