/**
 * cairo-test.c: Some simple cairo testing code
 * Copyright (c) 2007 Thomas Perl <thp@thpinfo.com>
 *
 * Compile with:
 * gcc -o cairo-test cairo-test.c `pkg-config --cflags --libs gtk+-2.0`
 **/

#include <gtk/gtk.h>

static gboolean
window_expose_event( GtkWidget* widget, GdkEventExpose* event) {
    cairo_t *cr;
    cairo_text_extents_t te;
    char* s = "silly_solid_20070809-1.wav";

    unsigned int height = widget->allocation.height,
                 width = widget->allocation.width;

    unsigned int tw, th;
    unsigned int b = 3;
    int i;

    cr = gdk_cairo_create( widget->window);

    for( i=0; i<10; i++) {
        cairo_move_to( cr, width*i/10, height-10);
        cairo_line_to( cr, width*(i+1)/10, 10);
        cairo_line_to( cr, width*(i+2)/10, height-10);
        cairo_set_source_rgb( cr, 0.2*i/10, 0.5*i/10, 0.0);
        cairo_stroke( cr);
    }

    cairo_select_font_face( cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);

    cairo_set_font_size( cr, 10);
    cairo_text_extents( cr, s, &te);
    tw = 2*b + te.width;
    th = 2*b + te.height;

    cairo_new_path( cr);
    cairo_rectangle( cr, width-tw-10, height-th-10, tw, th);
    cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
    cairo_fill( cr);
    cairo_set_source_rgb( cr, 1, 1, 1);
    cairo_move_to( cr, width-tw-10+b, height-th-10+b + th/2);
    cairo_show_text (cr, s);

    cairo_destroy (cr);
    return FALSE;
}

int
main (int argc, char *argv[])
{
    GtkWidget* w;
    GtkWidget* b;

    gtk_init( &argc, &argv);

    w = gtk_window_new( GTK_WINDOW_TOPLEVEL);
    b = gtk_button_new_with_label( "YOYO");
    gtk_container_add( GTK_CONTAINER(w), b);
    gtk_widget_show_all( w);
    g_signal_connect( w, "destroy", gtk_main_quit, NULL);
    g_signal_connect_after( b, "expose-event", GTK_SIGNAL_FUNC(window_expose_event), NULL);

    gtk_main();
    return 0;
}

