Diego A. Fons пишет:
[...][...]Still I don't understand why can't get a context and store it in a member variable. Then look here: this is Plot class definition: class Plot { public: Plot(Cairo::RefPtr<Cairo::Context>& context, Gdk::Rectangle& plotarea); ~Plot(); std::vector<Series*> series; ... private: Cairo::RefPtr<Cairo::Context> plot_context; Gdk::Color background_color, foreground_color; .... }; Plot constructor: Plot::Plot(Cairo::RefPtr<Cairo::Context>& context, Gdk::Rectangle& pltarea) { plotarea = pltarea; marginrect = Gdk::Rectangle(int(0.03*plotarea.get_width()), int(0.03*plotarea.get_height()), int(0.94*plotarea.get_width()), int(0.94*plotarea.get_height())); plotrect = marginrect; plot_context = context; background_color = Gdk::Color("white"); ... } Plot resizing: void Plot::resize(Cairo::RefPtr<Cairo::Context>& context, Gdk::Rectangle& pltarea) { // необходимые действия при изменении размера plot_context = context; plotarea = pltarea; plot_context->set_source_rgb(background_color.get_red(), background_color.get_green(), background_color.get_blue()); ... } And this is plot initialization from MainWindow: void Mainwindow::plot_init(void) { // начальная настройка графика plotarea_win = drawingarea->get_window(); ... win_context->set_source_rgb(color.get_red(), color.get_green(), color.get_blue()); //prepare a copy plotareaCopy = Gdk::Pixmap::create(plotarea_win, drawingarea->get_allocation().get_width(), drawingarea->get_allocation().get_height(), -1); gc = Gdk::GC::create(plotarea_win);//sorry... cairo = plotareaCopy->create_cairo_context(); int pwidth, pheight; plotareaCopy->get_size(pwidth, pheight); Gdk::Rectangle plot_area = Gdk::Rectangle(0, 0, pwidth, pheight); plot = new Plot(cairo, plot_area); .... drawingarea->signal_expose_event().connect( sigc::mem_fun(*this, &Mainwindow::on_drawingarea_expose_event)); } This is an expose event - sorry, but for the sake of speed I use here Gdk::GC approach for simple copying of area from a background copy: bool Mainwindow::on_drawingarea_expose_event(GdkEventExpose *event) { plotarea_win->draw_drawable(gc, plotareaCopy, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height); ... return true; } And here is resizing of a plot: bool Mainwindow::on_drawingarea_configure_event(GdkEventConfigure*) { // redefine demensions plotareaCopy = Gdk::Pixmap::create(plotarea_win, drawingarea->get_allocation().get_width(), drawingarea->get_allocation().get_height(), -1); if (plot) { cairo = plotareaCopy->create_cairo_context(); int pwidth, pheight; plotareaCopy->get_size(pwidth, pheight); Gdk::Rectangle plot_area = Gdk::Rectangle(0, 0, pwidth, pheight); plot->resize(cairo, plot_area); plot->drawplots(); } return true; } When I need printing I just call Plot::resize(Cairo::RefPt...) with the context and rectangle taken from Gtk::PrintContext. Hope it helps somewhat, Igor Gorbounov |
_______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list