# dont perform the libgen and libsocket test in configure for AROS.
[AROS-Contrib.git] / fish / surf / scrnio.c
blob429436622169667ca49f46e6bc7bcf57182ff0b6
1 /* main program */
3 #include <aros/oldprograms.h>
4 #include "scrnio.ih"
5 #ifdef MANX
6 #include <functions.h>
7 #endif /* MANX */
9 #include "scrndef.h"
10 #include "scrnio.h"
11 #include "gadgetdef.h"
12 #include "menudef.h"
14 struct Screen *SurfScrn = NULL;
15 struct Window *SurfWin = NULL;
16 struct Window *CntrlWin = NULL;
17 struct Window *GadWin = NULL;
19 * bit masks for waiting for signals
21 short CntrlSigBit, SurfSigBit, GadSigBit;
22 long SignalMask = 0;
24 struct RastPort *rp;
25 struct ViewPort *vp;
27 struct GfxBase *GfxBase = 0;
28 struct IntuitionBase *IntuitionBase = 0;
30 void OutErr(char *);
31 void MenuSetColMap();
32 void MenuSetScrn();
34 int XOR = COMPLEMENT, /* so my other modules don't need to */
35 WRITE = JAM1; /* include so many amiga includes */
37 int WinHOrig, WinVOrig;
38 int WinFgCol;
39 int ColorMax;
40 int NumColors;
43 * data structures needed to use amiga polygons routines
45 static WORD PolyArea[5*5];
46 static struct AreaInfo PolyInfo;
47 static PLANEPTR PolyWorkSpace;
48 static struct TmpRas PolyTmpRas;
52 static void ResetWinDat() {
54 WinHOrig = SurfWinDef.Width >>1;
55 WinVOrig = SurfWinDef.Height >>1;
58 rp = SurfWin->RPort;
59 SetDrMd( rp, JAM1 );
65 * open surface window/screen
67 void OpenSurf() {
68 NumColors = 1 << SurfScrnDef.Depth;
69 ColorMax = ( NumColors -1) * DitherLevels + 1;
70 WinFgCol = (NumColors - 1) & 0x1f;
72 SurfScrnDef.BlockPen = ( WinFgCol *3) /4;
73 SurfScrnDef.DetailPen = WinFgCol>>2;
75 SurfScrn = OpenScreen( &SurfScrnDef );
76 MenuSetColMap();
77 SurfWinDef.Screen = GadWinDef.Screen = SurfScrn;
78 SurfWinDef.Width = GadWinDef.Width = SurfScrnDef.Width;
79 SurfWinDef.Height = SurfScrnDef.Height - ButHeight;
81 SurfWin = OpenWindow( &SurfWinDef );
82 GadWin = OpenWindow( &GadWinDef );
83 SurfSigBit = SurfWin->UserPort->mp_SigBit;
84 GadSigBit = GadWin->UserPort->mp_SigBit;
85 SignalMask = (1<<CntrlSigBit) | (1<<SurfSigBit)| (1<<GadSigBit);
87 ResetWinDat();
88 ShowTitle( SurfScrn, 0L ); /* hide screen title behind backdrop */
90 InitArea( &PolyInfo, PolyArea, 5);
91 rp->AreaInfo = &PolyInfo;
93 PolyWorkSpace = AllocRaster( SurfWinDef.Width, SurfWinDef.Height);
95 if( !PolyWorkSpace ) {
96 CloseDisplay();
97 OutErr("no space for temporary rastern");
98 exit(0);
100 else {
101 InitTmpRas( &PolyTmpRas, PolyWorkSpace,
102 RASSIZE( SurfWinDef.Width, SurfWinDef.Height ));
103 rp->TmpRas = &PolyTmpRas;
108 void InitWindow()
110 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
111 if( GfxBase == 0 ) {
112 OutErr("graphics library won't open");
113 exit(10);
116 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
117 if( IntuitionBase == 0 ) {
118 OutErr("intuition library won't open");
119 exit(10);
122 InitGadgets();
123 CntrlWin = OpenWindow( &CntrlWinDef );
124 CntrlSigBit = CntrlWin->UserPort->mp_SigBit;
126 MenuSetScrn();
128 if( !SurfScrn || !SurfWin || !CntrlWin ) {
129 OutErr("couldn't open at least one window or screen");
130 CloseDisplay();
131 exit( 0 );
134 SetMenuStrip(CntrlWin, menu );
139 * remove surface window/screen
141 void CloseSurf() {
143 if( PolyWorkSpace)
144 FreeRaster( PolyWorkSpace, SurfWinDef.Width, SurfWinDef.Height );
146 if( SurfWin )
147 CloseWindow( SurfWin );
149 if( GadWin )
150 CloseWindow( GadWin );
152 if( SurfScrn )
153 CloseScreen( SurfScrn );
157 void CloseDisplay()
160 CloseSurf();
163 if( CntrlWin ) {
164 ClearMenuStrip( CntrlWin );
165 CloseWindow( CntrlWin );
168 EndGadgets();
170 if ( IntuitionBase )
171 CloseLibrary((struct Library *)IntuitionBase);
173 if ( GfxBase )
174 CloseLibrary((struct Library *)GfxBase);