\manpage {window} {} {Graphic Windows}
 
\definition
The data type $window$ provides an interface for the input and
output of basic two-dimensional geometric objects (cf.~section 5.1) using the
X11 window system.  Application programs using data type $window$ have to
be linked with {\em libWx.a} and the X11 library (cf.~section~1.6):

CC $prog.c$ -lP -lG -lL -lWx -lX11 -lm



An instance $W$ of the data type $window$ is an iso-oriented
rectangular window in the two-dimensional plane.
The default representation of $W$ on the screen is a square of maximal possible
edge length positioned in the upper right corner (cf.~creation, variant c)).
The coordinates and scaling of $W$ used for drawing operations are defined
by three double parameters:
$x_0$, the x-coordinate of the left side, $x_1$, the x-coordinate of the right
side, and $y_0$, the y-coordinate of the bottom side.
The y-coordinate of the top side of $W$ is determined by the current size and
shape of the window on the screen, which can be changed interactively.
A graphic window supports operations for drawing points, lines, segments,
arrows, circles, polygons, graphs, \dots and for graphical input of all these
objects using the mouse input device. Most of the drawing operations have an
optional color argument. Possible colors are $black$ (default), $white$,
$blue$, $green$, $red$, $violet$, and $orange$. On monochrome displays all
colors different from $white$ are turned to $black$. There are 6 parameters
used by the drawing operations:

\begin{enumerate}
\item
The {\sl line width} parameter (default value 1 pixel) defines the width of all
kinds of lines (segments, arrows, edges, circles, polygons).

\item
The {\sl line style} parameter defines the style of lines. Possible line
styles are $solid$ (default), $dashed$, and $dotted$.

\item
The {\sl node width} parameter (default value 10 pixels) defines the diameter
of nodes created by the draw\_node and draw\_filled\_node operations.

\item
The {\sl text mode} parameter defines how text is inserted into the window.
Possible values are $transparent$ (default)  and $opaque$.

\item
The {\sl drawing mode} parameter defines the logical operation that is used
for setting pixels in all drawing operations. Possible values are
$src\_mode$ (default) and $xor\_mode$. In $src\_mode$ pixels are set to
the respective color value, in $xor\_mode$ the value is bitwise added to the
current pixel value.

\item
The {\sl redraw function} parameter is used to redraw the entire window
whenever a redrawing is necessary, e.g., if the window shape on the screen
has  been changed. Its type is pointer to a void-function taking no arguments,
i.e., void (*F)();

\end{enumerate} 
 
\creation W  
 
\create {(float\ width,\ float\ height,\ float\ xpos,\ float\ ypos)}
   { creates a window $W$ of physical size $xpix \times ypix$ pixels
    with its upper left corner at position ($xpos,ypos$) on the screen,
    variant b) places $W$ into the upper right corner of the screen, and
    variant c) creates a maximal square window positioned into the
    upper right corner.
    All three variants initialize the coordinates of $W$ to $x0 = 0$,
    $x1 = 100$ and $y0 = 0$. The $init$ operation (see  below) can later
    be used to change the window coordinates and scaling. }
 
 
\operations 2.7 4.4
 

\medskip
{\bf 3.1 Initialization} 
 
\opl void init {(double\ x0, double\ x1, double\ y0)}
           {  sets the coordinates of $W$ to $x_0$, $x_1$, and $y_0$. }
 
 
\opl void set\_grid\_mode {(int\ d)}
           {  Adds a rectangular grid with integer coordinates and
             grid distance $d$ to $W$, if $d > 0$. Removes grid from
             $W$, if $d\le 0$. }
 
 
\opl void init {(double\ x0, double\ x1, double\ y0, int\ d)}
           {  like init($x_0,x_1,y_0$) followed by set\_grid\_mode($d$). }
 
 
\opl void clear {(color\ c=BG\_color)}
           {  clears $W$. }
 
 

\medskip
{\bf 3.2 Setting parameters} 
 
\opl int set\_line\_width {(int\ pix)}
           {  Sets the line width parameter to $pix$ pixels and
	     returns its previous value. }
 
 
\opl line\_style set\_line\_style {(line\_style\ s)}
           {  Sets the line style parameter to $s$ and returns its
	     previous value. }
 
 
