/*                                12 Feb 98
SHADEBOX()                        Copyright 1998 by Simon van Norden
                                  Thanks to Micheal Boldin for helpful
                                  advice.
Send comments or suggestions to:  svn@alum.mit.edu

This procedure procedure allows the user to "shade" (using a cross-hatch
pattern) an area on a GAUSS PQG plot.  It does so by setting up a _pline
global for use in subsequent plotting commands.

The command syntax is

 _pline = shadebox(dimen,custom);

where

  dimen   is a 2x2 matrix with the following elements:
    dimen[1,1] = top left x-coordinate of region    dimen[1,2] = top
left y-coordinate of region
    dimen[2,1] = bottom right x-coordinate of region  dimen[2,2] =
bottom right y-coordinate of region
    (Actually, the proc should function fine even if [1,1] >0 [2,1]
and/or [1,2] < [2,2].)

 custom   is a 4x1 vector that controls aspects of the shading:
    custom[1,1] = colour    (_pline[.,8])
    custum[2,1] = line thickness  (_pline[.,9])
    custom[3,1] = line pattern   (_pline[.,2])
    custom[4,1] = # of cross-hatch lines   (0 uses default value)

    If custom is a scalar, default values will be used for all of these.

    If any element of custom is zero, a default value will be used for
that entry.
*/


proc  shadebox(dimen,custom);

local pline, numhatch_default, numhatch, vec1, xinc, colour_default,
linestyle_default;
numhatch_default = 50;
colour_default = 7;
linestyle_default = 2;

if rows(custom) == 1; @ check for scalar custom @
 custom = zeros(4,1);
endif;

if custom[4,1] == 0;  @ Set number of cross-hatches @
 numhatch = numhatch_default;
else;
 numhatch = custom[4,1];
endif;

pline = ones(numhatch+4,9); @set up the basic _pline matrix.  4 extra
rows for outline @
vec1 = ones(rows(pline),1);

if custom[1,1] == 0;   @ set colour @
 pline[.,8] = vec1.*colour_default;
else;
 pline[.,8] = vec1.*custom[1,1];
endif;

pline[.,9] = vec1.*custom[2,1];  @ Set line thickness @

if custom[3,1] == 0;   @ Set line style @
 pline[.,2] = vec1.*linestyle_default;
else;
 pline[.,2] = vec1.*custom[3,1];
endif;

vec1 = ones(numhatch,1);
pline[1:numhatch,4] = vec1.*dimen[1,2];  @ Set the y coordinates @
pline[1:numhatch,6] = vec1.*dimen[2,2];

xinc = (dimen[2,1]-dimen[1,1])/numhatch;  @ Set the x coordinates @
pline[1:numhatch,3] = seqa(dimen[1,1],xinc,numhatch);
pline[1:numhatch,5] = seqa(dimen[1,1]+xinc,xinc,numhatch);


@add code for the outer box. @
pline[numhatch+1,3] = dimen[1,1];
pline[numhatch+1,4] = dimen[1,2];
pline[numhatch+1,5] = dimen[2,1];
pline[numhatch+1,6] = dimen[1,2];
pline[numhatch+2,3] = dimen[1,1];
pline[numhatch+2,4] = dimen[2,2];
pline[numhatch+2,5] = dimen[2,1];
pline[numhatch+2,6] = dimen[2,2];
pline[numhatch+3,3] = dimen[1,1];
pline[numhatch+3,4] = dimen[1,2];
pline[numhatch+3,5] = dimen[1,1];
pline[numhatch+3,6] = dimen[2,2];
pline[numhatch+4,3] = dimen[2,1];
pline[numhatch+4,4] = dimen[1,2];
pline[numhatch+4,5] = dimen[2,1];
pline[numhatch+4,6] = dimen[2,2];

retp(pline);

endp;
