-
[my-code/dfb-photoshow.git] / dfb-photoshow.c
index 68af401..ea96f8a 100644 (file)
@@ -1,12 +1,20 @@
 /*
  * dfb-photoshow.c
  *
- * author: hackbard
+ * build: gcc -o dfb-photoshow -O3 -Wall -I/usr/X11/include \
+ *        -I/usr/include/directfb dfb-photoshow.c
+ * usage: ./showdir <seconds> <directory>
+ *
+ * author: 
+ * hackbard@hackdaworld.dyndns.org
+ * download: 
+ * cvs -d:pserver:anonymous@hackdaworld.dyndns.org:/my-code co dfb-photoshow
  *
  */
 
 #include <stdio.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <directfb.h>
 
 IDirectFB *dfb = NULL;
@@ -23,12 +31,24 @@ int screen_height = 0;
  } \
 }
 
-IDirectFBSurface *logo = NULL;
-IDirectFBFont *font = NULL;
-char *text = "directfb photoshow (written by hackbard 2003)";
+IDirectFBInputDevice *keyboard=NULL;
+IDirectFBSurface *logo=NULL;
+IDirectFBFont *font=NULL;
+IDirectFBEventBuffer *k_buf=NULL;
+
+char *title_txt="directfb photoshow";
+char *exp_txt="an image presenter ...";
+char *hp_txt="http://hackdaworld.dyndns.org";
+char *msg1_txt="(press key to continue ...)";
+
+void clear_primary(void) {
+ DFBCHECK(primary->SetColor(primary,0x00,0x00,0x00,0x00));
+ DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
+}
 
 int main(int argc,char **argv) {
- int i;
+ int i,str_width;
+ DFBInputEvent k_event;
  DFBSurfaceDescription dsc;
  DFBFontDescription font_dsc;
  IDirectFBImageProvider *img_prov;
@@ -42,48 +62,77 @@ int main(int argc,char **argv) {
  dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
  DFBCHECK(dfb->CreateSurface(dfb,&dsc,&primary));
 
- font_dsc.flags = DFDESC_HEIGHT;
- font_dsc.height = 20;
- DFBCHECK(dfb->CreateFont(dfb,"./decker.ttf",&font_dsc,&font));
- DFBCHECK(primary->SetFont(primary,font));
-
  DFBCHECK(primary->GetSize(primary,&screen_width,&screen_height));
  fprintf(stdout,"dimensions: %dx%d\n",screen_width,screen_height);
 
- /* welcome */
- DFBCHECK(primary->SetColor(primary,0x00,0x00,0x00,0x00));
- DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
+ DFBCHECK(dfb->GetInputDevice(dfb,DIDID_KEYBOARD,&keyboard));
+ DFBCHECK(keyboard->CreateEventBuffer(keyboard,&k_buf));
+
+ /* title */
+ font_dsc.flags=DFDESC_HEIGHT;
+ font_dsc.height=screen_height/20;
+ DFBCHECK(dfb->CreateFont(dfb,"/usr/share/DFBSee/decker.ttf",&font_dsc,&font));
+ DFBCHECK(primary->SetFont(primary,font));
+ DFBCHECK(font->GetStringWidth(font,title_txt,-1,&str_width));
+ clear_primary();
  DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
- DFBCHECK(primary->DrawString(primary,text,-1,5,screen_height/2,DSTF_LEFT));
+ DFBCHECK(primary->DrawString(primary,title_txt,-1,(screen_width-str_width)/2,screen_height/4,DSTF_LEFT));
+ /* explanation,homepage,msg */
+ font_dsc.height=screen_height/40;
+ DFBCHECK(dfb->CreateFont(dfb,"/usr/share/DFBSee/decker.ttf",&font_dsc,&font));
+ DFBCHECK(primary->SetFont(primary,font));
+ DFBCHECK(font->GetStringWidth(font,exp_txt,-1,&str_width));
+ DFBCHECK(primary->DrawString(primary,exp_txt,-1,(screen_width-str_width)/2,screen_height/2,DSTF_LEFT));
+ DFBCHECK(font->GetStringWidth(font,hp_txt,-1,&str_width));
+ DFBCHECK(primary->DrawString(primary,hp_txt,-1,(screen_width-str_width)/2,(screen_height/2)+font_dsc.height,DSTF_LEFT));
+ DFBCHECK(font->GetStringWidth(font,msg1_txt,-1,&str_width));
+ DFBCHECK(primary->DrawString(primary,msg1_txt,-1,(screen_width-str_width)/2,(screen_height/2)+3*font_dsc.height,DSTF_LEFT));
  DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
sleep(10);
DFBCHECK(k_buf->WaitForEvent(k_buf));
  font->Release(font);
- for(i=2;i<argc;i++) {
-  DFBCHECK(dfb->CreateImageProvider(dfb,argv[i],&img_prov));
-  DFBCHECK(img_prov->GetSurfaceDescription(img_prov,&dsc));
-  DFBCHECK(dfb->CreateSurface(dfb,&dsc,&logo ));
-  DFBCHECK(img_prov->RenderTo(img_prov,logo,NULL));
-  img_prov->Release(img_prov);
-  DFBCHECK (primary->SetColor(primary,0x00,0x00,0x00,0x00));
-  DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
-  DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
-  DFBCHECK(primary->DrawLine(primary,0,0,screen_width-1,screen_height-1));
-  if((screen_width>=dsc.width)&&(screen_height>=dsc.height)) {
-   DFBCHECK(primary->Blit(primary,logo,NULL,(screen_width-dsc.width)/2,(screen_height-dsc.height)/2));
-  }
-  else {
-   DFBCHECK(primary->StretchBlit(primary,logo,NULL,NULL));
+
+ /* display pictures */
+ i=2;
+ while(i<argc) {
+  while(k_buf->GetEvent(k_buf,DFB_EVENT(&k_event))==DFB_OK) {
+   if(k_event.type==DIET_KEYPRESS) {
+    if(k_event.key_id==DIKI_ESCAPE) i=argc;
+    if(k_event.key_id==DIKI_SPACE) DFBCHECK(k_buf->WaitForEvent(k_buf));
+   }
+   else {
+    DFBCHECK(dfb->CreateImageProvider(dfb,argv[i],&img_prov));
+    DFBCHECK(img_prov->GetSurfaceDescription(img_prov,&dsc));
+    DFBCHECK(dfb->CreateSurface(dfb,&dsc,&logo ));
+    DFBCHECK(img_prov->RenderTo(img_prov,logo,NULL));
+    img_prov->Release(img_prov);
+    DFBCHECK (primary->SetColor(primary,0x00,0x00,0x00,0x00));
+    DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
+    DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
+    DFBCHECK(primary->DrawLine(primary,0,0,screen_width-1,screen_height-1));
+    if((screen_width>=dsc.width)&&(screen_height>=dsc.height)) {
+     DFBCHECK(primary->Blit(primary,logo,NULL,(screen_width-dsc.width)/2,(screen_height-dsc.height)/2));
+    }
+    else {
+     DFBCHECK(primary->StretchBlit(primary,logo,NULL,NULL));
+    }
+    DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
+    k_buf->WaitForEventWithTimeout(k_buf,atoi(argv[1]),0);
+    // sleep(atoi(argv[1]));
+    if(k_buf->HasEvent(k_buf)!=DFB_OK) {
+     k_event.key_id=DIKI_A;
+     DFBCHECK(k_buf->PostEvent(k_buf,DFB_EVENT(&k_event)));
+    }
+    logo->Release(logo);
+    ++i;
+   }
   }
-  DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
-  sleep(atoi(argv[1]));
-  logo->Release(logo);
  }
 
- primary->Release(logo);
+ k_buf->Release(k_buf);
+ keyboard->Release(keyboard);
+ logo->Release(logo);
  primary->Release(primary);
  dfb->Release(dfb);
 
  return 23; /* ;) */
 }
-