分类: C/C++
2006-08-27 02:24:37
#include #include #include static gboolean handle_expose(GtkWidget *widget, GdkEventExpose *event, gpointer *data) { cairo_t *cr; PangoLayout *layout; PangoFontDescription *desc; gint width, height; static gint i = 0; cr = gdk_cairo_create(widget->window); layout = pango_cairo_create_layout (cr); pango_layout_set_text(layout, "浣犲ソ,Xlyrics!", -1); desc = pango_font_description_from_string("SimSun Bold 81"); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); cairo_save(cr); cairo_set_source_rgb(cr, 0, 0, 0); pango_cairo_update_layout(cr, layout); pango_cairo_show_layout(cr, layout); cairo_restore(cr); cairo_save(cr); cairo_set_source_rgb(cr, 0, 1, 0); pango_cairo_update_layout(cr, layout); pango_layout_get_size(layout, &width, &height); cairo_rectangle(cr, 0, 0, i, height/PANGO_SCALE); cairo_clip(cr); pango_cairo_show_layout(cr, layout); cairo_restore(cr); g_object_unref(layout); cairo_destroy(cr); if(i >= width/PANGO_SCALE) i = 0; else i += 10; return FALSE; } static gboolean handle_timeout(GtkWidget *widget) { handle_expose(widget, NULL, NULL); return TRUE; } int main(int argc, char **argv) { GtkWidget *window, *drawing_area; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); gtk_window_set_title(GTK_WINDOW(window), "Xlyrics with pango and cairo"); g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL); drawing_area = gtk_drawing_area_new(); gtk_container_add(GTK_CONTAINER(window), drawing_area); g_signal_connect(drawing_area, "expose-event", G_CALLBACK(handle_expose), NULL); gtk_widget_show_all(window); g_timeout_add(100, handle_timeout, drawing_area); gtk_main (); return 0; } |