
;structure example


	include	"baselibs.i"
	include	"intuition.i"
	include	"baseintuition.i"
	include	"basegfx.i"


	#define		IDCMPflags,NEWSIZE|REFRESHWINDOW|MOUSEBUTTONS|CLOSEWINDOW|VANILLAKEY
	#define		flags,WINDOWSIZING|WINDOWDRAG|WINDOWCLOSE|ACTIVATE


	DATAAREA
	{
		structset	myscreen
		{
		sw	0
		sw	0	;ns_TopEdge
		sw	320	;ns_Width
		sw	256	;ns_Height
		sw	3	;ns_Depth
		sb	1	;ns_DetailPen
		sb	3	;ns_BlockPen
		sw	$40	;ns_ViewModes
		sw	15	;ns_Type
		sl	0	;ns_Font
		sl	0	;ns_DefaultTitle
		sl	0	;ns_Gadgets
		sl	64	;ns_CustomBitMap
		}
		structset	mywindow
		{
		sw	0	;nw_LeftEdge
		sw	0	;nw_TopEdge
		sw	310	;nw_Width
		sw	240	;nw_Height
		sb	1	;nw_DetailPen
		sb	3	;nw_BlockPen
		sl	IDCMPflags	;nw_IDCMPFlags
		sl	flags		;nw_Flags
		sl	0	;nw_FirstGadget
		sl	0	;nw_CheckMark
		sl	0	;nw_Title
		sl	0	;nw_Screen
		sl	0	;nw_BitMap
		sw	200	;nw_MinWidth
		sw	200	;nw_MinHeight
		sw	320	;nw_MaxWidth
		sw	256	;nw_MaxHeight
		sw	15	;nw_Type
		}
		structset	tmpras,tr_SIZEOF

		structset	areainfo,ai_SIZEOF
	}


	variables

	CPTR	_IntuitionBase
	CPTR	_GfxBase
	array	byte,areabuffer,400

		
	main()

	CPTR screenl
	CPTR	windowl
	CPTR	rp
	{

		func	_IntuitionBase,=,openlibrary,"intuition.library",0
		if	_IntuitionBase,!=,0,1
		{
			func	_GfxBase,=,openlibrary,"graphics.library",0
			if	_GfxBase,!=,0,2
			{
				func	screenl,=,openscreen,myscreen
				if	screenl,!=,0,3
				{

				;screenl address to window structure
					structput	mywindow,.,nw_Screen,=,screenl
					func	windowl,=,openwindow,mywindow
					if	windowl,!=,0,4
					{
						structput	rp,=,windowl,->,wd_RPort

					;rastport and windowl to a subroutine
						ROUTINE	draw,rp,windowl
					}
					ifend	4
					closewindow	windowl
				}
				ifend	3
				closescreen	screenl
			}	
			ifend	2
			closelibrary	_GfxBase
		}
		ifend	1
		closelibrary	_IntuitionBase
	}

;draw graphic into a window

		VOID	draw,rp,windowl
		;the first are taken the variables from the stack
	
		CPTR	rp,windowl
		short	width
		short	height
		CPTR	planePtr
	
		{
	
			calc	width,=,320
			calc	height,=,256
			
				func	planePtr,=,AllocRaster,width,height
				
				InitArea	areainfo,areabuffer,80
				structput	rp,->,rp_AreaInfo,=,areainfo

				InitTmpRas	tmpras,planePtr,width,height
				structput	rp,->,rp_TmpRas,=,tmpras

				SetRast		rp,0

				SetAPen		rp,1
				setopen		rp,3
				areamove		rp,50,50
				areaDraw		rp,50,200
				areaDraw		rp,100,200
				areaDraw		rp,200,50
				areaend			rp

				setapen		rp,3
				areamove	rp,100,100
				areadraw	rp,150,200
				areadraw	rp,260,150
				areadraw	rp,220,50
				areaend		rp


				FreeRaster	planePtr,width,height
				GetIntuiMsg	windowl
		
		}

		
	end