#include #include #include #include #include #include "mmi.h" #define DFBCHECK(x...) \ { \ DFBResult err = x; \ \ if (err != DFB_OK) \ { \ fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ DirectFBErrorFatal( #x, err ); \ } \ } static IDirectFB *dfb = NULL; static IDirectFBSurface *primary = NULL; static IDirectFBEventBuffer *events = NULL; static cairo_t *cr; static int screen_width = 0; static int screen_height = 0; static void cairo_draw_arc() { double xc = 128.0; double yc = 128.0; double radius = 100.0; double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */ double angle2 = 180.0 * (M_PI/180.0); /* in radians */ cairo_arc (cr, xc, yc, radius, angle1, angle2); cairo_stroke (cr); /* draw helping lines */ cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); cairo_set_line_width (cr, 6.0); cairo_arc (cr, xc, yc, 10.0, 0, 2*M_PI); cairo_fill (cr); cairo_arc (cr, xc, yc, radius, angle1, angle1); cairo_line_to (cr, xc, yc); cairo_arc (cr, xc, yc, radius, angle2, angle2); cairo_line_to (cr, xc, yc); cairo_stroke (cr); } static void cairo_draw_curve_to() { double x=25.6, y=128.0; double x1=102.4, y1=230.4, x2=153.6, y2=25.6, x3=230.4, y3=128.0; cairo_move_to (cr, x, y); cairo_curve_to (cr, x1, y1, x2, y2, x3, y3); cairo_set_line_width (cr, 10.0); cairo_stroke (cr); cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); cairo_set_line_width (cr, 6.0); cairo_move_to (cr,x,y); cairo_line_to (cr,x1,y1); cairo_move_to (cr,x2,y2); cairo_line_to (cr,x3,y3); cairo_stroke (cr); } static void cairo_draw_gradient() { cairo_pattern_t *pat; pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0); cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1); cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1); cairo_rectangle (cr, 0, 0, 256, 256); cairo_set_source (cr, pat); cairo_fill (cr); cairo_pattern_destroy (pat); pat = cairo_pattern_create_radial (115.2, 102.4, 25.6, 102.4, 102.4, 128.0); cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1); cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1); cairo_set_source (cr, pat); cairo_arc (cr, 128.0, 128.0, 76.8, 0, 2 * M_PI); cairo_fill (cr); cairo_pattern_destroy (pat); } static void cairo_draw_text_extents() { cairo_text_extents_t extents; const char *utf8 = "cairo"; double x,y; cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, 100.0); cairo_text_extents (cr, utf8, &extents); x=25.0; y=150.0; cairo_move_to (cr, x,y); cairo_show_text (cr, utf8); /* draw helping lines */ cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); cairo_set_line_width (cr, 6.0); cairo_arc (cr, x, y, 10.0, 0, 2*M_PI); cairo_fill (cr); cairo_move_to (cr, x,y); cairo_rel_line_to (cr, 0, -extents.height); cairo_rel_line_to (cr, extents.width, 0); cairo_rel_line_to (cr, extents.x_bearing, -extents.y_bearing); cairo_stroke (cr); } static int cairo_demo() { /* Cario Test */ cairo_surface_t *surface; surface = cairo_directfb_surface_create(dfb, primary); cr = cairo_create(surface); cairo_save(cr); //cairo_scale (cr, 256, 256); cairo_draw_arc(); //cairo_draw_curve_to(); //cairo_draw_gradient(); //cairo_draw_text_extents(); cairo_restore(cr); cairo_destroy (cr); cairo_surface_destroy (surface); } static int mmi_init(int *argc, char **argv[]) { DFBResult ret; DFBSurfaceDescription desc; /* Initialize DirectFB including command line parsing. */ ret = DirectFBInit( argc, argv ); if (ret) { DirectFBError( "DirectFBInit() failed", ret ); return 1; } DirectFBSetOption ("bg-none", NULL); /* Create the super interface. */ ret = DirectFBCreate(&dfb); if (ret) { DirectFBError("DirectFBCreate() failed", ret); return 2; } /* Request fullscreen mode. */ dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN); /* Fill the surface description. */ desc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT | DSDESC_PALETTE; desc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; //desc.flags = DSDESC_CAPS; //desc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; desc.pixelformat = DSPF_RGB32; //desc.pixelformat = DSPF_ARGB1555; /* Create an 8 bit palette surface. */ ret = dfb->CreateSurface( dfb, &desc, &primary ); if (ret) { DirectFBError( "IDirectFB::CreateSurface() failed", ret ); return 3; } /* Create an event buffer with key capable devices attached. */ ret = dfb->CreateInputEventBuffer(dfb, DICAPS_KEYS, DFB_FALSE, &events); if (ret) { DirectFBError("IDirectFB::CreateEventBuffer() failed", ret); return 4; } return 0; } static void mmi_exit() { /* Release the primary surface. */ if (primary) primary->Release(primary); /* Release the event buffer. */ if (events) events->Release(events); /* Release the super interface. */ if (dfb) dfb->Release(dfb); } int mmi_main(int argc, char *argv[]) { int quit; int ret; /* Initialize mmi */ ret = mmi_init(&argc, &argv); if (ret) { return ret; } DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height)); DFBCHECK (primary->SetColor (primary, 0xff, 0xff, 0xff, 0xff)); DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height)); DFBCHECK (primary->SetColor (primary, 0x80, 0x80, 0xff, 0xff)); DFBCHECK (primary->DrawLine (primary, 0, screen_height / 2, screen_width - 1, screen_height / 2)); /* cairo demo */ cairo_demo(); DFBCHECK (primary->Flip (primary, NULL, 0)); quit = 0; /* Main message Loop */ while (!quit) { DFBInputEvent event; events->WaitForEvent(events); while (events->GetEvent(events, DFB_EVENT(&event)) == DFB_OK) { /* Handle key press events. */ if (event.type == DIET_KEYPRESS) { switch (event.key_symbol) { case DIKS_ESCAPE: case DIKS_POWER: case DIKS_BACK: case DIKS_SMALL_Q: case DIKS_CAPITAL_Q: quit = 1; break; default: continue; } } } events->WaitForEvent(events); } mmi_exit(); /* nothing to do */ return 0; }