summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-10-08 13:51:32 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-10-08 14:43:14 +0100
commitf4004dbc963283f9bbbfd921642f820161a5aa5b (patch)
tree822e0947e55185405e39257b9472d52157ab0962
parent6528615d203eebd436769573cf347d0cc952efb0 (diff)
slideshow: Add a sliding transition effect
-rw-r--r--slideshow-demo.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/slideshow-demo.c b/slideshow-demo.c
index d006759..cbe9aec 100644
--- a/slideshow-demo.c
+++ b/slideshow-demo.c
@@ -209,6 +209,8 @@ int main(int argc, char **argv)
struct timeval start, last_tty, last_fps, now;
int frames, n;
int show_fps = 1;
+ int transition = 1;
+ double divide = 1.;
device = device_open(argc, argv);
@@ -223,6 +225,8 @@ int main(int argc, char **argv)
preload = 0;
} else if (strcmp (argv[n], "--hide-fps") == 0) {
show_fps = 0;
+ } else if (strcmp (argv[n], "--no-transition") == 0) {
+ transition = 0;
}
}
@@ -246,16 +250,16 @@ int main(int argc, char **argv)
n = frames = 0;
do {
struct framebuffer *fb = device->get_framebuffer (device);
- struct source *source = &sources[n++ % num_sources];
+ struct source *left = &sources[n % num_sources];
cairo_t *cr;
double delta;
cr = cairo_create (fb->surface);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_scale(cr,
- device->width/(double)source->width,
- device->height/(double)source->height);
- cairo_set_source_surface(cr, source->surface, 0, 0);
+ device->width/(double)left->width,
+ device->height/(double)left->height);
+ cairo_set_source_surface(cr, left->surface, 0, 0);
cairo_pattern_set_extend(cairo_get_source(cr),
CAIRO_EXTEND_NONE);
cairo_pattern_set_filter(cairo_get_source(cr),
@@ -263,6 +267,37 @@ int main(int argc, char **argv)
cairo_identity_matrix(cr);
cairo_paint(cr);
+ if (transition) {
+ struct source *right = &sources[(n + 1) % num_sources];
+ cairo_pattern_t *mask;
+
+ mask = cairo_pattern_create_linear(0, 0, device->width, device->height);
+ cairo_pattern_add_color_stop_rgba(mask, divide-.2, 0, 0, 0, 0);
+ cairo_pattern_add_color_stop_rgba(mask, divide, 0, 0, 0, 1);
+
+ cairo_set_operator(cr, CAIRO_OPERATOR_DEST_OUT);
+ cairo_set_source(cr, mask);
+ cairo_paint(cr);
+
+ cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
+ cairo_scale(cr,
+ device->width/(double)right->width,
+ device->height/(double)right->height);
+ cairo_set_source_surface(cr, right->surface, 0, 0);
+ cairo_pattern_set_extend(cairo_get_source(cr),
+ CAIRO_EXTEND_NONE);
+ cairo_pattern_set_filter(cairo_get_source(cr),
+ CAIRO_FILTER_BILINEAR);
+ cairo_identity_matrix(cr);
+ cairo_mask(cr, mask);
+ cairo_pattern_destroy(mask);
+
+ divide -= 0.05;
+ if (divide < 0)
+ divide = 1., n++;
+ } else
+ n++;
+
gettimeofday(&now, NULL);
if (show_fps) {
if (last_fps.tv_sec)