Using Cairo to draw on a Gtk::Window



Hi, I have been trying to use Cairo to draw on a Gtk::Window. I was
successful when I overrided on_draw(). But the only thing I saw was what I
drew everything else was black. What I did was

bool Window::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
        Gdk::Cairo::set_source_pixbuf(cr, m_image, 10, 10);
        cr->paint();

        return false;
}

On my second attempt I tried this:

Window::Window()
{
    auto cr = this->get_window()->create_cairo_context();
    cr->save();
    Gdk::Cairo::set_source_pixbuf(cr, m_image, 10, 10);
    cr->paint();
    cr->restore();
}

But this made the program crash. How can I draw on the Gtk::Window? Thank
You.



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