X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fdfb-photoshow.git;a=blobdiff_plain;f=dfb-photoshow.c;h=c3da3659ecc57a677c7a90c47b73aa51dba71463;hp=4975c733f7db7f1700061c2ae76f9abff8029176;hb=1a271d36354a6963451c441666ac8e489172c74f;hpb=4f8a1d8f1939a3c7ddd6a442be2e3ebf13bd5298 diff --git a/dfb-photoshow.c b/dfb-photoshow.c index 4975c73..c3da365 100644 --- a/dfb-photoshow.c +++ b/dfb-photoshow.c @@ -34,10 +34,12 @@ int screen_height = 0; IDirectFBInputDevice *keyboard=NULL; IDirectFBSurface *logo=NULL; IDirectFBFont *font=NULL; +IDirectFBEventBuffer *k_buf=NULL; + char *title_txt="directfb photoshow"; -char *author_txt="hackbard@hackdaworld.dyndns.org"; +char *exp_txt="an image presenter ..."; char *hp_txt="http://hackdaworld.dyndns.org"; -char *msg1_txt="(press return to continue ...)"; +char *msg1_txt="(press key to continue, space pauses, left key for last image, esc quits ...)"; void clear_primary(void) { DFBCHECK(primary->SetColor(primary,0x00,0x00,0x00,0x00)); @@ -46,8 +48,7 @@ void clear_primary(void) { int main(int argc,char **argv) { int i,str_width; - DFBInputDeviceKeyState state_enter=DIKS_UP; - DFBInputDeviceKeyState state_escape=DIKS_UP; + DFBInputEvent k_event; DFBSurfaceDescription dsc; DFBFontDescription font_dsc; IDirectFBImageProvider *img_prov; @@ -65,6 +66,7 @@ int main(int argc,char **argv) { fprintf(stdout,"dimensions: %dx%d\n",screen_width,screen_height); DFBCHECK(dfb->GetInputDevice(dfb,DIDID_KEYBOARD,&keyboard)); + DFBCHECK(keyboard->CreateEventBuffer(keyboard,&k_buf)); /* title */ font_dsc.flags=DFDESC_HEIGHT; @@ -75,48 +77,78 @@ int main(int argc,char **argv) { clear_primary(); DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff)); DFBCHECK(primary->DrawString(primary,title_txt,-1,(screen_width-str_width)/2,screen_height/4,DSTF_LEFT)); - /* author,homepage,msg */ + /* 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,author_txt,-1,&str_width)); - DFBCHECK(primary->DrawString(primary,author_txt,-1,(screen_width-str_width)/2,screen_height/2,DSTF_LEFT)); + 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)); - DFBCHECK(keyboard->GetKeyState(keyboard,DIKI_ESCAPE,&state_enter)); - while(state_enter==DIKS_UP) { - DFBCHECK(keyboard->GetKeyState(keyboard,DIKI_ENTER,&state_enter)); - } - font->Release(font); + DFBCHECK(k_buf->WaitForEvent(k_buf)); /* display pictures */ - while(state_escape==DIKS_UP) { - for(i=2;iGetEvent(k_buf,DFB_EVENT(&k_event))!=0) { + if(k_event.type==DIET_KEYPRESS) { + int a; + a=(int)k_event.key_id; + if(a==(int)DIKI_ESCAPE) { + i=argc; + break; + } + if(a==(int)DIKI_SPACE) { + char *pause_txt="paused (press button to continue)"; + DFBCHECK(font->GetStringWidth(font,pause_txt,-1,&str_width)); + DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff)); + 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)); + k_event.key_id=DIKI_A; /* no longer pause! */ + } + if(a==(int)DIKI_LEFT) { + i=((i<=3)?2:i-2); + k_event.key_id=DIKI_A; /* no longer back key! */ + break; + } + } + } DFBCHECK(dfb->CreateImageProvider(dfb,argv[i],&img_prov)); DFBCHECK(img_prov->GetSurfaceDescription(img_prov,&dsc)); + if((screen_width=q_h) { + dsc.width=(int)(dsc.width/q_w); + dsc.height=(int)(dsc.height/q_w); + } else { + dsc.width=(int)(dsc.width/q_h); + dsc.height=(int)(dsc.height/q_h); + } + } 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)); - } + clear_primary(); + DFBCHECK(primary->Blit(primary,logo,NULL,(screen_width-dsc.width)/2,(screen_height-dsc.height)/2)); DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC)); - sleep(atoi(argv[1])); + DFBCHECK(k_buf->Reset(k_buf)); + k_buf->WaitForEventWithTimeout(k_buf,atoi(argv[1]),0); logo->Release(logo); - DFBCHECK(keyboard->GetKeyState(keyboard,DIKI_ESCAPE,&state_escape)); - } + ++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); primary->Release(primary); @@ -124,4 +156,3 @@ int main(int argc,char **argv) { return 23; /* ;) */ } -