static int
DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
{
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
    IDirectFBSurface *destsurf = data->target;
    DFBRegion clip_region;
    int i;

    DirectFB_ActivateRenderer(renderer);

    PrepareDraw(renderer);

    destsurf->GetClip(destsurf, &clip_region);
    for (i=0; i<count; i++) {
        SDL_Rect dst = {rects[i]->x, rects[i]->y, rects[i]->w, rects[i]->h};
        dst.x += clip_region.x1;
        dst.y += clip_region.y1;
        SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, dst.x, dst.y,
                dst.w, dst.h));
    }

    return 0;
  error:
    return -1;
}
Esempio n. 2
0
static int l_DrawRectangle (lua_State* L)
{
	// [ sfc | x | y | w | h ]
	IDirectFBSurface* sfc = * (IDirectFBSurface**) luaL_checkudata(L, 1, "ldirectfb.IDirectFBSurface");
	DFBCHECK (sfc->DrawRectangle(sfc, luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5)));
	return 0;
}
Esempio n. 3
0
static int
DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
{
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
	IDirectFBSurface *destsurf = get_dfb_surface(data->window);
    int i;

    DirectFB_ActivateRenderer(renderer);

    PrepareDraw(renderer);

    for (i=0; i<count; i++)
    	SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y,
    			rects[i]->w, rects[i]->h));

    return 0;
  error:
    return -1;
}
Esempio n. 4
0
static DFBResult
Test_CreateSubWindow( IDirectFBDisplayLayer *layer, void *arg )
{
    IDirectFBWindow      *window;
    DFBWindowID           window_id;
    DFBDimension          size = { m_desc_sub.width, m_desc_sub.height };

    D_ASSERT( m_toplevel_id != 0 );

    /* Write window ID of top level into description */
    m_desc_sub.toplevel_id = m_toplevel_id;

    /*
     * Create a new sub window with 75% width/height and positioned at 20,20 within top level window
     */
    SHOW_TEST( "CreateWindow( %d,%d - %dx%d %s + toplevel ID %u, options 0x%08x )...",
               m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height,
               dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, m_desc_top.options );

    _T( layer->CreateWindow( layer, &m_desc_sub, &window ) );

    if (m_subcolor.valid) {
        DFBColor c = m_subcolor.color;

        SHOW_INFO( "  - SetColor( 0x%02x, 0x%02x, 0x%02x, 0x%02x )...", c.r, c.g, c.b, c.a );

        _T( window->SetColor( window, c.r, c.g, c.b, c.a ) );
    }

    /*
     * Query its surface and clear it with light gray (if not input or color only)
     */
    if (!(m_desc_sub.caps & (DWCAPS_INPUTONLY | DWCAPS_COLOR) )) {
        IDirectFBSurface     *surface;

        SHOW_INFO( "  - GetSurface()..." );

        _T( window->GetSurface( window, &surface ) );

        SHOW_INFO( "  - Clear( 0xC0, 0xC0, 0xC0, 0xFF )..." );

        _T( surface->Clear( surface, 0xC0, 0xC0, 0xC0, 0xFF ) );

        _T( surface->DrawRectangle( surface, 0, 0, size.w, size.h ) );

        _T( surface->FillRectangle( surface, size.w / 2,          1,          1, size.h - 2 ) );
        _T( surface->FillRectangle( surface,          1, size.h / 2, size.w - 2,          1 ) );

        surface->Release( surface );
    }

    /*
     * Show the window
     */
    SHOW_INFO( "  - SetOpacity( 255 )..." );

    _T( window->SetOpacity( window, 0xff ) );

    /*
     * Query and print ID of new window
     */
    SHOW_INFO( "  - GetID()..." );

    _T( window->GetID( window, &window_id ) );

    /*
     * Set association of new window
     */
    if (m_desc_sub.parent_id) {
        SHOW_INFO( "  - SetAssociation( %u )...", m_desc_sub.parent_id );

        _T( window->SetAssociation( window, m_desc_sub.parent_id ) );
    }

    /*
     * Set top level window ID (user hasn't specified one)
     */
    m_subwindow_id = window_id;
    m_subwindow    = window;

    SHOW_RESULT( "...CreateWindow( %d,%d - %dx%d %s + toplevel ID %u ) done. => Sub Window ID %u",
                 m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height,
                 dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, window_id );

    return DFB_OK;
}
int
main( int argc, char *argv[] )
{
     DFBResult              ret;
     bool                   quit = false;
     int                    i;
     IDirectFB              dfb;
     IDirectFBDisplayLayer  layer;
     IDirectFBSurface       surface;
     DFBDisplayLayerConfig  config;
     DFBDimension           sizes[2]  = { {400, 400}, {600, 600} };
     size_t                 num_sizes = D_ARRAY_SIZE(sizes);
     DFBInputEvent          evt;
     IDirectFBEventBuffer   keybuffer;

     /* Initialize DirectFB. */
     DirectFB::Init( &argc, &argv );

     /* Create super interface. */
     dfb = DirectFB::Create();

     layer = dfb.GetDisplayLayer( DLID_PRIMARY );

     /* Create an input buffer for key events */
     keybuffer = dfb.CreateInputEventBuffer( DICAPS_KEYS, DFB_TRUE );

     layer.SetCooperativeLevel( DLSCL_EXCLUSIVE );

     layer.GetConfiguration( &config );

     config.width  = sizes[0].w;
     config.height = sizes[0].h;

     layer.SetConfiguration( config );

     surface = layer.GetSurface();

     while (true) {
          surface.Clear( 0, 0, 0, 0xff );

          surface.SetColor( 0x00, 0xff, 0x00, 0xff );
          surface.DrawRectangle( 0, 0, config.width, config.height );

          surface.Flip( NULL, DSFLIP_NONE );


          keybuffer.WaitForEventWithTimeout( 3, 0 );

          /* Process keybuffer */
          while (keybuffer.GetEvent( DFB_EVENT(&evt) )) {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = 1;
                          break;

                      case DIKS_SPACE:
                      case DIKS_OK:
                          i++;

                          config.width  = sizes[i % num_sizes].w;
                          config.height = sizes[i % num_sizes].h;

                          layer.SetConfiguration( config );
                          break;

                      default:
                          break;
                  }
              }
          }
     }

     return 0;
}
Esempio n. 6
0
int
main( int argc, char *argv[] )
{
     DFBResult              ret;
     int                    i;
     int                    x, y;
     int                    dx, dy;
     int                    sw3, sh3;
     int                    opacity       = 255;
     int                    opacity_delta = -1;
     IDirectFB             *dfb;
     IDirectFBDisplayLayer *layer;
     IDirectFBSurface      *surface;
     DFBDisplayLayerConfig  config;
     DFBDimension           size;
     DFBInputEvent          evt;

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/Layer: DirectFBInit() failed!\n" );
          return ret;
     }


     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/Layer: DirectFBCreate() failed!\n" );
          return ret;
     }

     dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );

     /* Create an input buffer for key events */
     dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS,
                                  DFB_TRUE, &keybuffer);

     layer->SetCooperativeLevel( layer, DFSCL_EXCLUSIVE );

     layer->GetConfiguration( layer, &config );


     config.options    = DLOP_OPACITY | DLOP_SRC_COLORKEY;
     config.buffermode = DLBM_FRONTONLY;

     layer->SetConfiguration( layer, &config );
     layer->SetSrcColorKey( layer, 0x00, 0xff, 0x00 );



     ret = layer->GetSurface( layer, &surface );
     if (ret) {
          D_DERROR( ret, "DFBTest/Layer: GetSurface() failed!\n" );
          dfb->Release( dfb );
          return ret;
     }

     surface->GetSize( surface, &size.w, &size.h );

     sw3 = ((size.w / 3) + 1) & ~1;
     sh3 = ((size.h / 3) + 1) & ~1;


     surface->Clear( surface, 0, 0, 0, 0xff );

     for (i=0; i<10; i++) {
          surface->SetColor( surface, 0xff - i*16, 0xff - i*16, 0xff - i*16, 0xff );
          surface->DrawRectangle( surface, i, i, size.w - i*2, size.h - i*2 );
     }

     surface->FillRectangle( surface, 10, size.h/2, size.w - 20, 1 );
     surface->FillRectangle( surface, size.w/2, 10, 1, size.h - 20 );

     surface->SetColor( surface, 0xff, 0x00, 0x00, 0xff );
     surface->FillRectangle( surface, size.w/3, size.h/3, size.w/3, size.h/3 );

     surface->SetColor( surface, 0x00, 0xff, 0x00, 0xff );
     surface->FillRectangle( surface, size.w/3 + size.w/9, size.h/3 + size.h/9, size.w/9, size.h/9 );

     surface->Flip( surface, NULL, DSFLIP_NONE );

