我想在绘图区域中绘制多个实体。每次调用 queue_draw 函数时都会绘制背景。
bool DrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
cr->set_source_rgb(1.0, 1.0, 1.0); // white background
cr->paint();
cr->set_line_width(2.0);
if(entity == 1) // draw point
{
cr->set_source_rgb(0.0, 0.26, 0.26);
cr->save();
cr->arc(205.0, 110.0, 1.0, 0.0, 2 * M_PI); // full circle
cr->restore();
cr->stroke();
}
if(entity == 2) // draw line
{
cr->set_source_rgb(0.0, 0.26, 0.26);
cr->save();
cr->move_to(0,0);
cr->line_to(100,100);
cr->restore();
cr->stroke();
}
return true;
}
当调用以下代码中的 queue_draw 函数时,上述代码有效:
void DrawingArea :: on_point_cb()
{
entity = 1;
queue_draw();
std::cout<<"Point created"<<std::endl;
}
When a new entity is selected to be drawn, the previous one gets erased. 应该怎么做才能使先前绘制的实体持续存在?