/* Banner Press.c
   (C) 1989 Oliver Wagner, Landsberge 5, 4322 Sprockhövel, W-Germany
   for Aztec 3.6a
   CC banner -s +x3
   LN banner.o -lt -lc +cd

   t.lib is my personal tool library

   Update made 15.7.89

*/

#include <intuition/intuitionbase.h>


/* generic macro to create short code (PEA) when
   specifing x-y-coordinates as ints */
#define xy(x,y) (((long)(x)<<16L)+(y))

/* global for use with t.lib */
struct Window *w;
struct RastPort *rp;
extern long class;
extern int code;
long getmsg(),wgetmsg();

/* misc vars */
struct TextFont *font;
long pfile;
int xsize,ysize;
int pchar;

/* static data */
#define wxs 380
#define wys 58

/* general purpose buffer */
char multibuff[256];


struct Image blackimage={2,0,wxs-4,wys-10,2,0,0,2,0};
struct Gadget dragg={0,0,9,wxs,wys-9,GADGHNONE|GADGIMAGE,GADGIMMEDIATE,WDRAGGING,&blackimage,0,0,0,0,0,0};
struct Gadget printg={&dragg,167,45,45,9,0,RELVERIFY,BOOLGADGET,0,0,0,0,0,9};
char txt[256];
struct StringInfo texts={txt,multibuff,0,256,0,0};
struct Gadget textg={&printg,43,33,wxs-5-43,8,0,0,STRGADGET,0,0,0,0,&texts,0};
struct Gadget centg={&textg,308,13,52,7,0,TOGGLESELECT,BOOLGADGET,0,0,0,0,0,0};
struct Gadget narrg={&centg,308,23,52,7,0,TOGGLESELECT,BOOLGADGET,0,0,0,0,0,0};
char charb[4]={"42"};
struct StringInfo chars={charb,multibuff,0,4,0};
struct Gadget charg={&narrg,273,18,33,8,0,RELVERIFY|LONGINT,STRGADGET,0,0,0,0,&chars,3};
struct PropInfo ysizep={AUTOKNOB|FREEHORIZ,0,0,MAXBODY/9,0};
struct Border ysizeb;
struct Gadget ysizeg={&charg,60,21,120,8,0,GADGIMMEDIATE|RELVERIFY,PROPGADGET,
&ysizeb,0,0,0,&ysizep,2};
struct PropInfo xsizep={AUTOKNOB|FREEHORIZ,0,0,MAXBODY/9,0};
struct Border xsizeb;
struct Gadget xsizeg={&ysizeg,60,12,120,8,0,GADGIMMEDIATE|RELVERIFY,PROPGADGET,
&xsizeb,0,0,0,&xsizep,1};
struct NewWindow nw={0,0,wxs,wys,0,1,GADGETUP|GADGETDOWN|CLOSEWINDOW|MOUSEBUTTONS,
  RMBTRAP|ACTIVATE|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE,
&xsizeg,0,"Banner Press",0,0,0,0,0,0,WBENCHSCREEN};
struct TextAttr top80={"topaz.font",8,0,0};

/* the requester for printing */
int reqv[]={0,0,109,0,109,27,0,27,0,0};
struct Border reqb={0,0,3,0,0,5,reqv,0};
int stopv[]={0,0,35,0,35,10,0,10,0,0};
struct Border stopb={-1,-1,2,0,0,5,stopv,0};
struct IntuiText stopt={3,0,0,1,1,&top80,"STOP",0L};
struct Gadget stopg={0,30,15,34,9,0,RELVERIFY,BOOLGADGET|REQGADGET,&stopb,0,&stopt,0};
struct IntuiText reqt={2,0,0,10,4,&top80,"Printing...",0L};
struct Requester printreq={0,270/2,20,110,28,0,0,&stopg,&reqb,&reqt,0,1,0};

cleanup(s)
char *s;
{
 if(s) autoreq(w,0L,"So what!",0L,VANILLAKEY,s);
 if(w) CloseWindow(w);
 if(font) CloseFont(font);
 exit(0);
}

