Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

Reference Manual: ifm::Wstream Navigation: Up, Table of Contents, Index,

The Window Class (ifm::Wstream)

Definition

The class ifm::Wstream represents a window that can be used for IO-operations and an associated graphic context. The graphic context defines the drawing color (default: black), line width (default: 1) and drawing mode (default: GXcopy) and affects any output operation. There are a number of member functions to change the state of the graphic context. With the window comes a Cartesian coordinate system where the origin sits in the lower left corner, i.e., the window resides in the all-positive quadrant. All output is internally buffered, so in order to make it visible on the display, this buffer has to be flushed. Many functions handle expose-events, that means if parts of the window get obscured, their content is redrawn automatically, as soon as they get visible (exposed) again.

Creation

ifm::Wstream w ( string str = "ifm:: Wstream");
Creates a window with dimensions (512 x 512) and name str and positions it with upper left corner (100, 100) on the X display (your screen).

ifm::Wstream w ( int xsize, int ysize, string str = "ifm:: Wstream");
Precondition: 10 xsize, ysize 2048.
Creates a window with dimensions (xsize x ysize) and name str and positions it with upper left corner (100, 100) on the X display (your screen).

ifm::Wstream w ( int xpos, int ypos, int xsize, int ysize, string str);
Precondition: 10 xsize, ysize 2048.
Creates a window with dimensions (xsize x ysize) and name str and positions it with upper left corner (xpos, ypos) on the X display (your screen).

ifm::Wstream w ( ifm::Wstream);
copy constructor.

ifm::Wstream& w = ifm::Wstream copy assignment.

Operations

int w.xmin () returns minimal x-xoordinate in w.
int w.xmax () returns maximal x-xoordinate in w.
int w.ymin () returns minimal y-xoordinate in w.
int w.ymax () returns maximal y-xoordinate in w.
ifm::Wstream& & w << ifm::Drawable d
d is drawn into w.
ifm::Wstream& & w >> ifm::Getable d
d is set from w.
ifm::Wstream& w.flush () Buffer is flushed and all output drawn onto the display. Returns w.
ifm::Wstream& w.endl () same as flush.
ifm::Wstream& w.sync () Buffer is flushed, all output is drawn onto the display and all pending X-requests have been processed. Returns w.
ifm::Wstream& w.clear () Clears the window and flushes the buffer. Returns w.
ifm::Wstream& w.wait ( unsigned long microsec)
Flushes buffer and waits for microsec microseconds.
bool w.check_key () Returns true, iff there is a KeyRelease event pending.
bool w.check_mouse () Returns true, iff there is a MouseMotion event pending.
bool w.check_mouse_click ()
Returns true, iff there is a ButtonRelease event pending.
int w.get_key () Flushes buffer, waits for a KeyRelease event and returns the pressed key's ASCII-code. (65   A, 97   a). Expose events during the waiting period are handled.
void w.get_mouse ( int& x, int& y)
Flushes buffer, waits for a MouseMotion event and sets (x, y) to the mouse position. Expose events during the waiting period are handled.
int w.get_mouse_click ( int& x, int& y)
Flushes buffer, waits for a ButtonRelease event, sets (x, y) to the mouse position and returns the number of the pressed mouse button. (1   left, 2   middle, 3   right). Expose events during the waiting period are handled.
void w.wait_for_mouse_click ( int button = 0)
Precondition: 0 button 3.
Flushes buffer and waits until specified (0   any) mouse button gets released. Expose events during the waiting period are handled.
ifm::Wstream& w.set_draw_mode ( int m)
Drawing mode is set to m. (Possible values include GXcopy, GXxor, GXand, ....) Returns w.
ifm::Wstream& w.set_line_width ( int w)
Precondition: w > 0.
Drawing line width is set to w. Returns w.
int w.number_of_colors ()
Returns the number of available colors.
ifm::Wstream& w.set_color ( int c)
Precondition: 0 c number_of_colors().
Drawing color is set to c. The last two colors are always black and white, i.e., set_color(number_of_colors()) selects black. The rest is evenly divided by interpolating the following colors in order: red, orange, yellow, green, blue, magenta and purple. Returns w.

Example

The following code reads in a Circle c, draws c and its bounding square and then tracks the mouse pointer by drawing line segments between consecutive positions until finally a mouse button is pressed.

#include <IFM/window>

int main()
{
    // define a 200 x 200 pixel window  
    ifm::Wstream w(200, 200, "LibWindow-Example");

    // read in a circle
    ifm::Circle c;
    w >> c;
    
    // print c and its bounding square
    w << ifm::yellow << c << ifm::red
      << ifm::Rectangle(c.x() - c.r(), c.y() - c.r(),
                        c.x() + c.r(), c.y() + c.r())
      << ifm::flush;

    // tracks mouse pointer
    ifm::Point p_last(c.x(), c.y());
    do {
        int x, y;
        w.get_mouse(x, y);
        w << ifm::blue << ifm::Line(p_last.x(), p_last.y(), x, y) 
          << ifm::flush;
        p_last = ifm::Point(x, y);
    } while (!w.check_mouse_click());
    
    return 0;
}


Next: Class declaration of ifm::Point
Navigation: Up, Table of Contents, Index,
Michael Hoffmann. Wed, November 17, 2004.