; /*
sc RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE shutscreen.c
slink from lib:c.o shutscreen.o to //Clients/ShutScreen lib /lib/client.lib lib:sc.lib lib:amiga.lib SC SD STRIPDEBUG NOICONS
delete shutscreen.o
quit

 ShutScreen 1.3  (Client for BServer)

 Copyright © 1994-1995 Stefano Reksten of 3AM - The Three Amigos!!!
 All rights reserved.
*/

#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <graphics/scale.h>

#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>

#include "/include/client.h"
#include "/include/bitmap/bitmap.h"
#include "/include/bitmap/bitmap_pragmas.h"

char *ver = "$VER: ShutScreen 1.3 "__AMIGADATE__;

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *BitMapBase;

struct Screen *clonescr, *scr;
UWORD scrwidth, scrheight, scrdepth;
ULONG command;

struct BitMap *bmap, *scalebmap;
struct DisplayIDInformation *dinfo;

struct BitMapScaleInfo myscaleinfo = {
	NULL, NULL, NULL, 1, 1, 0, 0,
	0, 0, 0, 0, 0, 0, NULL };


void Shut( void )
{
BOOL still_blitting;
BOOL blanking, success = FALSE;
UWORD frame, top;

clonescr = IntuitionBase->FirstScreen;
scrwidth = clonescr->Width;
scrheight = clonescr->Height;
scrdepth = clonescr->RastPort.BitMap->Depth;

if ( scr = CloneFrontmostScreen( 100 ) )
	{
	if ( scalebmap = CreateBitMap( scrwidth, scrheight, scrdepth ) )
		{
		myscaleinfo.bsi_SrcBitMap = clonescr->RastPort.BitMap;
		myscaleinfo.bsi_TempBitMap = scalebmap;
		myscaleinfo.bsi_DestBitMap = scr->RastPort.BitMap;
		myscaleinfo.bsi_Width = scrwidth;
		myscaleinfo.bsi_Height = scrheight;
		myscaleinfo.bsi_VertDen = scrheight;

		success = TRUE;
		SpritesOff();

		blanking = TRUE;
		still_blitting = TRUE;
		frame = 0;
		top = 0;

		SetAPen( &scr->RastPort, DarkestColorIndex( scr ) );

		while( blanking )
			{
			if ( still_blitting )
				command = GetServerCommand();
			else
				command = WaitServerCommand();

			if ( command != COMMAND_IDLE )
				blanking = FALSE;
			else
			if ( still_blitting )
				{
				frame += 2;
				if ( frame > scrheight )
					{
					SetAPen( &scr->RastPort, 0 );
					SetRGB4( &scr->ViewPort, 0, 0, 0, 0 );
					SetRast( &scr->RastPort, 0 );
					still_blitting = FALSE;
					}
				else
					{
					myscaleinfo.bsi_VertNum = scrheight - frame;
					myscaleinfo.bsi_DestTopEdge = 1+top>>1;
					ScaleBitMap( &myscaleinfo );
					}

				Move( &scr->RastPort, 0, (top>>1) );
				Draw( &scr->RastPort, scrwidth - 1, (top>>1) );
				Move( &scr->RastPort, 0, scrheight - 1 - (top>>1));
				Draw( &scr->RastPort, scrwidth - 1, scrheight - 1 - (top>>1) );

				top += 2;
				}
			}

		SpritesOn();

		DisposeBitMap( scalebmap );
		}
	CloseScreen( scr );
	}

if ( !success )
	SendClientMsg( ACTION_FAILED );
}


void __main( void )
{
if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 36L ) )
	{
	if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library",0L ) )
		{
		if ( BitMapBase = OpenLibrary( "bitmap.library", 0L ) )
			{
			if ( dinfo = OpenCommunication() )
				{
				Shut();
				CloseCommunication( dinfo );
				}
			CloseLibrary( BitMapBase );
			}
		CloseLibrary( (struct Library *)GfxBase );
		}
	CloseLibrary( (struct Library *)IntuitionBase );
	}
}
