예제 #1
0
status_t ServerWindow::UpdateTitle (char *title){
	DFBFontDescription font_dsc;
	IDirectFBSurface *wsurface = NULL;
	int wdth;
	int ht;
	int width1, width2, width3;
	int height1, height2, height3;
		
	DFBCHECK(window->GetSurface(window, &wsurface));  
	DFBCHECK(window->GetSize(window, &wdth, &ht));
	
  if (fType==B_FLOATING_WINDOW){
  	DFBCHECK (shead->GetSize(shead, &width1, &height1));
	DFBCHECK (sok_button->GetSize(sok_button, &width2, &height2));
	DFBCHECK (sclose_button->GetSize(sclose_button, &width3, &height3));

	DFBRectangle rect;
	rect.x = 0;	rect.y = 0;	rect.h = height1;	rect.w = wdth-width2-width3;
	DFBCHECK (wsurface->StretchBlit (wsurface, shead, NULL, &rect));
	DFBCHECK (wsurface->Blit (wsurface, sok_button, NULL, rect.w, 0));
  	DFBCHECK (wsurface->Blit (wsurface, sclose_button, NULL, rect.w+width2, 0));	  		
	
  	// Draw the window title
  	font_dsc.flags = DFDESC_HEIGHT;
  	font_dsc.height = 10;
  	font_dsc.width = 10;  
  	DFBCHECK (app_server->dfb->CreateFont (app_server->dfb, "./decker.ttf", &font_dsc, &font));
  	DFBCHECK (wsurface->SetFont (wsurface, font));
  	DFBCHECK (wsurface->SetColor (wsurface, 0xff, 0x0, 0x0, 0xFF));  	
	DFBCHECK (wsurface->DrawString (wsurface, title, -1, 5, 2*height1/3, DSTF_LEFT));	
  }
  else if (fType==B_TITLED_WINDOW){
  	DFBCHECK (head->GetSize(head, &width1, &height1));
	DFBCHECK (ok_button->GetSize(ok_button, &width2, &height2));
	DFBCHECK (close_button->GetSize(close_button, &width3, &height3));

	DFBRectangle rect;
	rect.x = 0;	rect.y = 0;	rect.h = height1;	rect.w = wdth-width2-width3;
	DFBCHECK (wsurface->StretchBlit (wsurface, head, NULL, &rect));
	DFBCHECK (wsurface->Blit (wsurface, ok_button, NULL, rect.w, 0));
  	DFBCHECK (wsurface->Blit (wsurface, close_button, NULL, rect.w+width2, 0));	
  	
	// Draw the window title
  	font_dsc.flags = DFDESC_HEIGHT;
  	font_dsc.height = 15;
  	font_dsc.width = 15;  
  	DFBCHECK (app_server->dfb->CreateFont (app_server->dfb, "./decker.ttf", &font_dsc, &font));
  	DFBCHECK (wsurface->SetFont (wsurface, font));
  	DFBCHECK (wsurface->SetColor (wsurface, 0x0, 0x10, 0xfa, 0xFF));
	DFBCHECK (wsurface->DrawString (wsurface, title, -1, 6, 2*height1/3, DSTF_LEFT));	
  }	
}
예제 #2
0
static int l_SetFont (lua_State* L)
{
	// [ sfc | font ]
	IDirectFBSurface* sfc = * (IDirectFBSurface**) luaL_checkudata(L, 1, "ldirectfb.IDirectFBSurface");
	IDirectFBFont* font = * (IDirectFBFont**) luaL_checkudata(L, 2, "ldirectfb.IDirectFBFont");
	DFBCHECK (sfc->SetFont(sfc, font));
	return 0;
}
예제 #3
0
     /* render callback */
     virtual void Render( IDirectFBSurface &surface ) {
          surface.Clear( 0, 0, 255, 255 );


          surface.SetFont( font );

          surface.SetColor( 0, 0, 0, 255 );
          surface.SetSrcBlendFunction( DSBF_INVSRCALPHA );
          surface.SetDstBlendFunction( DSBF_INVSRCALPHA );

          surface.DrawString( "Test Text", -1, 10, 10, (DFBSurfaceTextFlags)(DSTF_TOPLEFT | DSTF_BLEND_FUNCS) );
     }
