//##ex mcpp:cppc -d __IGNORE_NOT_SUPPORTED__ -gs -o MoreIntuiText p:pLib/StartCode.o -pc MoreIntuiText.c p:pLib/StdIO.o -l pOSxA -l pOSStub -l pOS -l List

/*\
*** 04.02.1997, Michael Christoph, proDAD
*** Example:
*** Tag WA_RMBTrap
***     wird von pOS noch nicht unterstützt
\*/


#define INTUI_V36_NAMES_ONLY

#include <exec/types.h>
#include <intuition/intuition.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>

#include <stdio.h>

#ifdef LATTICE
int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
int chkabort(void) { return(0); }  /* really */
#endif

UBYTE *vers = "$VER: MoreIntuiText 1.0 (04.02.1997) (proDAD, Michael Christoph)";

#ifdef __pOS__
struct pOS_IntuiDevice  *gb_IntuiBase;
struct pOS_GfxBase      *gb_GfxBase;      /*** wird zusätzlich benötigt ***/
struct pOS_UtilityBase  *gb_UtilityBase;  /*** wird zusätzlich benötigt ***/
struct pOS_LayerBase    *gb_LayerBase;    /*** wird zusätzlich benötigt ***/
#else
struct Library          *IntuitionBase = NULL;
#endif

#define MYTEXT_LEFT (0)
#define MYTEXT_TOP  (0)

/*MIC*/ void PrintIText2(struct RastPort *rp, struct IntuiText *intuitext, LONG dx, LONG dy);

/*
** main routine. Open required library and window and draw the images.
** This routine opens a very simple window with no IDCMP.  See the
** chapters on "Windows" and "Input and Output Methods" for more info.
** Free all resources when done.
*/
VOID main(int argc, char **argv)
{
  struct Screen    *screen;
  struct DrawInfo  *drawinfo;
  struct Window    *win;
  struct IntuiText  myIText;
  struct IntuiText  myIText2;
  struct IntuiText  myIText3;
  struct TextAttr   myTextAttr;
  struct TextAttr   myTextAttr2={ "courier.font",24 };
  struct TextAttr   myTextAttr3={ "proDAD.font",16,FNTSTY_Normal,FNTFLGF_Proportional };

  ULONG myTEXTPEN;
  ULONG myBACKGROUNDPEN;

#ifdef __pOS__
  if(gb_UtilityBase=(struct pOS_UtilityBase *) pOS_OpenLibrary("pUtility.library",0))
  {
  if(gb_GfxBase=(struct pOS_GfxBase *) pOS_OpenLibrary("pGraphics.library",0))
  {
  if(gb_LayerBase=(pOS_LayerBase*) pOS_OpenLibrary("pLayer.library",0))
  {
  if(gb_IntuiBase=(struct pOS_IntuiDevice*) pOS_OpenLibrary("pIntui.library",0))
#else
  if( IntuitionBase = OpenLibrary("intuition.library",37) )
#endif
  {
    if (screen = LockPubScreen(NULL))
    {
      if (drawinfo = GetScreenDrawInfo(screen))
      {
        /* Get a copy of the correct pens for the screen.
        ** This is very important in case the user or the
        ** application has the pens set in a unusual way.
        */
        myTEXTPEN = drawinfo->dri_Pens[TEXTPEN];
        myBACKGROUNDPEN  = drawinfo->dri_Pens[BACKGROUNDPEN];

        /* create a TextAttr that matches the specified font. */
        myTextAttr.ta_Name  = drawinfo->dri_Font->tf_Message.mn_Node.ln_Name;
        myTextAttr.ta_YSize = drawinfo->dri_Font->tf_YSize;
        myTextAttr.ta_Style = drawinfo->dri_Font->tf_Style;
        myTextAttr.ta_Flags = drawinfo->dri_Font->tf_Flags;

        /* open a simple window on the workbench screen for displaying
        ** a text string.  An application would probably never use such a
        ** window, but it is useful for demonstrating graphics...
        */
        if (win = OpenWindowTags(NULL,
                          WA_PubScreen,    screen,
                          WA_RMBTrap,      TRUE,
#ifdef __pOS__
                          WA_Title,        NULL,
#endif
                          TAG_END))
        {
          myIText.FrontPen    = myTEXTPEN;
          myIText.BackPen     = myBACKGROUNDPEN;
          myIText.DrawMode    = JAM2;
          myIText.LeftEdge    = MYTEXT_LEFT;
          myIText.TopEdge     = MYTEXT_TOP;
          myIText.ITextFont   = &myTextAttr;
          myIText.IText       = "Hello, World.  ;-)";
          myIText.NextText    = &myIText2;

          myIText2.FrontPen    = 3;
          myIText2.BackPen     = 1;
          myIText2.DrawMode    = JAM2;
          myIText2.LeftEdge    = MYTEXT_LEFT+8;
          myIText2.TopEdge     = MYTEXT_TOP+10;
          myIText2.ITextFont   = &myTextAttr2;
          myIText2.IText       = "Hello, World.2";
          myIText2.NextText    = &myIText3;

          myIText3.FrontPen    = 2;
          myIText3.BackPen     = 4;
          myIText3.DrawMode    = JAM1;
          myIText3.LeftEdge    = MYTEXT_LEFT+16;
          myIText3.TopEdge     = MYTEXT_TOP+36;
          myIText3.ITextFont   = &myTextAttr3;
          myIText3.IText       = "Hello, World.3";
          myIText3.NextText    = NULL;

          /* ausgeben aller drei IntuiText-Strukturen mit Offset 10,10 */
          PrintIText(win->RPort,&myIText,10,10);

          /* Wait a bit, then quit.
          ** In a real application, this would be an event loop,
          ** like the one described in the Intuition Input and
          ** Output Methods chapter.
          */
          Delay(200);

          CloseWindow(win);
        }
        FreeScreenDrawInfo(screen,drawinfo);
      }
      UnlockPubScreen(NULL,screen);
    }
#ifdef __pOS__
    pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
#else
    CloseLibrary(IntuitionBase);
#endif
#ifdef __pOS__
  pOS_CloseLibrary((struct pOS_Library*)gb_LayerBase);
  }
  pOS_CloseLibrary((struct pOS_Library*)gb_GfxBase);
  }
  pOS_CloseLibrary((struct pOS_Library*)gb_UtilityBase);
  }
#endif
  }
}
