same cairo graphics context in multiple methods



Let's say I have a class which extends DrawingArea, and in the class, I have
declared:

Cairo::RefPtr<Cairo::Context> gfx;

and in a method of the class (I do this in: on_expose_event), I instantiate
gfx:

gfx=this->get_window()->create_cairo_context();

Now, I want to use that specific graphics context in other methods (all
within the same scope as gfx). This doesn't seem to be a problem (i.e. the
context collects the data I give it) until I call gfx->stroke(); at which
point my program crashes, with this error:
glibmm-ERROR **: 
unhandled exception (type std::exception) in signal handler:
what: <unknown error status>

For example, the following method generates an error when it's run the
second time (the same method being run a second time might as well be a
different method - the result is the same, anyway):
bool Canvas::on_expose_event(GdkEventExpose * event)
{
	//get dimensions
	Gtk::Allocation allocation = get_allocation();
	
	int width = allocation.get_width();
	int height = allocation.get_height();
	
	if(!gfx) 
	{
	gfx = this->get_window()->create_cairo_context();
	std::cout<<"creating new graphics context\n";
	//white rectangle
	gfx->set_source_rgb(1.0, 1.0, 1.0);
	gfx->move_to(0.0,0.0);
	gfx->line_to(0.0, height);
	gfx->line_to(width, height);
	gfx->line_to(width, 0.0);
	gfx->close_path();
	gfx->fill_preserve();
	gfx->stroke();
	}
	gfx->stroke();
}

Is what I'm trying even possible or am I going to have to generate a new
graphics context and stroke() for every method?
-- 
View this message in context: http://www.nabble.com/same-cairo-graphics-context-in-multiple-methods-tp16087358p16087358.html
Sent from the Gtkmm mailing list archive at Nabble.com.



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