Greetings, <br><br>Maybe a silly question but I still wonder why. Can it possible for Cairo::Context to be referred outside on_expose_event? I just want to preserve some configurations of the context, like line width and dash pattern, instead of always call set_line_width() inside on_expose_event, which I think is inefficient.<br>
<br>I tried to add a Cairo::RefPtr<Cairo::Context> member in my class and implement it like this<br><br>////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
class MyDrawingArea : public Gtk::DrawingArea<br>{<br>// bla bla bla<br>public:<br> Cairo::RefPtr<Cairo::Context> ctx_;<br>};<br><br>MyDrawingArea::MyDrawingArea()<br>{<br> Glib::RefPtr<Gdk::Window> window = get_window();<br>
if (window)<br> {<br> ctx_ = window->create_cairo_context();<br> // set basic graphical style for ctx_<br> }<br>}<br><br>bool MyDrawingArea::on_expose_event(GdkEventExpose* event)<br>
{<br> // Call cairo drawing primitives via ctx_<br> ctx_->XXX<br> return true;<br>}<br>/////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
<br>Unfortunately, the execution always crashes because get_window() in the constructor returns NULL. I have no idea at why this goes wrong. Could any one give me some explanations or solutions, thanks in advance.<br><br>
========<br>CHEN Kai<br>