home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 1 / CDPD_Vol1.bin / pd / 026-050 / 049 / polygon / polygon2.c < prev    next >
C/C++ Source or Header  |  1992-06-23  |  6KB  |  223 lines

  1. /* polygon drawing routine based on Polygon Constructor by John Jainschigg
  2. taken from Family Computing June 1986 */
  3. /* Polygon is based on an original program by Terry W. Gintz
  4. for the Apple Macintosh -- that used Quickdraw for the polygon drawing */
  5.  
  6. void IMsg();
  7.  
  8. /* Include the definitions and functions we need */
  9.  
  10. #include "polygon2.h"
  11. #include "polyg3.c"
  12. #include "palette.c"
  13. #include "save.c"
  14.  
  15. struct IntuiText Menu0IText [] = {
  16.  
  17.    {
  18.    0,3,JAM2,      /* Front Pen, Back Pen, Draw Mode */
  19.    0,0,            /* Left Edge, Top Edge */
  20.    &TestFont,         /* pointer to Text Font */
  21.    "  new pict  ",   /* text of Menu Item */
  22.    NULL            /* pointer to next IText */
  23.    },
  24.  
  25.    {0,3,JAM2,0,0,&TestFont,"modify color",NULL },
  26.    {0,3,JAM2,0,0,&TestFont,"cycle colors",NULL },
  27.    {0,3,JAM2,0,0,&TestFont,"stop drawing",NULL },
  28.    {0,3,JAM2,0,0,&TestFont,"save picture",NULL },
  29.    {0,3,JAM2,0,0,&TestFont,"    quit    ",NULL },
  30. };
  31.  
  32. struct MenuItem Menu0Item[6] = {
  33.    {
  34.    &Menu0Item[1],         /* pointer to next Item */
  35.    0,0,120,9,      /* Left, Top, Width, Height */
  36.    ITEMTEXT | ITEMENABLED | HIGHCOMP,   /* Flags */
  37.    0,            /* no mutual exclude */
  38.    (APTR)&Menu0IText[0],   /* Render info */   
  39.    NULL,NULL,NULL,         /*Alt Image, Command (amiga) char, subitem*/
  40.    MENUNULL      /* next select */
  41.    },
  42.  
  43.    {&Menu0Item[2],0,9,120,9,ITEMTEXT | ITEMENABLED | HIGHCOMP,
  44.    0,(APTR)&Menu0IText[1],NULL,NULL,NULL,MENUNULL},
  45.  
  46.    {&Menu0Item[3],0,18,120,9,ITEMTEXT | ITEMENABLED | HIGHCOMP,
  47.    0,(APTR)&Menu0IText[2],NULL,NULL,NULL,MENUNULL},
  48.  
  49.    {&Menu0Item[4],0,27,120,9,ITEMTEXT | ITEMENABLED | HIGHCOMP,
  50.    0,(APTR)&Menu0IText[3],NULL,NULL,NULL,MENUNULL},
  51.  
  52.    {&Menu0Item[5],0,36,120,9,ITEMTEXT | ITEMENABLED | HIGHCOMP,
  53.    0,(APTR)&Menu0IText[4],NULL,NULL,NULL,MENUNULL},
  54.  
  55.    {NULL,0,45,120,9,ITEMTEXT | ITEMENABLED | HIGHCOMP,
  56.    0,(APTR)&Menu0IText[5],NULL,NULL,NULL,MENUNULL}
  57. };
  58.  
  59. struct Menu BdMenu [1] = {
  60.    NULL,      /* ptr to next Menu */
  61.    10,0,120,0,   /* left,top,width,height--top and height ignored */
  62.    MENUENABLED,   /* Flags */
  63.    "   Polygons ",   /* menu title */
  64.    &Menu0Item[0]   /* First Item in list */
  65.    };
  66. int nf,cycle,delay,sav;
  67. UWORD color18, color19;
  68.  
  69. main()
  70. {
  71.    USHORT drawing;
  72. cycle=0;
  73. nf=0;
  74. delay=9000;
  75. initwind();
  76. init_colors();
  77. init_scr();
  78. drawing=1;
  79. poly();
  80. while(drawing)
  81.    {
  82.    IMsg();
  83.    }
  84. }   /* end of main */
  85.  
  86. void IMsg()
  87. {
  88.    struct IntuiMessage *BdMsg;      /* Intuition message structure */
  89.    ULONG Mclass;               /* Message class */
  90.    USHORT Mcode;            /* Message code */
  91.  
  92.    if (cycle==1)
  93.       cyclecolors();
  94.    if (nf==1)
  95.       poly();
  96.    while (BdMsg = (struct IntuiMessage *)GetMsg(w->UserPort)){
  97.       Mclass = BdMsg->Class;
  98.       Mcode = BdMsg->Code;
  99.       ReplyMsg(BdMsg);
  100.       switch (Mclass) {
  101.          case CLOSEWINDOW:
  102.             clear_colors();
  103.             Cleanup();
  104.             exit(TRUE);
  105.             break;
  106.          case MENUPICK:
  107.             switch (ITEMNUM(Mcode)){
  108.                   case 0:
  109.                      poly();
  110.                      break;
  111.                   case 1:
  112.                      palette(w);
  113.                      break;
  114.                   case 2:
  115.                      if (cycle==0)
  116.                         cycle=1;
  117.                      else
  118.                         cycle=0;
  119.                      break;
  120.                   case 3:
  121.                      break;
  122.                   case 4:
  123.                      sav=save(w);
  124.                      if (sav == 1){
  125.                         color18=GetRGB4(p_Co,18);
  126.                         color19=GetRGB4(p_Co,19);
  127.                         SetRGB4(vp,18,15,0,0);
  128.                         SetRGB4(vp,19,15,15,15);
  129.                         SetPointer(w,&PointImage,14,16,0,0);
  130.                         SavePicture();
  131.                         ClearPointer(w);
  132.                         *(p_ct+18)=(USHORT)color18;
  133.                         *(p_ct+19)=(USHORT)color19;
  134.                         LoadRGB4(vp,p_ct,CTSIZ);
  135.                      }
  136.                      break;
  137.                   case 5:
  138.                      clear_colors();
  139.                      Cleanup();
  140.                      exit(TRUE);
  141.                      break;
  142.             }
  143.       } 
  144.    }
  145. }
  146.  
  147. init_scr()
  148. {
  149.  
  150. SetMenuStrip(w,&BdMenu);
  151.  
  152. }   /* end of init_scr */
  153.  
  154. Cleanup()
  155. {
  156.    CloseWindow(w);
  157.    CloseScreen(screen);
  158. }
  159.  
  160. cyclecolors()
  161. {
  162.    int i,temp;
  163.  
  164.    temp=*(p_ct+5);
  165.    for (i=5;i<=30;i++)
  166.       *(p_ct+i)=*(p_ct+i+1);
  167.    *(p_ct+31)=temp;
  168.    LoadRGB4(vp,p_ct,CTSIZ);
  169.    for (i=0;i<=delay;i++)
  170.       ;
  171. }
  172.  
  173. int stopcheck()
  174. {
  175.    struct IntuiMessage *BdMsg;      /* Intuition message structure */
  176.    ULONG Mclass;               /* Message class */
  177.    USHORT Mcode,ItemNum;
  178.    int ex;
  179.  
  180.    if (cycle==1)
  181.       cyclecolors();
  182.    ex = 0;
  183.    nf = 0;
  184.    while (BdMsg = (struct IntuiMessage *)GetMsg(w->UserPort)) {
  185.       Mclass = BdMsg->Class;
  186.       Mcode = BdMsg->Code;
  187.       ReplyMsg(BdMsg);
  188.       switch (Mclass) {
  189.          case CLOSEWINDOW:
  190.             Cleanup();
  191.             exit(TRUE);
  192.             break;
  193.          case MENUPICK:
  194.             ItemNum = ITEMNUM(Mcode);
  195.             switch (ItemNum){
  196.                   case 0:
  197.                      ex = 1;
  198.                      nf = 1;
  199.                      break;
  200.                   case 1:
  201.                      palette(w);
  202.                      break;
  203.                   case 2:
  204.                      if (cycle==1)
  205.                         cycle=0;
  206.                      else
  207.                         cycle=1;
  208.                      break;
  209.                   case 3:
  210.                      ex=1;
  211.                      break;
  212.                   case 4:
  213.                      break;
  214.                   case 5:
  215.                      clear_colors();
  216.                      Cleanup();
  217.                      exit(TRUE);
  218.             }
  219.       }
  220.    }
  221.    return(ex);
  222. }
  223.