/* example Preview script file for MPMorph        */
/* This example shows a requester to request the  */
/* type of output, then renders and displays      */
/* $VER: Preview_MPM 4.4 (23.2.97)
 */

/* Lock the gui								*/
LockGui
/* Check file is saved						*/
options results
GetAttr saved var saved
options
if (saved = "0") then do
	address command 'requestchoice "MPMorph Preview Error" "File not saved" "OK"'
	UnlockGui
	exit
end
/* Check points not open					*/
options results
GetAttr openpoints var openpoints
options
if (openpoints = "1") then do
	address command 'requestchoice "MPMorph Preview Error" "Image windows must be closed" "OK"'
	UnlockGui
	exit
end
/* Get some info								*/
options results
GetAttr filename var filename
GetAttr start var start
GetAttr frames var frames
GetAttr single var single
GetAttr width var width
GetAttr height var height
GetAttr pubscreen var pubsc
options
/* parameters for the gui					*/
params = ''start' 'start+frames-1' 'frames/2+start' 'frames' 'min(frames,5)' 'width' 'min(width,128)' 'height' 'min(height,128)
/* Display the gui							*/
if (pubsc="") then
	address command 'MPMorph:RunMPGui MPMorph:gui/Preview.gui to t:mpprev.temp Help=MPMorph:Preview.guide relmouse newline params='params
else
	address command 'MPMorph:RunMPGui MPMorph:gui/Preview.gui to t:mpprev.temp Help=MPMorph:Preview.guide relmouse newline params='params' pubscreen="'pubsc'"'
/* quit if cancelled							*/
if (rc > 4) then do
	UnlockGui
	if (rc > 9) then do
		address command 'requestchoice "MPMorph Preview Error" "Failure calling RunMPGui" "OK"'
	end
	exit
end
/* Set the parameters defined				*/
address command 'execute t:mpprev.temp'
mpmode = getclip('mpmode');
if (mpmode = "single") then do
	mpframe = getclip('mpframe')
end
else do
	mpframes = getclip('mpframes')
end
mpx = getclip('mpx')
mpy = getclip('mpy')
mpdx = getclip('mpdx')
mpdy = getclip('mpdy')
/* Check not anim type morph/warp		*/
if (single < 2) then do
	/* Use integer if no FPU available	*/
	address command 'cpu check 68881 >nil:'
	if (rc > 0) then do
		runint = "YES"
	end
	else do
		runint = "NO"
	end
	if (mpmode = "single") then do
		/* Scale to new size, save and reopen	*/
		Scale x mpx y mpy
		SetAttr 'output' 't:mpprev.out'
		SaveAs 'filename' 't:mppreview'
		Open 'filename' '"'filename'"'
		UnlockGui
		/* call MPRender to render frame			*/
		/* this saves BW16 image					*/
		/* Uses MODE=8 for speed					*/
		SetMessage "Rendering_Preview"
		address command 'MPMorph:MPRender FILES=T:mppreview POSTSCRIPT=OFF CREATEICONSR=NO ANTIALIAS=NO PRESCRIPT=MPMorph:rexx/PreviewPre.MPM SAVEFORMAT=BW16 MODE=8 FORCEGREY=YES DX='mpdx' DY='mpdy' INTEGER='runint' PUBSCREEN='pubsc
		/* display image								*/
		SetMessage "Showing_Preview"
		address command 'MultiView T:mpprev.out SCREEN'
	end
	else do
		/* Scale to new size, save and reopen	*/
		Scale x mpx y mpy
		SetAttr 'output' 't:mpprev.%03ld'
		SaveAs 'filename' 't:mppreview'
		Open 'filename' '"'filename'"'
		UnlockGui
		/* call MPRender to render frame			*/
		/* this saves BW16 image					*/
		/* Uses MODE=10 for speed					*/
		SetMessage "Rendering_Preview"
		address command 'MPMorph:MPRender FILES=T:mppreview POSTSCRIPT=MPMorph:rexx/PostAnim.MPM CREATEICONSR=NO ANTIALIAS=NO PRESCRIPT=MPMorph:rexx/PreviewPre.MPM SAVEFORMAT=BW16 MODE=10 FORCEGREY=YES DX='mpdx' DY='mpdy' INTEGER='runint' PUBSCREEN='pubsc
		/* display image								*/
		SetMessage "Showing_Preview"
		address command 'MultiView T:mpm_anim SCREEN'
	end
end
else do
	address command 'requestchoice "MPMorph Preview Error" "Sorry!*nCan not preview Anim Warps/Morphs*nYet!" "OK"'
	UnlockGui
end
/* the end!										*/
exit