\opl int set\_node\_width {(int\ pix)}
           {  Sets the node width parameter to $pix$ pixels and
	     returns its previous value. }
 
 
\opl text\_mode set\_text\_mode {(text\_mode\ m)}
           {  Sets the text mode parameter to $m$ and returns
	     its previous value. }
 
 
\opl drawing\_mode set\_mode {(drawing\_mode\ m)}
           {  Sets the drawing mode parameter to $m$ and returns
	     its previous value. }
 
 
\opl void set\_frame\_label {(string\ s)}
           {  makes $s$ the window frame label.  }
 
 
\op  void reset\_frame\_label {()}
           {  restores the standard LEDA frame label.  }
 
 
\opl void set\_redraw {(void\ (*F)())}
           {  Sets the redraw function parameter to $F$. }
 
 
\opl void set\_flush {(bool\ b)}
           {  flush $X11$ output stream after each draw action
             iff $b = true$. }
 
 
\opl bool load\_text\_font {(string\ fn)}
           {  load $X11$ font $fn$ and use it as text font. Returns $true$
             on success and false if the font is not available. }
 
 
\opl bool load\_bold\_font {(string\ fn)}
           {  load $X11$ font $fn$ and use it as bold font. Returns true
             on success and false if the font is not available. }
 
 
\opl bool load\_message\_font {(string\ fn)}
           {  load $X11$ font $fn$ and use it as message font. Returns true
             on success and false if the font is not available. }
 
 

\medskip
{\bf 3.3 Reading parameters and window coordinates} 
 
\op  int get\_line\_width {()}
           {  returns the current line width. }
 
 
\op  line\_style get\_line\_style {()}
           {  returns the current line style. }
 
 
\op  int get\_node\_width {()}
           {  returns the current node width. }
 
 
\op  text\_mode get\_text\_mode {()}
           {  returns the current text mode. }
 
 
\op  drawing\_mode get\_mode {()}
           {  returns the current drawing mode. }
 
 
\op  double xmin {()}
           {  returns $x_0$, the minimal x-coordinate of $W$. }
 
 
\op  double ymin {()}
           {  returns $y_0$, the minimal y-coordinate of $W$. }
 
 
\op  double xmax {()}
           {  returns $x_1$, the maximal x-coordinate of $W$. }
 
 
\op  double ymax {()}
           {  returns $y_1$, the maximal y-coordinate of $W$. }
 
 
\op  double scale {()}
           {  returns the number of pixels of a unit length
	     line segment. }
 
 

\medskip
{\bf 3.4 Drawing points} 
\setopdims 1.2 4.4

 
\opl void draw\_point {(double\ x, double\ y, color\ c=FG\_color)}
           {  draws the point $(x,y)$ as a cross of a vertical
	     and a horizontal segment intersecting at $(x,y)$. }
 
 
\opl void draw\_point {( point\ p, color\ c=FG\_color)}
           {  draws point ($p$.xcoord(),$p$.ycoord()). }
 
 
\opl void draw\_pix {(double\ x, \ double\ y, \ color\ c=FG\_color\ )}
           {  sets the color of the pixel at position $(x,y)$ to $c$.  }
 
 
\opl void draw\_pix {( point\ p, \ color\ c=FG\_color\ )}
           {  sets the color of the pixel at position $p$ to $c$.  }
 
 

\medskip
{\bf 3.5 Drawing line segments}

 
\opl void draw\_segment {(double\ x1, \ double\ y1, \ double\ x2, \ double\ y2, \ color\ c=FG\_color)}
           {  draws a line segment from $(x_1,y_1)$ to $(x_2,y_2)$. }
 
 
\opl void draw\_segment {( point\ p, \  point\ q, \ color\ c=FG\_color\ )}
           {  draws a line segment from point $p$ to point $q$. }
 
 
\opl void draw\_segment {( segment\ s, \ color\ c=FG\_color\ )}
           {  draws line segment $s$. }
 
 

\medskip
{\bf 3.6 Drawing lines}

 
\opl void draw\_line {(double\ x1, \ double\ y1, \ double\ x2, \ double\ y2, \ color\ c=FG\_color\ )}
           {  draws a straight line passing through points $(x_1,y_1)$ and
	     $(x_2,y_2)$. }
 
 
