home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d154 / wicon.lha / Wicon / macwin.c < prev    next >
C/C++ Source or Header  |  1987-06-15  |  5KB  |  197 lines

  1. /***************************************************************************
  2.  *
  3.  *    MacWin.c    - routines for making OpenWindow & CloseWindow
  4.  *              behave like a Macintosh        10-Jan-88
  5.  *
  6.  *    Version 1.3 18-Jun-88 Copyright (c) 1988 - Steven Sweeting
  7.  *
  8.  *    Note: if the OpenWindow vector gets in before mwb
  9.  *          (ie run mwb first) then the opening of the window
  10.  *          is done on the real WBENCH screen.
  11.  *
  12.  ***************************************************************************/
  13.  
  14. #include <intuition/intuitionbase.h>
  15. #include "wicon.h"
  16.  
  17. extern    struct IntuitionBase   *IntuitionBase;
  18.  
  19. struct    Box
  20. {
  21.     LONG   Left, Right;
  22.     LONG   Top, Bottom;
  23. };
  24.  
  25. #define REC_FIRST    1
  26. #define REC_LAST    2
  27. #define REC_HIRES    4
  28.  
  29. #define MIN(a,b)        ((a)<(b) ? (a):(b))
  30. #define MAX(a,b)        ((a)>(b) ? (a):(b))
  31.  
  32.  
  33. /*************************************************************************
  34.  *  SizeRec - resizes a rectangle on the given Screen
  35.  *
  36.  * 03-Jan-88
  37.  */
  38. void
  39. SizeRec(Screen, From, To)
  40. struct    Screen    *Screen;
  41. struct    BoxInfo *From, *To;
  42. {
  43.     struct    Box    Box1, Box2, Box3;
  44.     short        inc;
  45.     long        Left, Right, Top, Bottom;
  46.     int        Flags;
  47.     long        factor, curr = 0, i;
  48.     struct RastPort *RastPort = &(Screen->RastPort);
  49.     static    WORD    ox1, oy1, ox2, oy2; /* Save them for redraw */
  50.  
  51.     Box1.Left   = MAX( From->LeftEdge,          0              );
  52.     Box1.Right  = MIN( Box1.Left + From->Width, Screen->Width  );
  53.     Box1.Top    = MAX( From->TopEdge,           0              );
  54.     Box1.Bottom = MIN( Box1.Top + From->Height, Screen->Height );
  55.  
  56.     Box2.Left   = MAX( To->LeftEdge,            0              );
  57.     Box2.Right  = MIN( Box2.Left + To->Width,   Screen->Width  );
  58.     Box2.Top    = MAX( To->TopEdge,             0              );
  59.     Box2.Bottom = MIN( Box2.Top + To->Height,   Screen->Height );
  60.  
  61.     if (Screen->Flags | HIRES)
  62.         Flags = REC_HIRES;
  63.     else
  64.         Flags = 0;
  65.  
  66.     SetDrMd(RastPort, (LONG)COMPLEMENT);
  67.  
  68.     if (Arg_Boxes)
  69.     {
  70.         SetDrMd(RastPort, (LONG)COMPLEMENT);
  71.  
  72.         LockLayers(&(Screen->LayerInfo));
  73.  
  74.         inc = 256/Arg_Boxes;
  75.  
  76.         DrawRec(RastPort, ox1 = Box1.Left, oy1 = Box1.Top,
  77.                   ox2 = Box1.Right, oy2 = Box1.Bottom );
  78.         inc = 256/Arg_Boxes;
  79.  
  80.         for (i=0; i<256; i += inc )
  81.         {
  82.         WaitTOF();
  83.  
  84.         DrawRec(RastPort, ox1, oy1, ox2, oy2 );
  85.  
  86.         DrawRec(
  87.             RastPort,
  88.             ox1 = (WORD)((Box1.Left   *(255-i) + Box2.Left   *i) >>8),
  89.             oy1 = (WORD)((Box1.Top    *(255-i) + Box2.Top    *i) >>8),
  90.             ox2 = (WORD)((Box1.Right  *(255-i) + Box2.Right  *i) >>8),
  91.             oy2 = (WORD)((Box1.Bottom *(255-i) + Box2.Bottom *i) >>8)
  92.                );
  93.         }
  94.  
  95.         DrawRec(RastPort, ox1, oy1, ox2, oy2);
  96.  
  97.  
  98.         UnlockLayers(&(Screen->LayerInfo));
  99.     }
  100.  
  101. }
  102.  
  103. /*************************************************************************
  104.  * DrawRec - draws an XOR rectangle on a given RastPort
  105.  *
  106.  * 03-Jan-88
  107.  */
  108. int
  109. DrawRec(RastPort, x1, y1, x2, y2, status)
  110. struct    RastPort    *RastPort;
  111. WORD    x1, y1, x2, y2;
  112. WORD    status;
  113. {
  114.     Move(RastPort, (LONG)x1, (LONG)y1);
  115.     Draw(RastPort, (LONG)x2, (LONG)y1);
  116.     Draw(RastPort, (LONG)x2, (LONG)y2);
  117.     Draw(RastPort, (LONG)x1, (LONG)y2);
  118.     Draw(RastPort, (LONG)x1, (LONG)y1);
  119.  
  120.     if (status & REC_HIRES)
  121.     {
  122.         Move(RastPort, (LONG)x1+1, (LONG)y1);
  123.         Draw(RastPort, (LONG)x1+1, (LONG)y2);
  124.         Move(RastPort, (LONG)x2-1, (LONG)y1);
  125.         Draw(RastPort, (LONG)x2-1, (LONG)y2);
  126.     }
  127. }
  128.  
  129. /*************************************************************************
  130.  * M_Open - opens a window - called from the OpenWindow vector
  131.  *        hence it is always run by the task that called it
  132.  *
  133.  */
  134. struct    BoxInfo SmallBox =   { 0, 0, 0, 0 };
  135.  
  136. struct Window *
  137. M_Open( NewWindow )
  138. struct NewWindow *NewWindow;
  139. {
  140.     extern    struct    Window *OldOpenWindow();
  141.  
  142.     struct Screen    *Screen;
  143.  
  144.     if ((NewWindow->Type & SCREENTYPE) == WBENCHSCREEN)
  145.         Screen = WorkBenchScreen;
  146.     else
  147.         Screen = NewWindow->Screen;
  148.  
  149.     SmallBox.LeftEdge = Screen->MouseX;
  150.     SmallBox.TopEdge  = Screen->MouseY;
  151.  
  152.     if (Arg_AllScreens || (Screen == WiconScreen))
  153.         SizeRec(Screen, &SmallBox, &(NewWindow->LeftEdge));
  154.  
  155.     return (OldOpenWindow(NewWindow));
  156. }
  157.  
  158. /*************************************************************************
  159.  * UnSetFunction - this routine handles properly
  160.  *           the opposite to SetFunction() which
  161.  *           replaces an AmigaDOS `OldVector'
  162.  *           with its own `NewVector'. This function
  163.  *           may never exit because the `NewVector'
  164.  *           may be lost by a newer function which
  165.  *           also does a SetFunction()
  166.  *  10-Jan-87
  167.  */
  168.  
  169. void UnSetFunction(LibraryBase, FunctionOffset, LibVector, PresentVector)
  170. struct    Library *LibraryBase;
  171. LONG        FunctionOffset;
  172. VOID        (*PresentVector)(),(*LibVector)();
  173. {
  174.     extern    void    (*SetFunction())();     /* AmigaDOS routine */
  175.     extern    void    (*GetFunction())();     /* Sweeting routine */
  176.  
  177.     Forbid();
  178.  
  179.     while (GetFunction( LibraryBase, FunctionOffset ) != PresentVector)
  180.     {
  181.         Permit();
  182.  
  183.         Delay(50L);     /* a second */
  184.  
  185.         Forbid();
  186.     }
  187.  
  188.         /* It may be illegal to do this within a Forbid()/Permit() */
  189.         /* But it seems to work OK    */
  190.  
  191.     SetFunction( LibraryBase, FunctionOffset, LibVector );
  192.  
  193.     Permit();
  194.  
  195. }
  196.  
  197.