%output=pdf

\startbuffer[setups]
\setupcolors[state=start]

\setupbodyfont[10pt]

\setuplayout[bottom=1cm]%   just to test it

\setupbackgrounds
   [page]
   [background=page]

\defineoverlay[page][\reuseMPgraphic{page}]

\setupheadertexts[left head][right head]
\setupfootertexts[left foot][right foot]
\stopbuffer


\startbuffer[areas]
\startreusableMPgraphic{page}
  StartPage;
  path p;
  fill Page withcolor .95white;

  % backspace and topspace
  p:= ulcorner Page -- 
      llcorner Page -- 
      llcorner Page shifted (BackSpace,0) --
      ulcorner Page shifted (BackSpace,0) -- cycle;
  fill p withcolor transparent(1,0.5,green);

  p:= ulcorner Page -- 
      urcorner Page -- 
      urcorner Page shifted (0,-TopSpace) --
      ulcorner Page shifted (0,-TopSpace) -- cycle;
  fill p withcolor transparent(1,0.5,blue);

  % a red bottom...
  p:= (Hstep[LeftEdge], Vstep[Bottom]) --
      (Hstep[RightEdge],Vstep[Bottom]) --
      (Hstep[RightEdge],Vstep[Bottom]+Vsize[Bottom]) -- 
      (Hstep[LeftEdge], Vstep[Bottom]+Vsize[Bottom]) -- cycle;
  fill p withcolor transparent(1,0.5,red);


  % leftmargin and rightmargin
  p:= (Hstep[LeftMargin],                    Vstep[Text])--
      (Hstep[LeftMargin] + Hsize[LeftMargin],Vstep[Text]) --
      (Hstep[LeftMargin] + Hsize[LeftMargin],Vstep[Text]+Vsize[Text])--
      (Hstep[LeftMargin],                    Vstep[Text]+Vsize[Text])-- cycle;
  draw p withpen pencircle scaled .5mm withcolor blue dashed evenly;

  p:= (Hstep[RightMargin],                     Vstep[Text])--
      (Hstep[RightMargin] + Hsize[RightMargin],Vstep[Text]) --
      (Hstep[RightMargin] + Hsize[RightMargin],Vstep[Text]+Vsize[Text])--
      (Hstep[RightMargin],                     Vstep[Text]+Vsize[Text])-- cycle;
  draw p withpen pencircle scaled .5mm withcolor blue dashed evenly;


  % let's draw the header (notice that Vsize[Header] and HeaderHeight
  %                        are the same!)
  p:= (BackSpace,             Vstep[Header]) -- 
      (BackSpace+MakeupWidth, Vstep[Header]) --
      (BackSpace+MakeupWidth, Vstep[Header]+Vsize[Header]) --
      (BackSpace,             Vstep[Header]+HeaderHeight) -- cycle ;

  draw p withpen pencircle scaled .5mm withcolor blue dashed evenly;

  
  % and now for the footer
  p:= (BackSpace,             Vstep[Footer]) -- 
      (BackSpace+MakeupWidth, Vstep[Footer]) --
      (BackSpace+MakeupWidth, Vstep[Footer]+FooterHeight) --
      (BackSpace,             Vstep[Footer]+FooterHeight) -- cycle ;

  draw p withpen pencircle scaled .5mm withcolor blue dashed evenly;

  % And now for something completely different :)
  drawoptions (withcolor transparent (1,0.9,yellow) withpen pencircle scaled .3mm);

  draw Field [Text][Top];
  draw Field [Text][Header];
  draw Field [Text][Text];   
  draw Field [Text][Footer];
  % Field[][] = Area[][] shifted Location[][]
  draw Area [Text][Bottom] shifted Location [Text][Bottom];
  
    
  % needed, since LeftMargin+LeftMarginDistance > BackSpace
  setbounds currentpicture to boundingbox Page; 
\stopreusableMPgraphic
\stopbuffer
\getbuffer[setups,areas]
\starttext

This document is an example on how to access the different layout
areas within the [page] background. It is too late now, but I should
have warned you about the excessive color usage.

