home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d170 / surf.lha / Surf / src / scrnio.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  4KB  |  171 lines

  1. /* main program */
  2.  
  3. #include "scrnio.ih"
  4. /*#include <functions.h>*/
  5.  
  6. #include "scrndef.h"
  7. #include "scrnio.h"
  8. #include "gadgetdef.h"
  9. #include "menudef.h"
  10.  
  11. struct Screen *SurfScrn = NULL;
  12. struct Window *SurfWin = NULL;
  13. struct Window *CntrlWin = NULL;
  14. struct Window *GadWin = NULL;
  15. /*
  16.  * bit masks for waiting for signals
  17.  */
  18. short CntrlSigBit, SurfSigBit, GadSigBit;
  19. long SignalMask = 0;
  20.  
  21. struct RastPort *rp;
  22. struct ViewPort *vp;
  23.  
  24. struct Library *GfxBase = 0,
  25.                *IntuitionBase = 0;
  26.  
  27. int XOR = COMPLEMENT, /* so my other modules don't need to */
  28.     WRITE = JAM1;     /* include so many amiga includes */
  29.  
  30. int WinHOrig, WinVOrig;
  31. int WinFgCol;
  32. int ColorMax;
  33. int NumColors;
  34.  
  35. /*
  36.  * data structures needed to use amiga polygons routines
  37.  */
  38. static WORD PolyArea[5*5];
  39. static struct AreaInfo PolyInfo;
  40. static PLANEPTR PolyWorkSpace;
  41. static struct TmpRas PolyTmpRas;
  42.  
  43.  
  44.  
  45. static void ResetWinDat() {
  46.  
  47.     WinHOrig = SurfWinDef.Width >>1;
  48.     WinVOrig = SurfWinDef.Height >>1;
  49.  
  50.  
  51.     rp = SurfWin->RPort;
  52.     SetDrMd( rp,  JAM1 );
  53. }
  54.  
  55.  
  56.  
  57. /*
  58.  * open surface window/screen
  59.  */
  60. OpenSurf() {
  61.     NumColors = 1 << SurfScrnDef.Depth;
  62.     ColorMax = ( NumColors -1) * 8 + 1;
  63.     WinFgCol = (NumColors - 1) & 0x1f;
  64.  
  65.     SurfScrnDef.BlockPen = ( WinFgCol *3) /4;
  66.     SurfScrnDef.DetailPen = WinFgCol>>2;
  67.  
  68.     SurfScrn = OpenScreen( &SurfScrnDef );
  69.     MenuSetColMap();
  70.     SurfWinDef.Screen = GadWinDef.Screen = SurfScrn;
  71.     SurfWinDef.Width = GadWinDef.Width = SurfScrnDef.Width;
  72.     SurfWinDef.Height = SurfScrnDef.Height - ButHeight;
  73.  
  74.     SurfWin = OpenWindow( &SurfWinDef );
  75.     GadWin = OpenWindow( &GadWinDef );
  76.     SurfSigBit = SurfWin->UserPort->mp_SigBit;
  77.     GadSigBit = GadWin->UserPort->mp_SigBit;
  78.     SignalMask = (1<<CntrlSigBit) | (1<<SurfSigBit)| (1<<GadSigBit);
  79.  
  80.     ResetWinDat();
  81.     ShowTitle( SurfScrn, 0L ); /* hide screen title behind backdrop */
  82.  
  83.     InitArea( &PolyInfo, PolyArea, 5);
  84.     rp->AreaInfo = &PolyInfo;
  85.  
  86.     PolyWorkSpace = AllocRaster( SurfWinDef.Width, SurfWinDef.Height);
  87.  
  88.     if( !PolyWorkSpace ) {
  89.         CloseDisplay();
  90.         perror("no space for temporary rastern");
  91.         exit(0);
  92.     }
  93.     else {
  94.         InitTmpRas( &PolyTmpRas, PolyWorkSpace,
  95.                     RASSIZE( SurfWinDef.Width, SurfWinDef.Height ));
  96.         rp->TmpRas = &PolyTmpRas;
  97.     }
  98. }
  99.  
  100.  
  101. void InitWindow()
  102. {
  103.     GfxBase = OpenLibrary("graphics.library",0);
  104.     if( GfxBase == 0 ) {
  105.         OutErr("graphics library won't open");
  106.         exit(10);
  107.     }
  108.  
  109.     IntuitionBase = OpenLibrary("intuition.library",0);
  110.     if( IntuitionBase == 0 ) {
  111.         OutErr("intuition library won't open");
  112.         exit(10);
  113.     }
  114.  
  115.     InitGadgets();
  116.     CntrlWin = OpenWindow( &CntrlWinDef );
  117.     CntrlSigBit = CntrlWin->UserPort->mp_SigBit;
  118.  
  119.     MenuSetScrn();
  120.  
  121.     if( !SurfScrn || !SurfWin || !CntrlWin ) {
  122.         OutErr("couldn't open at least one window or screen");
  123.         CloseDisplay();
  124.         exit( 0 );
  125.     }
  126.  
  127.     SetMenuStrip(CntrlWin, menu );
  128. }
  129.  
  130.  
  131. /*
  132.  * remove surface window/screen
  133.  */
  134. CloseSurf() {
  135.  
  136.     if( PolyWorkSpace)
  137.         FreeRaster( PolyWorkSpace, SurfWinDef.Width, SurfWinDef.Height );
  138.  
  139.     if( SurfWin )
  140.         CloseWindow( SurfWin );
  141.  
  142.     if( GadWin )
  143.         CloseWindow( GadWin );
  144.  
  145.     if( SurfScrn )
  146.         CloseScreen( SurfScrn );
  147. }
  148.  
  149.  
  150. void CloseDisplay()
  151. {
  152.  
  153.     CloseSurf();
  154.  
  155.  
  156.     if( CntrlWin ) {
  157.         ClearMenuStrip( CntrlWin );
  158.         CloseWindow( CntrlWin );
  159.     }
  160.  
  161.     EndGadgets();
  162.  
  163.     if ( IntuitionBase )
  164.         CloseLibrary(IntuitionBase);
  165.  
  166.     if ( GfxBase )
  167.         CloseLibrary(GfxBase);
  168. }
  169.  
  170.  
  171.