Drawing Lines

Example

Drawing lines is more interesting than just points, so here is a complete program:

Figure 14.1. Drawing Area - Lines

Drawing Area - Lines

Source Code

This program contains two classes. The first is a subclass of Gtk::DrawingArea and contains an on_expose_event member function. This method is called whenever the image in the drawing area needs to be redrawn. The four additional arguments to draw_line() (besides the graphics context as the first) are the coordinates for the start and end of the line.

The TestWindow class contains a drawing area. When it is created, it creates a drawing area of 50 pixels across by 50 pixels tall. If the window is resized, the graphic drawn is kept in the top left corner of the larger window. The drawing area is created with a default grey background.