/* main barchart program as found in the "Programmer's Guide to the Amiga */
/* by Robert A. Peck */
#include "barchart.h"
#include "patterns.h"

struct XYBase Myxyb;

static struct NewWindow myWindow = {
	30, 30, 500, 150, -1, -1, CLOSEWINDOW|NEWSIZE,
	SMART_REFRESH|NOCAREREFRESH|NORMALFLAGS|GIMMEZEROZERO, 0, 0,
	(unsigned char *)"Sample Chart", 0, 0, 10, 10, 640, 200,
	WBENCHSCREEN
};

main()
{
	struct Intuimessage *msg;
	long result;

	GfxBase = OpenLibrary("graphics.library", 0L);
	if (GfxBase == 0) {
		printf("graphics library won't open!\n");
		exit(10);
	}
	IntuitionBase = OpenLibrary("intuition.library", 0L);
	if (IntuitionBase == 0) {
		printf("intuition library won't open!\n");
		CloseLibrary(GfxBase);
		exit(10);
	}

	Window = OpenWindow(&myWindow);
	if (Window == 0) {
		printf("Window didn't open!\n");
		CloseLibrary(IntuitionBase);
		CloseLibrary(GfxBase);
		exit(10);
	}
	Rport = Window->RPort;

	redraw();

	handleevents();

	CloseWindow(Window);
	CloseLibrary(IntuitionBase);
	CloseLibrary(GfxBase);
	return(0);
}

redraw()
{
	register int i;
	static char *hlabels[] = {" ", "84", "85", "86", "87" };
	static char *vlabels[] = {"0", "10", "20", "30", "40" };


	drawaxes(Rport, &Myxyb, 35, 120, 350, 100, 1);

	labelhorizontal(Rport, &Myxyb, hlabels, 5);
	labelvertical(Rport, &Myxyb, vlabels, 5);

	SetAPen(Rport, 1L);
	SetDrMd(Rport, JAM1);

	for (i=1;i<5;i++) {
		drawbar(Rport, &Myxyb, -31+i*348/4, 20, i*12);
	}

	SetAPen(Rport, 1L);
	SetBPen(Rport, 2L);
	SetAfPt(Rport, Mypattern, 3L);
	SetOPen(Rport, 3L);
	SetDrMd(Rport, JAM2);

	for (i=1;i<5;i++) {
		drawbar(Rport, &Myxyb, -10+i*348/4, 20, i*18);
	}

	SetAPen(Rport, 255L);
	SetBPen(Rport, 0L);
	SetAfPt(Rport, Mymulti, -3L);
	SetOPen(Rport, 1L);
	SetDrMd(Rport, JAM2);

	for (i=1;i<5;i++) {
		drawbar(Rport, &Myxyb, 11+i*348/4, 20, i*22);
	}
}

_abort()
{
	if (Window)
		CloseWindow(Window);
	if (IntuitionBase)
		CloseLibrary(IntuitionBase);
	if (GfxBase)
		CloseLibrary(GfxBase);
	exit(1);
}