\opl void draw\_line {( point\ p, \  point\ q, \ color\ c=FG\_color)}
           {  draws a straight line passing through points $p$ and $q$. }
 
 
\opl void draw\_line {( segment\ s, \ color\ c=FG\_color)}
           {  draws the line supporting $s$. }
 
 
\opl void draw\_line {( line\ l, \ color\ c=FG\_color)}
           {  draws line $l$. }
 
 
\opl void draw\_hline {(double\ y, \ color\ c=FG\_color\ )}
           {  draws a horizontal line with y-coordinate $y$.  }
 
 
\opl void draw\_vline {(double\ x, \ color\ c=FG\_color\ )}
           {  draws a vertical line with x-coordinate $x$.  }
 
 
\opl void draw\_arc {( point\ p, \  point\ q, \ double\ r\ ,color=FG\_color)}
           {  draws a circular arc with radius r from p to q
             with the center lying  to the right of the
             directed segment $p\longrightarrow q$.   }
 
 

\medskip
{\bf 3.7 Drawing arrows}

 
\opl void draw\_arrow {(double, \ double, \ double, \ double, \ color=FG\_color\ )}
           {  draws an arrow pointing from $(x_1,y_1)$ to $(x_2,y_2)$. }
 
 
\opl void draw\_arrow {( point, \  point, \ color=FG\_color\ )}
           {  draws an arrow pointing from point $p$ to point $q$. }
 
 
\opl void draw\_arrow {( segment, \ color=FG\_color\ )}
           {  draws an arrow pointing from $s$.start() to $s$.end(). }
 
 
\opl void draw\_arc\_arrow {( point,  point,double,color=FG\_color)}
           {  draws a circular arc arrow with radius r pointing from
             p to q with the center lying  to the right of the
             directed segment $p\longrightarrow q$.   }
 
 

\medskip
{\bf 3.8 Drawing circles}

 
\opl void draw\_circle {(double\ x, double\ y, double\ r, color\ c=FG\_color)}
           {  draws the circle with center $(x,y)$ and radius $r$. }
 
 
\opl void draw\_circle {( point\ p, double\ r, color\ c=FG\_color)}
           {  draws the circle with center $p$ and radius $r$. }
 
 
\opl void draw\_circle {( circle\ C, color\ c=FG\_color)}
           {  draws circle $C$. }
 
 
\opl void draw\_ellipse {(double\ x, double\ y, double\ r1, \ double\ r2, \ color\ c=FG\_color)}
           {  draws the ellipse with center $(x,y)$ and radii $r1$ and $r2$. }
 
 
\opl void draw\_ellipse {( point\ p, \ double\ r1, \ double\ r2, \ color\ c=FG\_color)}
           {  draws the ellipse with center $p$ and radii $r1$ and $r2$. }
 
 

\medskip
{\bf 3.9 Drawing discs}

 
\opl void draw\_disc {(double\ x, double\ y, double\ r, color\ c=FG\_color)}
           {  draws a filled circle with center $(x,y)$ and radius $r$. }
 
 
\opl void draw\_disc {( point\ p, double\ r, color\ c=FG\_color)}
           {  draws a filled circle with center $p$ and radius $r$. }
 
 
\opl void draw\_disc {( circle\ C, color\ c=FG\_color)}
           {  draws filled circle $C$. }
 
 
\opl void draw\_filled\_ellipse {(double\ x, double\ y, double\ r1, double\ r2, color\ c=FG\_color)}
           {  draws a filled ellipse with center $(x,y)$ and radii $r1$ and $r2$. }
 
 
\opl void draw\_filled\_ellipse {( point\ p, double\ r1, double\ r2, color\ c=FG\_color)}
           {  draws a filled ellipse with center $p$ and radii $r1$ and $r2$. }
 
 

\medskip
{\bf 3.10 Drawing polygons }

 
\opl void draw\_polygon {( list\<point\>\ lp, \ color\ c=FG\_color\ )}
           {  draws the polygon with vertex sequence $lp$. }
 
 
