/* example script file for MPMorph                */
/* This example renders a preview                 */
/* using AmigaGuide                               */
/* $VER: RTPreview_MPM 4.4 (23.2.97)
 */

running = GetClip('mpRTP')
if (running = 1) then do
	call SetClip('mpRTP','0')
	SetMessage "RTPreview_stopping"
	exit
end
call SetClip('mpRTP','1')
SetMessage "RTPreview_starting..."
numeric digits 12
options results
GetAttr pubscreen var pubsc
GetAttr hook var hook
options
do while show(p,address())
	SetMessage "RTPreview_getting_attributes"
	lockgui
	options results
	GetAttr 'saved'
	oldsaved = result
	GetAttr 'start'
	start = result
	GetAttr 'frames'
	frames = result
	GetAttr 'width'
	width = result
	GetAttr 'height'
	height = result
	GetAttr 'pubscreen'
	pubscreen = result
	GetAttr 'output'
	xoutput = result
	options
	xwidth = width
	dx = 0
	do while (xwidth > 160)
		xwidth = xwidth / 2
		if (dx = 0) then do
			dx = 1
		end
		else do
			dx = dx * 2
		end
	end
	dy = 0
	xheight = height
	do while (xheight > 128)
		xheight = xheight / 2
		if (dy = 0) then do
			dy = 1
		end
		else do
			dy = dy * 2
		end
	end
	SetAttr 'output' 't:RTmpprev.out'
	SaveAs 'filename' 't:RTmppreview' 'copy'
	SetAttr 'output' xoutput
	SetAttr 'saved' oldsaved
	options results
	GetAttr 'lastupdate'
	lastupd1 = result
	options
	unlockgui
	xframe = (frames % 2) + start
	call SetClip('mpmode',"single")
	call SetClip('mpframe',xframe)
	/* call MPRender to render frame			*/
	/* this saves BW16 image					*/
	/* Uses MODE=8 for speed					*/
	if exists('t:RTmpprev.out') then do
		SetMessage "RTPreview_viewing_old_images"
		address command 'delete t:RTmpprev.old'
		address command 'rename t:RTmpprev.out t:RTmpprev.old'
		help 't:RTmpprev.old/main' prompt
	end
	SetMessage "RTPreview_rendering"
	comm1 = 'MPMorph:MPRender FILES=T:RTmppreview POSTSCRIPT=OFF CREATEICONSR=NO ANTIALIAS=NO'
	address command comm1' PRESCRIPT=MPMorph:rexx/PreviewPre.MPM SAVEFORMAT=BW16 MODE=8 FORCEGREY=YES DX='dx' DY='dy' INTEGER=YES NOPROGRESS=YES PUBSCREEN='pubsc' PROGRESSHOOK='hook
	if (~show(p,address())) then do
		call SetClip('mpRTP','0')
		exit
	end
	help 't:RTmpprev.out/main' prompt
	running = GetClip('mpRTP')
	if (running = 0) then do
		SetMessage "RTPreview_stopping"
		exit
	end
	options results
	GetAttr 'lastupdate'
	lastupd2 = result
	options
	do while (lastupd1 = lastupd2)
		SetMessage "RTPreview_waiting"
		address command 'wait 2'
		if (show(p,address())) then do
			SetMessage "RTPreview_checking_update"
			options results
			GetAttr 'lastupdate'
			lastupd2 = result
			options
		end
		else do
			call SetClip('mpRTP','0')
			exit
		end
		running = GetClip('mpRTP')
		if (running = 0) then do
			SetMessage "RTPreview_stopping"
			exit
		end
	end
	lastupd1 = lastupd2
end
call SetClip('mpRTP','0')
SetMessage "RTPreview_stopping"
exit