diff options
Diffstat (limited to 'abs/mv-core/ghosd/ghosd-0.0.1/examples/animation.c')
-rw-r--r-- | abs/mv-core/ghosd/ghosd-0.0.1/examples/animation.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/abs/mv-core/ghosd/ghosd-0.0.1/examples/animation.c b/abs/mv-core/ghosd/ghosd-0.0.1/examples/animation.c new file mode 100644 index 0000000..8c1a2c5 --- /dev/null +++ b/abs/mv-core/ghosd/ghosd-0.0.1/examples/animation.c @@ -0,0 +1,97 @@ +/* ghosd -- OSD with fake transparency, cairo, and pango. + * Copyright (C) 2006 Evan Martin <martine@danga.com> + */ + +#include <stdio.h> +#include <sys/time.h> +#include <sys/poll.h> +#include <time.h> + +#include <cairo/cairo.h> + +#include <ghosd/ghosd.h> + +typedef struct { + cairo_surface_t* foot; + float alpha; +} RenderData; + +static void +round_rect(cairo_t *cr, int x, int y, int w, int h, int r) { + cairo_move_to(cr, x+r, y); + cairo_line_to(cr, x+w-r, y); /* top edge */ + cairo_curve_to(cr, x+w, y, x+w, y, x+w, y+r); + cairo_line_to(cr, x+w, y+h-r); /* right edge */ + cairo_curve_to(cr, x+w, y+h, x+w, y+h, x+w-r, y+h); + cairo_line_to(cr, x+r, y+h); /* bottom edge */ + cairo_curve_to(cr, x, y+h, x, y+h, x, y+h-r); + cairo_line_to(cr, x, y+r); /* left edge */ + cairo_curve_to(cr, x, y, x, y, x+r, y); + cairo_close_path(cr); +} + +#define RADIUS 20 + +static void +render(Ghosd *ghosd, cairo_t *cr, void* data) { + RenderData *rdata = data; + + cairo_set_source_rgba(cr, rdata->alpha, 0, 0, 0.5); + cairo_new_path(cr); + round_rect(cr, 10, 10, 180, 230, RADIUS); + cairo_fill(cr); + + cairo_set_source_rgba(cr, 1, 1, 1, 1.0); + cairo_new_path(cr); + round_rect(cr, 20, 20, 160, 210, RADIUS); + cairo_stroke(cr); + + cairo_save(cr); + cairo_set_source_rgba(cr, 1, 1, 1, 1.0); + cairo_set_source_surface(cr, rdata->foot, 30, 30); + cairo_paint(cr); + cairo_restore(cr); +} + +int main(int argc, char* argv[]) { + Ghosd *ghosd; + RenderData data = {0}; + + const char *image = "/usr/share/pixmaps/gnome-background-image.png"; + data.foot = cairo_image_surface_create_from_png(image); + data.alpha = 0.5; + + ghosd = ghosd_new(); + ghosd_set_position(ghosd, 50, 50, 200, 240); + ghosd_set_render(ghosd, render, &data); + ghosd_render(ghosd); + ghosd_show(ghosd); + + ghosd_main_iterations(ghosd); + + const int STEP = 50; + float dalpha = 0.05; + + struct timeval tv_nextupdate; + + for (;;) { + gettimeofday(&tv_nextupdate, NULL); + tv_nextupdate.tv_usec += STEP*1000; + + ghosd_main_until(ghosd, &tv_nextupdate); + + data.alpha += dalpha; + if (data.alpha >= 1.0) { + data.alpha = 1.0; + dalpha = -dalpha; + } else if (data.alpha <= 0.0) { + data.alpha = 0.0; + dalpha = -dalpha; + } + ghosd_render(ghosd); + } + + return 0; +} + +/* vim: set ts=2 sw=2 et cino=(0 : */ |