| GTK+ Reference Manual | |||
|---|---|---|---|
| <<< Previous Page | Home | Up | Next Page >>> | 
| #include <gtk/gtk.h> struct GtkDrawingArea; GtkWidget* gtk_drawing_area_new (void); void gtk_drawing_area_size (GtkDrawingArea *darea, gint width, gint height); | 
The GtkDrawingArea widget is used for creating custom user interface elements. After creating a drawing area, the application may want to connect to:
Mouse and button press signals to respond to input from the user.
The "realize" signal to take any necessary actions when the widget
The "size_allocate" signal to take any necessary actions when the widget changes size.
The "expose_event" signal to handle redrawing the contents of the widget.
The following code portion demonstrates using a drawing area to implement a widget that draws a circle. As this example demonstrates, an expose handler should draw only the pixels within the requested area and should draw or clear all these pixels.
| gboolean
expose_event (GdkWidget *widget, GdkEventExpose *event, gpointer data)
{
  gdk_window_clear_area (widget->window,
                         event->area.x, event->area.y,
                         event->area.width, event->area.height);
  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
                             &event->area);
  gdk_draw_arc (widget->window,
                widget->style->fg_gc[widget->state],
                TRUE,
                0, 0, widget->allocation.width, widget->allocation.height,
                0, 64 * 360);
  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
                             NULL);
  return TRUE;
}
[...]
  GtkWidget *drawing_area = gdk_drawing_area_new();
  gdk_drawing_area_size (GTK_DRAWING_AREA (drawing_area),
                         100, 100);
  gtk_signal_connect (GTK_OBJECT (drawing_area),  | 
| struct GtkDrawingArea; | 
The GtkDrawingArea struct contains private data only, and should be accessed using the functions below.
| void gtk_drawing_area_size (GtkDrawingArea *darea, gint width, gint height); | 
Set the size that the drawing area will request in response to a "size_request" signal. The drawing area may actually be allocated a size larger than this depending on how it is packed within the enclosing containers.
| darea : | a GtkDrawingArea. | 
| width : | the width to request. | 
| height : | the height to request. |