-
[my-code/ivac.git] / dfb_api.c
1 /*
2  * dfb_api.c - api to dfb interface
3  */
4
5 /* std includes */
6 #include <stdio.h>
7 #include <unistd.h>
8
9 /* dfb includes */
10 #include <directfb.h>
11
12 #define MY_FONT_HEIGHT 18
13
14 /* global stuff */
15
16 /* well ... */
17 static IDirectFB *dfb = NULL;
18 static IDirectFBSurface *primary = NULL;
19 static int screen_width  = 0;
20 static int screen_height = 0;
21
22 static IDirectFBSurface *logo = NULL;
23
24 static IDirectFBFont *font = NULL;
25 static char *text_top="Internet Video / Audio Conferencing";
26
27 /* image to load */
28 char dfb_image[]="./images/ivac_logo.png";
29 /* font to use */
30 char dfb_font[]="./fonts/decker.ttf";
31
32 int main (int argc, char **argv) {
33   int i,font_width;
34   DFBFontDescription font_dsc;
35   DFBSurfaceDescription dsc;
36   /* image provider */
37   IDirectFBImageProvider *provider;
38
39   /* init */
40   DirectFBInit(&argc,&argv);
41   DirectFBCreate(&dfb);
42   dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN);
43   dsc.flags=DSDESC_CAPS;
44   // dsc.caps=DSCAPS_PRIMARY | DSCAPS_FLIPPING;
45   dsc.caps=DSCAPS_PRIMARY;
46   dfb->CreateSurface(dfb,&dsc,&primary);
47   primary->GetSize(primary,&screen_width,&screen_height);
48   printf("debug: w/h = %d / %d\n",screen_width,screen_height);
49
50   /* create the imag provider */
51   dfb->CreateImageProvider(dfb,dfb_image,&provider);
52   /* get image/provider description */
53   provider->GetSurfaceDescription(provider,&dsc);
54   printf("debug: w/h %d / %d\n",dsc.width,dsc.height);
55   /* create apropriate surface */
56   dfb->CreateSurface(dfb,&dsc,&logo);
57   /* render image */
58   provider->RenderTo(provider,logo,NULL);
59   provider->Release(provider);
60
61   /* create font */
62   font_dsc.flags=DFDESC_HEIGHT;
63   font_dsc.height=MY_FONT_HEIGHT;
64   dfb->CreateFont(dfb,dfb_font,&font_dsc,&font);
65
66   /* set font */
67   primary->SetFont(primary,font);
68   font->GetStringWidth(font,text_top,-1,&font_width);
69
70
71   /* slide logo + write text_top */
72   for(i = -dsc.width; i < screen_width; i++) {
73       /* clear screen */
74       primary->FillRectangle(primary,0,0,screen_width,screen_height);
75
76       /* write text */
77       primary->SetColor(primary,0x0,0x0,0x0,0xff);
78       primary->DrawString(primary,text_top,-1,(screen_width/2)-(font_width/2),
79                                 screen_height/4,DSTF_LEFT);
80
81       /* blit image */
82       primary->Blit(primary,logo,NULL,i,(screen_height-dsc.height)/2);
83
84       /* flip */
85       primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC);
86    }
87
88   /* release font */
89   font->Release(font);
90
91   /* release image */
92   logo->Release(logo);
93
94   primary->Release(primary);
95   dfb->Release(dfb);
96   
97   return 23;
98 }
99