
#include "exec/types.h"
#include "intuition/intuition.h"

extern long code;                   /*code from IntuiMessage*/
extern struct TextAttr DefaultAttr; /*Text attributes of default font*/

/* menus and menuitems */

struct IntuiText IText9 = {
   3,1,COMPLEMENT,  /*front and back text pens,drawmode and fill byte */
   CHECKWIDTH,0,    /* XY origin relative to container TopLeft */
   &DefaultAttr,    /* font pointer or NULL for default */
   "Italic",        /* pointer to text */
   NULL             /* next IntuiText structure */ 
};

struct MenuItem MenuItem4 = {
   NULL,   /* next MenuItem structure, or NULL for last one */                        
   0,24,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
   160,8,  /* hitbox width and height */
   ITEMTEXT+CHECKIT+COMMSEQ+ITEMENABLED+HIGHCOMP, /*Item flags */
   7,      /*each bit mutually excludes a sme-level item */
   (APTR)&IText9,  /*Item render (IntuiText or Image or NULL) */
    NULL,  /* Select render */
   'I',    /* alternate command-key */
   NULL,   /* SubItem list */
   MENUNULL       /*filled in by Intuition for drag selections */
};

struct IntuiText IText8 = {
   3,1,COMPLEMENT,
   CHECKWIDTH,0,
   &DefaultAttr,
   "Underlined",
   NULL
};

struct MenuItem MenuItem3 = {
   &MenuItem4,
   0,16,
   160,8,
   ITEMTEXT+CHECKIT+COMMSEQ+ITEMENABLED+HIGHCOMP,
   11,
   (APTR)&IText8,
   NULL,
   'U',
   NULL,
   MENUNULL
};

struct IntuiText IText7 = {
   3,2,COMPLEMENT,
   CHECKWIDTH,0,
   &DefaultAttr,
   "Bold",
   NULL
};

struct MenuItem MenuItem2 = {
   &MenuItem3,
   0,8,
   160,8,
   ITEMTEXT+CHECKIT+COMMSEQ+ITEMENABLED+HIGHCOMP,
   13,
   (APTR)&IText7,
   NULL,
   'B',
   NULL,
   MENUNULL
};

struct IntuiText IText6 = {
   3,2,COMPLEMENT,
   CHECKWIDTH,0,
   &DefaultAttr,
   "Normal",
   NULL
};

struct MenuItem MenuItem1 = {
   &MenuItem2,
   0,0,
   160,8,
   CHECKIT+ITEMTEXT+CHECKED+COMMSEQ+ITEMENABLED+HIGHCOMP,
   14,
   (APTR)&IText6,
   NULL,
   'N',
   NULL,
   MENUNULL
};
struct Menu Menu1 = {
   NULL,         /* next Menu structure */
   0,0,          /* XY origin of Menu hit box relative to screen TopLeft */
   87,0,         /* Menu hit box width and height */
   MENUENABLED,  /* Menu flags */
   "TEXT STYLE", /* text of Menu name */ 
   &MenuItem1    /* MenuItem linked list pointer */
};

/*gadgets and their border vectors */

 SHORT BorderVectors3[] = {
	0,0,
	59,0,
	59,54,
	0,54,
	0,0
};
 struct Border Border3 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors3,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

 SHORT BorderVectors1[] = {
	0,0,
	115,0,
	115,45,
	0,45,
	0,0
};
 struct Border Border1 = {
	-1,-1,	
	3,0,JAM1,
	5,	
	BorderVectors1,	
	NULL	
};

 struct Gadget Gadget3 = {
	NULL,	/* next gadget */
	172,74,	/* origin XY of hit box relative to window TopLeft */
	58,53,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border3,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	NULL,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	NULL,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

 SHORT BorderVectors2[] = {
	0,0,
	48,0,
	48,71,
	0,71,
	0,0
};
 struct Border Border2 = {
	-1,-1,	
	3,0,JAM1,
	5,	
	BorderVectors2,	
	NULL	
};

 struct Gadget Gadget4 = {
	&Gadget3,
	66,131,	
	47,70,	
	NULL,	
    RELVERIFY,	
	BOOLGADGET,	
	(APTR)&Border2,	
	NULL,	
	NULL,	
	NULL,	
	NULL,	
	NULL,	
	NULL	
};

struct Gadget Gadget2 = {
	&Gadget4,	
	173,155,	
	114,44,	
	NULL,	
	RELVERIFY,	
	BOOLGADGET,	
	(APTR)&Border1,	
	NULL,	
	NULL,	
	NULL,	
	NULL,	
	NULL,	
	NULL	
};

 SHORT BorderVectors4[] = {
	0,0,
	71,0,
	71,27,
	0,27,
	0,0
};
 struct Border Border4 = {
	-1,-1,	
	3,0,JAM1,
	5,	
	BorderVectors4,	
	NULL	
};


 struct IntuiText IText4 = {
	3,0,JAM2,
	135,16,	
	&DefaultAttr,
	"Garnet",	
	NULL	
};

 struct IntuiText IText3 = {
	3,0,JAM2,
	26,92,	
	&DefaultAttr,	
	"Quit",	
	&IText4	
};

 struct IntuiText IText2 = {
	3,0,JAM2,
	143,97,	
	&DefaultAttr,
	"Sapphire",	
	&IText3	
};

 struct IntuiText IText1 = {
	3,0,JAM2,
	0,7,	
	&DefaultAttr,	
	"Topaz 9",	
	&IText2	
};

 struct Gadget Gadget1 = {
	&Gadget2,
	45,70,	
	70,26,	
	NULL,	
	RELVERIFY,	
	BOOLGADGET,	
	(APTR)&Border4,	
	NULL,	
	&IText1,
	NULL,	
	NULL,	
	NULL,	
	NULL	
};




/*handles gadgetand menu events*/

void HandleEvent(object)
APTR object;
    {
     if (object==(APTR)&Gadget1) 
       {topaz();return;}            /*sets topaz font, height 9 */
     if (object==(APTR)&Gadget2) 
       {sapphire();return;}         /*sets sapphire font, height 14 */
     if (object==(APTR)&Gadget3) 
        {garnet();return;}          /*sets garnet font, height 16 */
     if (object==(APTR)&Gadget4) 
        {quit();return;}            /*sets the quit flag */ 
     if (object == (APTR)&MenuItem1) 
        { normal(); return; }       /*sets normal style  */
     if (object == (APTR)&MenuItem2) 
        { bold();return; }          /*sets bold style */
     if (object == (APTR)&MenuItem3) 
        { underlined(); return; }   /*sets underlined style */
     if (object == (APTR)&MenuItem4) 
        { italic(); return; }       /*sets italic style */
     return;
     }

/*handles menu events*/
/*finds the item address of the selected menu item*/
/*handles this event */
/*proceeds to the next menu event*/

void HandleMenuEvent()
     {
      struct MenuItem  *object;
     while(code!=MENUNULL)
       {
        object=(struct MenuItem *)ItemAddress(&Menu1,code);
        HandleEvent(object); 
        code=object->NextSelect;
       }
     }

