Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::Gtk::DrawingArea Class Reference

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

#include <xfc/gtk/drawingarea.hh>

Inheritance diagram for Xfc::Gtk::DrawingArea:

Xfc::Gtk::Widget Xfc::Gtk::Object Xfc::Atk::Implementor Xfc::G::Object Xfc::G::TypeInterface Xfc::G::TypeInstance Xfc::G::TypeInstance Xfc::Trackable Xfc::Trackable Xfc::Gtk::Curve List of all members.

Public Member Functions

Accessors

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 <xfc/main.hh>
 #include <xfc/gtk/drawingarea.hh>
 #include <xfc/gtk/style.hh>
 #include <xfc/gtk/window.hh>
 #include <xfc/gdk/window.hh>

 using namespace Xfc;

 class Window : public Gtk::Window
 {
        Gtk::DrawingArea *area;
 protected:
        bool on_area_expose_event(const Gdk::EventExpose& event);
 public:
        Window();
 };

 Window::Window()
 {
        area = new Gtk::DrawingArea(100, 100);
        area->signal_expose_event().connect(sigc::mem_fun(this, &Window::on_area_expose_event));
        add(*area);
        area->show();
 }

 bool
 Window::on_area_expose_event(const Gdk::EventExpose& event)
 {
        Gdk::Color color("blue");
        area->modify_fg(area->get_state(), &color);
        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.signal_destroy().connect(sigc::ptr_fun(&Xfc::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.)

See also: the DrawingArea Widget HOWTO and example.


Constructor & Destructor Documentation

Xfc::Gtk::DrawingArea::DrawingArea ( GtkDrawingArea *  drawing_area,
bool  owns_reference = false 
) [explicit, protected]

Construct a new DrawingArea from an existing GtkDrawingArea.

Parameters:
drawing_area A pointer to a GtkDrawingArea.
owns_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).

Xfc::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.

Xfc::Gtk::DrawingArea::DrawingArea ( GtkDrawingArea *  drawing_area,
bool  owns_reference = false 
) [explicit, protected]

Construct a new DrawingArea from an existing GtkDrawingArea.

Parameters:
drawing_area A pointer to a GtkDrawingArea.
owns_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).

Xfc::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: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3