~ubuntu-branches/ubuntu/trusty/imagination/trusty-updates

« back to all changes in this revision

Viewing changes to transitions/wave_down.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-12 07:19:02 UTC
  • Revision ID: james.westby@ubuntu.com-20090512071902-1qlldhv7rlfktvzl
Tags: upstream-1.0
Import upstream version 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2009 Tadej Borovšak   <tadeboro@gmail.com>
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License,or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU Library General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not,write to the Free Software
 
16
 *  Foundation,Inc.,59 Temple Place - Suite 330,Boston,MA 02111-1307,USA.
 
17
 *
 
18
 */
 
19
 
 
20
#include <gdk/gdk.h>
 
21
 
 
22
void img_transition_set_name(gchar **name)
 
23
{
 
24
        *name = "Wave Down";
 
25
}
 
26
 
 
27
void img_transition_render(GdkDrawable *window, GdkPixbuf *image_from, GdkPixbuf *image_to, gdouble progress, gint file_desc)
 
28
{
 
29
        cairo_t *cr;
 
30
        cairo_surface_t *surface;
 
31
        cairo_pattern_t *pattern;
 
32
        gint    width, height;
 
33
        gdouble wave_factor = 1.07;     // 50px
 
34
        gdouble stop;
 
35
 
 
36
        gdk_drawable_get_size(window, &width, &height);
 
37
 
 
38
        if(file_desc < 0)
 
39
        {
 
40
                cr = gdk_cairo_create(window);
 
41
        }
 
42
        else
 
43
        {
 
44
                surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
 
45
                cr = cairo_create(surface);
 
46
        }
 
47
 
 
48
        gdk_cairo_set_source_pixbuf(cr,image_from,0,0);
 
49
        cairo_paint(cr);
 
50
 
 
51
        gdk_cairo_set_source_pixbuf(cr,image_to,0,0);
 
52
        pattern = cairo_pattern_create_linear( width / 2, 0, width / 2, height );
 
53
        /* Add color stops */
 
54
        cairo_pattern_add_color_stop_rgba(pattern, (1 - wave_factor) / 2, 0, 0, 0, 1 ); // start
 
55
 
 
56
        stop = progress * wave_factor - ( wave_factor - 1 );
 
57
        cairo_pattern_add_color_stop_rgba(pattern, stop, 0, 0, 0, 1 );
 
58
 
 
59
        stop = progress * wave_factor;
 
60
        cairo_pattern_add_color_stop_rgba(pattern, stop, 0, 0, 0, 0 );
 
61
 
 
62
        cairo_pattern_add_color_stop_rgba(pattern, wave_factor, 0, 0, 0, 0 ); // stop
 
63
 
 
64
        cairo_mask(cr, pattern);
 
65
        cairo_destroy(cr);
 
66
        cairo_pattern_destroy(pattern);
 
67
        
 
68
        if(file_desc < 0)
 
69
                return;
 
70
 
 
71
        img_export_cairo_to_ppm(surface, file_desc);
 
72
        cairo_surface_destroy(surface);
 
73
}