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