/* Billboard v2.0 Copyright © 1992 Todd J. Petit */

#include <intuition/intuition.h>
#include <string.h>
#include <graphics/text.h>
#include <stdlib.h>

#define ok_exit 0
#define failure_exit 20
#define error_exit 10
#define warning_exit 5

struct IntuitionBase *IntuitionBase;
struct DosBase *DosBase;
struct GfxBase *GfxBase;
struct NewWindow MyWindow = 
       {160,50,300,60,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,10,10,
        0xFFFF,0xFFFF,WBENCHSCREEN};

/* graphic data "bored_man_pic", "speaker_pic", "logo_pic" */
#include "bbpics.h"

struct Image picture = {NULL,NULL,NULL,NULL,2,NULL,0x0003,0x0000,NULL};

/* --------------------------------------------------------------------- */

char opts[]="";
main(int argc, char *argv[])
{
  struct Window *wind;
  struct Rastport *rp;
  char option,*odata;
  int next = 1;
  int seconds = 0;
  int image_number = 1;
  int offset, linelen, pixellen, printline;
  char line[3][40] = { {"Welcome"},
                       {"to"},
                       {"Amiga!"} };;
      
  /* parse options */
  for(; (odata = argopt(argc,argv,opts,&next,&option)) != NULL;)
  { if (option == 's')
      seconds = atoi(odata);
      
    if (option == 'i')
      image_number = atoi(odata);   
      
    if (option == 'p')
    { strcpy(line[1], odata); 
      strcpy(line[0], "Loading");
      strcpy(line[2], "please wait...");
    }
    
    if (option == '1')
      strcpy(line[0], odata);
    if (option == '2')
      strcpy(line[1], odata);
    if (option == '3')
      strcpy(line[2], odata);
  }
  
  /* User wants info */
  for(; next < argc; next++)
  { if (!strcmp(argv[next], "?"))
     { puts("Billboard v2.0 Copyright © 1992 Todd J. Petit");
       puts("Usage: bb [-i<image#>] [-s<seconds>] [-p<program>]");
       puts("          [-1<string>] [-2<string>]  [-3<string>]");
       puts(" ");
       puts("where <image#>  is 1 (Commodore logo)");
       puts("                   2 (bored man)");
       puts("                   3 (speaker)");
       puts("      <seconds> is number of seconds to display (default is 5)");
       puts("      <program> is name of program to display with 'Loading'");
       puts("                   'please wait...' message");
       puts("      <string>  is text string to display on this line number");
       puts("                   (to display a string with imbedded spaces");
       puts("                    enclose it, with switch, in double quotes)");
       exit(warning_exit);
     }
  }     
  
  /* set seconds to default if User didn't set a time */
  if (seconds < 1) seconds = 5;
  
  /* Open libraries, exit on failure */
  if(!(IntuitionBase=
    (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
    exit(failure_exit);
  if(!(DosBase=
    (struct DosBase *)OpenLibrary("dos.library",0)))
    exit(failure_exit);
  if(!(GfxBase=
    (struct GfxBase *)OpenLibrary("graphics.library",0)))
    exit(failure_exit);    
 
  /* Open window, paste graphic into window */
  if(!(wind = (struct Window *) OpenWindow(&MyWindow)))
    exit (error_exit);
  rp = wind->RPort;
  switch (image_number)
  { default:
      picture.ImageData = logo_pic;
      picture.LeftEdge = 15;
      picture.TopEdge = 5;
      picture.Width = 112;
      picture.Height = 48;
      break;
    case 2:
      picture.ImageData = bored_man_pic;
      picture.LeftEdge = 15;
      picture.TopEdge = 4;
      picture.Width = 96;
      picture.Height = 51;
      break;
    case 3:
      picture.ImageData = speaker_pic;
      picture.LeftEdge = 15;
      picture.TopEdge = 2;
      picture.Width = 80;
      picture.Height = 54;
      break;
  }    
  DrawImage(rp,&picture,1,1);
 
  /* Write 3 lines of centered, italic, shadowed text */
  for(printline = 0; printline < 3; printline++)
  { linelen = strlen(line[printline]);
    pixellen = (linelen * 8);
    offset = (((200 - pixellen) / 2) + 100);
    SetDrMd(rp,0);
    SetSoftStyle(rp,FSF_ITALIC,FSF_ITALIC);
    SetAPen(rp,1); /* black */
    Move(rp,(offset+2),(23 + (printline * 10)));
    Text(rp,line[printline],linelen);
    SetAPen(rp,2); /* white */
    Move(rp,offset,(22 + (printline * 10)));
    Text(rp,line[printline],linelen);
  }  
  
  /* Hold window open for requested number of seconds */
  Delay(seconds * 50);

  /* Close all windows, libraries */
  CloseWindow(wind);
  CloseLibrary(IntuitionBase);
  CloseLibrary(DosBase);
  CloseLibrary(GfxBase);
  
  exit(ok_exit);
}
/* End of Program Source */