\opl void draw\_polygon {( polygon\ P, \ color\ c=FG\_color\ )}
           {  draws polygon $P$. }
 
 
\opl void draw\_filled\_polygon {( list\<point\>\ lp, \ color\ c=FG\_color\ )}
           {  draws the filled polygon with vertex sequence $lp$. }
 
 
\opl void draw\_filled\_polygon {( polygon\ P, color\ c=FG\_color\ )}
           {  draws filled polygon $P$. }
 
 

\medskip
{\bf 3.11 Drawing functions}

 
\opl void plot\_xy {(double\ x0, \ double\ x1, \ draw\_func\_ptr\ f, \ color\ c=FG\_color)}
           {  draws function $F$ in range $[x_0,x_1]$, i.e., all points
	     $(x,y)$ with $y = F(x)$ and $x_0\le x\le x_1$. }
 
 
\opl void plot\_yx {(double\ y0, \ double\ y1, \ draw\_func\_ptr\ f, \ color\ c=FG\_color)}
           {  draws function $F$ in range $[y_0,y_1]$, i.e., all points
	     $(x,y)$ with $x = F(y)$ and $y_0\le y\le y_1$. }
 
 

\medskip
{\bf 3.12 Drawing text}

 
\opl void draw\_text {(double\ x, \ double\ y, \ string\ s, \ color\ c=FG\_color)}
           {  writes string $s$ starting at position $(x,y)$. }
 
 
\opl void draw\_text {( point\ p, \ string\ s, \ color\ c=FG\_color)}
           {  writes string $s$ starting at position $p$. }
 
 
\opl void draw\_ctext {(double\ x, \ double\ y, \ string\ s, \ color\ c=FG\_color)}
           {  writes string $s$ centered at position $(x,y)$. }
 
 
\opl void draw\_ctext {( point\ p, \ string\ s, \ color\ c=FG\_color)}
           {  writes string $s$ centered at position $p$. }
 
 

\medskip
{\bf 3.13 Drawing nodes}
%Nodes are circles of diameter $node\_width$.

 
\opl void draw\_node {(double\ x0, double\ y0, color\ c=FG\_color)}
           {  draws a node at position $(x_0,y_0)$. }
 
 
\opl void draw\_node {( point\ p, \ color\ c=FG\_color)}
           {  draws a node at position $p$. }
 
 
\opl void draw\_filled\_node {(double\ x0, double\ y0, color\ c=FG\_color)}
           {  draws a filled node at position $(x_0,y_0)$. }
 
 
\opl void draw\_filled\_node {( point\ p, \ color\ c=FG\_color)}
           {  draws a filled node at position $p$. }
 
 
\opl void draw\_text\_node {(double\ x, double\ y, string\ s, color\ c=BG\_color)}
           {  draws a node with label $s$ at position $(x,y)$.  }
 
 
\opl void draw\_text\_node {( point\ p\ , string\ s, color\ c=BG\_color)}
           {  draws a node with label $s$ at position $p$.  }
 
 
\opl void draw\_int\_node {(double\ x, double\ y, int\ i, color\ c=BG\_color)}
           {  draws a node with integer label $i$ at position
	     $(x,y)$.  }
 
 
\opl void draw\_int\_node {( point\ p\ , int\ i, color\ c=BG\_color)}
           {  draws a node with integer label $i$ at position $p$.  }
 
 

\medskip
{\bf 3.14 Drawing edges}
%Edges are straigth line segments or arrows with a clearance of 
%$node\_width/2$ at each end.

 
\opl void draw\_edge {(double, double,double,double,\ color\ c=FG\_color)}
           {  draws an edge from $(x_1,y_1)$ to $(x_2,y_2)$. }
 
 
\opl void draw\_edge {( point, \  point, \ color=FG\_color\ )}
           {  draws an edge from $p$ to $q$. }
 
 
\opl void draw\_edge {( segment, \ color=FG\_color\ )}
           {  draws an edge from $s$.start() to $s$.end(). }
 
 
\opl void draw\_edge\_arrow {(double, double,double,double,\ color\ c=FG\_color)}
           {  draws a directed edge from $(x_1,y_1)$ to $(x_2,y_2)$. }
 
 
