Cairo and gtkmm



Hi,

I am currently experimenting with using the new gdk Cairo integration
from within gtkmm (with CVS versions of gtk+, gtkmm and Cairo checked
out this weekend and compiled on a Gentoo Linux box). This is a simple
test program:

#include "gtkmm/main.h"
#include "gtkmm/window.h"
#include "gtkmm/drawingarea.h"

class CairoArea
: public Gtk::DrawingArea
{
    protected:
        virtual bool on_expose_event(GdkEventExpose* e)
        {
            Glib::RefPtr<Gdk::Window> window = get_window();
            GdkWindow* gdkWindow = window->gobj();
            GdkDrawable* gdkDrawable;
            gint xOffset;
            gint yOffset;
            gdk_window_get_internal_paint_info(gdkWindow,
                &gdkDrawable, &xOffset, &yOffset);
            cairo_t* cairo = gdk_cairo_create(gdkDrawable);
            if ((xOffset != 0) || (yOffset != 0))
            {
                cairo_save(cairo);
                cairo_translate(cairo, -xOffset, -yOffset);
            }
            Gtk::Allocation allocation = get_allocation();
            int width = allocation.get_width();
            int height = allocation.get_height();
            paint(cairo, width, height);
            if ((xOffset != 0) || (yOffset != 0))
                cairo_restore(cairo);
            cairo_destroy(cairo);
            return false;
        }

        virtual void paint(cairo_t* cairo, int width, int height)
        {
            cairo_set_source_rgb(cairo, 0.0, 0.0, 1.0);
            cairo_rectangle(cairo, 0.0, 0.0, width, height);
            cairo_fill(cairo);
        }

    public:
        CairoArea() { }
        virtual ~CairoArea() { }
};

class MainWindow
: public Gtk::Window
{
    protected:
        CairoArea* cairoArea;

    public:
        MainWindow()
        {
            set_default_size(400, 400);
            set_title("Test");
            set_position(Gtk::WIN_POS_CENTER);
            cairoArea = Gtk::manage(new CairoArea());
            add(*cairoArea);
            cairoArea->show();
        }

        virtual ~MainWindow() { }
};

int main(int argc, char* argv[])
{
    Gtk::Main gtkMain(argc, argv);
    MainWindow mainWindow;
    gtkMain.run(mainWindow);
    return 0;
}

It seems to basically work, meaning the window is filled with the solid
blue color and correctly redrawn if resized or maximized. However, if I
move another window over the area, parts of the window are not redrawn,
like this:

http://stuff.ionflux.de/screen9177.png

I would appreciate any hints on what might cause this problem.
tests/testcairo from gtk+ seems to work fine (redraws are somewhat slow,
but ultimately correct).

Cheers,

Jörn



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]