/**********************************************************************
* This ARexx program demonstrates how to control the InfoPlayer
* via its ARexx messageport.  Use as follows:
*   
*    1> run InfoPlayer -arexx
*     (wait for player to load...)
*    1> rx scdir.inch
*   
* The program displays a list of all files in the current directory.
*   
* You may also specify a directory name:
*   
*    1> rx scdir Work:InfoChannel/Backgrounds
*
* Depending on your harddisk setup, you might have to change the
* assignment of "picture_file = ..." below.
**********************************************************************/

/* trace results */

parse arg dir

picture_file = ":InfoChannel/Backgrounds/Texture002"  /* Background picture 	*/

tmpfile1 = "ram:scdir1.tmp"		/* Temporary file #1 		*/
tmpfile2 = "ram:scdir2.tmp"		/* Temporary file #2 		*/

pagenum	= 0

prepare_page()	  	/* Set up a new page, but don't display yet... 	*/


address command				/* Talk to DOS 			*/
/* Use AmigaDOS "LIST" to obtain a list of files.  The list is placed
   in a temporary file in RAM */
'list >' tmpfile1 ' ' dir ' quick nohead'
'sort' tmpfile1 tmpfile2

/* Read and display all filenames in the list */
if open(file,tmpfile2,'Read') then do
    do while ~eof(file)
	name = readln(file)		/* Get next filename		*/
	address 'rexx_VISUAL'		/* Talk to InfoPlayer		*/
	if length(name) > 0 then
	    text x y '"'||name||'"' 33 0 10 	/* Write text, use transition	*/
	y = y + 20
	if y > 380 then do
	    y = 80
	    x = x + 210
	    if x >= 630 then do		/* Filled up a page?		*/
	    	show			/* Yes: display the page	*/
	    	pause 1			/* Wait for a second...		*/
	    	prepare_page()		/* Set up the next page 	*/
	    end
	end
    end
    close(file)
    /* Delete the temporary file from RAM: */
    address command
    'delete ' tmpfile1 tmpfile2
end

/* All filenames are processed; we have set up a page wich is now
   ready to be displayed */
address 'rexx_VISUAL'			/* Talk to InfoPlayer again...  */
show					/* Show the page!		*/
pause 3					/* Wait a bit...		*/
show off				/* Turn off the picture,	*/
quit					/* make InfoPlayer die, 	*/
exit					/* and exit!			*/


/*
* Subroutine:
* Set up a new page with background picture, heading, page number.
* The page is not displayed until a "SHOW" command is issued.
*/
prepare_page:
    pagenum = pagenum + 1
    address 'rexx_VISUAL'		/* Talk to InfoPlayer 		*/
    picture picture_file		/* Use background IFF picture 	*/
    wipe 34 5				/* Transition 34 between pages 	*/
    font "franklin.font" 23		/* Select font 			*/
    color 9 0 0 0 0 0 0			/* Set text colors 		*/
    style 0 3 4 3 6 2 1 29 4 1 20 0 5 2	/* Set text style parameters 	*/
    attributes underline shadow	/* Draw text with underline and shadow 	*/
    /* Display heading */
    text 20 40 '"Directory:                                                                                               "'
    if length(dir) > 0 then 
    	text 160 40 dir
    else
    	text 160 40 '"(Current Directory)"'
    text 530 40 '"' || '(Page' pagenum || ')"'
    font "franklin.font" 18
    style 0 3 4 3 6 2 1 14 2 1 20 0 5 2
    color 1 0 0 0 0 0 0
    /* Turn off underline but keep shadow */
    attributes shadow
    x = 20
    y = 80
return ''