\opl void draw\_edge\_arrow {( point, \  point, \ color=FG\_color\ )}
           {  draws a directed edge from $p$ to $q$. }
 
 
\opl void draw\_edge\_arrow {( segment, \ color=FG\_color\ )}
           {  draws a directed edge from $s$.start() to $s$.end(). }
 
 
\opl void draw\_arc\_edge {( point, \  point, \ double, \ color=FG\_color\ )}
           {  draws a circular edge arc with radius r from p to q
             with the center lying  to the right of the
             directed segment $p\longrightarrow q$.   }
 
 
\opl void draw\_arc\_edge\_arrow {( segment, \ double, \ color=FG\_color\ )}
           {  draws a circular directed edge arc with radius r from p
             to q with the center lying  to the right of the
             directed segment $p\longrightarrow q$.   }
 
 

\medskip
{\bf 3.15 Mouse Input}

 
\op  int read\_mouse {()}
           {  displays the mouse cursor until a button is pressed.
	     Returns integer 1 for the left, 2 for the middle, and
	     3 for the right button (-1,-2,-3, if the shift key is
	     pressed simultaneously). }
 
 
\opl int read\_mouse {(double\&\ x, \ double\&\ y)}
           {  displays the mouse cursor on the screen until a
	     button is pressed. When a button is pressed the
             current position of the cursor is assigned to
             to $(x,y)$ and the pressed button is returned. }
 
 
\opl int read\_mouse {(point\&\ p)}
           {  displays the mouse cursor on the screen until a
	     button is pressed. When a button is pressed the
             current position of the cursor is assigned to
             to $p$ and the pressed button is returned. }
 
 
\opl int read\_mouse\_seg {(double\ x0, \ double\ y0, \ double\&\ x, \ double\&\ y)}
           {  displays a line segment from $(x_0,y_0)$ to the
	     current cursor position until a mouse button is
	     pressed. When a button is pressed the current
	     position is assigned to $(x,y)$ and the pressed
	     button is returned. }
 
 
\opl int read\_mouse\_seg {( point\ p, \ point\&\ q)}
           {  displays a line segment from $p$ to the current
             cursor position until a mouse button is
	     pressed. When a button is pressed the current
	     position is assigned to $q$ and the pressed
	     button is returned. }
 
 
\opl int read\_mouse\_rect {(double\ x0, \ double\ y0, \ double\&\ x, \ double\&\ y)}
           {  displays a rectangle with diagonal from $(x_0,y_0)$
     	     to the current cursor position until a mouse button 
	     is pressed. When a button is pressed the current 
	     position is assigned to $(x,y)$ and the pressed 
	     button is returned. }
 
 
\opl int read\_mouse\_rect {( point\ p\ , \ point\&\ q)}
           {  displays a rectangle with diagonal from $p$
     	     to the current cursor position until a mouse button 
	     is pressed. When a button is pressed the current 
	     position is assigned to $q$ and the pressed 
	     button is returned. }
 
 
\opl int read\_mouse\_circle {(double\ x0, \ double\ y0, \ double\&\ x, \ double\&\ y)}
           {  displays a circle with center $(x_0,y_0)$ passing
	     through the current cursor position until a mouse 
	     button is pressed. When a button is pressed the 
	     current position is assigned to $(x,y)$ and the 
	     pressed button is returned. }
 
 
\opl int read\_mouse\_circle {( point\ p, \ point\&\ q)}
           {  displays a circle with center $p$ passing
	     through the current cursor position until a mouse 
	     button is pressed. When a button is pressed the 
	     current position is assigned to $q$ and the 
	     pressed button is returned. }
 
 
\op  int get\_button {()}
           {  non-blocking read operation, i.e., if a button was pressed
            its number is returned, otherwise $0$ is returned.  }
 
 
\opl int get\_button {(double\&\ x, \ double\&\ y)}
           {  if a button was pressed the corresponding position is
            assigned to $(x,h)$ and the button number is returned, 
            otherwise $0$ is returned.  }
 
 
\op  int get\_button {(point\&\ p)}
           {  if a button was pressed the corresponding position is
            assigned to $p$ and the button number is returned, 
            otherwise $0$ is returned.  }
 
 

