DrawingArea-komponenten

The DrawingArea widget is a blank window that gives you the freedom to create any graphic you desire. Along with that freedom comes the responsibility to draw on the widget. When a widget is first shown, or when it is covered and then uncovered again it needs to redraw itself. Most widgets have code to do this, but the DrawingArea does not, allowing you to write your own draw function to determine how the contents of the widget will be drawn. This is done by setting a draw function with a call to the set_draw_func() member function.

GTK använder Cairos rit-API. Med gtkmm kan du använda C++-API:t cairomm för cairo.

You can draw very sophisticated shapes using Cairo, but the methods to do so are quite basic. Cairo provides methods for drawing straight lines, curved lines, and arcs (including circles). These basic shapes can be combined to create more complex shapes and paths which can be filled with solid colors, gradients, patterns, and other things. In addition, Cairo can perform complex transformations, do compositing of images, and render antialiased text.

Cairo och Pango

Även om Cairo kan rendera text så är det inte tänkt som en ersättning för Pango. Pango är ett bättre val om du behöver utföra mer avancerad textrendering som att radbryta eller elliptisera text. Att rita text med Cairo bör bara göras om texten är del av en grafik.

In this section of the tutorial, we'll cover the basic Cairo drawing model, describe each of the basic drawing elements in some detail (with examples), and then present a simple application that uses Cairo to draw a custom clock widget.