home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff374.lzh / PopArt / sorcery / stor.c < prev    next >
C/C++ Source or Header  |  1990-10-08  |  12KB  |  422 lines

  1.  
  2.  
  3.               /*  stor.c  ---   gotta stick'm someplace!  */
  4.  
  5. #include <exec/memory.h>
  6. #include <ctype.h>
  7. #include "stuff.h"
  8.  
  9. #define ABS(x) ((x<0)?(-(x)):(x))
  10.  
  11.  
  12.         extern struct Screen   *scr;
  13.         extern struct Window   *win;
  14.         extern struct RastPort *reep;
  15.         extern ULONG            thisCol;
  16.         extern    int           curOnion;
  17.         extern    int           togOnion;
  18.         extern struct Gadget    TGads [];
  19.         extern  UWORD           mrQ;
  20.                struct Window   *seqwin;
  21.                struct Window   *clipWin;
  22.  
  23.     UBYTE sequence [SEQLEN] = (UB) "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16";
  24.     struct SUPERwindow SuperWindows [ maxsupwin ];
  25.     int CurrentWindow = 0;
  26.  
  27.     SS NewWindow winstamp = {  237,12, ImageWid + 8, MaxDN + 27, 0,1,
  28.         CLOSEWINDOW | MOUSEBUTTONS /* IDCMP */, WINDOWCLOSE |
  29.         WINDOWDEPTH | WINDOWDRAG | SMART_REFRESH | RMBTRAP /* Flags */,
  30.         NL,NL,NL,NL,NL,0,0,0,0, CUSTOMSCREEN };
  31.  
  32.  
  33. NewSuperWindow ()
  34. {
  35.     REG int okay = 0;
  36.     char nookie [126];
  37.  
  38.  
  39.     while (swin (okay) && okay < maxsupwin)  ++okay;
  40.     if (okay >= maxsupwin)  {  ALERT ("Too many windows!");  RET 0;  }
  41.     winstamp.DetailPen  =  okay      % 16;
  42.     winstamp.BlockPen   = (okay + 8) % 16;
  43.     winstamp.Screen     = scr;
  44.  
  45.     IFN (swin (okay) = OpenWindow (&winstamp))  {
  46.         ALERT ("No Chips Left!  No More Windows!");  RET 0;  }
  47.  
  48.     SetAPen (zreep (okay) = swin (okay)->RPort, 22L);
  49.     decimal (okay, nookie);
  50.     Move (zreep (okay), 8L, (long) MaxDN + 22L);
  51.     Text (zreep (okay), nookie, (long) strlen (nookie));
  52.     SetAPen (zreep (okay), (long) thisCol);
  53.     newactive (okay);
  54.     return 1;
  55.  
  56. }
  57.  
  58.  
  59.                       void
  60. dealwithit (idx, msg)  struct IntuiMessage *msg;
  61. {
  62.  
  63.     SWITCH (msg->Class) {
  64.         CS MOUSEBUTTONS:
  65.             if (msg->Code != SELECTUP)    RET;
  66.             if (swin (idx)->MouseY <= 8)  RET;
  67.  
  68.             if izCtrl (msg->Qualifier & Qmask)  {
  69.                 if (idx == curOnion)  {
  70.                     if (togOnion)  Mess ("This IS the Shadow Image!!!");
  71.                     return;  }
  72.  
  73.                 ifn (togOnion)  {  togOnion = 1;  onionOn ();  }
  74.                 newOnion (curOnion = idx);  RET;  }
  75.  
  76.             newactive (idx);
  77.             blow ();
  78.             return;
  79.  
  80.         CS CLOSEWINDOW:
  81.             deadwindow (idx);
  82.             return;  }
  83.  
  84. }
  85.  
  86.  
  87.                 void
  88. newactive (idx)
  89. {
  90.  
  91.     if swin (CurrentWindow)  SetWindowTitles (swin (CurrentWindow), "  ", -1L);
  92.     if swin (idx)      SetWindowTitles (swin (CurrentWindow = idx), "IT", -1L);
  93.  
  94. }
  95.  
  96.  
  97.             /*   void*/
  98. deadwindow (idx)
  99. {
  100.  
  101.     if (idx == CurrentWindow)  {  Mess ("You can't close \"It\"!");  RET;  }
  102.  
  103.     if (idx == curOnion && togOnion)  {
  104.         Mess ("You can't close the Shadow Image!"); RET;}
  105.  
  106.     if (idx == curOnion)  curOnion = CurrentWindow;
  107.     if (swin (idx))  CloseWindow (swin (idx));
  108.     swin (idx) = NL;
  109.     zreep (idx) = NL;
  110.  
  111. }
  112.  
  113.  
  114.         void
  115. stor ()
  116. {
  117.  
  118.     ifn (NewSuperWindow ())  return;
  119.     suck ();
  120.  
  121.     if (curOnion + 2 == CurrentWindow && swin (CurrentWindow - 1))
  122.         newOnion (++curOnion);
  123.  
  124. }
  125.  
  126.  
  127.                 void
  128. zapAllWindows ()
  129. {
  130.     REG int k = maxsupwin;
  131.  
  132.  
  133.     while (k--)  if (swin (k))  CloseWindow (swin (k));
  134.  
  135. }
  136.  
  137.  
  138.         void
  139. stack ()
  140. {
  141.     REG int k = maxsupwin;
  142.  
  143.  
  144.     WindowToFront (swin (CurrentWindow));
  145.  
  146.     while (k--)
  147.         if (swin (k) && k != CurrentWindow)
  148.             MoveWindow (swin (k),
  149.                 (LONG) swin (CurrentWindow)->LeftEdge - swin (k)->LeftEdge,
  150.                 (LONG) swin (CurrentWindow)-> TopEdge - swin (k)-> TopEdge);
  151.  
  152. }
  153.  
  154.  
  155.     SS NewWindow clipwinstamp = {  0,0,0,0, 0,1,
  156.         MOUSEBUTTONS /* IDCMP */,
  157.         WINDOWDRAG | SMART_REFRESH | RMBTRAP /* Flags */,
  158.         NL,NL,NL,NL,NL,0,0,0,0, CUSTOMSCREEN };
  159.  
  160. #define INSIDE(x,j) ((x) >= 36 && (x) < 36 + ImageWid * Ratio && \
  161.                      (j) >= 21 && (j) < 21 + MaxDN * Ratio)
  162.  
  163.                    void
  164. clipAction (clipQ)  UWORD clipQ;
  165. {
  166.     REG USHORT xx, yy, xxx, yyy;
  167.     ULONG wasCol = thisCol;
  168.     extern int popping;
  169.     int waspopping = popping;
  170.  
  171.     USHORT lef = clipWin->LeftEdge,  top = clipWin->TopEdge,
  172.            max = clipWin->Width - 3, may = clipWin->Height - 3;
  173.  
  174.  
  175.     Mess ("Copying ...");
  176.     offInput ();
  177.     popping = 0;
  178.  
  179.     LOOP     (xx =  4;  xx < max;  xx += Ratio)
  180.         loop (yy = 12;  yy < may;  yy += Ratio)  {
  181.             xxx = xx + lef;  xxx -= xxx % Ratio;
  182.             yyy = yy + top;  yyy -= yyy % Ratio;
  183.             thisCol = ReadPixel (clipWin->RPort, (long) xx, (long) yy);
  184.  
  185.             switch (clipQ)  {
  186.               case LSHIFT:
  187.               case RSHIFT:
  188.                 if (wasCol == thisCol)  continue;
  189.                 break;
  190.  
  191.               case RALT:
  192.               case LALT:
  193.                 if (wasCol != thisCol)  continue;
  194.                 break;
  195.  
  196.               case RCOM:
  197.                 if (wasCol == ReadPixel (reep, (long) xxx, (long) yyy))
  198.                     continue;
  199.  
  200.                 break;
  201.  
  202.               case LCOM:
  203.                 if (wasCol != ReadPixel (reep, (long) xxx, (long) yyy))
  204.                     continue;
  205.  
  206.             }                      /*  could be worse ...  could be PC-DOS  */
  207.  
  208.             if INSIDE (xxx, yyy)  maybedospot (xxx, yyy);  }     /* uh huh  */
  209.  
  210.     Mess ("Done Copying");
  211.     onInput ();
  212.     thisCol = wasCol;
  213.     popping = waspopping;
  214.  
  215. }
  216.  
  217.  
  218.         void
  219. doBox ()
  220. {
  221.     extern USHORT Mx, My;
  222.     int cX = Mx - Mx % Ratio - 2, cY = My - My % Ratio - 2, eX, eY;
  223.     void rectal ();
  224.     extern ULONG msgclass;
  225.     extern USHORT msgcode;
  226.  
  227.  
  228.     SetDrMd (reep, COMPLEMENT);
  229.  
  230.     do  {  extern int picking, no_help;
  231.         eX = Mx + Ratio - Mx % Ratio - 2;
  232.         eY = My + Ratio - My % Ratio - 2;
  233.         if (eX < 35)  eX = 35;
  234.         if (eY < 21)  eY = 21;
  235.         if (eX > 36 + ImageWid * Ratio)  eX = 36 + ImageWid * Ratio;
  236.         if (eY > 21 + MaxDN    * Ratio)  eY = 21 + MaxDN    * Ratio;
  237.         rectal (cX, cY, eX, eY);
  238.         picking = no_help = 1;
  239.         ifn (input ())  quit ("bye!");
  240.         picking = no_help = 0;
  241.         rectal (cX, cY, eX, eY);  }
  242.     while (msgclass == MOUSEMOVE ||
  243.         (msgclass == MOUSEBUTTONS && msgcode == SELECTDOWN) /* && izShift (mrQ */);
  244.  
  245.     if (ABS (cX - eX) < Ratio * 3 || ABS (cY - eY) < Ratio * 3)  goto labull;
  246.     clozeClipWin ();
  247.     clipwinstamp.DetailPen  =  20;
  248.     clipwinstamp.BlockPen   =  29;
  249.     clipwinstamp.Screen     = scr;
  250.     clipwinstamp.LeftEdge   = (cX < eX? cX: eX) -  3;
  251.     clipwinstamp.TopEdge    = (cY < eY? cY: eY) - 12;
  252.     clipwinstamp.Width      = ABS (cX - eX) +  6;
  253.     clipwinstamp.Height     = ABS (cY - eY) + 15;
  254.     clipwinstamp.Title      = (UB) "ClipBoard";
  255.  
  256.     IFN (clipWin = OpenWindow (&clipwinstamp))  {
  257.         ALERT ("Can't Copy Rectangle!  Lo Mem!");  goto labull;  }
  258.  
  259.     ClipBlit (reep, (long) (cX < eX? cX: eX), (long) (cY < eY? cY: eY),
  260.         clipWin->RPort, 3L, 12L, (long) ABS(cX-eX), (long) ABS(cY-eY), 0x0c0L);
  261.  
  262.     Mess ("Move & Click to Copy; Ctrl == Kill");
  263.  
  264. labull:
  265.     SetDrMd (reep, JAM2);
  266.  
  267. }
  268.  
  269.  
  270. void clozeClipWin ()  {  if (clipWin)  CloseWindow (clipWin);  clipWin = NL;  }
  271.  
  272.  
  273.                       void
  274. rectal (x, y, xx, yy)
  275. {
  276.  
  277.     RectFill (reep, (long) (x < xx? x: xx), (long) (y < yy? y: yy),
  278.                     (long) (x < xx? xx: x), (long) (y < yy? yy: y));
  279.  
  280. }
  281.  
  282.  
  283.             void
  284. offInput ()
  285. {
  286.  
  287.     ModifyIDCMP (win, NULL);
  288.  
  289. }
  290.  
  291.  
  292.             void
  293. onInput ()
  294. {
  295.  
  296.     ModifyIDCMP (win, CLOSEWINDOW | MOUSEMOVE | MOUSEBUTTONS |
  297.                       GADGETUP | RAWKEY | INACTIVEWINDOW);
  298.  
  299. }
  300.  
  301.  
  302.     UBYTE timer [6] = (UB) "5";
  303.  
  304.     SS StringInfo timeinfo = { timer, NL, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5 };
  305.  
  306.     SS Gadget timegad = { NL,252,12,48,18, GADGHCOMP,STRINGCENTER|
  307.         RELVERIFY|LONGINT,STRGADGET,NL,NL,NL,NL,(APTR) &timeinfo,0,NL};
  308.  
  309.     SS StringInfo infoname = { sequence, NL, 0, 120 };
  310.  
  311.     SS Gadget gadname = { &timegad,8,12,240,18, GADGHCOMP,STRINGCENTER|
  312.         RELVERIFY,STRGADGET,NL,NL,NL,NL,(APTR) &infoname,SQSTG,NL};
  313.  
  314.     SS NewWindow seqwinstamp = { 0, 158, 319, 24, 4,8, CLOSEWINDOW /* IDCMP */,
  315.         WINDOWCLOSE|WINDOWDEPTH|ACTIVATE|WINDOWDRAG|SMART_REFRESH|RMBTRAP /* Flags */,
  316.         &gadname, NL,NL,NL,NL,0,0,0,0, CUSTOMSCREEN };
  317.  
  318.               void
  319. openSeqWin ()
  320. {
  321.  
  322.     seqwinstamp.Screen = scr;
  323.     seqwinstamp.Title  = (UB) "Image Sequence ============= Time";
  324.     Mess ("Time == Tenths of Seconds");
  325.  
  326.     ifn (seqwin = OpenWindow (&seqwinstamp))  {
  327.         ALERT ("Low Chip Mem!  Sorry!");  RET;  }
  328.  
  329.     Delay (2L);
  330.     ActivateGadget (&gadname, seqwin, NL);            /*  this is a no-no!  */
  331.     SetAPen (seqwin->RPort, 4L);
  332.     Move (seqwin->RPort, 253L, 11L);
  333.     Draw (seqwin->RPort, 253L, 20L);
  334.  
  335. }
  336.  
  337.  
  338.                void
  339. closeSeqWin ()
  340. {
  341.  
  342.     if (seqwin)  {
  343.         seqwinstamp.TopEdge = seqwin->TopEdge;
  344.         CloseWindow (seqwin);  }
  345.  
  346.     seqwin = NL;
  347.  
  348. }                                      /*  user friendliness strikes again  */
  349.  
  350.  
  351.         void
  352. roll ()                   /*  make a little movie out of the window images  */
  353. {
  354.     SS NewWindow d = {  0,0, 320, 186, 0,1, MOUSEBUTTONS /* IDCMP */,
  355.         SMART_REFRESH | ACTIVATE | RMBTRAP /* Flags */,
  356.         NL,NL,NL,NL,NL,0,0,0,0, CUSTOMSCREEN };
  357.  
  358.     REG int evil;
  359.     char *good;
  360.     struct Window *newwin, *realwin;
  361.     struct IntuiMessage *mail;
  362.  
  363.  
  364.     d.Screen = scr;
  365.  
  366.     if (newwin = OpenWindow (&d))
  367.         realwin = newwin;
  368.     else  {
  369.         realwin = win;
  370.         SetAPen (reep, 0L);
  371.         RectFill (reep, 35L, 20L, ImageWid * Ratio + 36L, MaxDN * Ratio + 21L);
  372.         SetAPen (reep, thisCol);  }
  373.  
  374.     Mess ("L-Mouse == Quit, R-Mouse == Seq");
  375.     offInput ();
  376.     ifn (newwin)  ModifyIDCMP (win, MOUSEBUTTONS);
  377.  
  378. doThatAgain:
  379.     while (!(mail = (struct IntuiMessage *)  GetMsg (realwin->UserPort)))  {
  380.         good = (char *) sequence;
  381.         while (!isdigit (*good) && *good)  ++good;
  382.  
  383.         while (good < &sequence [SEQLEN - 1] && *good)  {
  384.             evil = atoi (good);
  385.  
  386.             if (evil >= 0 && evil < maxsupwin && swin (evil))  {
  387.                 ClipBlit (zreep (evil), 4L, 14L, realwin->RPort, 113L, 69L,
  388.                                 (LONG) ImageWid, (LONG) MaxDN, (LONG) 0xc0);
  389.  
  390.                 if (mail = (struct IntuiMessage *)
  391.                     GetMsg (realwin->UserPort))  goto f__kPascal;
  392.  
  393.                 Delay (timeinfo.LongInt > 100L? 100L: timeinfo.LongInt);  }
  394.  
  395.             while ( isdigit (*good) && *good)  ++good;
  396.             while (!isdigit (*good) && *good)  ++good;
  397.         }                                  /*  end of while-therez-numbers  */
  398.     }                                                   /*  end of forever  */
  399.  
  400. f__kPascal:                     /*  gad what a mess.  Looks like BASIC ...  */
  401.     if (mail->Class == MOUSEBUTTONS &&
  402.        (mail->Code == MENUUP || mail->Code == MENUDOWN))  {
  403.         if (mail->Code == MENUUP)  {  ReplyMsg (mail);  goto doThatAgain;  }
  404.         if (seqwin)  WindowToFront (seqwin);  else  openSeqWin ();
  405.         ReplyMsg (mail);
  406.         goto doThatAgain;  }
  407.  
  408.     ReplyMsg (mail);
  409.  
  410.     if (newwin)
  411.         CloseWindow (newwin);
  412.     else  {
  413.         SetAPen (reep, 0L);
  414.         RectFill (reep, 35L, 20L, ImageWid * Ratio + 36L, MaxDN * Ratio + 21L);
  415.         SetAPen (reep, thisCol);
  416.         redrawWorkArea (0);  }
  417.  
  418.     Mess ("That's All, Folks!");
  419.     onInput ();
  420.  
  421. }  /*  I don't need a pretentious language like Pascal to pretend it's a mathematical proof, and treat both the computer it lives in and the programmer who suffers for it like naughty children it has to spank all the time.  Those who actually like this sort of thing may also like sticking their heads up their asses and yodelling.  */
  422.