/*-----------------------------------------------------------
--  Programm: DiskFont.c
--     Autor: Intuition Ed 
--     Datum: Thu May 24
--  Funktion: Beispielprogramm für eine Diskfont.
--            Es wird die ruby.font geöffnet, die sich
--            im aktuellen Fonts-Verzeichnis befinden sollte.
------------------------------------------------------------/*


/*-------------------
--  Includes  :    --
-------------------*/

#include <intuition/intuition.h>


/*-------------------
--  Defines  :     --
-------------------*/



/*-------------------
--  Funktionen  :  --
-------------------*/

void                   Open_All() ;
void                   Close_All();

/*-------------------
--  externe        --
--  Variablen  :   --
-------------------*/

struct IntuitionBase  *IntuitionBase;
struct GfxBase        *GfxBase;
ULONG                 *DiskfontBase;
struct Window         *Window;
struct Font           *Text1Font;

/*-------------------
--  Strukturen  :  --
-------------------*/


struct TextAttr Text1TextAttr =
{
 (STRPTR) "ruby.font",                    /* ta_Name                   */
  15,                                     /* ta_YSize                  */
 NULL,                                    /* ta_Style                  */
 FPF_DISKFONT ,                           /* ta_Flags                  */
};

struct IntuiText Text1 =
{
  -1, -1,                                 /* FrontPen , BackPen        */
 JAM1,                                    /* DrawMode                  */
  20, 20,                                 /* LeftEdge , TopEdge        */
 &Text1TextAttr ,                         /* TextAttr                  */
 (UBYTE *) "ruby.font   (15)",            /* Text                      */
 NULL,                                    /* Last Text !               */
};

/*-  NewWindow  :   ---
---  Window         -*/

struct NewWindow NewWindow =
{
  10, 20,                                 /* LeftEdge , TopEdge        */
 300, 50,                                 /* Width , Height            */
   0,  1,                                 /* DetailPen , BlockPen      */
 NULL,                                    /* IDCMP Flags               */
 WINDOWSIZING                             /* Flags                     */
 | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | ACTIVATE,
 NULL,                                    /* No Gadget                 */
 NULL,                                    /* Check Mark                */
 (UBYTE *) "Beispiel für eine Diskfont :", /* Title                     */
 NULL,                                    /* Screen                    */
 NULL,                                    /* BitMap                    */
 100, 20,                                 /* MinWidth , MinHeight      */
 640,256,                                 /* MaxWidth , MaxHeight      */
 WBENCHSCREEN,                            /* ScreenType                */
};

/*-----------------------------------------------------------
--      Funktion: main
--  Benötigte oder veränderte globale Variablen
--              :         --
--  Rückgabewert:         --
--     Bemerkung: ruft Open_All und Close_All auf.
------------------------------------------------------------*/

void main()
{
Open_All();
Delay(1000L);
Close_All();
}

/*-----------------------------------------------------------
--      Funktion: Open_All
--       Aufgabe: Öffnet die Intuitionslibrary,
--                öffnet alle Intuitionselemente.
--  Benötigte oder veränderte globale Variablen
--              :         --
--  Rückgabewert:         --
--     Bemerkung: Ruft bei einem Fehler Close_All auf.
------------------------------------------------------------*/


void Open_All()
{
 void                  PrintIText();
 struct Window        *OpenWindow();
 struct Font          *OpenDiskFont();
 void                 *OpenLibrary();

 if (NOT(IntuitionBase = (struct IntuitionBase *)
       OpenLibrary ("intuition.library", 0L)))
 {
  printf("Keine Intuition Library gefunden.");
  Close_All();
  exit(FALSE);
 }

 if (NOT(GfxBase = (struct GfxBase *)
    OpenLibrary("graphics.library",0L)))
 {
  printf("Keine Grafik Library gefunden.");
  Close_All();
  exit(FALSE);
 }

 if (NOT(DiskfontBase = (ULONG *)
    OpenLibrary("diskfont.library",0L)))
 {
  printf("Keine DiskFont Library gefunden.");
  Close_All();
  exit(FALSE);
 }

 if (NOT(Window = (struct Window *)
       OpenWindow (&NewWindow )))
 {
  printf("Das Window -  WB-Window läßt sich nicht öffnen.\n");
  Close_All();
  exit(FALSE);
 }

 if (NOT(Text1Font = (struct Font *)
   OpenDiskFont (&Text1TextAttr)))
 {
  printf("Die DiskFont Text1Font läßt sich nicht öffnen.\n");
  Close_All();
  exit(FALSE);
 }

 SetFont (Window->RPort,Text1Font);

 PrintIText (Window->RPort,&Text1,0L,0L);
}

/*-----------------------------------------------------------
--      Funktion: Close_All
--       Aufgabe: Schließt die Intuitionslibrary,
--                schließt alle Intuitionselemente
--  Benötigte oder veränderte globale Variablen
--              :         --
--  Rückgabewert:         --
--     Bemerkung:         --
------------------------------------------------------------*/

void Close_All()
{
 void                  CloseWindow();
 void                  CloseLibrary();

 if (Text1Font)  CloseFont(Text1Font);
 if (Window)   CloseWindow (Window) ;

 if (GfxBase)           CloseLibrary(GfxBase);
 if (DiskfontBase)      CloseLibrary(DiskfontBase);
 if (IntuitionBase)     CloseLibrary(IntuitionBase);
}
