Navigation: Up, Table of Contents, Index,

The Window Class (IfmWindow)

Definition

The class IfmWindow 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

IfmWindow w ( string str = "IFM Window");
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).

IfmWindow w ( int xsize, int ysize, string str = "IFM Window");
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).

IfmWindow 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).

IfmWindow w ( IfmWindow);
copy constructor.

IfmWindow& w = IfmWindow 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.
IfmWindow& & w << IfmDrawable d
d is drawn into w.
IfmWindow& & w >> IfmGetable d
d is set from w.
IfmWindow& w.flush () Buffer is flushed and all output drawn onto the display. Returns w.
IfmWindow& w.endl () same as flush.
IfmWindow& w.sync () Buffer is flushed, all output is drawn onto the display and all pending X-requests have been processed. Returns w.
IfmWindow& w.clear () Clears the window and flushes the buffer. Returns w.
IfmWindow& 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.
IfmWindow& w.set_draw_mode ( int m)
Drawing mode is set to m. (Possible values include GXcopy, GXxor, GXand, ....) Returns w.
IfmWindow& 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.
IfmWindow& 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 <ifmwindow>

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

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

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


Next: Class declaration of Point
Navigation: Up, Table of Contents, Index,
Michael Hoffmann. Mon, October 7, 2002.