home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / devcon / milan_1991 / devcon91.2 / tiga / demos / cursor.c < prev    next >
C/C++ Source or Header  |  1992-09-01  |  6KB  |  184 lines

  1. #include <exec/types.h>
  2. #include <exec/devices.h>
  3. #include <intuition/intuition.h>
  4. #include <dos.h>
  5.  
  6. #include <a2410/typedefs.h>
  7. #include <a2410/devtiga.h>
  8. #include <clib/a2410_protos.h>
  9.  
  10. struct    GfxBase        *GfxBase;
  11. struct    IntuitionBase    *IntuitionBase;
  12. struct    Window        *Window;
  13.  
  14. /* pack the color 00redbluegreen */
  15. CURSOR pencil = 
  16. {
  17. 0x0000,0x001B,0x0011,0x001C,0x0020,0x00FF0000,1,8,0L
  18. };
  19.  
  20. UBYTE pencil_data[]={
  21. 0xFF,0x87,0x03,0x00,0xFF,0x03,0x03,0x00,
  22. 0xFF,0x03,0x02,0x00,0xFF,0x01,0x02,0x00,0xFF,0x01,0x03,0x00,0xFF,0x00,0x03,0x00,
  23. 0xFF,0x80,0x03,0x00,0x7F,0x80,0x03,0x00,0x7F,0xC0,0x03,0x00,0x3F,0xC0,0x03,0x00,
  24. 0x3F,0xE0,0x03,0x00,0x1F,0xE0,0x03,0x00,0x1F,0xF0,0x03,0x00,0x0F,0xF0,0x03,0x00,
  25. 0x0F,0xF8,0x03,0x00,0x07,0xF8,0x03,0x00,0x07,0xFC,0x03,0x00,0x03,0xFC,0x03,0x00,
  26. 0x03,0xFE,0x03,0x00,0x01,0xFE,0x03,0x00,0x01,0xFF,0x03,0x00,0x00,0xFF,0x03,0x00,
  27. 0x80,0xFF,0x03,0x00,0xC0,0xFF,0x03,0x00,0xE0,0xFF,0x03,0x00,0xF0,0xFF,0x03,0x00,
  28. 0xF8,0xFF,0x03,0x00,0xFD,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,
  29. 0x00,0xF8,0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x72,0x00,0x00,
  30. 0x00,0x26,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x11,0x00,0x00,0x80,0x10,0x00,0x00,
  31. 0x80,0x08,0x00,0x00,0x40,0x08,0x00,0x00,0x40,0x04,0x00,0x00,0x20,0x04,0x00,0x00,
  32. 0x20,0x02,0x00,0x00,0x10,0x02,0x00,0x00,0x10,0x01,0x00,0x00,0x08,0x01,0x00,0x00,
  33. 0x88,0x00,0x00,0x00,0x84,0x00,0x00,0x00,0x44,0x00,0x00,0x00,0x4E,0x00,0x00,0x00,
  34. 0x3E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
  35. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  36. };
  37.  
  38.  
  39.  
  40.  
  41. struct NewWindow NW = {
  42.    0,0,200, 100,         /*LeftEdge,TopEdge,Width,Height*/
  43.    -1,-1,
  44.    MOUSEBUTTONS|MOUSEMOVE|CLOSEWINDOW,    /*IDCMP */
  45.    REPORTMOUSE|SMART_REFRESH|ACTIVATE|WINDOWDRAG|WINDOWCLOSE|WINDOWDEPTH, /*FLAGS */
  46.    NULL,   /* i MuteColor : (struct Gadget *)&GraphicGadget[0] FirstGadget*/
  47.    NULL,                 /*  CheckMark   */
  48.    "TIGA Window",                 /*Title*/
  49.    NULL,                 /*  Screen: Kan foerst saettes naar screen er OK */
  50.    NULL,                 /* BitMap */
  51.    100, 25, 640 ,512 ,   /*MinWidth,MinHeight,MaxWidth,MaxHeight */
  52.    (UWORD) WBENCHSCREEN };        /* Screen Type */
  53.  
  54. /* -------------------------------------------------------------------------------- */
  55.  
  56. void install_cursor(type)
  57. short type;      /* 0=default(arrow), 1=user(pencil)        */
  58. {
  59.     /* Address of user cursor in GSP mem            */
  60.     PTR UserCursData = 0L;
  61.     PTR UserCurs = 0L;
  62.  
  63.     if (type)
  64.     {     /* User cursor type specified            */
  65.         /* Execute this block 1st time only    */
  66.         UserCursData = (PTR) gsp_malloc(sizeof(pencil_data));
  67.             if (UserCursData == 0)
  68.         { printf("Error allocating pencil data\n"); return;}
  69.             pencil.data = UserCursData;
  70.             UserCurs = (PTR)gsp_malloc(sizeof(pencil));
  71.         if (UserCurs==0)
  72.         { printf("Error allocating user cursor data structure\n");
  73.           gsp_free(UserCursData);
  74.           return;
  75.         }
  76.         /*try first sending down first 5 elements of the header*/
  77.             host2gsp ((char*)&pencil, UserCurs, 10, 0);
  78.         /* now send down the color ,which is a long */
  79.         host2gsp((char*)&(pencil.color),(UserCurs+0x50L),4,2);
  80.         /* now send down the two raster ops  */ 
  81.         host2gsp((char*)&(pencil.mask_rop),(UserCurs+0x70L),4,0); 
  82.             /* and the data pointer */
  83.         host2gsp((char*)&(pencil.data),(UserCurs+0x90L),4,2);
  84.         /* now send down the data  itself*/
  85.         host2gsp(pencil_data,UserCursData,sizeof(pencil_data),1);
  86.         printf("Setting the shape to UserCurs\n");
  87.             set_curs_shape(UserCurs);
  88.     }
  89.        else
  90.     {
  91.          printf("Setting the shape to default cursor\n");
  92.          set_curs_shape( (PTR) 0);    /* Use default if type==0 */
  93.     }
  94.     set_curs_state(1);    /* enable */
  95. }   
  96.  
  97. void    remove_cursor()
  98. {
  99.     set_curs_state(0);
  100. }
  101. /* ================================================================================ */
  102. void InitGraphics()
  103. {
  104.  
  105.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 33 );
  106.   if ( GfxBase == NULL ) return;
  107.  
  108.   IntuitionBase = (struct IntuitionBase *)  OpenLibrary("intuition.library", 33 );
  109.   if ( IntuitionBase == NULL) return;
  110.  
  111.   if (( Window = (struct Window *)OpenWindow(&NW)) == NULL)
  112.      return;
  113. }/* END InitrGraphic() */
  114. /* ----------------------------------------------------------------- */
  115. void    CloseGraphics(void)
  116. {
  117.   if (Window) CloseWindow(Window);
  118.   if (IntuitionBase) CloseLibrary(IntuitionBase);
  119.   if (GfxBase) CloseLibrary(GfxBase);
  120. }
  121.  
  122.  
  123. void    GetInput()
  124. {       /* waits for closegadg event */
  125.   ULONG  class;
  126.   UWORD  code,stop,x_coor,y_coor,old_x,old_y;
  127.   struct IntuiMessage  *message;
  128.   int       WakeupMask;
  129.  
  130.   stop = FALSE;
  131.   old_x = Window->MouseX;    /* start where pointer is right now */
  132.   old_y = Window->MouseY;
  133.   while (!stop)
  134.   { 
  135.      WakeupMask = Wait( (1<<Window->UserPort->mp_SigBit) );
  136.      if ( WakeupMask & ((1<<Window->UserPort->mp_SigBit)) )
  137.       {
  138.           while ( message = (struct IntuiMessage *)    
  139.                 GetMsg( Window -> UserPort ) )      
  140.           {
  141.             class = message -> Class;
  142.             code  = message -> Code;
  143.         x_coor = message->MouseX;
  144.         y_coor = message->MouseY;    
  145.             ReplyMsg( message );
  146.  
  147.             switch (class)
  148.             {
  149.               case MOUSEMOVE:
  150.         set_curs_xy(x_coor,y_coor);
  151.         draw_line(old_x,old_y,x_coor,y_coor);
  152.         old_x = x_coor;
  153.         old_y = y_coor;
  154.         break;
  155.               case MOUSEBUTTONS :
  156.               case GADGETDOWN : 
  157.               case GADGETUP   : 
  158.               case MENUPICK   : break;
  159.           case CLOSEWINDOW: stop = TRUE;break;
  160.               default         : break;
  161.             }
  162.           }
  163.       }
  164.   }
  165. } /* END:  GetInput() */
  166. /* --------------------------------------------------------------------------------- */
  167.  
  168. main()
  169. {
  170.     if (TIGA_Init())
  171.      {
  172.         InitGraphics();
  173.         install_cursor(0);
  174.         GetInput();
  175.         install_cursor(1);
  176.         GetInput();
  177.         remove_cursor();
  178.         CloseGraphics();
  179.         TIGA_Close();
  180.      }
  181. }
  182.  
  183. /* ===================================================================================== */
  184.