#ifdef BUILD_AUTOMATION
     sleep( 2 );
#else
     sleep( 12 );
#endif
     layer->SetSourceRectangle( layer, 0, 0, size.w - sw3, size.h - sh3 );

     layer->SetScreenPosition( layer, 100, 100 );
     layer->SetScreenRectangle( layer, 100, 100, size.w - sw3, size.h - sh3 );

     sleep( 2 );
#ifdef BUILD_AUTOMATION
     sleep( 20 );
     quit = 1;
#endif

     for (x=0, y=0, dx=1, dy=1; !quit ; x+=dx, y+=dy) {
          layer->SetOpacity( layer, opacity );

          if (opacity == 255)
               opacity_delta = -1;
          else if (opacity == 0)
               opacity_delta = 1;

          opacity += opacity_delta;


          layer->SetSourceRectangle( layer, x, y, size.w - sw3, size.h - sh3 );

          surface->Flip( surface, NULL, DSFLIP_UPDATE );

          if (dx > 0) {
               if (x == size.w/3) {
                    dx = -1;

                    usleep( 500000 );
               }
          }
          else if (x == 0) {
               dx = 1;

               usleep( 500000 );
          }

          if (dy > 0) {
               if (y == size.h/3) {
                    dy = -1;

                    usleep( 500000 );
               }
          }
          else if (y == 0) {
               dy = 1;

               usleep( 500000 );
          }

          usleep( 10000 );

          /* Process keybuffer */
          while (keybuffer->GetEvent( keybuffer, DFB_EVENT(&evt)) == DFB_OK)
          {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = 1;
                          break;
                      default:
                          break;
                  }
              }
          }

     }

     surface->Release( surface );
     layer->Release( layer );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}