【发布时间】:2019-12-18 06:29:42
【问题描述】:
我正在开发实时绘图应用程序,其中将在屏幕上绘制数据流。之前使用 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以外的地方禁止画画吗?
【问题讨论】: