redrawing drawingarea contents on refresh
- From: misho <misho88 gmail com>
- To: gtkmm-list gnome org
- Subject: redrawing drawingarea contents on refresh
- Date: Sat, 19 Apr 2008 22:29:39 -0700 (PDT)
Short version:
I have a Cairo::RefPtr<Cairo:: Surface> and I want to copy the object it
points to and have another Cairo::RefPtr<Cairo:: Surface> pointing to the
copy.
How can I do this?
Long version:
I'm trying to learn how to do some fairly basic programming with gtkmm. So,
I decided I should make a program that lets me draw a few squiggles and then
save them to a file. I figured that since gtk and cario were developed
largely for writing the GIMP, this should be easy, and for the most part, it
is.
The problem, as with pretty much all graphical programming, is that whatever
I've drawn disappears once the window is re-drawn, so I'm trying to figure
out how I can save that information.
This is the class I draw with:
class Canvas : public Gtk::DrawingArea
Then, in a method, I would create the graphics context as follows:
Cairo::RefPtr<Cairo::Context> gfx =
this->get_window()->create_cairo_context();
One thing I managed to find is that gfx->get_target() returns a pointer
(sort of) to a Cairo::Surface. This object contains a method for outputting
to a png file, and when using this, I find that it outputs a complete
picture with whatever is on the Canvas at that moment, regardless of which
function it was created from. Also, given a Cairo::Surface, I can draw its
contents within a Cairo::Context. The solution seemed fairly obvious:
1. on a mouse release event, grab gfx->get_target()
2. on an expose event, draw it over the entire Cairo::Context
Step 1. is a lot harder than I initially thought it would be.
gfx->get_target() returns a Cairo::RefPtr<Cairo::Surface> and I have no clue
how to deal with that.
So, I tried keeping a reference to the surface which is global to the class,
but that didn't work, presumably because the graphics context and its
associated target are destroyed before the next expose event.
Then, I figure I might try copying the object, and realized I have no idea
how that might work.
Any clues on how to do this, or, possibly, on an alternate way to redraw?
--
View this message in context: http://www.nabble.com/redrawing-drawingarea-contents-on-refresh-tp16790637p16790637.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]