File: misc_shape_wipe.c

package info (click to toggle)
imagination 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,460 kB
  • sloc: ansic: 12,955; sh: 4,166; makefile: 376; xml: 61
file content (181 lines) | stat: -rw-r--r-- 4,510 bytes parent folder | download | duplicates (8)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
** Copyright (C) 2009 Tadej Borovšak <tadeboro@gmail.com>
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <cairo.h>
#include <glib.h>

/* Local functions declarations go here */
static void
transition_render( cairo_t         *cr,
				   cairo_surface_t *image_from,
				   cairo_surface_t *image_to,
				   gdouble          progress,
                   gint				type,
				   gboolean			direction );


/* Plug-in API */
void
img_get_plugin_info( gchar  **group,
                     gchar ***trans )
{
    gint i = 0;
    *group = "Misc Shape Wipe";

    *trans = g_new( gchar *, 13 );

    (*trans)[i++] = "Heart In";
    (*trans)[i++] = "img_heart_in";
    (*trans)[i++] = GINT_TO_POINTER( 56 );

    (*trans)[i++] = "Heart Out";
    (*trans)[i++] = "img_heart_out";
    (*trans)[i++] = GINT_TO_POINTER( 57 );

    (*trans)[i++] = "Keyhole In";
    (*trans)[i++] = "img_key_in";
    (*trans)[i++] = GINT_TO_POINTER( 58 );

    (*trans)[i++] = "Keyhole Out";
    (*trans)[i++] = "img_key_out";
    (*trans)[i++] = GINT_TO_POINTER( 59 );

    (*trans)[i++] = NULL;
}

void
img_heart_in( cairo_t         *cr,
			  cairo_surface_t *image_from,
			  cairo_surface_t *image_to,
			  gdouble          progress )
{
    transition_render( cr, image_from, image_to, progress, 1, TRUE );
}

void
img_heart_out( cairo_t         *cr,
			   cairo_surface_t *image_from,
			   cairo_surface_t *image_to,
			   gdouble          progress )
{
    transition_render( cr, image_from, image_to, progress, 1, FALSE );
}

void
img_key_in( cairo_t         *cr,
			cairo_surface_t *image_from,
			cairo_surface_t *image_to,
			gdouble          progress )
{
    transition_render( cr, image_from, image_to, progress, 2, TRUE );
}

void
img_key_out( cairo_t         *cr,
			 cairo_surface_t *image_from,
			 cairo_surface_t *image_to,
			 gdouble          progress )
{
    transition_render( cr, image_from, image_to, progress, 2, FALSE );
}

/* Local functions definitions */
static void
transition_render(	cairo_t         *cr,
					cairo_surface_t *image_from,
					cairo_surface_t *image_to,
					gdouble          progress,
					gint         type,
					gboolean     direction )
{
	gint width, height, w2, h2, offset;
	cairo_surface_t *layer1, *layer2;

	width  = cairo_image_surface_get_width( image_from );
	height = cairo_image_surface_get_height( image_from );

    /* Drawing code goes here */
	if( direction )
	{
		layer2 = image_from;
		layer1 = image_to;
		progress = 1 - progress;
	}
	else
	{
		layer2 = image_to;
		layer1 = image_from;
	}
	w2 = width / 2;
	h2 = height / 2;

	cairo_set_source_surface( cr, layer1, 0, 0 );
	cairo_paint( cr );

	if( type == 1 )
		offset = 100;
	else
		offset = 40;

	cairo_set_source_surface( cr, layer2, 0, 0 );
	cairo_translate( cr, w2, h2 - ( 1 - progress ) * offset );
	cairo_scale( cr, progress, progress );
	switch( type )
	{
		case 1: /* Heart */
			cairo_move_to( cr, 0, - h2 );

			/* Left hand side */
			cairo_curve_to( cr, - 275, - 355 - h2,
								- 930, - 5 - h2,
								- 450, 495 - h2 );
			cairo_curve_to( cr, - 155, 840 - h2,
								-65, 940 - h2,
								0, 1020 - h2 );
			
			/* Right hand side */
			cairo_curve_to( cr, 65, 940 - h2,
								155, 840 - h2,
								450, 495 - h2 );
			cairo_curve_to( cr, 930, -5 - h2,
								275, - 355 - h2,
								0, - h2 );
			break;

		case 2: /* Keyhole */
			cairo_move_to( cr, 0, - 725 );

			cairo_curve_to( cr, - 275, -725,
								- 500, -500,
								- 500, -230 );
			cairo_curve_to( cr, - 500, -100,
								- 450, 25,
								- 360, 110 );
			cairo_line_to( cr, - 480, 725 );
			cairo_line_to( cr, 480, 725 );
			cairo_line_to( cr, 360, 110 );
			cairo_curve_to( cr, 450, 25,
								500, - 100,
								500, - 230 );
			cairo_curve_to( cr, 500, - 500,
								275, - 725,
								0, - 725 );
			break;
	}
	cairo_fill( cr );
}