improved event stuff, though not very nice
authorhackbard <hackbard>
Wed, 26 Feb 2003 18:40:47 +0000 (18:40 +0000)
committerhackbard <hackbard>
Wed, 26 Feb 2003 18:40:47 +0000 (18:40 +0000)
dfb-photoshow.c

index ea96f8a..f13b926 100644 (file)
@@ -89,45 +89,58 @@ int main(int argc,char **argv) {
  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));
  DFBCHECK(k_buf->WaitForEvent(k_buf));
- font->Release(font);
 
  /* display pictures */
+ DFBCHECK(k_buf->Reset(k_buf));
  i=2;
  while(i<argc) {
-  while(k_buf->GetEvent(k_buf,DFB_EVENT(&k_event))==DFB_OK) {
+  do {
    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));
+    int a;
+    puts("debug: key pressed!");
+    a=(int)k_event.key_id;
+    printf("debug: key id -> %d\n",a);
+    printf("\tp=%d,' '=%d\n",(int)DIKI_ESCAPE,(int)DIKI_SPACE);
+    if(a==(int)DIKI_ESCAPE) {
+     i=argc;
+     break;
     }
-    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)));
+    if(a==(int)DIKI_SPACE) {
+     char *pause_txt="paused (press button to continue)";
+     DFBCHECK(font->GetStringWidth(font,pause_txt,-1,&str_width));
+     DFBCHECK(primary->DrawString(primary,pause_txt,-1,(screen_width-str_width)/2,screen_height/2,DSTF_LEFT));
+     DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
+     DFBCHECK(k_buf->Reset(k_buf));
+     DFBCHECK(k_buf->WaitForEvent(k_buf));
     }
-    logo->Release(logo);
-    ++i;
+    DFBCHECK(k_buf->Reset(k_buf)); /* destroy space press */
+    DFBCHECK(k_buf->Reset(k_buf)); /* destroy space release */
    }
-  }
+   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));
+   // sleep(atoi(argv[1]));
+   k_buf->WaitForEventWithTimeout(k_buf,atoi(argv[1]),0);
+   logo->Release(logo);
+   ++i;
+   if(i==argc) break;
+  } while(k_buf->GetEvent(k_buf,DFB_EVENT(&k_event))==DFB_OK);
  }
 
+ font->Release(font);
  k_buf->Release(k_buf);
  keyboard->Release(keyboard);
  logo->Release(logo);