File: VIEW.C | Size: 3,318 bytes | Download file | Back to directory listing | BWPOW's homepage
#include <conio.h>
#include <allegro.h>
#include <sp1.h>
#include <jpeg.h>
#include <algbm.h>
#include <loadpng.h>
 
extern char gfx_ch;
 
extern char s_d,s_m;
extern int s_w,s_h;
 
int key_checker()
{
      if (key[KEY_ESC]||key[KEY_ENTER]||key[KEY_BACKSPACE])
	 return 1;
      else
	 return 0;
}
 
/*
Return:
 0 - OK
 1 - next
 2 - previous
 3 - select and next
-1 - error
 
*/
int paceplay_view(char t,char d,int w,int h,char filename[45])
{
/*
0 - allegro
1 - jpeg
2 - flic
3 - bgm
4 - SAN
5 - png
*/
   BITMAP *bmp;
   PALETTE pal,bpal;
   int x,y,xx=0,yy=0,c=1;
   int vx,vy,p;
   int sx,sy;
   int k=-1;
   char r=0;
 
//   get_palette(bpal);
 
   if(t==4){
     view_san(filename);
     gfx_ch=1;
     default_gfx();
     return 0;
   }
 
   if(gfx_ch==0){
     gfx_ch=1;
     set_color_depth(d);
     if(set_gfx_mode(0,w,h,0,0)!=0){
       default_gfx();
       billalert("ERROR","Unable to select gfx mode!",0,"&OK",0,'o',0);
       delete_this_gfx_mode();
       return -1;
     }
   }
   if(t==2)
   {
     play_fli(filename,screen,1,key_checker);
     if(key[KEY_ENTER]) r=1;
     if(key[KEY_BACKSPACE]) r=2;
     if(key[KEY_SPACE]) r=3;
 
   }
   if((t==0)||(t==1)||(t==3)||(t==5)||(t==6)){
     if(t==0) bmp=load_bitmap(filename,pal);
     if(t==1) bmp=load_jpeg(filename,pal);
     if(t==3) bmp=load_gbm(filename,pal);
     if(t==5) bmp=load_png(filename,pal);
     if(t==6) bmp=load_sp1(filename);
 
     if(bmp==NULL){
       default_gfx();
       billalert("ERROR","Error loading image!",0,"&OK",0,'o',0);
       return -1;
     }
 
     backgfx:;
     c=1;
 
     set_palette(pal);
 
     xx=bmp->w;yy=bmp->h;
     x=0;y=0;
 
     sx=w/2-xx/2;
     if(sx<0) sx=0;
     sy=h/2-yy/2;
     if(sy<0) sy=0;
 
     vx=xx;
     if(vx>w) vx=w;
     vy=yy;
     if(vy>h) vy=h;
 
     clear(screen);
     while(k!=1)
     {
       if(c==1){
         blit(bmp,screen,x,y,sx,sy,vx,vy);
         c=0;
       }
       if(key[KEY_RSHIFT]||key[KEY_LSHIFT]){
         p=1;
       }
       else p=25;
 
 
       if(key[KEY_UP]&&sy==0){
         y-=p;
         c=1;
         if(y<0){y=0;}
       }
       if(key[KEY_DOWN]&&sy==0){
         y+=p;
         c=1;
         if(y>yy-h){y=yy-h;}
       }
 
 
       if(key[KEY_LEFT]&&sx==0){
         x-=p;
         c=1;
         if(x<0){x=0;}
       }
       if(key[KEY_RIGHT]&&sx==0){
         x+=p;
         c=1;
         if(x>xx-w){x=xx-w;}
       }
 
       if(key[KEY_ASTERISK]){
         if(from_pict_make_gfx_mode()==1){
           gfx_ch=1;
           d=s_d;
           w=s_w;h=s_h;
           set_color_depth(d);
           if(set_gfx_mode(0,w,h,0,0)!=0){
             default_gfx();
             billalert("ERROR","Unable to select gfx mode!",0,"&OK",0,'o',0);
             delete_this_gfx_mode();
             return -1;
           }
           goto backgfx;
         }
 
 
       }
 
       if(key[KEY_ESC]){k=1;r=0;}
       if(key[KEY_ENTER]){k=1;r=1;}
       if(key[KEY_BACKSPACE]){k=1;r=2;}
       if(key[KEY_SPACE]){k=1;r=3;}
     }
 
     destroy_bitmap(bmp);
   }
   if(r==0) default_gfx();
   while(key[KEY_ESC]);
   while(key[KEY_ENTER]);
   while(key[KEY_BACKSPACE]);
   clear_keybuf();
   return r;
}