我已经开发了几个带有 GUI 的应用程序来做这种事情。
我最满意的是 VASE:一种用于创建布局、设置参数和查看流程模拟器结果的 GUI。
这不是一项微不足道的任务,虽然一旦你完成了一两个,有很多想法可以重复使用,而且进展很快。
两个最大的挑战是绘制连接对象的线(如您所见,即使在 VASE 中,这个问题也没有完全解决),以及以易于恢复和重绘的格式存储该布局。
您有什么特殊问题需要帮助吗?
如果您想要一个非常非常简单的示例来帮助您入门,我已经重新实现了一些基本功能(一切都很好,干净,没有版权限制) - 左键单击选择,拖动移动,右键单击连接。
这里是源代码库 - http://66.199.140.183/cgi-bin/vase.cgi/home
这就是它的样子
我已经实现了一个简化的连接器,我称之为管道。为了让您了解如何做这些事情,这里是当用户右键单击时添加管道的代码
/**
User has right clicked
If he right clicks on a flower
and there is a different flower selected
then connect the selected flower to the right clicked flower
if he right clicks on empty background
create a new flower
*/
void cVase::MouseRightDown( wxMouseEvent& event )
{
// find flower under click
iterator iter_flower_clicked = find( event.GetPosition() );
// check there was a flower under click
if( iter_flower_clicked != end() ) {
// check that we have a selected flower
if( ! mySelected )
return;
// check that selected flower is different from one clicked
if( mySelected == (*iter_flower_clicked) )
return;
// construct pipe from selected flower to clicked flower
myPipe.push_back(cPipe( mySelected, *iter_flower_clicked ));
} else {
// no flower under click
// make one appear!
cFlower * pflower = Add();
pflower->setLocation( event.GetPosition() );
}
// redraw everything
Refresh();
}
这是绘制管道的代码
/**
Draw the pipe
From starting flower's exit port to ending flower's entry port
*/
void cPipe::Paint( wxPaintDC& dc )
{
dc.SetPen( *wxBLUE_PEN );
dc.DrawLine( myStart->getExitPort(), myEnd->getEntryPort() );
}
您可以通过浏览源代码库来查看将所有这些联系在一起的 wxWidgets 代码的其余部分。