/*Amiga Computing*/
/*Code Clinic*/
/*Feb1991- intuition*/
/*A500 upwards*/

/*c source code   -  gadgetsandmenus*/

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

extern int code;

/*new screen sctructure for main screen*/

 struct NewScreen NewScreenStructure = {
	0,0,	/* screen XY origin relative to View */
	320,256,	/* screen width and height */
	2,	/* screen depth (number of bitplanes) */
	0,1,	/* detail and block pens */
	NULL,	/* display modes for this screen */
	CUSTOMSCREEN,	/* screen type */
	NULL,	/* pointer to default screen font */
	"demo screen",	/* screen title */
	NULL,	/* first in list of custom screen gadgets */
	NULL	/* pointer to custom BitMap structure */
};

/*gadgets and their border vectors for main screen*/

 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,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors1,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

 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,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors2,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

 struct Gadget Gadget4 = {
	&Gadget3,	/* next gadget */
	66,131,	/* origin XY of hit box relative to window TopLeft */
	47,70,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border2,	/* 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 */
};

struct Gadget Gadget2 = {
	&Gadget4,	/* next gadget */
	173,155,	/* origin XY of hit box relative to window TopLeft */
	114,44,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border1,	/* 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 BorderVectors4[] = {
	0,0,
	71,0,
	71,27,
	0,27,
	0,0
};
 struct Border Border4 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors4,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

 struct IntuiText IText5 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	139,39,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"disc",	/* pointer to text */
	NULL	/* next IntuiText structure */
};

 struct IntuiText IText4 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	135,16,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"read",	/* pointer to text */
	&IText5	/* next IntuiText structure */
};

 struct IntuiText IText3 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	26,92,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"quit",	/* pointer to text */
	&IText4	/* next IntuiText structure */
};

 struct IntuiText IText2 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	143,97,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"gadget 2",	/* pointer to text */
	&IText3	/* next IntuiText structure */
};

 struct IntuiText IText1 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	0,7,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"gadget 1",	/* pointer to text */
	&IText2	/* next IntuiText structure */
};

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

