/* Sample arexx client program for iX-Guide */
/* Miscellaneous graphics routines */

if ~show('l', "rexxsupport.library") then
    addlib('rexxsupport.library',0,-30,0)

OPTIONS RESULTS

/*
** Every rexx client receives pointer to iXG window as the last argument
** in form 'iXW=<address>'. That is the window the rexx client was launched
** from. You always have to pass this pointer to ADDCLIENT !
*/

PARSE ARG 'iXW=' windowPTR .

/*
** Port name of every rexx client should be in the following form:
** "IXCL_anythingyouwant_windowPTR"
*/

portname = "IXCL_demoCL2_"
portname = INSERT(windowPTR,portname,LENGTH(portname))

/************************************************************************/

if show('p',portname) then exit   /* we are already running */

ADDRESS IXGUIDE

/*
** Add this client to iX-Guide and pass received window pointer
*/

AddClient windowPTR

/************************************************************************/

call openport(portname)
setport portname MISC
AllocRaster 3
if rc ~= 0 then exit
rp=result
Refresh rp
SetABPen rp 1 0
OpenFont 'times.font' 24; f1 = result
OpenFont 'times.font' 18; f2 = result
OpenFont 'topaz.font' 8; f3 = result

call LoadImage()

call GraphDemo()

shutdown=0

do until shutdown
 call waitpkt(portname)
 msg = getpkt(portname)
 
 if msg ~= '0000 0000'x then do
  cmd = getarg(msg)
  
  if cmd='0000 0000'x then shutdown=1  /* pointer to window is NULL */
  else if cmd=windowPTR then do        /* this is message from our window */
  cmd = getarg(msg,1)
  
  if cmd='MISC' then do
   a4=getarg(msg,2)
   
   if a4='CLOSEWIN' then
    shutdown=1
   
   if a4='QUIT' then
    shutdown=1
   
   if a4='NEWSCREEN' then do
    /* we need to reload picture
    DisposePicture pobj
    call LoadImage()
    call GraphDemo()*/
    shutdown=1
    end
  
  end
  end
  call reply(msg,0)
 end
end

DisposePicture pobj
CloseFont f1;CloseFont f2;CloseFont f3
FreeRaster rp
RemClient
call closeport(portname)
exit

LoadImage:
 NewPicture 'images/mainback.iff' 
 if rc ~= 0 then do
  say 'Cannot load mainback.iff !'
  CloseFont f1;CloseFont f2;CloseFont f3
  FreeRaster rp
  RemClient
  call closeport(portname)
 exit
 end
 pobj = result
 
 GetBitMap pobj; bm = result
 PWidth pobj; w = result
 PHeight pobj; h = result
 BltBitMapRP bm 0 0 rp 5 5 w h 192

return 0

GraphDemo:
 SetDrMd rp 0
 SetFont rp f1
 Move rp 5 25
 Text rp '"iX-Guide arexx graphics"'
 Move rp 55 50
 SetFont rp f2
 SetDrMd rp 1
 SetABPen rp 0 1
 Text rp '"You can have different"'
 Move rp 55 70
 Text rp '"fonts, colors, styles..."'
 SoftStyle rp 1
 SetFont rp f3
 SetABPen rp 1
 SetDrMd rp 0
 Move rp 10 90
 Text rp '"bold "';SoftStyle rp 2;Text rp '"underlined "';
 SoftStyle rp 4;Text rp 'italic'; 
 SoftStyle rp 0
 Move rp 30 100
 Text rp '"You can load datatype pictures"'
 Move rp 30 110
 Text rp '"like picture in this rectangle"'
 
 DrawEllipse rp 150 70 30 30 
 
return 0
