/*
 *  Source generated with GadToolsBox V1.4
 *  which is (c) Copyright 1991,92 Jaba Development
 */

#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/utility.h>
#include <string.h>

#include "window.h"

struct Screen         *Scr = NULL;
APTR                   VisualInfo = NULL;
struct Window         *AppWnd = NULL;
UWORD                  AppLeft = 223;
UWORD                  AppTop = 49;
UWORD                  AppWidth = 176;
UWORD                  AppHeight = 27;
UBYTE                 *AppWdt = (UBYTE *)"pat2icon v1.0";

struct TextAttr topaz8 = {
    ( STRPTR )"topaz.font", 8, 0x00, 0x01 };

struct IntuiText  AppIText[] = {
    2, 0, JAM1,21, 7, &topaz8, (UBYTE *)"Drop icons here!", NULL };

int SetupScreen( void )
{
    if ( ! ( Scr = LockPubScreen( NULL )))
        return( 1L );

    if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
        return( 2L );

    return( 0L );
}

void CloseDownScreen( void )
{
    if ( VisualInfo ) {
        FreeVisualInfo( VisualInfo );
        VisualInfo = NULL;
    }

    if ( Scr        ) {
        UnlockPubScreen( NULL, Scr );
        Scr = NULL;
    }
}

void AppRender( void )
{
    UWORD        offx, offy;

    offx = AppWnd->BorderLeft;
    offy = AppWnd->BorderTop;

    PrintIText( AppWnd->RPort, AppIText, offx, offy );
}

int OpenAppWindow( void )
{
    struct NewGadget     ng;
    struct Gadget       *g;
    UWORD                lc, tc;
    UWORD                offx = Scr->WBorLeft,offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;

    if ( ! ( AppWnd = OpenWindowTags( NULL,
                    WA_Left,          AppLeft,
                    WA_Top,           AppTop,
                    WA_Width,         AppWidth,
                    WA_Height,        AppHeight + offy,
                    WA_IDCMP,         IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
                    WA_Flags,         WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
                    WA_Title,         AppWdt,
                    WA_PubScreen,     Scr,
                    TAG_DONE )))
        return( 4L );

    GT_RefreshWindow( AppWnd, NULL );

    AppRender();

    return( 0L );
}

void CloseAppWindow( void )
{
    if ( AppWnd        ) {
        CloseWindow( AppWnd );
        AppWnd = NULL;
    }
}