main()
{
 openlibs();
/* init char stuff */
 font=OpenFont(&top80);
 chars.LongInt='*';
/* open window */
 if(!(w=OpenWindow(&nw))) cleanup("Can't open window");
 rp=w->RPort;
 SetFont(rp,font);
 setrp(3,0L);
 text(xy(6,19),"X-Size");
 text(xy(6,28),"Y-Size");
 text(xy(210,19),"Printer");
 text(xy(210,28),"Char:");
 text(xy(310,19),"Narrow");
 text(xy(310,29),"Center");
 text(xy(6,39),"Text");
 textf(xy(171,52),"PRINT");
 setrp(1,0L);
 rtextf(xy(170,52));
 border(xy(272,17),xy(297,26));
 border(xy(307,12),xy(360,20));
 border(xy(307,22),xy(360,30));
 border(xy(42,32),xy(371,41));
 border(xy(166,44),xy(212,54));
 printsize();
 printchar();
 SetWindowTitles(w,-1L,"Banner Press  © 1990 UCA / Ølli!");
 for(;;) {
  if(wgetmsg()==CLOSEWINDOW) cleanup(0L);
  if(class==GADGETDOWN) switch(code) {
   case 1:
   case 2:
    while(!getmsg()) { printsize(); Delay(3L); }
    break;
  }
  if(class==GADGETUP) switch(code) {
   case 1:
   case 2:
    printsize();
    break;
   case 3:
    printchar();
    break;
   case 9:
    doprint();
    break;
  }
  if(class==MOUSEBUTTONS&&code==MENUUP) {
   autoreq(w,0L,"Click Click",0L,VANILLAKEY,
"Banner Press|Written by Oliver Wagner|Landsberge 5|D-4322 Sprockhoevel 2");
  }
 }
}

static printsize()
{
 setrp(1,xy(2,1));
 textf(xy(185,19),"%-2d",xsize=1+xsizep.HorizPot/(MAXBODY/9));
 textf(xy(185,28),"%-2d",ysize=1+ysizep.HorizPot/(MAXBODY/9));
}
static printchar()
{
 setrp(1,xy(2,1));
 textf(xy(252,28),"%c",(int)(pchar=chars.LongInt));
}

/* voila, the print routine */
struct BitMap cbm;
struct RastPort crp;
int bitmap[8];

doprint()
{
 register int x,c,v,l,offs,ch,m;

 if(!(pfile=Open("prt:",1005L))) {
  autoreq(w,0L,"I hate Thursdays!",0L,VANILLAKEY,"Can't open PRT:");
  return;
 }
 Request(&printreq,w);
 InitBitMap(&cbm,1L,16L,8L);
 cbm.Planes[0]=bitmap;
 InitRastPort(&crp);
 crp.BitMap=&cbm;
 SetDrMd(&crp,JAM2);
 SetAPen(&crp,1L);
 SetBPen(&crp,0L);
 SetFont(&crp,font);
 Write(pfile,"\33[0m\33[0q",8L);
 Write(pfile,(narrg.Flags&SELECTED)?"\33[0z":"\33[1z",4L);
 offs=(80-(xsize<<3))>>1;
 if(!(centg.Flags&SELECTED)) offs=0;
 for(c=0; c<offs; multibuff[c++]=32);
 for(c=0; c<strlen(txt); c++) {
  Move(&crp,8L,6L);
  Text(&crp,&txt[c],1L);
  for(v=7; v>=0; v--) {
   l=offs;
   for(x=7; x>=0; x--) {
    ch=(bitmap[x]&(1<<v))?pchar:32;
    for(m=0; m<xsize; m++) multibuff[l++]=ch;
   }
   if(getmsg()) goto leave;
   multibuff[l++]=10;
   multibuff[l++]=13;
   multibuff[l++]=0;
   for(m=0; m<ysize; m++) Write(pfile,multibuff,(long)strlen(multibuff));
  }
 }
leave:
 Write(pfile,"\x0a\x0d",2L);
 EndRequest(&printreq,w);
 Close(pfile);
}


/* stub routines to generate shorter code
   will result in warnings during link stage
   which can be ignored */
#asm
	public	__wb_parse
	public	__cli_parse
__wb_parse:
__cli_parse:
	rts
#endasm
