title bild
[my-code/dfb-photoshow.git] / dfb-photoshow.c
1 /*
2  * dfb-photoshow.c
3  *
4  * author: hackbard
5  *
6  */
7
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include <directfb.h>
12
13 IDirectFB *dfb = NULL;
14 IDirectFBSurface *primary = NULL;
15 int screen_width  = 0;
16 int screen_height = 0;
17
18 #define DFBCHECK(x...) \
19 { \
20  DFBResult err=x; \
21  if(err!=DFB_OK) { \
22   fprintf(stderr,"file: %s , line: %d !\n\t",__FILE__,__LINE__); \
23   DirectFBErrorFatal( #x, err ); \
24  } \
25 }
26
27 IDirectFBSurface *logo = NULL;
28 IDirectFBFont *font = NULL;
29 char *title_txt = "directfb photoshow";
30 char *author_txt="hackbard@hackdaworld.dyndns.org";
31 char *hp_txt="http://hackdaworld.dyndns.org";
32 char *msg1_txt="(press return to continue ...)";
33
34 void clear_primary(void) {
35  DFBCHECK(primary->SetColor(primary,0x00,0x00,0x00,0x00));
36  DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
37 }
38
39 int main(int argc,char **argv) {
40  int i,str_width;
41  DFBSurfaceDescription dsc;
42  DFBFontDescription font_dsc;
43  IDirectFBImageProvider *img_prov;
44
45  DFBCHECK(DirectFBInit (&argc, &argv));
46
47  DFBCHECK(DirectFBCreate(&dfb));
48  DFBCHECK(dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN));
49
50  dsc.flags=DSDESC_CAPS;
51  dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
52  DFBCHECK(dfb->CreateSurface(dfb,&dsc,&primary));
53
54  DFBCHECK(primary->GetSize(primary,&screen_width,&screen_height));
55  fprintf(stdout,"dimensions: %dx%d\n",screen_width,screen_height);
56
57  /* title */
58  font_dsc.flags=DFDESC_HEIGHT;
59  font_dsc.height=screen_height/20;
60  DFBCHECK(dfb->CreateFont(dfb,"/usr/share/DFBSee/decker.ttf",&font_dsc,&font));
61  DFBCHECK(primary->SetFont(primary,font));
62  DFBCHECK(font->GetStringWidth(font,title_txt,-1,&str_width));
63  clear_primary();
64  DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
65  DFBCHECK(primary->DrawString(primary,title_txt,-1,(screen_width-str_width)/2,screen_height/4,DSTF_LEFT));
66  /* author,homepage,msg */
67  font_dsc.height=screen_height/40;
68  DFBCHECK(dfb->CreateFont(dfb,"/usr/share/DFBSee/decker.ttf",&font_dsc,&font));
69  DFBCHECK(primary->SetFont(primary,font));
70  DFBCHECK(font->GetStringWidth(font,author_txt,-1,&str_width));
71  DFBCHECK(primary->DrawString(primary,author_txt,-1,(screen_width-str_width)/2,screen_height/2,DSTF_LEFT));
72  DFBCHECK(font->GetStringWidth(font,hp_txt,-1,&str_width));
73  DFBCHECK(primary->DrawString(primary,hp_txt,-1,(screen_width-str_width)/2,(screen_height/2)+font_dsc.height,DSTF_LEFT));
74  DFBCHECK(font->GetStringWidth(font,msg1_txt,-1,&str_width));
75  DFBCHECK(primary->DrawString(primary,msg1_txt,-1,(screen_width-str_width)/2,(screen_height/2)+3*font_dsc.height,DSTF_LEFT));
76  DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
77  getc(stdin);
78  font->Release(font);
79
80  /* display pictures */ 
81  for(i=2;i<argc;i++) {
82   DFBCHECK(dfb->CreateImageProvider(dfb,argv[i],&img_prov));
83   DFBCHECK(img_prov->GetSurfaceDescription(img_prov,&dsc));
84   DFBCHECK(dfb->CreateSurface(dfb,&dsc,&logo ));
85   DFBCHECK(img_prov->RenderTo(img_prov,logo,NULL));
86   img_prov->Release(img_prov);
87   DFBCHECK (primary->SetColor(primary,0x00,0x00,0x00,0x00));
88   DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
89   DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
90   DFBCHECK(primary->DrawLine(primary,0,0,screen_width-1,screen_height-1));
91   if((screen_width>=dsc.width)&&(screen_height>=dsc.height)) {
92    DFBCHECK(primary->Blit(primary,logo,NULL,(screen_width-dsc.width)/2,(screen_height-dsc.height)/2));
93   }
94   else {
95    DFBCHECK(primary->StretchBlit(primary,logo,NULL,NULL));
96   }
97   DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
98   sleep(atoi(argv[1]));
99   logo->Release(logo);
100  }
101
102  primary->Release(logo);
103  primary->Release(primary);
104  dfb->Release(dfb);
105
106  return 23; /* ;) */
107 }
108