4 * build: gcc -o dfb-photoshow -O3 -Wall -I/usr/X11/include \
5 * -I/usr/include/directfb dfb-photoshow.c
6 * usage: ./showdir <seconds> <directory>
9 * hackbard@hackdaworld.dyndns.org
11 * cvs -d:pserver:anonymous@hackdaworld.dyndns.org:/my-code co dfb-photoshow
20 IDirectFB *dfb = NULL;
21 IDirectFBSurface *primary = NULL;
23 int screen_height = 0;
25 #define DFBCHECK(x...) \
29 fprintf(stderr,"file: %s , line: %d !\n\t",__FILE__,__LINE__); \
30 DirectFBErrorFatal( #x, err ); \
34 IDirectFBInputDevice *keyboard=NULL;
35 IDirectFBSurface *logo=NULL;
36 IDirectFBFont *font=NULL;
37 char *title_txt="directfb photoshow";
38 char *author_txt="hackbard@hackdaworld.dyndns.org";
39 char *hp_txt="http://hackdaworld.dyndns.org";
40 char *msg1_txt="(press return to continue ...)";
42 void clear_primary(void) {
43 DFBCHECK(primary->SetColor(primary,0x00,0x00,0x00,0x00));
44 DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
47 int main(int argc,char **argv) {
49 DFBInputDeviceKeyState state_enter=DIKS_UP;
50 DFBInputDeviceKeyState state_escape=DIKS_UP;
51 DFBSurfaceDescription dsc;
52 DFBFontDescription font_dsc;
53 IDirectFBImageProvider *img_prov;
55 DFBCHECK(DirectFBInit (&argc, &argv));
57 DFBCHECK(DirectFBCreate(&dfb));
58 DFBCHECK(dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN));
60 dsc.flags=DSDESC_CAPS;
61 dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
62 DFBCHECK(dfb->CreateSurface(dfb,&dsc,&primary));
64 DFBCHECK(primary->GetSize(primary,&screen_width,&screen_height));
65 fprintf(stdout,"dimensions: %dx%d\n",screen_width,screen_height);
67 DFBCHECK(dfb->GetInputDevice(dfb,DIDID_KEYBOARD,&keyboard));
70 font_dsc.flags=DFDESC_HEIGHT;
71 font_dsc.height=screen_height/20;
72 DFBCHECK(dfb->CreateFont(dfb,"/usr/share/DFBSee/decker.ttf",&font_dsc,&font));
73 DFBCHECK(primary->SetFont(primary,font));
74 DFBCHECK(font->GetStringWidth(font,title_txt,-1,&str_width));
76 DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
77 DFBCHECK(primary->DrawString(primary,title_txt,-1,(screen_width-str_width)/2,screen_height/4,DSTF_LEFT));
78 /* author,homepage,msg */
79 font_dsc.height=screen_height/40;
80 DFBCHECK(dfb->CreateFont(dfb,"/usr/share/DFBSee/decker.ttf",&font_dsc,&font));
81 DFBCHECK(primary->SetFont(primary,font));
82 DFBCHECK(font->GetStringWidth(font,author_txt,-1,&str_width));
83 DFBCHECK(primary->DrawString(primary,author_txt,-1,(screen_width-str_width)/2,screen_height/2,DSTF_LEFT));
84 DFBCHECK(font->GetStringWidth(font,hp_txt,-1,&str_width));
85 DFBCHECK(primary->DrawString(primary,hp_txt,-1,(screen_width-str_width)/2,(screen_height/2)+font_dsc.height,DSTF_LEFT));
86 DFBCHECK(font->GetStringWidth(font,msg1_txt,-1,&str_width));
87 DFBCHECK(primary->DrawString(primary,msg1_txt,-1,(screen_width-str_width)/2,(screen_height/2)+3*font_dsc.height,DSTF_LEFT));
88 DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
89 DFBCHECK(keyboard->GetKeyState(keyboard,DIKI_ESCAPE,&state_enter));
90 while(state_enter==DIKS_UP) {
91 DFBCHECK(keyboard->GetKeyState(keyboard,DIKI_ENTER,&state_enter));
95 /* display pictures */
97 while(state_escape==DIKS_UP) {
98 DFBCHECK(dfb->CreateImageProvider(dfb,argv[i],&img_prov));
99 DFBCHECK(img_prov->GetSurfaceDescription(img_prov,&dsc));
100 DFBCHECK(dfb->CreateSurface(dfb,&dsc,&logo ));
101 DFBCHECK(img_prov->RenderTo(img_prov,logo,NULL));
102 img_prov->Release(img_prov);
103 DFBCHECK (primary->SetColor(primary,0x00,0x00,0x00,0x00));
104 DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
105 DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
106 DFBCHECK(primary->DrawLine(primary,0,0,screen_width-1,screen_height-1));
107 if((screen_width>=dsc.width)&&(screen_height>=dsc.height)) {
108 DFBCHECK(primary->Blit(primary,logo,NULL,(screen_width-dsc.width)/2,(screen_height-dsc.height)/2));
111 DFBCHECK(primary->StretchBlit(primary,logo,NULL,NULL));
113 DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
114 sleep(atoi(argv[1]));
116 DFBCHECK(keyboard->GetKeyState(keyboard,DIKI_ESCAPE,&state_escape));
118 if(i==argc) state_escape=DIKS_DOWN;
122 keyboard->Release(keyboard);
124 primary->Release(primary);