\startlinenumbering
\typebuffer[setups]
\typebuffer[areas]
\stoplinenumbering

\page
These are the parameters you can use inside the \METAPOST-sections
\startcolumns[n=4]
\startlines
PageNumber          
PaperHeight         
PaperWidth          
PrintPaperHeight    
PrintPaperWidth     
TopSpace            
BottomSpace         
BackSpace           
CutSpace            
MakeupHeight        
MakeupWidth         
TopHeight           
TopDistance         
HeaderHeight        
HeaderDistance      
TextHeight          
FooterDistance      
FooterHeight        
BottomDistance      
BottomHeight        
LeftEdgeWidth       
LeftEdgeDistance    
LeftMarginWidth     
LeftMarginDistance  
TextWidth           
RightMarginDistance 
RightMarginWidth    
RightEdgeDistance   
RightEdgeWidth      
PageOffset          
PageDepth           
\stoplines
\stopcolumns

\blank[2*big]
With the pair {\it Location} and the paths {\it Area} and {\it Field},
you can use these array indexes (see the example above):

\starttabulate[|l|l|]
\HR
\NC Horizontal          \NC Vertical        \NC\NR
\HR
\NC LeftEdge            \NC Top             \NC\NR
\NC LeftEdgeSeparator   \NC TopSeparator    \NC\NR
\NC LeftMargin          \NC Header          \NC\NR
\NC LeftMarginSeparator \NC HeaderSeparator \NC\NR
\NC Text                \NC Text            \NC\NR
\NC RightMarginSeparator\NC FooterSeparator \NC\NR
\NC RightMargin         \NC Footer          \NC\NR
\NC RightEdgeSeparator  \NC BottomSeparator \NC\NR
\NC RightEdge           \NC Bottom          \NC\NR
\HR
\stoptabulate

There are also the {\it Hsize}, {\it Hstep}, {\it Vsize} and {\it
Vstep} arrays. They take these the same parameters as given in the
table above. (Obviously the {\it Hsize} and {\it Hstep} arrays take
horizontal parameters and the {\it Vsize} and {\it Vstep} arrays the
vertical.)

To use all these, you should not forget to initialize the variables
with the StartPage \METAFUN\ macro! This will also give you a path
{\it Page} with the page outline!

%\showsetups
\blank[3*big]
Info: March 2003 Patrick Gundlach. See also section {\it Crossing
Borders} in the Metafun manual in chapter  {\it Page backgrounds} by
Hans Hagen.
\stoptext
\endinput

% Old stuff

%% \setupbackgrounds
%%    [bottom]
%%    [leftedge,leftmargin,text,rightmargin,rightedge]
%%    [background=justaframe]

%% \defineoverlay[justaframe][\useMPgraphic{justaframe}]

%% \startbuffer[frames]
%% \startuseMPgraphic{justaframe}
%% draw OverlayBox withpen pencircle scaled .5mm dashed evenly 
%%                 withcolor transparent (1,0.5,black);
%% \stopuseMPgraphic
%% \stopbuffer
%% \starttabulate[|l|l|]
%% \HR
%% \NC Vsize, Vstep   \NC Hsize, Hstep        \NC\NR
%% \HR
%% \NC Top            \NC LeftEdge            \NC\NR
%% \NC TopSeparator   \NC LeftEdgeSeparator   \NC\NR
%% \NC Header         \NC LeftMargin          \NC\NR
%% \NC HeaderSeparator\NC LeftMarginSeparator \NC\NR
%% \NC Text           \NC Text                \NC\NR
%% \NC FooterSeparator\NC RightMargin         \NC\NR
%% \NC Footer         \NC RightMarginSeparator\NC\NR
%% \NC BottomSeparator\NC RightEdge           \NC\NR
%% \NC Bottom         \NC RightEdgeSeparator  \NC\NR
%% \HR
%% \stoptabulate





%%% Local Variables: 
%%% mode: context
%%% TeX-master: t
%%% End: 
