[net.micro.amiga] Hello World

eric@topaz.RUTGERS.EDU (Eric Lavitsky) (09/04/85)

Hi,

 Well here is the first ever Amiga source to be posted on the net. The
following code was taken from the Amiga User Interface Manual. This
program uses the Intuition user interface under V28 of the operating
system. Intuition controls all the window sizing and dragging for the
application, though you can tell Intuition to tell your program about
certain events (like resizing) so you can take your own action. The
code is not ultimately clean - all the structures could be initialized 
like the first one etc. I kept most of the original comments from the
example and added one or two of my own.

 The program opens its own screen (320x200) and creates a window that
can be dragged, sized, pushed up or down and closed. The screen can also
be pushed down or popped up and be pulled down to reveal the screen below
it (one of my favorite features!)

Enjoy!


/***************************************************************************
 *
 *       "Hello World"
 *
 **************************************************************************/

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

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;

#define INTUITION_REV 28	/* You must be sure this is correct */
#define GRAPHICS_REV 28

/* This font declaration will be used for our new screen */

struct TextAttr MyFont =
   {
   "topaz.font",     /* Font Name *
   TOPAZ_SIXTY,      /* Font Height */
   FS_NORMAL,        /* Style */
   FPF_ROMFONT       /* Preferences */
   };

/* This is the declaration of a pre-initialized NewScreen data block.
 * It often requires less work, and often uses less code space, to
 * pre-initialize data structures in this fashion.
 */

struct NewScreen NewScreen =
   {
   0,                /* the LeftEdge should be equal to zero */
   0,                /* TopEdge */
   320,              /* Width (lo-resolution) */
   200,		     /* Height (non-interlace) */
   2,		     /* Depth (16 colors will be available) */
   0, 1,             /* the DetailPen and BlockPen specifications */
   NULL,             /* no special display modes */
   CUSTOMSCREEN,     /* the Screen Type */
   &MyFont,          /* Use my own font */
   "My Own Screen",  /* this declaration is compiled as a text pointer */
   NULL,             /* no special Screen Gadgets */
   NULL              /* no special Custom BitMap */
   };

main()
{
   struct Screen *Screen;
   struct NewWindow NewWindow;
   struct Window *Window;

   /* Open the Intuition library. The result returned by this call is
    * used to connect your program to the actual Intuition routines
    * in ROM. If the result of this call is zero, something is wrong
    * and the Intuition you requested is not available, so your program
    * should exit immediately
    */

   IntuitionBase = (struct IntuitionBase *)
      OpenLibrary("intuition.library",INTUITION_REV);
   if(IntuitionBase == NULL)
      exit(FALSE);

   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",GRAPHICS_REV);
   if(GfxBase == NULL)
      exit(FALSE);

   if((Screen = (struct Screen *) OpenScreen(&NewScreen)) == NULL)
      exit(FALSE);

   /* Initialize the NewWindow structure for the call to OpenWindow() */

   NewWindow.LeftEdge = 20;
   NewWindow.TopEdge = 20;
   NewWindow.Width = 300;
   NewWindow.Height = 100;
   NewWindow.DetailPen = 0;
   NewWindow.BlockPen = 1;
   NewWindow.Title = "A Simple Window";
   NewWindow.Flags = WINDOWCLOSE | SMART_REFRESH | ACTIVATE
      | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH;
   NewWindow.IDCMPFlags = CLOSEWINDOW;	/* Tell us about CLOSEWINDOW events */
   NewWindow.Type = CUSTOMSCREEN;
   NewWindow.FirstGadget = NULL;
   NewWindow.CheckMark = NULL;
   NewWindow.Screen = Screen;
   NewWindow.BitMap = NULL;
   NewWindow.MinWidth = 100;
   NewWindow.MinHeight = 25;
   NewWindow.MaxWidth = 32767;
   NewWindow.MaxHeight = 32767;

   /* Try to open the window. Like the call to OpenLibrary(), if
    * the OpenWindow call is successful, it returns a pointer to
    * the structure for your new window. If the OpenWindow() call
    * fails, it returns a zero.
    */

   if(( Window = (struct Window *) OpenWindow(&NewWindow)) == NULL)
      exit(FALSE);

   Move(Window->RPort,20,20);
   Text(Window->RPort,"Hello World",11);

   for(;;)
     {
     Wait(1 << Window->UserPort->mp_SigBit);
     CloseWindow(Window);	/* Close the Window */
     CloseScreen(Screen);	/* Close the Screen */
     exit(TRUE);		/* Exit */
     }
}


---------------

Eric
-- 

ARPA:	LAVITSKY@RUTGERS
UUCP:	...{harvard,seismo,ut-sally,sri-iu,ihnp4}!topaz!eric
SNAIL:	16 Oak St., Flr 2
	New Brunswick, NJ  08903