\bigskip
{\bf 3.16 Events}

 
\op  int get\_button {(point\&\ p)}
           {  returns $X11$ time-stamp of last button press event.  }
 
 
\op  int get\_button {(point\&\ p)}
           {  returns $X11$ time-stamp of last button release event.  }
 
 

\bigskip
{\bf 3.17 Panel Input}

 
\op  int confirm {(string\ s)}
           {  displays string $s$ and asks for confirmation.
	     Returns true iff the answer was ``yes''. }
 
 
\opl void acknowledge {(string\ s)}
           {  displays string $s$ and asks for acknowledgement. }
 
 
\opl int read\_panel {(string, \ int, \ string*)}
           {  displays a panel with header $h$ and an array $S[1..n]$
	     of $n$ string buttons, returns the index of the selected 
	     button. }
 
 
\opl int read\_vpanel {(string, \ int, \ string*)}
           {  like read\_panel with vertical button layout. }
 
 
\op  string  read\_string {(string)}
           {  displays a panel with prompt $p$ for string input,
    	     returns the input. }
 
 
\op  double  read\_real {(string)}
           {  displays a panel with prompt $p$ for real input
 	     returns the input. }
 
 
\op  int     read\_int {(string)}
           {  displays a panel with prompt $p$ for integer input,
	     returns the input. }
 
 
\op  void message {(string\ s)}
           {  displays message $s$ (each call adds a new line). }
 
 
\op  void del\_messages {()}
           {  deletes the text written by all previous message
	     operations. }
 
 

\bigskip
{\bf 3.18 Input and output operators}

For input and output of basic geometric objects in the plane such as points, 
lines, line segments, circles, and polygons the $<<$ and $>>$ operators can 
be used. Similar to \CC input streams windows have an internal state indicating
whether there is more input to read or not. Its initial value is true and it 
is turned to false if an input sequence is terminated  by clicking the right 
mouse button (similar to ending stream input by the eof character). In 
conditional statements objects of type $window$ are automatically converted 
to boolean by returning this internal state. Thus, they can be used in 
conditional statements in the same way as \CC input streams. For example,
to read a sequence of points terminated by a right button click,  use 
`` {\bf while} ($W\ >>\ p$) $\{\  \dots\ \}$ ''. 

 

\medskip
{\bf 3.18.1 Output}
\setopdims 2.5 4.4

 
\binop window\& << { point\ p}
         {  like $W$.draw\_point($p$). }
 
 
\binop window\& << { segment\ s}
         {  like $W$.draw\_segment($s$). }
 
 
\binop window\& << { line\ l}
         {  like $W$.draw\_line($l$). }
 
 
\binop window\& << { circle\ C}
         {  like $W$.draw\_circle($C$). }
 
 
\binop window\& << { polygon\ P}
         {  like $W$.draw\_polygon($P$). }
 
 

\bigskip
{\bf 3.18.2 Input}

 
\binop window\& >> {point\&}
         {  reads a point $p$: clicking the left button
	     assigns the current cursor position to $p$. }
 
 
\binop window\& >> {segment\&}
         {  reads a segment $s$: use the left button to input
	     the start and end point of $s$. }
 
 
\binop window\& >> {line\&}
         {  reads a line $l$: use the left button to input
	     two different points on $l$. }
 
 
\binop window\& >> {circle\&}
         {  reads a circle $C$: use the left button to input
	     the center of $C$ and a point on $C$. }
 
 
\binop window\& >> {polygon\&}
         {  reads a polygon $P$: use the left button to input
	     the sequence of vertices of $P$, end the sequence 
	     by clicking the middle button. }
 
 

As long as an input operation has not been completed the last read point can 
be erased by simultaneously pressing the shift key and the left mouse button.

 

\bigskip
{\bf 3.19 Non-Member Functions} 

 
\func  int read\_mouse {(window*\&\ w, \ double\&\ x, \ double\&\ y)}
           {  waits for mouse input, assigns a pointer to the
            corresonding window to $w$ and the position in 
            $*w$ to $(x,y)$ and returns the number of the 
            pressed button.  }
 
 
\func  void put\_back\_event {()}
           {  puts last read event back to the input stream of events.  }
 
 
