Definition
The data type window provides an interface for graphical input and output of basic two-dimensional geometric objects. Application programs using this data type have to be linked with libW.a and (on UNIX systems) with the X11 base library libX11.a (cf. section 1.6):
CC prog.c -lW -lP -lG -lL -lX11 -lm
An instance W of 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 of the display.
In general, a window consists of two rectangular sections, a panel section in the upper part and a drawing section in the rest of the window. The panel section contains panel items such as sliders, choice fields, string items and buttons. They have to be created before the window is opened by special panel operations described in section panel-operations.
The drawing section can be used for the output of geometric objects such as points, lines, segments, arrows, circles, polygons, graphs, ...and for the input of all these objects using the mouse input device. All drawing and input operations in the drawing section use a coordinate system that is defined by three parameters of type double: xmin, the minimal x-coordinate, xmax, the maximal x-coordinate, and ymin, the minimal y-coordinate. The two parameters xmin and xmax define the scaling factor scaling as w/(xmax - xmin), where w is the width of the drawing section in pixels. The maximal y-coordinate ymax of the drawing section is equal to ymin + h*scaling and depends on the actual shape of the window on the screen. Here, h is the height of the drawing section in pixels.
A list of all window parameters:
#include < LEDA/window.h >
Creation
window | W | creates a squared window with maximal possible edge length (minimum of width and height of the display). |
window | W(const char* label) | creates a maximal squared window with frame label label. |
window | W(float w, float h) | creates a window W of physical size w pixels x h pixels . |
window | W(float w, float h, const char* label) | |
creates a window W of physical size w pixels x h pixels and frame label label. |
All four variants initialize the coordinates of W to xmin = 0,
xmax = 100 and ymin = 0. The init operation (see below) can later
be used to change the window coordinates and scaling. Please note, that a
window is not displayed before the function display is called for it.
Operations
3.1 Initialization
void | W.init(double x0, double x1, double y0) | |
sets xmin to x0, xmax to x1, and ymin to y0, the scaling factor scaling to w/(xmax - xmin), and ymax to ymin + h*scaling. Here w and h are the width and height of the drawing section in pixels. | ||
double | W.set_grid_dist(double d) | sets the grid distance of W to d. |
grid_style | W.set_grid_style(grid_style s) | |
sets the grid style of W to s. | ||
int | W.set_grid_mode(int d) | sets the grid distance of W to d pixels. |
int | W.set_precision(int prec) | sets the precision of W to prec. |
void | W.init(double x0, double x1, double y0, int d, bool erase=true) | |
same as W.init( x0, x1, y0) followed by W.set_grid_mode(d). If the optional flag erase is set to false the window will not be erased. | ||
void | W.display() | opens W and displays it with its right upper corner in the upper right corner of the screen. Note that W.display() has to be called before all drawing operations and that all operations adding panel items to W (cf. panel-operations) have to be called before the first call of W.display(). |
void | W.display(int x, int y) | opens W and displays it with its left upper corner at position (x, y). Special values for x and y are window : : min, window : : center, and window : : max for positioning W at the minimal or maximal x or y coordinate or centering it in the x or y dimension. |
void | W.display(window& w, int x, int y) | |
opens W and displays it with its left upper corner at position (x, y) relative to the upper left corner of window W0. |
W.open...can be used as a synonym for W.display... Note, that the open operation for panels (cf. Panels) is defined slightly different.
void | W.close() | closes W by removing it from the display. |
void | W.clear() | clears W using the current background color or pixmap, i.e., if W has a background pixmap defined it is tiled with P such that the upper left corner is the tiling origin. Otherwise, it is filled with background color of W. |
void | W.clear(double x0, double y0, double x1, double y1) | |
only clears the rectangular area (x0, y0, x1, y1) of window W using the current background color or pixmap. | ||
void | W.clear(color c) | clears W with color c and sets the background color of W to c. |
void | W.clear(double xorig, double yorig) | |
clears W. If a background pixmap is defined the point (xorig, yorig) is used as the origin of tiling. | ||
void | W.redraw() | repaints the drawing area if W has a redraw function. |
color | W.set_color(color c) | sets the foreground color parameter to c and returns its previous value. |
color | W.set_fill_color(color c) | sets the fill color parameter (used by << operators) to c and returns its previous value. |
color | W.set_bg_color(color c) | sets the background color parameter to c and returns its previous value. |
char* | W.set_bg_pixmap(char* pr) | sets the background pixmap to pr and returns its previous value. |
int | W.set_line_width(int pix) | sets the line width parameter to pix pixels and returns its previous value. |
line_style | W.set_line_style(line_style s) | |
sets the line style parameter to s and returns its previous value. | ||
int | W.set_node_width(int pix) | sets the node width parameter to pix pixels and returns its previous value. |
text_mode | W.set_text_mode(text_mode m) | |
sets the text mode parameter to m and returns its previous value. | ||
drawing_mode | W.set_mode(drawing_mode m) | |
sets the drawing mode parameter to m and returns its previous value. | ||
int | W.set_cursor(int cursor_id = -1) | |
sets the mouse cursor of W to cursor_id. Here cursor_id must be one of the constants predefined in <X11/cursorfont.h> or -1 for the system default cursor. Returns the previous cursor. | ||
void | W.set_show_coordinates(bool b) | |
sets the show coordinates flag to b. | ||
void | W.set_frame_label(string s) | |
makes s the window frame label. | ||
void | W.set_icon_label(string s) | |
makes s the window icon label. | ||
void | W.reset_frame_label() | restores the standard LEDA frame label. |
void | W.set_window_delete_handler(void (*F)(window*)) | |
sets the window delete handler function parameter to F. | ||
void | W.set_show_coord_handler(void (*F)(window*, double, double)) | |
sets the show coordinate handler function parameter to F. | ||
void | W.set_redraw(void (*F)(window*)) | |
sets the redraw function parameter to F. | ||
void | W.set_redraw(void (*F)(window*, double, double, double, double)=0) | |
sets the redraw function parameter to F. | ||
void | W.set_bg_redraw(void (*F)(window*, double, double, double, double)=0) | |
sets the background redraw function parameter to F. | ||
void | W.start_timer(int msec, void (*F)(window*)) | |
starts a timer that runs F every msec milliseconds with a pointer to W. | ||
void | W.stop_timer() | stops the timer. |
void | W.set_flush(bool b) | sets the flush parameter to b. |
void | W.set_icon_pixrect(char* pr) | |
makes pr the new icon of W. | ||
void* | W.set_client_data(void* p, int i=0) | |
sets the i-th client data pointer of W to p and returns its previous value. Precondition i < 16. |
3.3 Reading parameters
int | W.get_line_width() | returns the current line width. |
line_style | W.get_line_style() | returns the current line style. |
int | W.get_node_width() | returns the current node width. |
text_mode | W.get_text_mode() | returns the current text mode. |
drawing_mode | W.get_mode() | returns the current drawing mode. |
int | W.get_cursor() | returns the id of the current cursor, i.e, one of the constants predefined in <X11/cursorfont.h> or -1 for the default cursor. |
double | W.xmin() | returns the minimal x-coordinate of the drawing area of W. |
double | W.ymin() | returns the minimal y-coordinate of the drawing area of W. |
double | W.xmax() | returns the maximal x-coordinate of the drawing area of W. |
double | W.ymax() | returns the maximal y-coordinate of the drawing area of W. |
double | W.scale() | returns the scaling factor of the drawing area of W, i.e. the number of pixels of a unit length line segment. |
double | W.get_grid_dist() | returns the width of the current grid (zero if no grid is used). |
grid_style | W.get_grid_style() | returns the current grid style. |
int | W.get_grid_mode() | returns the width of the current grid in pixels (zero if no grid is used). |
void* | W.get_client_data(int i=0) | |
returns the i-th client data pointer of of W. Precondition i < 16. | ||
GraphWin* | W.get_graphwin() | returns a pointer to the GraphWin (see Graph Windows) that uses W as its display window or NULL if W is not used by any GraphWin. |
() | returns a pointer to the GeoWin (see Geo Windows) that uses W as its display window or NULL if W is not used by any GeoWin. | |
int | W.width() | returns the width of W in pixels. |
int | W.height() | returns the height of W in pixels. |
int | W.xpos() | returns the x-coordinate of the upper left corner of the frame of W. |
int | W.ypos() | returns the y-coordinate of the upper left corner of the frame of W. |
int | W.get_state() | returns the state of W. |
void | W.set_state(int stat) | sets the state of W to stat. |
bool | W.contains(point p) | returns true if p lies in the drawing area. |
3.4 Drawing Operations
All drawing operations have an optional color argument at the end of the parameter list. If this argument is omitted the current foreground color (cf. section parameters) of W is used.
3.4.1 Drawing points 1.2cm4.4cm
void | W.draw_point(double x, double y, color c=window::fgcol) | |
draws the point (x, y) (a cross of two short segments). | ||
void | W.draw_point(point p, color c=window::fgcol) | |
draws point p. | ||
void | W.draw_pixel(double x, double y, color c=window::fgcol) | |
sets the color of the pixel at position (x, y) to c. | ||
void | W.draw_pixel(point p, color c=window::fgcol) | |
sets the color of the pixel at position p to c. | ||
void | W.draw_pixels(list<point> L, color c=window::fgcol) | |
sets the color of all pixels in L to c. | ||
void | W.draw_pixels(int n, double* xcoord, double* ycoord, color c=window::fgcol) | |
draws all pixels (xcoord[i], ycoord[i]) for 0 < = i < = n - 1. |
3.4.2 Drawing line segments
void | W.draw_segment(double x1, double y1, double x2, double y2, color c=window::fgcol) | |
draws a line segment from (x1, y1) to (x2, y2). | ||
void | W.draw_segment(point p, point q, color c=window::fgcol) | |
draws a line segment from point p to point q. | ||
void | W.draw_segment(segment s, color c=window::fgcol) | |
draws line segment s. | ||
void | W.draw_segment(point p, point q, line l, color c = window::fgcol) | |
draws the part of the line l between p and q. This version of draw_segment should be used if p or q may lie far outside W. Precondition p and q lie on l or at least close to l. | ||
void | W.draw_segments(list<segment> L, color c=window::fgcol) | |
draws all segments in L. |
3.4.3 Drawing lines
void | W.draw_line(double x1, double y1, double x2, double y2, color c=window::fgcol) | |
draws a straight line passing through points (x1, y1) and (x2, y2). | ||
void | W.draw_line(point p, point q, color c=window::fgcol) | |
draws a straight line passing through points p and q. | ||
void | W.draw_line(segment s, color c=window::fgcol) | |
draws the line supporting segment s. | ||
void | W.draw_line(line l, color c=window::fgcol) | |
draws line l. | ||
void | W.draw_hline(double y, color c=window::fgcol) | |
draws a horizontal line with y-coordinate y. | ||
void | W.draw_vline(double x, color c=window::fgcol) | |
draws a vertical line with x-coordinate x. |
3.4.4 Drawing Rays
void | W.draw_ray(double x1, double y1, double x2, double y2, color c=window::fgcol) | |
draws a ray starting in (x1, y1) and passing through (x2, y2). | ||
void | W.draw_ray(point p, point q, color c=window::fgcol) | |
draws a ray starting in p and passing through q. | ||
void | W.draw_ray(segment s, color c=window::fgcol) | |
draws a ray starting in s.source() containing s. | ||
void | W.draw_ray(ray r, color c=window::fgcol) | |
draws ray r. | ||
void | W.draw_ray(point p, point q, line l, color c = window::fgcol) | |
draws the part of the line l on the ray with source p and passing through q. This version of draw_ray should be used if p may lie far outside W. Precondition p and q lie on l or at least close to l. |
3.4.5 Drawing Arcs and Curves
void | W.draw_arc(point p, point q, point r, color c=window::fgcol) | |
draws a circular arc starting in p passing through q and ending in r. | ||
void | W.draw_bezier(list<point> C, int n, color c=window::fgcol) | |
draws the bezier curve with control polygon C by a polyline with n points. | ||
void | W.draw_spline(list<point> L, int n, color c=window::fgcol) | |
draws a spline curve through the points of L. Each segment is approximated by a polyline with m points. | ||
void | W.draw_closed_spline(list<point> L, int n, color c=window::fgcol) | |
draws a closed spline through the points of L. | ||
void | W.draw_spline(polygon P, int n, color c=window::fgcol) | |
draws a closed spline through the vertices of P. |
3.4.6 Drawing arrows
void | W.draw_arrow(double x1, double y1, double x2, double y2, color c =window::fgcol) | |
draws an arrow pointing from (x1, y1) to (x2, y2). | ||
void | W.draw_arrow(point p, point q, color c=window::fgcol) | |
draws an arrow pointing from point p to point q. | ||
void | W.draw_arrow(segment s, color=window::fgcol) | |
draws an arrow pointing from s.start() to s.end(). | ||
void | W.draw_polyline_arrow(list<point> lp, color c=window::fgcol) | |
draws a polyline arrow with vertex sequence lp. | ||
void | W.draw_arc_arrow(point p, point q, point r, color c=window::fgcol) | |
draws a circular arc arrow starting in p passing through q and ending in r. | ||
void | W.draw_bezier_arrow(list<point> C, int n, color c=window::fgcol) | |
draws the bezier curve with control polygon C by a polyline with n points, the last segment is drawn as an arrow. | ||
void | W.draw_spline_arrow(list<point> L, int n, color c=window::fgcol) | |
draws a spline curve through the points of L. Each segment is approximated by a polyline with n points. The last segment is drawn as an arrow. | ||
point | W.draw_arrow_head(point p, double dir, color c=window::fgcol) | |
draws an arrow head at position p pointing to direction dir, where dir is an angle from [0, 2]. |
3.4.7 Drawing circles
void | W.draw_circle(double x, double y, double r, color c=window::fgcol) | |
draws the circle with center (x, y) and radius r. | ||
void | W.draw_circle(point p, double r, color c=window::fgcol) | |
draws the circle with center p and radius r. | ||
void | W.draw_circle(circle C, color c=window::fgcol) | |
draws circle C. | ||
void | W.draw_ellipse(double x, double y, double r1, double r2, color c=window::fgcol) | |
draws the ellipse with center (x, y) and radii r1 and r2. | ||
void | W.draw_ellipse(point p, double r1, double r2, color c=window::fgcol) | |
draws the ellipse with center p and radii r1 and r2. |
3.4.8 Drawing discs
void | W.draw_disc(double x, double y, double r, color c=window::fgcol) | |
draws a filled circle with center (x, y) and radius r. | ||
void | W.draw_disc(point p, double r, color c=window::fgcol) | |
draws a filled circle with center p and radius r. | ||
void | W.draw_disc(circle C, color c=window::fgcol) | |
draws filled circle C. | ||
void | W.draw_filled_ellipse(double x, double y, double r1, double r2, color c=window::fgcol) | |
draws a filled ellipse with center (x, y) and radii r1 and r2. | ||
void | W.draw_filled_ellipse(point p, double r1, double r2, color c=window::fgcol) | |
draws a filled ellipse with center p and radii r1 and r2. |
3.4.9 Drawing polygons
void | W.draw_polyline(list<point> lp, color c=window::fgcol) | |
draws a polyline with vertex sequence lp. | ||
void | W.draw_polyline(int n, double* xc, double* yc, color c=window::fgcol) | |
draws a polyline with vertex sequence (xc[0], yc[0]),...,(xc[n - 1], yc[n - 1]). | ||
void | W.draw_polygon(list<point> lp, color c=window::fgcol) | |
draws the polygon with vertex sequence lp. | ||
void | W.draw_oriented_polygon(list<point> lp, color c=window::fgcol) | |
draws the polygon with vertex sequence lp and indicates the orientation by an arrow. | ||
void | W.draw_polygon(polygon P, color c=window::fgcol) | |
draws polygon P. | ||
void | W.draw_oriented_polygon(polygon P, color c=window::fgcol) | |
draws polygon P and indicates the orientation by an arrow. | ||
void | W.draw_filled_polygon(list<point> lp, color c=window::fgcol) | |
draws the filled polygon with vertex sequence lp. | ||
void | W.draw_filled_polygon(polygon P, color c=window::fgcol) | |
draws filled polygon P. | ||
void | W.draw_polygon(gen_polygon P, color c=window::fgcol) | |
draws polygon P. | ||
void | W.draw_oriented_polygon(gen_polygon P, color c=window::fgcol) | |
draws polygon P and indicates the orientation by an arrow. | ||
void | W.draw_filled_polygon(gen_polygon P, color c=window::fgcol) | |
draws filled polygon P. | ||
void | W.draw_rectangle(double x0, double y0, double x1, double y1, color=window::fgcol) | |
draws a rectangle with lower left corner (x0, y0) and upper
right corner (x1, y1).
Precondition x0 < x1 and y0 < y1. |
||
void | W.draw_rectangle(point p, point q, color=window::fgcol) | |
draws a rectangle with lower left corner p and upper
right corner q.
Precondition p < q. |
||
void | W.draw_rectangle(rectangle R, color=window::fgcol) | |
draws rectangle R. | ||
void | W.draw_box(double x0, double y0, double x1, double y1, color c=window::fgcol) | |
draws a filled rectangle with lower left corner (x0, y0) and upper
right corner (x1, y1).
Precondition x0 < x1 and y0 < y1. |
||
void | W.draw_filled_rectangle(point p, point q, color=window::fgcol) | |
draws a filled rectangle with lower left corner p and upper
right corner q.
Precondition p < q. |
||
void | W.draw_filled_rectangle(rectangle R, color=window::fgcol) | |
draws rectangle R. | ||
void | W.draw_box(point p, point q, color c=window::fgcol) | |
same as draw_filled_rectangle(p,q,c). | ||
void | W.draw_box(rectangle R, color c=window::fgcol) | |
same as draw_filled_rectangle(p,q,c). | ||
void | W.draw_roundrect(double x0, double y0, double x1, double y1, double rndness, color col=window::fgcol) | |
draws a rectangle (x0, y0, x1, y1) with round corners. The rndness argument must be real number in the intervall [0, 1] and defined the ``roundness'' of the rectangle. | ||
void | W.draw_rectangle(point p, point q, double rndness, color col=window::fgcol) | |
draws a round rectangle with lower left corner p, upper right corner q, and roundness rndness. | ||
void | W.draw_roundbox(double x0, double y0, double x1, double y1, double rndness, color col=window::fgcol) | |
draws a filled rectangle (x0, y0, x1, y1) with round corners. The rndness argument must be real number in the intervall [0, 1] and defined the ``roundness'' of the rectangle. | ||
void | W.draw_roundbox(point p, point q, double rndness, color col=window::fgcol) | |
draws a round filled rectangle with lower left corner p, upper right corner q, and roundness rndness. | ||
void | W.draw_triangle(point a, point b, point c, color=window::fgcol) | |
draws triangle (a, b, c). | ||
void | W.draw_filled_triangle(point a, point b, point c, color=window::fgcol) | |
draws filled triangle (a, b, c). |
3.4.10 Drawing functions
void | W.plot_xy(double x0, double x1, win_draw_func F, color c=window::fgcol) | |
draws the graph of function F in the x-range [x0, x1], i.e., all pixels (x, y) with y = F(x) and x0 < = x < = x1. | ||
void | W.plot_yx(double y0, double y1, win_draw_func F, color c=window::fgcol) | |
draws the graph of function F in the y-range [y0, y1], i.e., all pixels (x, y) with x = F(y) and y0 < = y < = y1. |
3.4.11 Drawing text
void | W.draw_text(double x, double y, string s, color c=window::fgcol) | |
writes string s starting at position (x, y). | ||
void | W.draw_text(point p, string s, color c=window::fgcol) | |
writes string s starting at position p. | ||
void | W.draw_ctext(double x, double y, string s, color c=window::fgcol) | |
writes string s centered at position (x, y). | ||
void | W.draw_ctext(point p, string s, color c=window::fgcol) | |
writes string s centered at position p. | ||
void | W.draw_ctext(string s, color c=window::fgcol) | |
writes string s centered in window W. | ||
double | W.text_box(double x0, double x1, double y, string s, bool draw=true) | |
formats and writes string s into a box with its left border at x-coordinate x0, its right border at x1, and its upper border at y-coordinate y. Some LaTeX-like formatting commands can be used: \bf, \tt, \rm, \n, \c, \<color>, ... returns y-coordinate of lower border of box. If the optional last parameter draw is set to false no drawing takes place and only the lower y-coordinate of the box is computed. | ||
void | W.text_box(string s) | as above with x = W.xmin(), x1 = W.xmax(), and y = W.ymax(). |
void | W.message(string s) | displays the message s (each call adds a new line). |
void | W.del_message() | deletes the text written by all previous message operations. |
3.4.12 Drawing nodes
Nodes are represented by circles of diameter nodewidth.
void | W.draw_node(double x0, double y0, color c=window::fgcol) | |
draws a node at position (x0, y0). | ||
void | W.draw_node(point p, color c=window::fgcol) | |
draws a node at position p. | ||
void | W.draw_filled_node(double x0, double y0, color c=window::bgcol) | |
draws a filled node at position (x0, y0). | ||
void | W.draw_filled_node(point p, color c=window::bgcol) | |
draws a filled node at position p. | ||
void | W.draw_text_node(double x, double y, string s, color c=window::bgcol) | |
draws a node with label s at position (x, y). | ||
void | W.draw_text_node(point p, string s, color c=window::bgcol) | |
draws a node with label s at position p. | ||
void | W.draw_int_node(double x, double y, int i, color c=window::bgcol) | |
draws a node with integer label i at position (x, y). | ||
void | W.draw_int_node(point p, int i, color c=window::bgcol) | |
draws a node with integer label i at position p. |
3.4.13 Drawing edges
Edges are drawn as straigth line segments or arrows with a clearance of nodewidth/2 at each end.
void | W.draw_edge(double x1, double y1, double x2, double y2, color c=window::fgcol) | |
draws an edge from (x1, y1) to (x2, y2). | ||
void | W.draw_edge(point p, point q, color c=window::fgcol) | |
draws an edge from p to q. | ||
void | W.draw_edge(segment s, color c=window::fgcol) | |
draws an edge from s.start() to s.end(). | ||
void | W.draw_edge_arrow(double x1, double y1, double x2, double y2, color c=window::fgcol) | |
draws a directed edge from (x1, y1) to (x2, y2). | ||
void | W.draw_edge_arrow(point p, point q, color c=window::fgcol) | |
draws a directed edge from p to q. | ||
void | W.draw_edge_arrow(segment s, color c=window::fgcol) | |
draws a directed edge from s.start() to s.end(). |
3.4.14 Bitmaps and Pixrects
char* | W.create_bitmap(int w, int h, char* bm_data) | |
creates a bitmap (monochrome pixrect) of width w, height h, from the bits in data. | ||
char* | W.create_pixrect(const char** xpm_str) | |
creates a pixrect from the xpm data string xpm_str. | ||
char* | W.create_pixrect(string xpm_file) | |
creates a pixrect from the xpm file xpm_file. | ||
char* | W.create_pixrect(int w, int h, char* bm_data, int fg=window::fgcol, int bg=window::bgcol) | |
creates a pixrect of width w, height h, foreground color fg, and background color bg from bitmap data. | ||
char* | W.get_pixrect(double x1, double y1, double x2, double y2) | |
creates a color pixrect of width w = x2 - x1, height h = y2 - y1, and copies all pixels from the rectangular area (x1, x2, y1, y2) of W into it. | ||
char* | W.get_window_pixrect() | creates a pixrect copy of the current window contents. |
int | W.get_width(char* pr) | returns the width (number of pixels in a row) of pixrect pr. |
int | W.get_height(char* pr) | returns the height (number of pixels in a column) of pixrect pr. |
void | W.put_pixrect(double x, double y, char* pr) | |
copies the contents of pixrect pr with lower left corner at position (x, y) into W. | ||
void | W.put_pixrect(point p, char* pr) | |
copies the contents of pixrect pr with lower left corner at position p into W. | ||
void | W.center_pixrect(double x, double y, char* pr) | |
copies the contents of pixrect pr into W such that its center lies on position (x, y). | ||
void | W.put_pixrect(char* pr) | copies the contents of pixrect pr with lower left corner at position (W.xmin(),W.ymin()) into W. |
void | W.put_bitmap(double x, double y, char* bm, color c=window::fgcol) | |
draws all pixels corresponding to 1-bits in bm with color c, here the lower left corner of bm corresponds to the pixel at position (x, y) in W. | ||
void | W.put_pixrect(double x, double y, char* pr, int x0, int y0, int w, int h) | |
copies (pixel) rectangle (x0, y0, x0 + w, y0 + h) of pr with lower left corner at position (x, y) into W. | ||
void | W.del_bitmap(char* bm) | destroys bitmap bm. |
void | W.del_pixrect(char* pr) | destroys pixrect pr. |
void | W.copy_rect(double x0, double y0, double x1, double y1, double x, double y) | |
copies all pixels of rectangle (x0, y0, x1, y1) into the rectangle (x, y, x + w, y + h), where w = x1 - x0 and h = y1 - y0. |
3.4.15 Buffering
3.4.16 Clipping
3.5 Input
The main input operation for reading positions, mouse clicks, and buttons from a window W is the operation W.read_mouse(). This operation is blocking, i.e., waits for a button to be pressed which is either a ``real'' button on the mouse device pressed inside the drawing area of W or a button in the panel section of W. In both cases, the number of the selected button is returned. Mouse buttons have pre-defined numbers MOUSE_BUTTON(1) for the left button, MOUSE_BUTTON(2) for the middle button, and MOUSE_BUTTON(3) for the right button. The numbers of the panel buttons can be defined by the user. If the selected button has an associated action function or sub-window this function/window is executed/opened (cf. panel-operations for details).
There is also a non-blocking version W.get_mouse() which returns the constant NO_BUTTON if no button was pressed.
The window data type also provides two more general input operations W.read_event() and W.get_event() for reading events. They return the event type (enumeration in < LEDA/impl/x_window.htex2html_wrap_inline> ), the value of the event, the position of the event in the drawing section, and a time stamp of the event.
3.5.1 Read Mouse
int | W.read_mouse() | waits until a mouse button is pressed inside of the drawing area or until a button of the panel section is selected. In both cases, the number n of the button is returned which is one of the predefined constants MOUSE_BUTTON(i) with i {1, 2, 3} for mouse buttons and a user defined value (defined when adding the button with W.button()) for panel buttons. If the button has an associated action function this function is called with parameter n. If the button has an associated window M it is opened and M.read_mouse() is returned. |
int | W.read_mouse(double& x, double& y) | |
If a button is pressed inside the drawing area the current position of the cursor is assigned to (x, y). The operation returns the number of the pressed button (see W.read_mouse().) | ||
int | W.read_mouse(point& p) | If a button is pressed inside the drawing area the current position of the cursor is assigned to p. The operation returns the number of the pressed button (see W.read_mouse().) |
int | W.read_mouse_seg(double x0, double y0, double& x, double& y) | |
displays a line segment from (x0, y0) to the current cursor position until a mouse button is pressed inside the drawing section of W. When a button is pressed the current position is assigned to (x, y) and the number of the pressed button is returned. | ||
int | W.read_mouse_seg(point p, point& q) | |
displays a line segment from p to the current cursor position until a mouse button is pressed inside the drawing section of W. When a button is pressed the current position is assigned to q and the number of the pressed button is returned. | ||
int | W.read_mouse_rect(double x0, double y0, double& x, double& y) | |
displays a rectangle with diagonal from (x0, y0) to the current cursor position until a mouse button is pressed inside the drawing section of W. When a button is pressed the current position is assigned to (x, y) and the number of the pressed button is returned. | ||
int | W.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 inside the drawing section of W. When a button is pressed the current position is assigned to q and the number of the pressed button is returned. | ||
int | W.read_mouse_circle(double x0, double y0, double& x, double& y) | |
displays a circle with center (x0, y0) passing through the current cursor position until a mouse button is pressed inside the drawing section of W. When a button is pressed the current position is assigned to (x, y) and the number of the pressed button is returned. | ||
int | W.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 inside the drawing section of W. When a button is pressed the current position is assigned to q and the number of the pressed button is returned. | ||
int | W.get_mouse() | non-blocking read operation, i.e., if a button was pressed its number is returned, otherwise the constant NO_BUTTON is returned. |
int | W.get_mouse(double& x, double& y) | |
if a mouse button was pressed the corresponding position is assigned to (x, y) and the button number is returned, otherwise the constant NO_BUTTON is returned. | ||
int | W.get_mouse(point& p) | if a mouse button was pressed the corresponding position is assigned to p and the button number is returned, otherwise the constant NO_BUTTON is returned. |
int | W.read_mouse(double x0, double y0, int timeout1, int timeout2, bool& double_click, bool& drag) | |
... | ||
int | W.read_mouse(point p, int timeout1, int timeout2, bool& double_click, bool& drag) | |
... |
3.5.2 Events
int | W.read_event(int& val, double& x, double& y, unsigned long& t) | |
waits for next event in window W and returns it. Assigns the button or key to val, the position in W to (x, y), and the time stamp of the event to t. Possible events are (cf. < LEDA/impl/x_window.htex2html_wrap_inline> ): key_press_event, key_release_event, button_press_event, button_release_event, configure_event, motion_event, destroy_event. | ||
int | W.read_event(int& val, double& x, double& y, unsigned long& t, int timeout) | |
as above, but waits only timeout milliseconds; if no event occured the special event noevent is returned. | ||
int | W.read_event(int& val, double& x, double& y) | |
waits for next event in window W and returns it. Assigns the button or key to val and the position in W to (x, y). | ||
int | W.get_event(int& val, double& x, double& y) | |
if there is an event for window W in the event queue a W.readevent operation is performed, otherwise the integer constant noevent is returned. | ||
bool | W.shift_key_down() | returns true if a shift key was pressed during the last handled mouse button event. |
bool | W.ctrl_key_down() | returns true if a ctrl key was pressed during the last handled mouse button event. |
bool | W.alt_key_down() | returns true if an alt key was pressed during the last handled mouse button event. |
int | W.button_press_time() | returns the time-stamp (in msec) of the last button press event. |
int | W.button_release_time() | returns the time-stamp (in msec) of the last button release event. |
3.6 Panel Input
The operations listed in this section are useful for simple input of strings, numbers, and Boolean values.
bool | W.confirm(string s) | displays string s and asks for confirmation. Returns true iff the answer was ``yes''. |
void | W.acknowledge(string s) | displays string s and asks for acknowledgement. |
int | W.read_panel(string h, int n, string* S) | |
displays a panel with header h and an array of n buttons with labels S[0..n - 1], returns the index of the selected button. | ||
int | W.read_vpanel(string h, int n, string* S) | |
like read_panel with vertical button layout. | ||
string | W.read_string(string p) | displays a panel with prompt p for string input, returns the input. |
double | W.read_real(string p) | displays a panel with prompt p for double input returns the input. |
int | W.read_int(string p) | displays a panel with prompt p for integer input, returns the input. |
3.7 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 tex2html_wrap_inline> tex2html_wrap_inline> operators can be used. Similar to C++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 C++input streams. For example, to read a sequence of points terminated by a right button click, use `` while (W > > p) { ...} ''.
3.7.1 Output 2.5cm4.4cm
window& | W << point p | like W.draw_point(p). |
window& | W << segment s | like W.draw_segment(s). |
window& | W << ray r | like W.draw_ray(r). |
window& | W << line l | like W.draw_line(l). |
window& | W << circle C | like W.draw_circle(C). |
window& | W << polygon P | like W.draw_polygon(P). |
window& | W << gen_polygon P | like W.draw_polygon(P). |
window& | W << rectangle R | like W.draw_rectangle(R). |
3.7.2 Input
window& | W >> point& p | reads a point p: clicking the left button assigns the current cursor position to p. |
window& | W >> segment& s | reads a segment s: use the left button to input the start and end point of s. |
window& | W >> ray& r | reads a ray r: use the left button to input the start point and a second point on r. |
window& | W >> line& l | reads a line l: use the left button to input two different points on l. |
window& | W >> circle& C | reads a circle C: use the left button to input the center of C and a point on C. |
window& | W >> polygon& P | reads a polygon P: use the left button to input the sequence of vertices of P, end the sequence by clicking the right button. |
list<point> | W.read_polygon() | as above, however, returns list of vertices. |
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.
3.8 Non-Member Functions
The panel section of a window is used for displaying text messages and for updating the values of variables. It consists of a list of panel items and a list of buttons. The operations in this section add panel items or buttons to the panel section of W. Note that they have to be called before the window is displayed the first time.
In general, a panel item consists of a string label and an associated variable of a certain type (int, bool, string, double, color). The value of this variable can be manipulated through the item. Each button has a label (displayed on the button) and an associated number. The number of a button is either defined by the user or is the rank of the button in the list of all buttons. If a button is pressed (i.e. selected by a mouse click) during a readmouse operation its number is returned.
Action functions can be associated with buttons and some items (e.g. slider items) whenever a button with an associated action function is pressed this function is called with the number of the button as actual parameter. Action functions of items are called whenever the value of the corresponding variable is changed with the new value as actual parameter. All action functions must have the type void func(int).
Another way to define a button is to associate another window with it. In this case the button will have a menu sign and as soon as it is pressed the attached window will open. This method can be used to implement pop-up menues. The return value of the current readmouse operation will be the number associated with the button in the menu.
3.9.1 General Settings
void | W.set_panel_bg_color(color c) | |
sets the background color of the panel area to c. | ||
void | W.buttons_per_line(int n) | defines the maximal number n of buttons per line. |
void | W.set_button_space(int s) | sets the space between to adjacent buttons to s pixels. |
void | W.set_item_height(int h) | sets the vertical size of all items to h pixels. |
void | W.set_item_width(int w) | sets the horizontal size of all slider and string items to w pixels. |
void | W.set_bitmap_colors(int c0, int c1) | |
sets the unpressed/pressed colors used for drawing the pixels in bitmap buttons to c0 and c1. |
3.9.2 Simple Panel Items
panel_item | W.text_item(string s) | adds a text_item s to W. |
panel_item | W.bool_item(string s, bool& x, const char* hlp=0) | |
adds a boolean item with label s and variable x to W. | ||
panel_item | W.bool_item(string s, bool& x, void (*F)(int), const char* hlp=0) | |
as above with action function F. | ||
panel_item | W.int_item(string s, int& x, const char* hlp=0) | |
adds an integer item with label s and variable x to W. | ||
panel_item | W.string_item(string s, string& x, void (*F)(char*), const char* hlp=0) | |
as above with action function F. | ||
panel_item | W.string_item(string s, string& x, const char* hlp=0) | |
adds a string item with label s and variable x to W. | ||
panel_item | W.double_item(string s, double& x, const char* hlp=0) | |
adds a real item with label s and variable x to W. | ||
panel_item | W.color_item(string s, color& x, const char* hlp=0) | |
adds a color item with label s and variable x to W. | ||
panel_item | W.color_item(string s, color& x, void (*F)(int), const char* hlp=0) | |
as above with action function F. | ||
panel_item | W.pstyle_item(string s, point_style& x, const char* hlp=0) | |
adds a point style item with label s and variable x to W. | ||
panel_item | W.pstyle_item(string s, point_style& x, void(*F)(int), const char* hlp=0) | |
as above with action function F. | ||
panel_item | W.lstyle_item(string s, line_style& x, const char* hlp=0) | |
adds a line style item with label s and variable x to W. | ||
panel_item | W.lstyle_item(string s, line_style& x, void(*F)(int), const char* hlp=0) | |
as above with action function F. | ||
panel_item | W.lwidth_item(string s, int& x, const char* hlp=0) | |
adds a line width item with label s and variable x to W. | ||
panel_item | W.lwidth_item(string s, int& x, void(*F)(int), const char* hlp=0) | |
as above with action function F. |
3.9.3 Integer Choice Items
panel_item | W.int_item(string s, int& x, int l, int h, int step, const char* hlp=0) | |
adds an integer choice item with label s, variable x, range l,..., h, and step size step to W. | ||
panel_item | W.int_item(string s, int& x, int l, int h, int step, void (*F)(int), const char* hlp=0) | |
adds an integer choice item with label s, variable x, range l,..., h, and step size step to W. Function F(x) is executed whenever the value of x is changed. | ||
panel_item | W.int_item(string s, int& x, int l, int h, const char* hlp=0) | |
adds an integer slider item with label s, variable x, and range l,...,h to W. | ||
panel_item | W.int_item(string s, int& x, int l, int h, void (*F)(int), const char* hlp=0) | |
adds an integer slider item with label s, variable x, and range l,...,h to W. Function F(x) is executed whenever the value of x has changed by moving the slider. |
3.9.4 String Menu Items
panel_item | W.string_item(string s, string& x, list<string> L, const char* hlp=0) | |
adds a string item with label s, variable x, and menu L to W. | ||
panel_item | W.string_item(string s, string& x, list<string> L, void (*F)(char*), const char* hlp=0) | |
as above with action function F. | ||
panel_item | W.string_item(string s, string& x, list<string> L, int sz, const char* hlp=0) | |
menu L is displayed in a scroll box of height sz. | ||
panel_item | W.string_item(string s, string& x, list<string> L, int sz, void (*F)(char*), const char* hlp=0) | |
as above with action function F. | ||
void | W.set_menu(panel_item it, list<string> L, int sz=0) | |
replaces the menu of string menu item it by a menu for list L (table style if sz = 0 and scroll box with sz entries otherwise). |
3.9.5 Choice Items
panel_item | W.choice_item(string s, int& x, list<string> L, void (*F)(int)=0, const char* hlp=0) | |
adds an integer item with label s, variable x, and choices from L to W. | ||
panel_item | W.choice_item(string s, int& x, string s1, ..., string sk) | |
adds an integer item with label s, variable x, and choices s1, ..., sk to W (k < = 8). | ||
panel_item | W.choice_item(string s, int& x, int n, int w, int h, char** bm, const char* hlp=0) | |
adds an integer item with label s, variable x, and n
bitmaps bm[0], ..., bm[n-1] each of width w
and height h. |
||
panel_item | W.choice_item(string s, int& x, int n, int w, int h, char** bm, void (*F)(int), const char* hlp=0) | |
3.9.6 Multiple Choice Items
panel_item | W.choice_mult_item(string s, int& x, list<string> L, const char* hlp=0) | |
panel_item | W.choice_mult_item(string s, int& x, list<string> L, void (*F)(int), const char* hlp=0) | |
panel_item | W.choice_mult_item(string s, int& x, int n, int w, int h, char** bm, const char* hlp=0) | |
panel_item | W.choice_mult_item(string s, int& x, int n, int w, int h, char** bm, void (*F)(int), const char* hlp=0) | |
3.9.7 Buttons
The first occurence of character '&' in a button label makes the following character c an accelerator character, i.e., the button can be selected by typing ALT-c from the keyboard.
int | W.button(string s, int n, const char* hlp=0) | |
adds a button with label s and number n to W. | ||
int | W.fbutton(string s, int n, const char* hlp=0) | |
as above but makes this button the focus button of W, i.e., this button can be selected by pressing the return key. | ||
int | W.button(string s, const char* hlp=0) | |
adds a new button to W with label s and number equal to its position in the list of all buttons (starting with 0). | ||
int | W.fbutton(string s, const char* hlp=0) | |
as above but makes this button the focus button. | ||
int | W.button(int w, int h, char* bm, string s, int n, const char* hlp=0) | |
adds a button with bitmap bm, label s, and number n to W. | ||
int | W.button(char* pr1, char* pr2, string s, int n, const char* hlp=0) | |
adds a button with pixrects pr1 and pr2, label s, and number n to W. | ||
int | W.button(int w, int h, char* bm, string s, const char* hlp=0) | |
adds a new button to W with bitmap bm, label s, and number equal to its position in the list of all buttons (starting with 0). | ||
int | W.button(string s, int n, void (*F)(int), const char* hlp=0) | |
adds a button with label s, number n and action function F to W. Function F is called with actual parameter n whenever the button is pressed. | ||
int | W.fbutton(string s, int n, void (*F)(int), const char* hlp=0) | |
as above but makes this button the focus button. | ||
int | W.button(int w, int h, char* bm, string s, int n, void (*F)(int), const char* hlp=0) | |
adds a button with bitmap bm, label s, number n and action function F to W. Function F is called with actual parameter n whenever the button is pressed. | ||
int | W.button(char* pr1, char* pr2, string s, int n, void (*F)(int), const char* hlp=0) | |
as above, but with pixrect pr1 and pr2. | ||
int | W.button(string s, void (*F)(int), const char* hlp=0) | |
adds a button with label s, number equal to its rank and action function F to W. Function F is called with the value of the button as argument whenever the button is pressed. | ||
int | W.button(int w, int h, char* bm, string s, void (*F)(int), const char* hlp=0) | |
adds a button with bitmap bm, label s, number equal to its rank and action function F to W. Function F is called with the value of the button as argument whenever the button is pressed. | ||
int | W.button(char* pr1, char* pr2, string s, void (*F)(int), const char* hlp=0) | |
as above, but with pixrect pr1 and pr2. | ||
int | W.button(string s, int n, window& M, const char* hlp=0) | |
adds a button with label s, number n and attached sub-window (menu) M to W. Window M is opened whenever the button is pressed. | ||
int | W.button(int w, int h, char* bm, string s, int n, window& M, const char* hlp=0) | |
adds a button with bitmap bm, label s, number n and attached sub-window (menu) M to W. Window M is opened whenever the button is pressed. | ||
int | W.button(char* pr1, char* pr2, string s, int n, window& M, const char* hlp=0) | |
as above, but with pixrect pr1 and pr2. | ||
int | W.button(string s, window& M, const char* hlp=0) | |
adds a button with label s and attached sub-window M to W. The number returned by readmouse is the number of the button selected in sub-window M. | ||
int | W.button(int w, int h, char* bm, string s, window& M, const char* hlp=0) | |
adds a button with bitmap bm, label s and attached sub-window M to W. The number returned by readmouse is the number of the button selected in sub-window M. | ||
int | W.button(char* pr1, char* pr2, string s, window& M, const char* hlp=0) | |
as above, but with pixrect pr1 and pr2. | ||
void | W.make_menu_bar() | inserts a menu bar at the top of the panel section that contains all previously added menu buttons (buttons with an attached subwindow). |
window* | window::get_call_window() | A static function that can be called in action functions attached to panel items or buttons to retrieve a pointer to the window containing the corresponding item or button. |
panel_item | window::get_call_item() | A static function that can be called in action functions attached to panel items to retrieve the corresponding item. |
int | window::get_call_button() | A static function that can be called in action functions attached to panel buttons to retrieve the number of the corresponding button. |
3.9.8. Manipulating Panel Items and Buttons
Disabling and Enabling Items or buttons
void | W.disable_item(panel_item it) | |
disables panel item it. | ||
void | W.enable_item(panel_item it) | |
enables panel item it. | ||
bool | W.is_enabled(panel_item it) | |
tests whether item it is enabled or not. | ||
void | W.disable_button(int b) | disables button b. |
void | W.enable_button(int b) | enables button b. |
bool | W.is_enabled(int b) | tests whether button b is enabled or not. |
void | W.disable_panel() | disables the entire panel section of W. |
void | W.enable_panel() | enables the entire panel section of W. |
Accessing and Updating Item Data
void | W.set_text(panel_item it, string s) | |
replaces the text of text item it by s. | ||
panel_item | W.get_item(string s) | returns the item with label s and NULL if no such item exists in W. |
int | W.get_button(string s) | returns the button with label s and -1 if no such button exists in W. |
string | W.get_button_label(int but) | |
returns the label of button but. | ||
void | W.set_button_label(int but, string s) | |
sets the label of button but to s. | ||
window* | W.get_window(int but) | returns a pointer to the subwindow attached to button but (NULL if but has no subwindow) |
window* | W.set_window(int but, window* M) | |
associates subwindow (menu) *M with button but. Returns a pointer to the window previously attached to but. | ||
void | W.set_function(int but, void (*F)(int)) | |
assign action function F to button but. | ||
void | W.redraw_panel() | redraw the panel area of W. |
void | W.redraw_panel(panel_item it) | |
redraw item i in the panel area of W. | ||
void | W.display_help_text(string fname) | |
displays the help text contained in name.hlp. The file name.hlp must exist either in the current working directory or in $LEDAROOT/incl/Help. |
Example
Example programs can be found on LEDAROOT/demo/win and LEDAROOT/test/win.