How to maintain a reference to Cairo::Context or Cairo::Surface?
- From: "BC Zhu" <zhubicen gmail com>
- To: gtkmm-list gnome org
- Subject: How to maintain a reference to Cairo::Context or Cairo::Surface?
- Date: Wed, 3 Dec 2008 16:36:08 +0800
Now i am using Gtkmm. I want to maintain a reference to Cairo::Context or Cairo::Surface, so i can draw something on it anywhere.
I am trying to do this , but failed.
With following code , i am trying to keep a reference to Cairo:::Surface,but when on_expose_event was called secondly , it will fail.
And i have tried to maintain a reference to Cairo::Context too, but failed either.
Could some body give me an advice?
Thanks in advance!
class MyArea : public Gtk::DrawingArea
{
public:
virtual ~MyArea();
protected:
//Override default signal handler:
virtual bool on_expose_event(GdkEventExpose* event);
private:
Cairo::RefPtr<Cairo::Surface> surf_;
};
MyArea::MyArea()
{
}
MyArea::~MyArea()
{
}
bool MyArea::on_expose_event(GdkEventExpose* event)
{
// This is where we draw on the window
if(!surf_){
Glib::RefPtr<Gdk::Window> window = get_window();
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
surf_ = cr->get_target();
}
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surf_);
cr->set_line_width(10.0);
cr->move_to(0, 0);
cr->line_to(100, 100);
cr->stroke();
return true;
}
--
Best Regards
Bicen.Zhu
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]