\startcomponent co-backgrounds

\environment contextref-env
\product contextref

\chapter[backgrounds]{Backgrounds and Overlays}

\section[background text]{Text backgrounds}
\index{screens}
\index{backgrounds+text}
\macro{\tex{setupscreens}}
\macro{\tex{setupbackground}}
\macro{\tex{background}}
\macro{\tex{startbackground}}
\macro{\tex{startraster}}

In a number of commands, for example \type {\framed}, you
can use backgrounds. A background may have a color or a
screen (pure gray). By default the \type {backgroundscreen} is
set at \type {0.95}. Usable values lie between ~0.70
and~1.00.

Building screens in \TEX\ is memory consuming and may cause
error messages. The screens are therefore build up
externally by means of \POSTSCRIPT\ or \PDF\ instructions.
This is set up with:

\showsetup{setupscreens}

The parameter \type {factor} makes only sense when the
method \type {line} or \type {dot} is chosen. The parameter
\type {screen} determines the \quote {grid} of the screen.
Text on a screen of 0.95 is still readable.

Visually the \TEX\ screens are comparable with \POSTSCRIPT\
screens. When memory and time are non issues \TEX\ screens
come out more beautiful than postscript screens. There are
many ways to implement screens but only the mentioned
methods are implemented.

\startbackground
Behind the text in the pagebody screens can be typeset.
This is done by enclosing the text with the commands:

\startexample
\starttyping
\startbackground
\stopbackground
\stoptyping
\stopexample

We have done so in this text. Backgrounds can cross page
boundaries when necessary. Extra vertical whitespace is
added around the text for reasons of readability.
\stopbackground

\showsetup{startbackground}

The background can be set up with:

\showsetup{setupbackground}

The command \type {\background} can be used in combination
with for example placeblocks:

\startexample
\starttyping
\placetable
  {Just a table.}
  \background
  \starttable[|c|c|c|]
  \HL
  \VL red  \VL green   \VL blue   \VL \AR
  \VL cyan \VL magenta \VL yellow \VL \AR
  \HL
  \stoptable
\stoptyping
\stopexample

The command  \type{\background} expects an argument.
Because a table is \quote {grouped} it will generate
\argchars\ by itself and no extra braces are necessary.

\showsetup{background}

A fundamental difference between colors and screens is that
screens are never converted. There is a command \type
{\startraster} that acts like \type {\startcolor}, but in
contrast to the color command, \CONTEXT\ does not keep track
of screens across page boundaries. This makes sense,
because screens nearly always are used as simple backgrounds.

\section[backgrounds layout]{Layout backgrounds}
\index{screens}
\index{backgrounds+layout}
\macro{\tex{setupbackgrounds}}

In interactive or screen documents the different screen
areas may have different functions. Therefore the systematic
use of backgrounds may seem obvious. It is possible to
indicate all areas or compartments of the pagebody
(screenbody). This is done with:

\showsetup{setupbackgrounds}

Don't confuse this command with \type {\setupbackground}
(singular). A background is only calculated when something
has changed. This is more efficient while generating a
document. When you want to calculate each background
separately you should set the parameter \type {state} at
\type {repeat}. The page background is always recalculated,
since it provides an excellent place for page dependent
buttons.

After \type {\setupbackgrounds} without any
arguments the backgrounds are also re||calculated.

A specific part of the layout is identified by means of
an axis (see \in{figure}[fig:axis]).

\placefigure
  [hier][fig:axis]
  {The coordinates in \type{\setupbackgrounds}.}
  {\getbuffer[colo-5]}

You are allowed to provide more than one coordinate at a
time, for example:

\startexample
\starttyping
\setupbackgrounds
  [header,text,footer]
  [text]
  [background=screen]
\stoptyping
\stopexample

or

\startexample
\starttyping
\setupbackgrounds
  [text]
  [text,rightedge]
  [background=color,backgroundcolor=MyColor]
\stoptyping
\stopexample

Some values of the paremeter \type{page}, like \type{offset}
and \type{corner} also apply to other compartments, for
example:

\startexample
\starttyping
\setupbackgrounds
  [page]
  [offset=.5\bodyfontsize
   depth=.5\bodyfontsize]
\stoptyping
\stopexample

When you use menus in an interactive or screen document
alignment is automatically adjusted for offset and|/|or depth.
It is also possible to set the parameter \type{page} to the
standard colors and screens.

If for some reason an adjustment is not generated you can
use \type{\setupbackgrounds} (without an argument). In
that case \CONTEXT\ will calculate a new background.

\section[overlays]{Overlays}
\index{overlays}
\macro{\tex{defineoverlay}}

\TEX\ has only limited possibilities to enhance the layout
with specific features. In \CONTEXT\ we have the possibility
to \quote{add something to a text element}. You can think of
a drawing made in some package or other ornaments. What we
technically do is lay one piece of text over another piece
text. That is why we speak of \quote {overlays}.

When we described the backgrounds you saw the paremeters
\type {color} and \type {screen}. These are both examples of
an overlay. You can also define your own background:

\startbuffer
\defineoverlay[gimmick][\green a green text on a background]

\framed
  [height=2cm,background=gimmick,align=middle]
  {at\\the\\foreground}
\stopbuffer

\typebuffer

This would look like this:

\startlinecorrection
\getbuffer
\stoplinecorrection

An overlay can be anything:

\startbuffer
\defineoverlay
  [gimmick]
  [{\externalfigure[cow][width=\overlaywidth,height=\overlayheight]}]
\framed
  [height=2cm,width=5cm,background=gimmick,align=right]
  {\vfill this is a cow}
\stopbuffer

\typebuffer

We can see that in designing an overlay the width and height
are available in macros. This enables us to scale the
figure.

\startlinecorrection
\getbuffer
\stoplinecorrection

We can combine overlays with one another or with a screen and
color.

\startbuffer
\defineoverlay
  [gimmick]
  [{\externalfigure[cow][width=\overlaywidth,height=\overlayheight]}]
\defineoverlay
  [nextgimmick]
  [\red A Cow]
\framed
  [height=2cm,width=.5\textwidth,
   background={screen,gimmick,nextgimmick},align=right]
  {\vfill this is a cow}
\stopbuffer

\startlinecorrection
\getbuffer
\stoplinecorrection

The \TEX\ definitions look like this:

\typebuffer

\stopcomponent
