#include #ifdef ENABLE_CAIRO #include "ftk_cairo.h" static cairo_t* cr = NULL; static void paint_clip_image(int x, int y, int width, int height) { int w, h; cairo_surface_t *image; char filename[FTK_MAX_PATH+1] = {0}; cairo_translate (cr, x, y); cairo_arc (cr, width/2, height/4, width/3, 0, 2*M_PI); cairo_clip (cr); cairo_new_path (cr); /* path not consumed by clip()*/ ftk_snprintf(filename, FTK_MAX_PATH, "%s/png1.png", ftk_config_get_test_data_dir(ftk_default_config())); image = cairo_image_surface_create_from_png (filename); w = cairo_image_surface_get_width (image); h = cairo_image_surface_get_height (image); // cairo_scale (cr, 256.0/w, 256.0/h); cairo_set_source_surface (cr, image, 0, 0); cairo_paint (cr); cairo_surface_destroy (image); return; } static void paint_rect(int x, int y, int width, int height) { /* a custom shape that could be wrapped in a function */ double x0 = 25.6, /* parameters like cairo_rectangle */ y0 = 25.6, rect_width = 204.8, rect_height = 204.8, radius = 102.4; /* and an approximate curvature radius */ double x1,y1; cairo_translate (cr, x, y); x1=x0+rect_width; y1=y0+rect_height; if (!rect_width || !rect_height) return; if (rect_width/2 0 ? g_index - 1 : 0; ftk_widget_invalidate(ftk_widget_lookup(ctx, 100)); return RET_OK; } static Ret button_next_clicked(void* ctx, void* obj) { g_index++; g_index = g_index % (sizeof(paints)/sizeof(paints[0])); ftk_widget_invalidate(ftk_widget_lookup(ctx, 100)); return RET_OK; } static Ret button_quit_clicked(void* ctx, void* obj) { ftk_widget_unref(ctx); return RET_OK; } #ifdef FTK_AS_PLUGIN #include "ftk_app_demo.h" FTK_HIDE int FTK_MAIN(int argc, char* argv[]); FtkApp* ftk_app_demo_cairo_create() { return ftk_app_demo_create(_("cairo"), ftk_main); } #else #define FTK_HIDE extern #endif /*FTK_AS_PLUGIN*/ FTK_HIDE int FTK_MAIN(int argc, char* argv[]) { int width = 0; int height = 0; FtkWidget* win = NULL; FtkWidget* button = NULL; FtkWidget* painter = NULL; FTK_INIT(argc, argv); win = ftk_app_window_create(); width = ftk_widget_width(win); height = ftk_widget_height(win); button = ftk_button_create(win, 0, 10, width/3, 60); ftk_widget_set_text(button, "prev"); ftk_button_set_clicked_listener(button, button_prev_clicked, win); button = ftk_button_create(win, width/3, 10, width/3, 60); ftk_widget_set_text(button, "next"); ftk_button_set_clicked_listener(button, button_next_clicked, win); button = ftk_button_create(win, width*2/3, 10, width/3, 60); ftk_widget_set_text(button, "quit"); ftk_button_set_clicked_listener(button, button_quit_clicked, win); painter = ftk_painter_create(win, 0, 70, width, height); ftk_widget_set_id(painter, 100); ftk_painter_set_paint_listener(painter, on_paint, NULL); ftk_widget_set_text(win, "cairo demo"); ftk_widget_show_all(win, 1); FTK_QUIT_WHEN_WIDGET_CLOSE(win); FTK_RUN(); return 0; } #endif