home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / graphics / sprite_bob_anim / bob / bob.c next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  6.1 KB  |  217 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /* bob.c 19oct89
  23. **
  24. ** lattice c 5.04
  25. ** lc -b1 -cfist -v -y bob.c
  26. ** blink FROM LIB:c.o bob.o /animtools/animtools.o LIB LIB:lc.lib TO bob
  27. */
  28. #include <exec/types.h>
  29. #include <intuition/intuition.h>
  30. #include <graphics/gels.h>
  31. #include <exec/memory.h>
  32. #include <libraries/dos.h>
  33.  
  34. #include <proto/all.h>
  35. #include <stdlib.h>
  36.  
  37. #include "/animtools/animtools.h"
  38. #include "/animtools/animtools_proto.h"
  39.  
  40. VOID bobDrawGList(struct RastPort *rport, struct ViewPort *vport);
  41. VOID process_window(struct Window *win, struct Bob *myBob);
  42. VOID do_Bob(struct Window *win);
  43.  
  44. struct GfxBase         *GfxBase;       /* pointer to Graphics library */
  45. struct IntuitionBase *IntuitionBase; /* pointer to Intuition library */
  46.  
  47. int return_code;
  48.  
  49. /* number of lines in the bob */
  50. #define GEL_SIZE    4
  51.  
  52. /* bob data - there are two sets that are alternated between.
  53. ** note that this data is at the resolution of the screen.
  54. */
  55. WORD chip bob_data1[2 * 2 * GEL_SIZE] =
  56.     { /* data is 2 planes by 2 words by GEL_SIZE lines */
  57.     /* plane 1 */
  58.     0xffff, 0x0003, 0xfff0, 0x0003, 0xfff0, 0x0003, 0xffff, 0x0003,
  59.     /* plane 2 */
  60.     0x3fff, 0xfffc, 0x3ff0, 0x0ffc, 0x3ff0, 0x0ffc, 0x3fff, 0xfffc,
  61.     };
  62.  
  63. WORD chip bob_data2[2 * 2 * GEL_SIZE] =
  64.     { /* data is 2 planes by 2 words by GEL_SIZE lines */
  65.     /* plane 1 */
  66.     0xc000, 0xffff, 0xc000, 0x0fff, 0xc000, 0x0fff, 0xc000, 0xffff,
  67.     /* plane 2 */
  68.     0x3fff, 0xfffc, 0x3ff0, 0x0ffc, 0x3ff0, 0x0ffc, 0x3fff, 0xfffc,
  69.     };
  70.  
  71. /* information for the new bob
  72. ** structure defined in animtools.h
  73. */
  74. NEWBOB myNewBob =
  75.     {
  76.     bob_data2,            /* initial image            */
  77.     2,                    /* WORD width                */
  78.     GEL_SIZE,            /* line height                */
  79.     2,                    /* image depth                */
  80.     3, 0,                /* plane pick, plane on off    */
  81.     SAVEBACK | OVERLAY,    /* vsprite flags            */
  82.     0,                    /* dbuf (0 == false)        */
  83.     2,                    /* raster depth                */
  84.     160, 100,            /* x,y position                */
  85.     0,0,                /* hit mask, me mask        */
  86.     };
  87.  
  88. /* information for the new window */
  89. struct NewWindow myNewWindow =
  90.     {
  91.     80, 20, 400, 150, -1, -1, CLOSEWINDOW | INTUITICKS,
  92.     ACTIVATE | WINDOWCLOSE | WINDOWDEPTH | RMBTRAP,
  93.     NULL, NULL, "Bob", NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
  94.     };
  95.  
  96. /*-------------------------------------------------------------
  97. ** draw the bobs into the rast port.
  98. */
  99. VOID bobDrawGList(struct RastPort *rport, struct ViewPort *vport)
  100. {
  101. /* only need to MrgCop() LoadView() if using TRUE VSprites */
  102. SortGList(rport);
  103. DrawGList(rport, vport);
  104. WaitTOF() ;
  105. }
  106.  
  107. /*-------------------------------------------------------------
  108. ** process window and dynamically change bob:
  109. ** - get messages.
  110. ** - go away on CLOSEWINDOW.
  111. ** - update and redisplay bob on INTUITICKS.
  112. ** - wait for more messages.
  113. */
  114. VOID process_window(struct Window *win, struct Bob *myBob)
  115. {
  116. struct IntuiMessage *msg;
  117.  
  118. FOREVER
  119.     {
  120.     Wait(1L << win->UserPort->mp_SigBit);
  121.  
  122.     while (NULL != (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  123.         {
  124.         /* only CLOSEWINDOW and INTUITICKS are active */
  125.         if (msg->Class == CLOSEWINDOW)
  126.             {
  127.             ReplyMsg((struct Message *)msg);
  128.             return;
  129.             }
  130.  
  131.         /* must be INTUITICKS:  change x and y values on the fly
  132.         ** note:  do not have to add window offset, bob is relative
  133.         ** to the window (sprite relative to screen).
  134.         */
  135.         myBob->BobVSprite->X = msg->MouseX + 20;
  136.         myBob->BobVSprite->Y = msg->MouseY + 1;
  137.         ReplyMsg((struct Message *)msg);
  138.         }
  139.  
  140.     /* after getting a message, change image data on the fly */
  141.     myBob->BobVSprite->ImageData =
  142.         (myBob->BobVSprite->ImageData == bob_data1) ? bob_data2 : bob_data1;
  143.  
  144.     InitMasks(myBob->BobVSprite); /* set up masks for new image */
  145.     bobDrawGList(win->RPort, ViewPortAddress(win));
  146.     }
  147. }
  148.  
  149. /*-------------------------------------------------------------
  150. ** working with the bob:
  151. ** - setup the gel system, and get a new bob (makeBob()).
  152. ** - add the bob to the system and display.
  153. ** - use the bob.
  154. ** - when done, remove the bob and update the display without the bob.
  155. ** - cleanup everything.
  156. */
  157. VOID do_Bob(struct Window *win)
  158. {
  159. struct Bob       *myBob;
  160. struct GelsInfo       *my_ginfo;
  161.  
  162. if (NULL == (my_ginfo = setupGelSys(win->RPort, 0xfc)))
  163.     return_code = RETURN_WARN;
  164. else
  165.     {
  166.     if (NULL == (myBob = makeBob(&myNewBob)))
  167.         return_code = RETURN_WARN;
  168.     else
  169.         {
  170.         AddBob(myBob, win->RPort);
  171.         bobDrawGList(win->RPort, ViewPortAddress(win));
  172.  
  173.         process_window(win, myBob);
  174.  
  175.         RemBob(myBob);
  176.         bobDrawGList(win->RPort, ViewPortAddress(win));
  177.  
  178.         freeBob(myBob, myNewBob.nb_RasDepth);
  179.         }
  180.     cleanupGelSys(my_ginfo,win->RPort);
  181.     }
  182. }
  183.  
  184. /*-------------------------------------------------------------
  185. ** example bob program:
  186. ** - first open up the libraries and a window.
  187. */
  188. VOID main(int argc, char **argv)
  189. {
  190. struct Window       *win;
  191.  
  192. return_code = RETURN_OK;
  193.  
  194. if (NULL == (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",33L)))
  195.     return_code = RETURN_FAIL;
  196. else
  197.     {
  198.     if (NULL == (IntuitionBase =
  199.             (struct IntuitionBase *)OpenLibrary("intuition.library",33L)))
  200.         return_code = RETURN_FAIL;
  201.     else
  202.         {
  203.         if (NULL == (win = OpenWindow(&myNewWindow)))
  204.             return_code = RETURN_FAIL;
  205.         else
  206.             {
  207.             do_Bob(win);
  208.  
  209.             CloseWindow(win);
  210.             }
  211.         CloseLibrary(IntuitionBase);
  212.         }
  213.     CloseLibrary(GfxBase);
  214.     }
  215. exit(return_code);
  216. }
  217.