예제 #4
0
static mrb_value surface_set_font(mrb_state *mrb, mrb_value self)
{
    IDirectFBSurface* surface = mrb_directfb_surface(mrb, self);
    DFBResult ret = -1;
    if (surface != NULL) {
        mrb_value font_object;
        IDirectFBFont* font = NULL;
        mrb_get_args(mrb, "o", &font_object);
        font = mrb_directfb_font(mrb, font_object);
        ret = surface->SetFont(surface, font);
        if (!ret) {
            mrb_iv_set(mrb, self, mrb_intern_lit(mrb, "font"), font_object);
        }
    }
    return mrb_fixnum_value(ret);
}
예제 #5
0
int main( int argc, char *argv[] )
{
     IDirectFB              *dfb;
     IDirectFBDisplayLayer  *layer;

     IDirectFBSurface       *bgsurface;
     IDirectFBImageProvider *provider;

     IDirectFBWindow        *window1;
     IDirectFBWindow        *window2;
     IDirectFBSurface       *window_surface1;
     IDirectFBSurface       *window_surface2;

     IDirectFBEventBuffer   *buffer;

     DFBDisplayLayerConfig  layer_config;

#if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23))
     DFBCardCapabilities    caps;
#else
     DFBGraphicsDeviceDescription caps;
#endif
     IDirectFBWindow*       upper;
     DFBWindowID            id1;

     IDirectFBFont          *font;
     int fontheight;
     int err;
     int quit = 0;


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

#if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23))
     dfb->GetCardCapabilities( dfb, &caps );
#else
     dfb->GetDeviceDescription( dfb, &caps );
#endif

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

     if (!((caps.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
           (caps.blitting_flags & DSBLIT_BLEND_COLORALPHA  )))
     {
          layer_config.flags = DLCONF_BUFFERMODE;
          layer_config.buffermode = DLBM_BACKSYSTEM;

          layer->SetConfiguration( layer, &layer_config );
     }

     layer->GetConfiguration( layer, &layer_config );
     layer->EnableCursor ( layer, 1 );

     {
          DFBFontDescription desc;

          desc.flags = DFDESC_HEIGHT;
          desc.height = layer_config.width/50;

          DFBCHECK(dfb->CreateFont( dfb, PACKAGE_DATA_DIR"/grunge.ttf", &desc, &font ));
          font->GetHeight( font, &fontheight );
     }

     {
          DFBSurfaceDescription desc;

          DFBCHECK(dfb->CreateImageProvider( dfb,
                                             PACKAGE_DATA_DIR"/bg.png",
                                             &provider ));

          desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT;
          desc.width = layer_config.width;
          desc.height = layer_config.height;

          DFBCHECK(dfb->CreateSurface( dfb, &desc, &bgsurface ) );


          provider->RenderTo( provider, bgsurface, NULL );
          provider->Release( provider );

	  DFBCHECK(bgsurface->SetFont( bgsurface, font ));

          bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF );
          bgsurface->DrawString( bgsurface,
                                 "Move the mouse over a window to activate it.",
                                 -1, 10, 0, DSTF_LEFT | DSTF_TOP );

          bgsurface->SetColor( bgsurface, 0xFF, 0xCF, 0xFF, 0xFF );
          bgsurface->DrawString( bgsurface,
                    "You can drag them around, too, if you want.",
                                 -1, 10 , 40, DSTF_LEFT | DSTF_TOP );

          bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF );
	  bgsurface->DrawString( bgsurface,
                    "The one with funky stuff happening and things flying around is an evas.",
                                 -1, 10, 80, DSTF_LEFT | DSTF_TOP );




          layer->SetBackgroundImage( layer, bgsurface );
          layer->SetBackgroundMode( layer, DLBM_IMAGE );
     }
     {
	  DFBWindowDescription desc;
	  desc.flags = ( DWDESC_POSX | DWDESC_POSY |
                         DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS );

	  desc.posx = 20;
          desc.posy = 120;
          desc.width = 200;
          desc.height = 200;
	  desc.caps = DWCAPS_ALPHACHANNEL;

          DFBCHECK( layer->CreateWindow( layer, &desc, &window2 ) );
          window2->GetSurface( window2, &window_surface2 );

          window2->SetOpacity( window2, 0xFF );

          window2->CreateEventBuffer( window2, &buffer );

	  {
	     window_surface2->SetColor( window_surface2,
		   0x00, 0x30, 0x10, 0xc0 );
	     window_surface2->DrawRectangle( window_surface2, 0, 0,
		   desc.width, desc.height );
	     window_surface2->SetColor( window_surface2,
		   0x80, 0xa0, 0x00, 0x90 );
	     window_surface2->FillRectangle( window_surface2, 1, 1,
		   desc.width-2, desc.height-2 );


	     DFBCHECK(window_surface2->SetFont(window_surface2, font ));
	     window_surface2->SetColor( window_surface2, 0xCF, 0xFF, 0xCF, 0xFF );

	     window_surface2->DrawString( window_surface2,
		   "Pants!",
		   -1,10, fontheight + 5, DSTF_LEFT | DSTF_TOP );

	  }

          window_surface2->Flip( window_surface2, NULL, 0 );
     }

     {
          DFBWindowDescription desc;

          desc.flags = ( DWDESC_POSX | DWDESC_POSY |
                         DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS );
          desc.posx = 200;
          desc.posy = 200;
          desc.width = 240;
          desc.height = 320;
          desc.caps = DWCAPS_ALPHACHANNEL;

          DFBCHECK(layer->CreateWindow( layer, &desc, &window1 ) );
          window1->GetSurface( window1, &window_surface1 );

          window_surface1->SetColor( window_surface1, 0xFF, 0x20, 0x20, 0x90 );
          window_surface1->DrawRectangle( window_surface1, 0, 0,
                                          desc.width, desc.height );

          window_surface1->Flip( window_surface1, NULL, 0 );

          window1->SetOpacity( window1, 0xFF );

          window1->GetID( window1, &id1 );

          window1->AttachEventBuffer( window1, buffer );
     }

     window1->RequestFocus( window1 );
     window1->RaiseToTop( window1 );
     upper = window1;
     {
	evas_init();
	evas = evas_new();
	evas_output_method_set(evas, evas_render_method_lookup("directfb"));
	evas_output_size_set(evas, 240, 320);
	evas_output_viewport_set(evas, 0, 0, 240, 320);
	{
	   Evas_Engine_Info_DirectFB *einfo;

	   einfo = (Evas_Engine_Info_DirectFB *) evas_engine_info_get(evas);

	   einfo->info.dfb = dfb;
	   einfo->info.surface = window_surface1;
	   einfo->info.flags = DSDRAW_BLEND;
	   evas_engine_info_set(evas, (Evas_Engine_Info *) einfo);
	}
	setup();
	evas_render(evas);
	start_time = get_time();
     }

     while (!quit) {
          static IDirectFBWindow* active = NULL;
          static int grabbed = 0;
          static int startx = 0;
          static int starty = 0;
          static int endx = 0;
          static int endy = 0;
          DFBWindowEvent evt;

          buffer->WaitForEventWithTimeout( buffer, 0, 10 );

          while (buffer->GetEvent( buffer, DFB_EVENT(&evt) ) == DFB_OK) {
               IDirectFBWindow* window;

               if (evt.window_id == id1)
                    window = window1;
               else
                    window = window2;

               if (active) {
                    switch (evt.type) {

                    case DWET_BUTTONDOWN:
                         if (!grabbed && evt.button == DIBI_LEFT) {
                              grabbed = 1;
                              layer->GetCursorPosition( layer,
                                                        &startx, &starty );
                              window->GrabPointer( window );
                         }
                         break;

                    case DWET_BUTTONUP:
                         switch (evt.button) {
                              case DIBI_LEFT:
                                   if (grabbed) {
                                        window->UngrabPointer( window );
                                        grabbed = 0;
                                   }
                                   break;
                              case DIBI_MIDDLE:
                                   upper->LowerToBottom( upper );
                                   upper = (upper == window1) ? window2 : window1;
                                   break;
                              case DIBI_RIGHT:
                                   quit = DIKS_DOWN;
                                   break;
                              default:
                                   break;
                         }
                         break;

                    case DWET_KEYDOWN:
                         if (grabbed)
                              break;
                         switch (evt.key_id) {
                              case DIKI_RIGHT:
                                   active->Move (active, 1, 0);
                                   break;
                              case DIKI_LEFT:
                                   active->Move (active, -1, 0);
                                   break;
                              case DIKI_UP:
                                   active->Move (active, 0, -1);
                                   break;
                              case DIKI_DOWN:
                                   active->Move (active, 0, 1);
                                   break;
                              default:
                                   break;
                         }
                         break;

                    case DWET_LOSTFOCUS:
                         if (!grabbed)
                              active = NULL;
                         break;

                    default:
                         break;

                    }
               }
               else if (evt.type == DWET_GOTFOCUS)
                    active = window;

               switch (evt.type) {

               case DWET_MOTION:
                    endx = evt.cx;
                    endy = evt.cy;
                    break;

               case DWET_KEYDOWN:
                    switch (evt.key_symbol) {
                    case DIKS_ESCAPE:
                    case DIKS_SMALL_Q:
                    case DIKS_CAPITAL_Q:
                    case DIKS_BACK:
                    case DIKS_STOP:
                         quit = 1;
                         break;
                    default:
                         break;
                    }
                    break;

               default:
                    break;
               }
          }

          if (active) {
               if (grabbed) {
                    active->Move( active, endx - startx, endy - starty);
                    startx = endx;
                    starty = endy;
               }
               active->SetOpacity( active,
                                   (sin( myclock()/300.0 ) * 85) + 170 );
          }
	  loop();
	  {
	     Eina_List *updates;

	     updates = evas_render_updates(evas);
	     /* efficient update.. only flip the rectangle regions that changed! */
	     if (updates)
	       {
		  DFBRegion region;
		  Eina_List *l;

		  for (l = updates; l; l = l->next)
		    {
		       Evas_Rectangle *rect;

		       rect = l->data;
		       region.x1 = rect->x;
		       region.y1 = rect->y;
		       region.x2 = rect->x + rect->w - 1;
		       region.y2 = rect->y + rect->h - 1;
		       window_surface1->Flip(window_surface1, &region,
					     DSFLIP_BLIT);
		    }
		  evas_render_updates_free(updates);
	       }
	  }
     }

     buffer->Release( buffer );
     window_surface2->Release( window_surface2 );
     window_surface1->Release( window_surface1 );
     window2->Release( window2 );
     window1->Release( window1 );
     layer->Release( layer );
     bgsurface->Release( bgsurface );
     dfb->Release( dfb );

   evas_shutdown();
   return 0;
}
예제 #6
0
int main( int argc, char *argv[] )
{
     int                   quit = 0;
     pthread_t             render_loop_thread = -1;

     IDirectFBSurface     *primary;
     IDirectFBEventBuffer *buffer;

     DFBSurfaceDescription dsc;


     srand((long)time(0));

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     /* get an interface to the primary keyboard and create an
        input buffer for it */
     DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL, DFB_FALSE, &buffer ));

     /* set our cooperative level to DFSCL_FULLSCREEN for exclusive access to
        the primary layer */
     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* get the primary surface, i.e. the surface of the primary layer we have
        exclusive access to */
     dsc.flags = DSDESC_CAPS;
     dsc.caps = DSCAPS_PRIMARY | DSCAPS_DOUBLE;

     DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary ));

     DFBCHECK(primary->GetSize( primary, &xres, &yres ));

     /* load font */
     {
          DFBFontDescription desc;

          desc.flags = DFDESC_HEIGHT;
          desc.height = yres/10;

          DFBCHECK(dfb->CreateFont( dfb, FONT, &desc, &font ));
          DFBCHECK(primary->SetFont( primary, font ));
     }

     projection = matrix_new_perspective( 400 );
     camera = matrix_new_identity();

     load_stars();

     generate_starfield();

     pthread_mutex_lock( &render_start );
     pthread_mutex_lock( &render_finish );
     pthread_create( &render_loop_thread, NULL, render_loop, (void*)primary );

     /* main loop */
     while (!quit) {
          static float  translation[3] = { 0, 0, 0 };
          DFBInputEvent evt;

          /* transform world to screen coordinates */
          transform_starfield();

          /* start rendering before waiting for events */
          start_rendering();


          buffer->WaitForEvent( buffer );

          /* process event buffer */
          while (buffer->GetEvent( buffer, DFB_EVENT(&evt)) == DFB_OK) {
               if (evt.type == DIET_KEYPRESS) {
                    switch (evt.key_id) {
                         case DIKI_ESCAPE:
                              /* quit main loop */
                              quit = 1;
                              break;

                         case DIKI_LEFT:
                              translation[0] =  10;
                              break;

                         case DIKI_RIGHT:
                              translation[0] = -10;
                              break;

                         case DIKI_UP:
                              translation[2] = -10;
                              break;

                         case DIKI_DOWN:
                              translation[2] =  10;
                              break;

                         default:
                              break;
                    }
               } else
               if (evt.type == DIET_KEYRELEASE) {
                    switch (evt.key_id) {
                         case DIKI_LEFT:
                         case DIKI_RIGHT:
                              translation[0] = 0;
                              break;

                         case DIKI_UP:
                         case DIKI_DOWN:
                              translation[2] = 0;
                              break;

                         default:
                              break;
                    }
               } else
               if (evt.type == DIET_AXISMOTION  && (evt.flags & DIEF_AXISREL)) {
                    switch (evt.axis) {
                         case DIAI_X:
                              matrix_rotate( camera, Y, -evt.axisrel/80.0f );
                              break;

                         case DIAI_Y:
                              matrix_rotate( camera, X,  evt.axisrel/80.0f );
                              break;

                         default:
                              break;
                    }
               }
          }

          matrix_translate( camera,
                            translation[0], translation[1], translation[2] );

          /* finish rendering before retransforming the world */
          finish_rendering();
     }

     pthread_cancel( render_loop_thread );
     pthread_mutex_unlock( &render_start );
     pthread_join( render_loop_thread, NULL );
     render_loop_thread = -1;


     unload_stars();

     free( camera );
     free( projection );

     buffer->Release( buffer );
     primary->Release( primary );
     dfb->Release( dfb );

     return 0;
}
예제 #7
0
int
main( int argc, char *argv[] )
{
     int                    i;
     DFBResult              ret;
     DFBSurfaceDescription  desc;
     IDirectFB             *dfb;
     IDirectFBSurface      *dest            = NULL;
     const char            *url             = NULL;
     DFBFontAttributes      attributes      = DFFA_NONE;
     DFBSurfaceTextFlags    text_flags      = DSTF_TOPLEFT;
     int                    outline_width   = 0x10000;
     int                    outline_opacity = 255;
     const DFBColorID       color_ids[2]    = { DCID_PRIMARY, DCID_OUTLINE };
     const DFBColor         colors[2]       = { { 0xff, 0xff, 0xff, 0xff },
                                                { 0xff, 0x00, 0x80, 0xff } };

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

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          const char *arg = argv[i];

          if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
               return print_usage( argv[0] );
          else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
               fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
               return false;
          }
          else if (strcmp (arg, "-o") == 0 || strcmp (arg, "--outline") == 0) {
               attributes |= DFFA_OUTLINED;
               text_flags |= DSTF_OUTLINE;
          }
          else if (strcmp (arg, "-ow") == 0 || strcmp (arg, "--outline-width") == 0) {
               if (++i == argc)
                    return print_usage( argv[0] );

               if (sscanf( argv[i], "%d", &outline_width ) != 1)
                    return print_usage( argv[0] );

               outline_width <<= 16;
          }
          else if (strcmp (arg, "-oo") == 0 || strcmp (arg, "--outline-opacity") == 0) {
               if (++i == argc)
                    return print_usage( argv[0] );

               if (sscanf( argv[i], "%d", &outline_opacity ) != 1)
                    return print_usage( argv[0] );
          }
          else if (!url)
               url = arg;
          else
               return print_usage( argv[0] );
     }

     /* Check if we got an URL. */
     if (!url)
          return print_usage( argv[0] );

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

     /* Fill description for a primary surface. */
     desc.flags = DSDESC_CAPS;
     desc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* Create a primary surface. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/Font: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }

     dest->GetSize( dest, &desc.width, &desc.height );
     dest->GetPixelFormat( dest, &desc.pixelformat );

     D_INFO( "DFBTest/Font: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     for (i=10; i<50; i++) {
          IDirectFBFont *font;

          font = CreateFont( dfb, url, i, attributes, outline_width, outline_opacity );

          RenderChecker( dest, 64, 64 );

          dest->SetColors( dest, color_ids, colors, 2 );

          dest->SetFont( dest, font );
          dest->DrawString( dest, "Test String AVAWA", -1, 100, 100, text_flags );

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

          font->Release( font );

          usleep( 500000 );
     }


