home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 432b.lha / EzLib / src / demo.c < prev    next >
C/C++ Source or Header  |  1990-11-10  |  4KB  |  133 lines

  1. /* This program "demos" most of the features of ezlib.
  2.  *
  3.  * The big thing to notice is how much it abstracts the code you are
  4.  * writing.  You no longer have to write gobs and gobs of crap to deal
  5.  * with screens, and windows.
  6.  *
  7.  * Also notice, that you still should error check results from the ez.lib
  8.  * functions.  This is the Amiga and not a protected memory environment,
  9.  * so failure to check the return values could be dangerous.
  10.  */
  11.  
  12. #include "ezlib.h"          /* get in the door with ez.lib */
  13.  
  14.  
  15. main()
  16. {
  17.  struct Screen *screen=NULL;        /* our custom screen           */
  18.  struct Window *wind=NULL;        /* our window               */
  19.  struct Gadget *gadg=NULL;        /* do-nothing gadget           */
  20.  struct RastPort *rp;            /* rastport for Gfx calls      */
  21.  struct TextFont *tf=NULL;        /* disk font ptr           */
  22.  char *string=NULL;            /* return ptr from getstring() */
  23.  
  24.  
  25.  /* in reality, this call to openlibs() isn't even needed as it will happen
  26.   * in makescreen() or makewindow().  However it makes things look more
  27.   * symetric with the closelibs() call at the end (which you really should
  28.   * make).
  29.   */
  30.  if (openlibs(GFX|INTUI) == NULL)
  31.    {  MSG("no libs?\n"); exit(10L); }
  32.  
  33.  
  34.  screen = makescreen(HIRES, 3);       /* gets a 640x400 8 color screen */
  35.  if (screen == NULL)
  36.   { closelibs(); exit(10); }          /* safe exit just in case... */
  37.  
  38.  
  39.  /* set up some some nice colors */
  40.  setcolor(screen, 0, BLACK);   setcolor(screen, 1, PINK);
  41.  setcolor(screen, 2, YELLOW);  setcolor(screen, 3, ORANGE);
  42.  setcolor(screen, 4, INDIGO);  setcolor(screen, 5, GREEN);
  43.  
  44.  
  45.  /* notice that even though these window dimensions are totally off, they
  46.   * are corrected in makewindow()
  47.   */
  48.  wind = makewindow(screen, 0, 0, -1, -1);
  49.  if (wind == NULL)
  50.   { killscreen(screen); closelibs(); exit(10); }   /* exit path */
  51.  
  52.  
  53.  SetWindowTitles(wind, "EzLib Demo Program", -1);
  54.  
  55.  rp = wind->RPort;       /* get a RastPort for calling the gfx library */
  56.  
  57.  
  58.  /* if you happen to have this font in your fonts: directory, you're all
  59.   * set.  If not, no biggie - we'll just use the default font.
  60.   */
  61.  
  62.  tf = getfont("toronto.font", 12);
  63.  if (tf != NULL)
  64.    SetFont(rp, tf);
  65.  
  66.  /* get an input string from the user. */
  67.  
  68.  string = getstring(screen, "Enter a string here:", "This is a default string");
  69.  
  70.  if (string != NULL) {
  71.    Move(rp, 160, 40);
  72.    Print(rp, "You typed :");    /* ezlib #define for printing window text */
  73.    Print(rp, string);
  74.    FreeMem(string, strlen(string)+1);
  75.  }
  76.  
  77.  
  78.  draw_stuff(rp);       /* draw some simple graphics in the window */
  79.  
  80.  
  81.  /* create a simple do-nothing gagdet */
  82.  gadg = makeboolgadget(wind, 210, 175, "Don't have a cow dude!", 43);
  83.  
  84.  Move(rp, 200, 150);
  85.  Print(rp, "Ezlib makes programming fun.");     /* be obnoxious here */
  86.  Move(rp, 190, 170);
  87.  Print(rp, "Click the close gadget to exit");
  88.  
  89.  
  90.  /* since the window has a close gadget, the first message will be from
  91.   * the user clicking the CLOSE gadget.  Soooooo, we can just exit.
  92.   */
  93.  WaitPort(wind->UserPort);
  94.  
  95.  getyn(wind, "Boy this sure is neat huh?");   /* just be annoying */
  96.  
  97.  /* here we go through the motions of closing up shop */
  98.  
  99.  if (tf)
  100.    CloseFont(tf);  /* close the font we opened with the call to getfont() */
  101.  
  102.  if (gadg)
  103.    killgadget(wind, gadg);   /* free gadget resources                      */
  104.  
  105.  killwindow(wind);           /* close the window with error checking       */
  106.  killscreen(screen);         /* do same for the screen                     */
  107.  closelibs();                /* close any opened libraries here            */
  108.  exit(0);                    /* and finally call the normal exit() routine */
  109. }
  110.  
  111.  
  112. /* this function will draw some simple graphics into your rastport.
  113.  * Some numbers are hardcoded, yes, but this is just a demo....
  114.  */
  115. draw_stuff(rp)
  116.  struct RastPort *rp;
  117. {
  118.  int i;
  119.  
  120.  /* lets just draw some stuff on the screen */
  121.  for(i=40; i < 160; i++ ) {
  122.    Line(rp, 10, i, 620, (200 - i) );   /* ezlib #define for drawing lines */
  123.    SetAPen(rp, i % 16);                /* change colors for each line */
  124.  }
  125.  
  126.  for(i=20; i < 50; i++) {
  127.    Line(rp, 10, i, 620, i);
  128.    Circle(rp, 310, i, 10);       /* ezlib #define for drawing circles */
  129.    SetAPen(rp, i % 16);
  130.  }
  131. }
  132.  
  133.