Reference Manual
Inti Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Inti::Gtk::DrawingArea Class Reference

A GtkDrawingArea C++ wrapper class. More...

#include <inti/gtk/drawingarea.h>

Inheritance diagram for Inti::Gtk::DrawingArea:

Inti::Gtk::Widget Inti::Gtk::Object Inti::Atk::Implementor Inti::G::Object Inti::G::TypeInterface Inti::G::TypeInstance Inti::MemoryHandler Inti::G::TypeInstance Inti::ReferencedBase Inti::ReferencedBase Inti::Gtk::Curve List of all members.

Public Member Functions

Constructors
Accessors

Protected Member Functions

Constructors

Detailed Description

A GtkDrawingArea C++ wrapper class.

The DrawingArea widget is used for creating custom user interface elements. It's essentially a blank widget you can draw on. After creating a drawing area, the application may want to connect to mouse and button press signals to respond to input from the user. Use Gtk::Widget::add_events() to enable events you wish to receive. Connect to the "realize" signal to take any necessary actions when the widget is instantiated on a particular display. (Create GDK resources in response to this signal.) Connect to the "configure_event" signal to take any necessary actions when the widget changes size. Connect to the "expose_event" signal to handle redrawing the contents of the widget.

The following code portion demonstrates using a drawing area to display a circle in the normal widget foreground color. Note that GDK automatically clears the exposed area to the background color before sending the expose event, and that drawing is implicitly clipped to the exposed area.

Example: Simple DrawingArea usage.

    #include <inti/main.h>
    #include <inti/gtk/drawingarea.h>
    #include <inti/gtk/style.h>
    #include <inti/gtk/window.h>
    #include <inti/gdk/window.h>
   
    using namespace Inti;
   
    class Window : public Gtk::Window
    {
        Gtk::DrawingArea *area;
    protected:
        bool on_area_expose_event(GdkEventExpose *event);
    public:
        Window();
    };
   
    Window::Window()
    {
        area = new Gtk::DrawingArea(100, 100);
        area->sig_expose_event().connect(slot(this, &Window::on_area_expose_event));
        add(*area);
        area->show();
    }
   
    bool
    Window::on_area_expose_event(GdkEventExpose *event)
    {
        area->get_window()->draw_arc(*area->get_style()->fg_gc(area->get_state()), // context
                                     0, 0, // x, y,
                                     area->get_allocation().width, // width
                                     area->get_allocation().height, // height
                                     0, 64 * 360); // angle1, angle2
        return true;
    }
   
    int main (int argc, char *argv[])
    {
        using namespace Main;
   
        init(&argc, &argv);
   
        Window window;
        window.sig_destroy().connect(slot(&Inti::Main::quit));
        window->show();
   
        run();
        return 0;
    }

Expose events are normally delivered when a drawing area first comes onscreen, or when it's covered by another window and then uncovered (exposed). You can also force an expose event by adding to the "damage region" of the drawing area's window; Gtk::Widget::queue_draw_area() and Gdk::Window::invalidate_rect() are equally good ways to do this. You'll then get an expose event for the invalid region. (See also Gdk::Pixbuf::render_to_drawable() for drawing a Gdk::Pixbuf.)

To receive mouse events on a drawing area, you will need to enable them with Gtk::Widget::add_events(). To receive keyboard events, you will need to set the CAN_FOCUS flag on the drawing area, and should probably draw some user-visible indication that the drawing area is focused. Use Gtk::Widget::has_focus() in your expose event handler to decide whether to draw the focus indicator. (See Gtk::Style::draw_focus() for one way to draw the focus.)


Constructor & Destructor Documentation

Inti::Gtk::DrawingArea::DrawingArea GtkDrawingArea *  drawing_area,
bool  reference = false
[explicit, protected]
 

Construct a new DrawingArea from an existing GtkDrawingArea.

Parameters:
drawing_area A pointer to a GtkDrawingArea.
reference Set false if the initial reference count is floating, set true if it's not.

The drawing_area can be a newly created GtkDrawingArea or an existing GtkDrawingArea (see G::Object::Object).

Inti::Gtk::DrawingArea::DrawingArea int  width,
int  height
 

Construct a new DrawingArea with the specified width and height.

Parameters:
width The width to request.
height The height to request.


The documentation for this class was generated from the following file: Main Page - Footer


Generated on Sun Sep 14 20:08:14 2003 for Inti by doxygen 1.3.2 written by Dimitri van Heesch, © 1997-2002