我正在实时绘图应用程序上工作,在该应用程序上将在屏幕上绘制数据流。以前使用gtkmm2时,我是使用自定义窗口小部件(源自Gtk::Bin
)完成此操作的,在该窗口小部件中,我具有一个成员函数,该函数创建cairo上下文并进行绘图。
现在带有gtkmm3除了on_draw
之外,我无法以其他任何方法进行绘制。这是我的自定义绘制方法主体的外观]
Gtk::Allocation oAllocation = get_allocation();
Glib::RefPtr <Gdk::Window> refWindow = get_window();
Cairo::RefPtr <Cairo::Context> refContext =
refWindow->create_cairo_context();
refWindow->begin_paint_rect(oAllocation); //added later
refContext->save();
refContext->reset_clip();
refContext->set_source_rgba(1,
1,
1,
1);
refContext->move_to(oAllocation.get_x(),
oAllocation.get_y());
refContext->line_to(oAllocation.get_x()
+ oAllocation.get_width(),
oAllocation.get_y()
+ oAllocation.get_height());
refContext->stroke();
refContext->restore();
refWindow->end_paint();
[最初,我从Gtk::DrawingArea
派生了该类,然后在添加Gtk::Bin
调用时尝试了begin_paint_rect
。
是否禁止在on_draw
以外的任何地方绘图?
除了on_draw以外,是否禁止在其他任何地方绘画?
基本上:是。
这个想法是,当您想进行重绘时,您呼叫gtk_widget_queue_draw()
或gtk_widget_queue_draw_area()
。