/*the menus and submenus for the screen*/

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

 struct MenuItem MenuItem3 = {
	NULL,	/* next MenuItem structure */
	0,16,	/* XY of Item hitbox relative to TopLeft of parent hitbox */
	80,8,	/* hit box width and height */
	ITEMTEXT+ITEMENABLED+HIGHCOMP,	/* Item flags */
	0,	/* each bit mutually-excludes a same-level Item */
	(APTR)&IText6,	/* Item render  (IntuiText or Image or NULL) */
	NULL,	/* Select render */
	NULL,	/* alternate command-key */
	NULL,	/* SubItem list */
	MENUNULL	/* filled in by Intuition for drag selections */
};

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

 struct MenuItem SubItem3 = {
	NULL,	/* next SubItem structure */
	65,15,	/* XY of Item hitbox relative to TopLeft of parent hitbox */
	72,8,	/* hit box width and height */
	ITEMTEXT+ITEMENABLED+HIGHCOMP,	/* Item flags */
	0,	/* each bit mutually-excludes a same-level Item */
	(APTR)&IText7,	/* Item render  (IntuiText or Image or NULL) */
	NULL,	/* Select render */
	NULL,	/* alternate command-key */
	NULL,	/* no SubItem list for SubItems */
	MENUNULL	/* filled in by Intuition for drag selections */
};

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

 struct MenuItem SubItem2 = {
	&SubItem3,	/* next SubItem structure */
	65,7,	/* XY of Item hitbox relative to TopLeft of parent hitbox */
	72,8,	/* hit box width and height */
	ITEMTEXT+ITEMENABLED+HIGHCOMP,	/* Item flags */
	0,	/* each bit mutually-excludes a same-level Item */
	(APTR)&IText8,	/* Item render  (IntuiText or Image or NULL) */
	NULL,	/* Select render */
	NULL,	/* alternate command-key */
	NULL,	/* no SubItem list for SubItems */
	MENUNULL	/* filled in by Intuition for drag selections */
};

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

 struct MenuItem SubItem1 = {
	&SubItem2,	/* next SubItem structure */
	65,-1,	/* XY of Item hitbox relative to TopLeft of parent hitbox */
	72,8,	/* hit box width and height */
	ITEMTEXT+ITEMENABLED+HIGHCOMP,	/* Item flags */
	0,	/* each bit mutually-excludes a same-level Item */
	(APTR)&IText9,	/* Item render  (IntuiText or Image or NULL) */
	NULL,	/* Select render */
	NULL,	/* alternate command-key */
	NULL,	/* no SubItem list for SubItems */
	MENUNULL	/* filled in by Intuition for drag selections */
};

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

 struct MenuItem MenuItem2 = {
	&MenuItem3,	/* next MenuItem structure */
	0,8,	/* XY of Item hitbox relative to TopLeft of parent hitbox */
	80,8,	/* hit box width and height */
	ITEMTEXT+ITEMENABLED+HIGHCOMP,	/* Item flags */
	0,	/* each bit mutually-excludes a same-level Item */
	(APTR)&IText10,	/* Item render  (IntuiText or Image or NULL) */
	NULL,	/* Select render */
	NULL,	/* alternate command-key */
	&SubItem1,	/* SubItem list */
	MENUNULL	/* filled in by Intuition for drag selections */
};

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

 struct MenuItem MenuItem1 = {
	&MenuItem2,	/* next MenuItem structure */
	0,0,	/* XY of Item hitbox relative to TopLeft of parent hitbox */
	80,8,	/* hit box width and height */
	ITEMTEXT+ITEMENABLED+HIGHCOMP,	/* Item flags */
	0,	/* each bit mutually-excludes a same-level Item */
	(APTR)&IText11,	/* Item render  (IntuiText or Image or NULL) */
	NULL,	/* Select render */
	NULL,	/* alternate command-key */
	NULL,	/* SubItem list */
	MENUNULL	/* filled in by Intuition for drag selections */
};

 struct Menu Menu1 = {
	NULL,	/* next Menu structure */
	0,0,	/* XY origin of Menu hit box relative to screen TopLeft */
	79,0,	/* Menu hit box width and height */
	MENUENABLED,	/* Menu flags */
	"demo menu",	/* text of Menu name */
	&MenuItem1	/* MenuItem linked list pointer */
};


/*the structure for the new window*/
 
struct NewWindow NewWindowStructure = {
	0,0,	/* window XY origin relative to TopLeft of screen */
	320,240,	/* window width and height */
	0,1,	/* detail and block pens */
	GADGETDOWN+GADGETUP+MENUPICK+RAWKEY+MENUVERIFY+INTUITICKS,	/* IDCMP flags */
	WINDOWDEPTH+ACTIVATE+NOCAREREFRESH,	/* other window flags */
	&Gadget1,	/* first gadget in gadget list */
	NULL,	/* custom CHECKMARK imagery */
	"demo window",	/* window title */
	NULL,	/* custom screen pointer */
	NULL,	/* custom bitmap */
	320,240,	/* minimum width and height */
	320,240,	/* maximum width and height */
	CUSTOMSCREEN	/* destination screen type */
};


void HandleEvent(object)
APTR object;
    {
     if (object==(APTR)&Gadget1) {printf("Gadget1\n");return;}
     if (object==(APTR)&Gadget2) {printf("Gadget2\n");return;}
     if (object==(APTR)&Gadget3) {readdisc();return;}
     if (object==(APTR)&Gadget4) {Quit();return;}
     if (object == (APTR)&MenuItem1) { printf("MenuItem1\n"); return; }
     if (object == (APTR)&MenuItem3) { printf("MenuItem3\n"); return; }
     if (object == (APTR)&SubItem1) { printf("SubItem1\n");  return; }
     if (object == (APTR)&SubItem2) { printf("SubItem2\n");  return; }
     if (object == (APTR)&SubItem3) {printf("SubItem3\n");  return; }
     return;
     }

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