Claudio Ciccani wrote:
> Ben Combee wrote:
>> Claudio, the Unbind semantics are a little odd.  Can you update the
>> header to clairfy
>>
>> 1) can a window be bound to multiple windows at once?
> 
> You can't bind (attach) the same window to multiple windows
> but a window can have multiple windows bound (attached) to it.
> That is because if you bind a window to another, then the bound window
> must "follow" the window to which it's attached when the latter moves to
> a new position.
> It's intutive that a window can't "follow" more than one window.
> 
>> 2) if not, what error is returned
> 
> None.
> The new Bind() overrides the previous one (i.e. it automatically
> unbounds the window before binding it to the new window).
> 
>> 3) if you can't bind to multiple windows, why specify a "unbind"
>> window in the Unbind call?
> 
> Because a window might have multiple windows bound (attached) to it.
>> I like the idea a lot, just curious about the execution.
> 
> I realize that the documention should be detailed enough to let people
> understand these concepts immediatly, so i have just committed a change
> to the header to clarify these aspects.
> 

An example (attached) will clarify things.


-- 
Regards,
     Claudio Ciccani

[EMAIL PROTECTED]
http://directfb.org
http://sf.net/projects/php-directfb
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <directfb.h>

#define DFBCHECK( x... ) {\
     DFBResult ret; \
     ret = x; \
     if (ret) \
          DirectFBError( #x, ret ); \
}

int
main( int argc, char **argv )
{
     IDirectFB             *dfb;
     IDirectFBDisplayLayer *layer;
     IDirectFBFont         *font;
     IDirectFBWindow       *window1;
     IDirectFBWindow       *window2;
     IDirectFBWindow       *window3;
     IDirectFBWindow       *window4;
     IDirectFBSurface      *surface;
     IDirectFBEventBuffer  *buffer;
     DFBWindowDescription   dsc;
     int                    quit = 0;

     DirectFBInit( &argc, &argv );
     DirectFBCreate( &dfb );

     dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );
     
     dfb->CreateFont( dfb, NULL, NULL, &font );

     /* window 1 */
     dsc.flags  = DWDESC_WIDTH | DWDESC_HEIGHT;
     dsc.width  = 300;
     dsc.height = 300;

     layer->CreateWindow( layer, &dsc, &window1 );
     window1->GetSurface( window1, &surface );
     surface->Clear( surface, 0xff, 0xff, 0xff, 0xff );
     surface->SetFont( surface, font );
     surface->SetColor( surface, 0x00, 0x00, 0x00, 0xff );
     surface->DrawString( surface, "1", -1, 4, 2, DSTF_LEFT | DSTF_TOP );
     surface->Flip( surface, NULL, 0 );
     surface->Release( surface );
     window1->SetOptions( window1, DWOP_SCALE );
     window1->SetOpacity( window1, 0xff );

     /* window 2 */
     dsc.flags  = DWDESC_WIDTH | DWDESC_HEIGHT;
     dsc.width  = 128;
     dsc.height = 128;
 
     layer->CreateWindow( layer, &dsc, &window2 );
     window2->GetSurface( window2, &surface );
     surface->Clear( surface, 0xff, 0x00, 0x00, 0xff );
     surface->SetFont( surface, font );
     surface->SetColor( surface, 0x00, 0x00, 0x00, 0xff );
     surface->DrawString( surface, "2", -1, 4, 2, DSTF_LEFT | DSTF_TOP );
     surface->Flip( surface, NULL, 0 ); 
     surface->Release( surface );
     window2->PutAtop( window2, window1 );
     window2->SetOptions( window2, DWOP_SCALE | DWOP_KEEP_STACKING );
     window2->SetOpacity( window2, 0xff );

     /* window 3 */
     dsc.flags  = DWDESC_WIDTH | DWDESC_HEIGHT;
     dsc.width  = 64;
     dsc.height = 64;
     layer->CreateWindow( layer, &dsc, &window3 );
     window3->GetSurface( window3, &surface );
     surface->Clear( surface, 0x00, 0xff, 0xff, 0xff );
     surface->SetFont( surface, font );
     surface->SetColor( surface, 0x00, 0x00, 0x00, 0xff );
     surface->DrawString( surface, "3", -1, 4, 2, DSTF_LEFT | DSTF_TOP );
     surface->Flip( surface, NULL, 0 );
     surface->Release( surface ); 
     window3->PutAtop( window3, window2 );
     window3->SetOptions( window3, DWOP_SCALE | DWOP_KEEP_STACKING );
     window3->SetOpacity( window3, 0xff );
     
     /* window 4 */
     dsc.flags  = DWDESC_WIDTH | DWDESC_HEIGHT;
     dsc.width  = 64;
     dsc.height = 64;
     layer->CreateWindow( layer, &dsc, &window4 );
     window4->GetSurface( window4, &surface );
     surface->Clear( surface, 0xff, 0xff, 0x00, 0xff );
     surface->SetFont( surface, font );
     surface->SetColor( surface, 0x00, 0x00, 0x00, 0xff );
     surface->DrawString( surface, "4", -1, 4, 2, DSTF_LEFT | DSTF_TOP );
     surface->Flip( surface, NULL, 0 );
     surface->Release( surface ); 
     window4->PutAtop( window4, window2 );
     window4->SetOptions( window4, DWOP_SCALE | DWOP_KEEP_STACKING );
     window4->SetOpacity( window4, 0xff );
     
     /* bind window 2 to window 1 */
     DFBCHECK(window1->Bind( window1, window2, 300, 300 ));
     /* bind window 3 to window 2 */
     DFBCHECK(window2->Bind( window2, window3, 96, -32 ));
     /* bind window 4 to window 2 */
     DFBCHECK(window2->Bind( window2, window4, -32, 96 ));
     
     /* try moving window 2 (fails with DFB_UNSUPPORTED) */
     //DFBCHECK(window2->MoveTo( window2, 100, 100 ));

     window1->CreateEventBuffer( window1, &buffer );
     
     printf( "Press ENTER to bind/unbind window 2\n" );
     fflush( stdout );
     
     while (!quit) {
          DFBWindowEvent evt;
          static int     bound = 1;
     
          buffer->WaitForEvent( buffer );
          while (buffer->GetEvent( buffer, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DWET_KEYDOWN:
                         if (evt.key_symbol == DIKS_ESCAPE) {
                              quit = 1;
                         }
                         else if (evt.key_symbol == DIKS_ENTER) {
                              bound = !bound;
                              if (bound) {
                                   int x1, y1;
                                   int x2, y2;
                                   window1->GetPosition( window1, &x1, &y1 );
                                   window2->GetPosition( window2, &x2, &y2 ); 
                                   window1->Bind( window1, window2, x2-x1, y2-y1 );
                              }
                              else {
                                   window1->Unbind( window1, window2 );
                              }
                         }
                         break;
                    case DWET_CLOSE:
                    case DWET_DESTROYED:
                         quit = 1;
                         break;
                    default:
                         break;
               }
          }               
     }

     buffer->Release( buffer );
     window4->Release( window4 );
     window3->Release( window3 );
     window2->Release( window2 );
     window1->Release( window1 );
     font->Release( font );
     layer->Release( layer );
     dfb->Release( dfb );

     return 0;
}
_______________________________________________
directfb-dev mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev

Reply via email to