Re: Using Cairo to draw on a Gtk::Window



On 11/01/16 10:56 PM, someone555 sigaint org wrote:
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;
}


I would use a Gtk::DrawingArea to draw in instead.

But since you saw what you draw, it is working. Maybe if you call the
superclass on_draw() first?

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.

I wouldn't expect in the constructor that the window be in the right
state to do that. You don't give the stack trace, but either
get_window() returns null of create_cairo_context() does. (and by NULL I
mean the raw pointer)


Hub


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