home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / code_examples / fade / fade.zoo / test.c < prev   
C/C++ Source or Header  |  1989-06-15  |  6KB  |  310 lines

  1. #include    <exec/types.h>
  2. #include    <intuition/intuition.h>
  3. #include    <proto/intuition.h>
  4. #include    <proto/exec.h>
  5. #include    <intuition/screens.h>
  6. #include    <graphics/view.h>
  7.  
  8. #define Black        0
  9. #define White        1
  10. #define Red        2
  11. #define Green        3
  12. #define Blue        4
  13. #define Yellow        5
  14. #define Purple        6
  15. #define Gray        7
  16.  
  17. WORD colortable1[] = {
  18.     0x0000,
  19.     0x0fff,
  20.     0x0f00,
  21.     0x00f0,
  22.     0x025f,
  23.     0x0ff0,
  24.     0x0a0f,
  25.     0x0888 };
  26.  
  27. WORD colortable2[] = {
  28.     0x0f00,
  29.     0x00b1,
  30.     0x061f,
  31.     0x0fac,
  32.     0x06fe,
  33.     0x0fb0,
  34.     0x0fff,
  35.     0x0c1f };
  36.  
  37. UWORD chip sys_in_dat[144] = {
  38.  
  39. /* Plane 0 */
  40.  
  41. 0xffff, 0xffff, 0xffff, 0xffc0, 
  42. 0xe1ff, 0xffff, 0xf81f, 0xffc0, 
  43. 0xccff, 0xffff, 0xfe7f, 0xffc0, 
  44. 0xc7cc, 0xe0ff, 0xfe78, 0x3fc0, 
  45. 0xe3cc, 0xcfc0, 0xfe79, 0x9fc0, 
  46. 0xf8cc, 0xe1ff, 0xfe79, 0x9fc0, 
  47. 0xcce1, 0xfcff, 0xfe79, 0x9fc0, 
  48. 0xe1f3, 0xc1ff, 0xf819, 0x9fc0, 
  49. 0xffc7, 0xffff, 0xffff, 0xffc0, 
  50. 0xffff, 0xffff, 0xffff, 0xffc0, 
  51. 0x0000, 0x0000, 0x0000, 0x0000, 
  52. 0x0000, 0x0000, 0x0000, 0x0000, 
  53.  
  54. /* Plane 1 */
  55.  
  56. 0x0000, 0x0000, 0x0000, 0x0000, 
  57. 0x0000, 0x0000, 0x0000, 0x003c, 
  58. 0x0000, 0x0000, 0x0000, 0x003c, 
  59. 0x0000, 0x0000, 0x0000, 0x003c, 
  60. 0x0000, 0x0000, 0x0000, 0x003c, 
  61. 0x0000, 0x0000, 0x0000, 0x003c, 
  62. 0x0000, 0x0000, 0x0000, 0x003c, 
  63. 0x0000, 0x0000, 0x0000, 0x003c, 
  64. 0x0000, 0x0000, 0x0000, 0x003c, 
  65. 0x0000, 0x0000, 0x0000, 0x003c, 
  66. 0x3fff, 0xffff, 0xffff, 0xfffc, 
  67. 0x3fff, 0xffff, 0xffff, 0xfffc, 
  68.  
  69. /* Plane 2 */
  70.  
  71. 0x0000, 0x0000, 0x0000, 0x0000, 
  72. 0x0000, 0x0000, 0x0000, 0x0000, 
  73. 0x0000, 0x0000, 0x0000, 0x0000, 
  74. 0x0000, 0x0000, 0x0000, 0x0000, 
  75. 0x0000, 0x0000, 0x0000, 0x0000, 
  76. 0x0000, 0x0000, 0x0000, 0x0000, 
  77. 0x0000, 0x0000, 0x0000, 0x0000, 
  78. 0x0000, 0x0000, 0x0000, 0x0000, 
  79. 0x0000, 0x0000, 0x0000, 0x0000, 
  80. 0x0000, 0x0000, 0x0000, 0x0000, 
  81. 0x0000, 0x0000, 0x0000, 0x0000, 
  82. 0x0000, 0x0000, 0x0000, 0x0000
  83. };
  84.  
  85. struct Image chip sys_in_image = {
  86.      0, 0,
  87.      62,
  88.      12,
  89.      3,
  90.      (USHORT *)&sys_in_dat,
  91.      7, 0,
  92.      NULL
  93. };
  94.  
  95. UWORD chip sys_out_dat[144] = {
  96.  
  97. /* Plane 0 */
  98.  
  99. 0xffff, 0xffff, 0xffff, 0xffc0, 
  100. 0xe1ff, 0xffff, 0xe3ff, 0xfbc0, 
  101. 0xccff, 0xffff, 0xc9ff, 0xf3c0, 
  102. 0xc7cc, 0xe0ff, 0x9ccc, 0xe0c0, 
  103. 0xe3cc, 0xcfc0, 0x9ccc, 0xf3c0, 
  104. 0xf8cc, 0xe1ff, 0x9ccc, 0xf3c0, 
  105. 0xcce1, 0xfcff, 0xc9cc, 0xf2c0, 
  106. 0xe1f3, 0xc1ff, 0xe3e2, 0x79c0, 
  107. 0xffc7, 0xffff, 0xffff, 0xffc0, 
  108. 0xffff, 0xffff, 0xffff, 0xffc0, 
  109. 0x0000, 0x0000, 0x0000, 0x0000, 
  110. 0x0000, 0x0000, 0x0000, 0x0000, 
  111. /* Plane 1 */
  112.  
  113. 0x0000, 0x0000, 0x0000, 0x0000, 
  114. 0x0000, 0x0000, 0x0000, 0x003c, 
  115. 0x0000, 0x0000, 0x0000, 0x003c, 
  116. 0x0000, 0x0000, 0x0000, 0x003c, 
  117. 0x0000, 0x0000, 0x0000, 0x003c, 
  118. 0x0000, 0x0000, 0x0000, 0x003c, 
  119. 0x0000, 0x0000, 0x0000, 0x003c, 
  120. 0x0000, 0x0000, 0x0000, 0x003c, 
  121. 0x0000, 0x0000, 0x0000, 0x003c, 
  122. 0x0000, 0x0000, 0x0000, 0x003c, 
  123. 0x3fff, 0xffff, 0xffff, 0xfffc, 
  124. 0x3fff, 0xffff, 0xffff, 0xfffc, 
  125. /* Plane 2 */
  126.  
  127. 0x0000, 0x0000, 0x0000, 0x0000, 
  128. 0x0000, 0x0000, 0x0000, 0x0000, 
  129. 0x0000, 0x0000, 0x0000, 0x0000, 
  130. 0x0000, 0x0000, 0x0000, 0x0000, 
  131. 0x0000, 0x0000, 0x0000, 0x0000, 
  132. 0x0000, 0x0000, 0x0000, 0x0000, 
  133. 0x0000, 0x0000, 0x0000, 0x0000, 
  134. 0x0000, 0x0000, 0x0000, 0x0000, 
  135. 0x0000, 0x0000, 0x0000, 0x0000, 
  136. 0x0000, 0x0000, 0x0000, 0x0000, 
  137. 0x0000, 0x0000, 0x0000, 0x0000, 
  138. 0x0000, 0x0000, 0x0000, 0x0000};
  139.  
  140. struct Image chip sys_out_image = {
  141.      0, 0,
  142.      62,
  143.      12,
  144.      3,
  145.      (USHORT *)&sys_out_dat,
  146.      7, 0,
  147.      NULL };
  148.  
  149. struct Gadget sys_in_gad = {
  150.     NULL,
  151.     10,
  152.     10,
  153.     58,
  154.     10,
  155.     GADGHIMAGE | GADGIMAGE,
  156.     RELVERIFY | TOGGLESELECT,
  157.     BOOLGADGET,
  158.     (APTR)&sys_in_image,
  159.     (APTR)&sys_out_image,
  160.     NULL,
  161.     NULL,
  162.     NULL,
  163.     1,
  164.     NULL
  165. };
  166.  
  167. #define SYS_IN        1
  168.  
  169. struct NewScreen NewScreen = {
  170.     0,135,640,65,3,
  171.     Green,Gray,
  172.     HIRES,
  173.     CUSTOMSCREEN,
  174.     NULL,
  175.     "This test (Green/Gray test)",
  176.     NULL,
  177.     NULL
  178. };
  179.  
  180. struct NewWindow NewWindow = {
  181.     0,
  182.     10,
  183.     120,
  184.     30,
  185.     Blue,
  186.     Yellow,
  187.     GADGETUP|CLOSEWINDOW,
  188.     WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SIZEBRIGHT,
  189.     &sys_in_gad,
  190.     NULL,
  191.     "0,10,120,30,Blue,Yellow  test of window with gad",
  192.     NULL,
  193.     NULL,
  194.     10,
  195.     10,
  196.     640,
  197.     49,
  198.     CUSTOMSCREEN
  199. };
  200.  
  201. struct Screen *MyScreen;
  202. struct GfxBase *GfxBase;
  203. struct Window *MyWindow;
  204. struct IntuitionBase *IntuitionBase;
  205. void openall(), closeall(), die();
  206.  
  207. main()
  208. {
  209.     struct IntuiMessage *imsg;
  210.     ULONG Class;
  211.     APTR IAddress;
  212.     struct Gadget *GadAddress;
  213.     
  214.     openall();
  215.     
  216.     FOREVER
  217.     {
  218.         Wait(1L << MyWindow->UserPort->mp_SigBit);
  219.         while((imsg = (struct IntuiMessage *)GetMsg(MyWindow->UserPort)) != NULL)
  220.         {
  221.             Class = imsg->Class;
  222.             IAddress = imsg->IAddress;
  223.             ReplyMsg((struct Message *)imsg);
  224.             switch (Class)
  225.             {
  226.                 case CLOSEWINDOW:
  227.                     closeall();
  228.                     exit(0);
  229.                     break;
  230.                 case GADGETUP:
  231.                     GadAddress = (struct Gadget *)IAddress;
  232.                     if (GadAddress->GadgetID == SYS_IN)
  233.                     {
  234.                         if(GadAddress->Flags & SELECTED)
  235.                             Fade(MyScreen, colortable2, 2, 8);
  236.                         /*    printf("Gad->SysIO turned on\n"); */
  237.                         else
  238.                             Fade(MyScreen, colortable1, 2, 8);
  239.                         /*    printf("Gad->SysIO turned off\n"); */
  240.                     }
  241.                     break;
  242.                 default:
  243.                     break;
  244.             }
  245.         }
  246.     }
  247. }
  248.  
  249. void openall()
  250. {
  251.     if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  252.     {
  253.         printf("Can't open graphics library\n");
  254.         die();
  255.     }
  256.     
  257.     if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  258.     {
  259.         printf("Can't open Intuition library... Aborting\n");
  260.         die();
  261.     }
  262.     
  263.     if((MyScreen = (struct Screen *)OpenScreen(&NewScreen)) == NULL)
  264.     {
  265.         printf("Can't open screen... Aborting\n");
  266.         die();
  267.     }
  268.  
  269.     SetRGB4 (&(MyScreen->ViewPort),0,0,0,0);
  270.     SetRGB4 (&(MyScreen->ViewPort),1,0,0,0);
  271.     SetRGB4 (&(MyScreen->ViewPort),2,0,0,0);
  272.     SetRGB4 (&(MyScreen->ViewPort),3,0,0,0);
  273.     SetRGB4 (&(MyScreen->ViewPort),4,0,0,0);
  274.     SetRGB4 (&(MyScreen->ViewPort),5,0,0,0);
  275.     SetRGB4 (&(MyScreen->ViewPort),6,0,0,0);
  276.     SetRGB4 (&(MyScreen->ViewPort),7,0,0,0);
  277.     
  278.     NewWindow.Screen = MyScreen;
  279.     
  280.     if((MyWindow = (struct Window *)OpenWindow(&NewWindow)) == NULL)
  281.     {
  282.         printf("Can't open window... Aborting\n");
  283.         die();
  284.     }
  285.     
  286.     Fade(MyScreen, colortable1, 2, 8);
  287. }
  288.  
  289. void closeall()
  290. {
  291.     if(MyWindow && MyScreen)
  292.         FadeToBlack(MyScreen, 2, 8);
  293.     if(MyWindow)
  294.         CloseWindow(MyWindow);
  295.     if(MyScreen)
  296.         CloseScreen(MyScreen);
  297.     if(IntuitionBase)
  298.         CloseLibrary(IntuitionBase);
  299.     if(GfxBase)
  300.         CloseLibrary(GfxBase);
  301. }
  302.  
  303. void die()
  304. {
  305.     closeall();
  306.     exit (-1);
  307. }
  308.  
  309.  
  310.