标签:
wxGraphicsContext是wxWidgets高级绘图类。
wx的手册上有个如下的Demo:
void MyCanvas::OnPaint(wxPaintEvent &event) { // Create paint DC wxPaintDC dc(this); // Create graphics context from it wxGraphicsContext *gc = wxGraphicsContext::Create( dc ); if (gc) { // make a path that contains a circle and some lines gc->SetPen( *wxRED_PEN ); wxGraphicsPath path = gc->CreatePath(); path.AddCircle( 50.0, 50.0, 50.0 ); path.MoveToPoint(0.0, 50.0); path.AddLineToPoint(100.0, 50.0); path.MoveToPoint(50.0, 0.0); path.AddLineToPoint(50.0, 100.0 ); path.CloseSubpath(); path.AddRectangle(25.0, 25.0, 50.0, 50.0); gc->StrokePath(path); delete gc; } }
我一般在windows使用wx,可事实上,这段代码没效果。
所以我就去看了一下sample(Drawer)
精简了一下,使用方法如下:
wxGCDC gdc; wxGraphicsRenderer* const renderer = wxGraphicsRenderer::GetDefaultRenderer(); wxGraphicsContext* gc; if ( wxPaintDC *paintdc = wxDynamicCast(&dc, wxPaintDC) ) { gc = renderer->CreateContext(*paintdc); } else if ( wxMemoryDC *memdc = wxDynamicCast(&dc, wxMemoryDC) ) { gc = renderer->CreateContext(*memdc); } if (gc) { gc->SetPen( *wxRED_PEN ); wxGraphicsPath path = gc->CreatePath(); //操作path ... //stroke是显示路径 gc->StrokePath(path); //另外fillPath是填充路径,closePath是连接首尾点,会多一条线出来 }
wxGraphicsContext,wxGraphicsPath怎么使用
标签:
原文地址:http://my.oschina.net/u/264056/blog/384955