home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / s1 / sesanim / !SESanim / Sources / c / unbuffered < prev   
Text File  |  1997-05-12  |  6KB  |  214 lines

  1. #include "Wimp.h"
  2. #include "Desklib:Event.h"
  3. #include "Desklib:Error.h"
  4. #include "Desklib:Window.h"
  5. #include "Desklib:Resource.h"
  6. #include "Desklib:WimpSwis.h"
  7. #include "Desklib:icon.h"
  8. #include "Desklib:Pointer.h"
  9. #include "Desklib:Window.h"
  10. #include "Desklib:Template.h"
  11. #include "Desklib:Handler.h"
  12. #include "Desklib:SWI.h"
  13. #include "Desklib:File.h"
  14. #include "Desklib:Sprite.h"
  15. #include "InterGif:Bitmap.h"
  16. #include "InterGif:MakeOne.h"
  17. static sprite_area usersp;
  18. static int next=1<<29;
  19. static BOOL quit=FALSE;
  20. static anim image;
  21. static int size;
  22. static window_handle info_window, main_window, ctrl_window;
  23. static menu_ptr main_menu;
  24. sprite_area f=NULL;
  25. static int width,height;
  26. static int number;
  27. static char namebuffer[256];
  28. static int pend=0;
  29. static void * file;
  30.  
  31. static BOOL Close(event_pollblock *e,void *r){
  32.   if(e->data.words[0]==main_window){
  33.     quit=TRUE;
  34.   }else{
  35.     Wimp_CloseWindow(e->data.words[0]);
  36.   }
  37. }
  38.  
  39.  
  40. static BOOL OpenCtrl(event_pollblock *e, void *r){
  41.   drag_block g;
  42.   switch(e->data.mouse.button.value){
  43.     case 4 : Window_Show(ctrl_window,open_WHEREVER);break;
  44.     case 1 : quit=TRUE;break;
  45.     case 2 : g.window=main_window;g.type=drag_MOVEWINDOW;
  46.       Wimp_DragBox(&g);break;
  47.   }
  48.   return 1;
  49. }
  50.  
  51.  
  52.  
  53. static BOOL Update(event_pollblock *e,void *r){
  54.    window_redrawblock g;
  55.    int more;
  56.    int delay,late=0;
  57.      if(Icon_GetSelect(ctrl_window,0)){
  58.        number=((number+1)%image->nFrames);
  59.        SWI(0,1,SWI_OS_ReadMonotonicTime,&next);
  60.      }
  61.      Anim_MakeOneSprite(image,f,size,number,&delay);
  62.      if(Icon_GetSelect(ctrl_window,0)){
  63.        next+=delay;
  64.      }else{
  65.        next=1<<29;
  66.      }
  67.      Icon_printf(ctrl_window,6,"%d",number);
  68.      g.window=main_window;
  69.      g.rect.min.x=0;
  70.      g.rect.min.y=-height;
  71.      g.rect.max.x=width;
  72.      g.rect.max.y=0;
  73.      if(!(int)r){
  74.        Wimp_UpdateWindow(&g,&more);
  75.        while(more!=0){
  76.          Wimp_GetRectangle(&g,&more);
  77.         }
  78.      }
  79.   return 1;
  80. }
  81.  
  82. void MakeWind(int x1,int x2, int flags,int behind){
  83.   window_block b;
  84.   icon_createblock i;
  85.   int d;
  86.   b.screenrect.min.x=x1;
  87.   b.screenrect.min.y=x2;
  88.   b.screenrect.max.x=width+x1;
  89.   b.screenrect.max.y=height+x2;
  90.   b.scroll.x=0;
  91.   b.scroll.y=0;
  92.   b.behind=behind;
  93.   b.flags.value=flags;
  94.   b.colours[0]=7;
  95.   b.colours[1]=2;
  96.   b.colours[2]=7;
  97.   b.colours[3]=1;
  98.   b.colours[4]=3;
  99.   b.colours[5]=1;
  100.   b.colours[6]=12;
  101.   b.colours[7]=0;
  102.   b.workarearect.min.x=0;
  103.   b.workarearect.max.y=0;
  104.   b.workarearect.min.y=-height;
  105.   b.workarearect.max.x=width;
  106.   b.titleflags.value=0x19;
  107.   b.workflags.value=3<<19;
  108.   b.spritearea=(void *) 1;
  109.   b.minsize.x=0;
  110.   b.minsize.y=0;
  111.   strcpy(b.title.text,"Animation");
  112.   b.numicons=0;
  113.   Wimp_CreateWindow(&b,&main_window);
  114.   i.window=main_window;
  115.   i.icondata.workarearect.min.x=0;
  116.   i.icondata.workarearect.min.y=-height;
  117.   i.icondata.workarearect.max.x=width;
  118.   i.icondata.workarearect.max.y=0;
  119.   i.icondata.flags.value=0x311A;
  120.   i.icondata.data.indirectsprite.name=(char *) f;
  121.   i.icondata.data.indirectsprite.spritearea=f;
  122.   i.icondata.data.indirectsprite.nameisname=0;
  123.   Wimp_CreateIcon(&i,&d);
  124. }
  125.  
  126. static BOOL load(char *name)
  127. {
  128.   int w,h,m,eg,delay;
  129.   size=File_Size(name);
  130.   file=(void *) malloc(size);
  131.   File_LoadTo(name,file,&size);
  132.   image = Anim_FromData(file,size);
  133.   size=Anim_MakeOneSprite(image,NULL,0,0,NULL);
  134.   f = (sprite_area) malloc(size);
  135.   Anim_MakeOneSprite(image,f,size,0,&delay);
  136.   SWI(3,7,SWI_OS_SpriteOp,512+40,(int) f,((int)f)+f->firstoffset,
  137.     NULL,NULL,NULL,&w,&h,NULL,&m);
  138.   SWI(2,3,SWI_OS_ReadModeVariable,m,4,NULL,NULL,&eg);
  139.   width=w<<eg;
  140.   SWI(2,3,SWI_OS_ReadModeVariable,m,5,NULL,NULL,&eg);
  141.   height=h<<eg;
  142.   MakeWind(0,0,Icon_GetSelect(ctrl_window,8) ? 0x80000012 : 0xFF000012,-1);
  143.   number=-1;
  144.   Icon_SetSelect(ctrl_window,0,1);
  145.   Icon_SetSelect(ctrl_window,1,0);
  146.   SWI(0,1,SWI_OS_ReadMonotonicTime,&next);
  147.   Update(NULL,(void *)0);
  148.   Window_Show(main_window,open_CENTERED);
  149.   return 1;
  150. }
  151.  
  152.  
  153.  
  154.  
  155. static BOOL CtrlClick(event_pollblock *e, void *r){
  156.   int x,y;
  157.   window_state state;
  158.   switch (e->data.mouse.icon){
  159.     case 0 : next=0;Update(NULL,NULL);break;
  160.     case 1 : Update(NULL,NULL);next=1<<29;break;
  161.     case 2 :
  162.       Icon_SetSelect(ctrl_window,0,0);
  163.       Icon_SetSelect(ctrl_window,1,1);
  164.       number=(number+1)%image->nFrames;
  165.       Update(NULL,NULL);
  166.       next=1<<29;break;
  167.     case 3 :
  168.       Icon_SetSelect(ctrl_window,0,0);
  169.       Icon_SetSelect(ctrl_window,1,1);
  170.       y=(number-1)%image->nFrames;
  171.       for(number=0;number<y;number++){
  172.         Update(NULL,(void *)1);
  173.       }
  174.       Update(NULL,(void *)0);
  175.       next=1<<29;break;
  176.     case 8 :
  177.       Wimp_GetWindowState(main_window,&state);
  178.       Window_Delete(main_window);
  179.       MakeWind(state.openblock.screenrect.min.x,
  180.                state.openblock.screenrect.min.y,
  181.                Icon_GetSelect(ctrl_window,8) ? 0x80000012 : 0xFF000012,
  182.                state.openblock.behind);
  183.       Wimp_GetWindowState(main_window,&state);
  184.       Wimp_OpenWindow(&state.openblock);
  185.   }
  186.   return 1;
  187. }
  188.  
  189. void main(int argc, char * argv[]){
  190.   icon_handle baricon;
  191.   event_pollblock event;
  192.   event_pollmask mask;
  193.   char appname[64] = "Animation";
  194.   Resource_Initialise("SESAnimate");
  195.   usersp = Sprite_LoadFile("<SESAnimate$Dir>.Sprites");
  196.   Event_Initialise(appname);
  197.   Template_LoadFile("Templates");
  198.   Template_UseSpriteArea(usersp);
  199.   ctrl_window=Window_Create("Control",30);
  200.   Icon_SetSelect(ctrl_window,0,1);
  201.   Icon_printf(ctrl_window,5,"Frame");
  202.   Event_Claim(event_CLICK,ctrl_window,event_ANY,CtrlClick,NULL);
  203.   Event_Claim(event_CLICK,event_ANY,event_ANY,OpenCtrl,NULL);
  204.   Event_Claim(event_OPEN,event_ANY,event_ANY,Handler_OpenWindow,NULL);
  205.   Event_Claim(event_CLOSE,event_ANY,event_ANY,Close,NULL);
  206.   Event_Claim(event_NULL,event_ANY,event_ANY,Update,0);
  207.   if(argc==2) load(argv[1]);
  208.   while(!quit){
  209.     mask.value=0;
  210.     Wimp_PollIdle(mask,&event,next);
  211.     Event_Process(&event);
  212.   }
  213. }
  214.