out:
     if (dest)
          dest->Release( dest );

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

     return ret;
}
예제 #8
0
//---------------------------------------------------------------------------------
//--------------------------wael work----------------------
//---------------------------------------------------------------------------------
status_t ServerWindow::CreateWindow (IDirectFBDisplayLayer *layer){

  DFBFontDescription font_dsc;
  DFBWindowDescription wdsc;  
  IDirectFBSurface *wsurface = NULL;
  DFBSurfaceDescription dsc;
  
//  char *title;TODO: I need to convert the fTitle from BString to char *
  char title[fTitle.CountChars()+1];
  fTitle.CopyInto(title, 0, fTitle.CountChars());
  DFBRectangle frame;
  frame.x=(int)fFrame.LeftTop().x;
  frame.y=(int)fFrame.LeftTop().y;
  frame.w=(int)fFrame.IntegerWidth();
  frame.h=(int)fFrame.IntegerHeight();
    
  int width1, width2, width3;
  int height1, height2, height3;

  //create window inside the primary layer  
  wdsc.flags = (DFBWindowDescriptionFlags)(DWDESC_CAPS | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS);
  wdsc.caps = DWCAPS_ALPHACHANNEL;
  wdsc.width = frame.w;
  wdsc.height = frame.h;
  wdsc.posx = frame.x;
  wdsc.posy = frame.y;
  wdsc.surface_caps = DSCAPS_FLIPPING;
  DFBCHECK(layer->CreateWindow(layer, &wdsc, &window));
  
  //Get the window surface and clear it
  DFBCHECK(window->GetSurface(window, &wsurface));  
  DFBCHECK(wsurface->Clear (wsurface, 0x00, 0x00, 0x00, 0x00));
  DFBCHECK(window->SetOpaqueRegion (window, 0, 0, frame.h, frame.w));
  
  //Set the window options to be transparent
  DFBWindowOptions options;
  window->GetOptions (window, &options);
  
  options = (DFBWindowOptions) ( options | DWOP_SHAPED );
  DFBCHECK(window->SetOptions (window, options));  
  wsurface->SetSrcColorKey(wsurface, R, G, B);
  wsurface->SetBlittingFlags(wsurface, DSBLIT_SRC_COLORKEY);  
        
  if (fType==B_FLOATING_WINDOW){
  	DFBCHECK (shead->GetSize(shead, &width1, &height1));
	DFBCHECK (sok_button->GetSize(sok_button, &width2, &height2));
	DFBCHECK (sclose_button->GetSize(sclose_button, &width3, &height3));

	DFBRectangle rect;
	rect.x = 0;
	rect.y = 0;
	rect.h = height1;
	rect.w = frame.w-width2-width3;
	DFBCHECK (wsurface->StretchBlit (wsurface, shead, NULL, &rect));
	DFBCHECK (wsurface->Blit (wsurface, sok_button, NULL, rect.w, 0));
  	DFBCHECK (wsurface->Blit (wsurface, sclose_button, NULL, rect.w+width2, 0));	  	

  	// Draw the window title
  	font_dsc.flags = DFDESC_HEIGHT;
  	font_dsc.height = 10;
  	font_dsc.width = 10;  
  	DFBCHECK (app_server->dfb->CreateFont (app_server->dfb, "./decker.ttf", &font_dsc, &font));
  	DFBCHECK (wsurface->SetFont (wsurface, font));
  	DFBCHECK (wsurface->SetColor (wsurface, 0xff, 0x0, 0x0, 0xFF));
	int size = 0;
	DFBRectangle rect1;		
  	DFBCHECK (font->GetStringExtents (font, title, -1, NULL, &rect1));
	if (rect1.w > rect.w){
		do{
			size++;
			DFBCHECK (font->GetStringExtents (font, title, size, NULL, &rect1));
		}while (rect1.w < rect.w);
		size--;
	}  		  	
	DFBCHECK (wsurface->DrawString (wsurface, title, size-1, 5, 2*height1/3, DSTF_LEFT));	
		
	rect.x = 0;
	rect.y = height1;
	rect.w = frame.w;
	rect.h = frame.h-height1;
	DFBCHECK (wsurface->StretchBlit (wsurface, body, NULL, &rect));	
  }
  else if (fType==B_TITLED_WINDOW){
  	DFBCHECK (head->GetSize(head, &width1, &height1));
	DFBCHECK (ok_button->GetSize(ok_button, &width2, &height2));
	DFBCHECK (close_button->GetSize(close_button, &width3, &height3));

	DFBRectangle rect;
	rect.x = 0;
	rect.y = 0;
	rect.h = height1;
	rect.w = frame.w-width2-width3;
	DFBCHECK (wsurface->StretchBlit (wsurface, head, NULL, &rect));
	DFBCHECK (wsurface->Blit (wsurface, ok_button, NULL, rect.w, 0));
  	DFBCHECK (wsurface->Blit (wsurface, close_button, NULL, rect.w+width2, 0));
	
	// Draw the window title
  	font_dsc.flags = DFDESC_HEIGHT;
  	font_dsc.height = 15;
  	font_dsc.width = 15;  
  	DFBCHECK (app_server->dfb->CreateFont (app_server->dfb, "./decker.ttf", &font_dsc, &font));
  	DFBCHECK (wsurface->SetFont (wsurface, font));
  	DFBCHECK (wsurface->SetColor (wsurface, 0x0, 0x10, 0xfa, 0xFF));
	int size = 0;
	DFBRectangle rect1;		
  	DFBCHECK (font->GetStringExtents (font, title, -1, NULL, &rect1));
	if (rect1.w > rect.w){
		do{
			size++;
			DFBCHECK (font->GetStringExtents (font, title, size, NULL, &rect1));
		}while (rect1.w < rect.w);
		size-=2;
	}  		
	DFBCHECK (wsurface->DrawString (wsurface, title, -1, 6, 2*height1/3, DSTF_LEFT));	
		
	rect.x = 0;
	rect.y = height1;
	rect.w = frame.w;
	rect.h = frame.h-height1;
  	DFBCHECK (wsurface->StretchBlit (wsurface, body, NULL, &rect));  	
  }
  else if (fType==B_MODAL_WINDOW){
  }
  created = true;

}
예제 #9
0
int
main( int argc, char *argv[] )
{
     DFBResult ret;
     int       i;
     int       quit = 0;
     const int num = 2;
     Context   contexts[num];

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

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

     /* create the default font */
     DFBCHECK(dfb->CreateFont( dfb, NULL, NULL, &font ));

     for (i=0; i<num; i++) {
          IDirectFBWindow      *window;
          IDirectFBSurface     *surface;
          IDirectFBGL          *gl;
          DFBWindowDescription  desc;

          desc.flags  = DWDESC_POSX | DWDESC_POSY |
                        DWDESC_WIDTH | DWDESC_HEIGHT;
          desc.posx   = (i%3) * 200 + 10;
          desc.posy   = (i/3) * 200 + 10;
          desc.width  = 180;
          desc.height = 180;

          DFBCHECK(layer->CreateWindow( layer, &desc, &window ));
          DFBCHECK(window->GetSurface( window, &surface ));
          DFBCHECK(surface->GetGL( surface, &gl ));

          contexts[i].window    = window;
          contexts[i].surface   = surface;
          contexts[i].gl        = gl;

          contexts[i].last_time = get_millis();
          contexts[i].frames    = 0;
          contexts[i].fps       = 0;

          setup( &contexts[i] );

          if (events)
               DFBCHECK(window->AttachEventBuffer( window, events ));
          else
               DFBCHECK(window->CreateEventBuffer( window, &events ));
          
          DFBCHECK(surface->SetFont( surface, font ));

          window->SetOpacity( window, 0xff );
     }
     
     while (!quit) {
          DFBWindowEvent evt;

          for (i=0; i<num; i++)
               update( &contexts[i] );
          
          while (events->GetEvent( events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DWET_KEYDOWN:
                         switch (evt.key_symbol) {
                              case DIKS_ESCAPE:
                                   quit = 1;
                                   break;

                              default:
                                   break;
                         }
                         break;

                    default:
                         break;
               }
          }
     }

     events->Release( events );

     for (i=0; i<num; i++) {
          contexts[i].gl->Release( contexts[i].gl );
          contexts[i].surface->Release( contexts[i].surface );
          contexts[i].window->Release( contexts[i].window );
     }

     font->Release( font );
     layer->Release( layer );
     dfb->Release( dfb );

     return 0;
}
예제 #10
0
파일: test_pcba.c 프로젝트: vonfritz/owl
static void *handle_record_button(DirectThread *thread, void *arg)
{
	IDirectFBSurface *surface = arg;
	IDirectFBFont 		*font, *font_s;
	DFBFontDescription 	font_desc;
	bool local_flg = false;
	int width, height;
	int font_big_height, font_little_height;
	
	char font_file[50] = "/misc/font/wqy-zenhei.ttc";
	
	DFBCHECK(surface->GetSize(surface, &width, &height));
	
	font_big_height = 48;
	while(font_big_height > (height / 2))
	{
		font_big_height -= 4;
	}
	font_desc.flags = DFDESC_HEIGHT;
	font_desc.height = font_big_height;
	DFBCHECK(dfb->CreateFont( dfb, font_file,  &font_desc, &font));
	
	font_little_height = 32;
	while(font_little_height > (height / 4))
	{
		font_little_height -= 4;
	}
	font_desc.height = font_little_height;
	DFBCHECK(dfb->CreateFont( dfb, font_file,  &font_desc, &font_s));
	
	printf("font size is %d %d\n", font_big_height, font_little_height);
	
	DFBCHECK(surface->SetFont(surface, font_s));
	
	DFBCHECK(surface->SetColor(surface, 0x8C, 0x8C, 0x8C, 0xff));
	DFBCHECK(surface->DrawString(surface, "点击录音", -1, width / 2, 0, DSTF_TOPCENTER));
	
	DFBCHECK(surface->SetColor(surface, 0x41, 0x41, 0x41, 0xff));
	DFBCHECK(surface->DrawString(surface, "测试TP请避开此区域", -1, width / 2, height / 4, DSTF_TOPCENTER));
	
	DFBCHECK(surface->SetFont(surface, font));
	DFBCHECK(surface->SetColor(surface, 0xE3, 0x6C, 0x4C, 0xff));
	DFBCHECK(surface->DrawString(surface, "状态:停止录音", -1, width / 2, height / 2, DSTF_TOPCENTER));
	DFBCHECK(surface->Flip(surface, NULL, 0));
	while(true)
	{
		if(record_flg != local_flg)
		{
			local_flg = record_flg;
			DFBCHECK(surface->SetColor(surface, 0xff, 0xff, 0xff, 0xff));
			DFBCHECK(surface->FillRectangle(surface, 0 , height / 2, width, font_big_height + 4));  //need fix
			DFBCHECK(surface->SetColor(surface, 0xE3, 0x6C, 0x4C, 0xff));
			if(local_flg)
			{
				DFBCHECK(surface->DrawString(surface, "状态:正在录音", -1, width / 2, height / 2, DSTF_TOPCENTER));
			}
			else
			{
				DFBCHECK(surface->DrawString(surface, "状态:停止录音", -1, width / 2, height / 2, DSTF_TOPCENTER));
			}
			DFBCHECK(surface->Flip(surface, NULL, 0));
		}
		direct_thread_sleep(100000);
	}
	
	font->Release(font);
	font_s->Release(font_s);
}