Drawing Rectangles and Polygons


Google

The draw_rectangle() method draws rectangles and squares. The second argument determines whether the rectangle is filled. Give a non-zero value to have the rectangle filled. The third and fourth arguments specify the x and y coordiates of the upper-left corner of the rectangle, respectively. The last two arguments specify the width and height (in pixels) of the rectangle.

Because of the way X handles drawing, an outline rectangle is one pixel taller and wider than a filled rectangle. If you want a rectangle with an outline of one color and a fill of another color, you need to draw the filled rectangle first. Otherwise the filled rectangle will obscure the top and left edges of the outline rectangle. You may need to subtract one pixel from the width and height of the outline rectangle to get the size you expect.

The draw_polygon() method can take either a Gdk::Points or a pointer to an array of Gdk::Point and an int holding the number of points in the array. The first argument is the Gdk::GC and the second argument determines if the polygon is a filled one or an outline, just like for the draw_rectangle(). The polygon's shape is taken by drawing a line from the first point to the second, and so on to the last point in the list, and from there a line is drawn back to the first point. This of course implies that you do not need to repeat the first point as the last point.