VDF常见问题整理(四十一):如何突出显示vdInsert?
VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。
VectorDraw Developer Framework试用版下载
问:
如果想要实现当将鼠标悬停在一些元素上时,它们突出显示,或者是能够在内部绘制阴影线。这能够实现吗?当然,也有可能不可能实现,因为这是vdInsert而不是像rect这样的标准形状。
答:
突出显示Insert对象是无法实现的,但是我们可以以块的边界框的大小创建一个新的矩形,而不是突出显示该矩形。
下面是一个使用AddBlockFromFile(ccc.vds)方法加载vds文件并创建一个新块(aaa)的示例,之后我们调用vdmousemove和vdmouseout方法,当光标在包含该块的矩形上方时,需要依次调用该vdmousemove和vdmouseout方法,然后将该矩形突出显示。当光标移出该矩形区域之外时,使用vdmouseout方法 将不再突出显示。
以下是操作演示图:
以下是操作代码:
var lastSelectedEntity = null;//Keep the entity in a variable function _vdmousemove(e) { if (vdcanvas.ActiveAction().IsStarted()) return;// We check tha action in case another action has been started var entity = e.target.GetEntityFromPoint(e.xPix, e.yPix);// Found the entity above the cursor if (entity == lastSelectedEntity) return; lastSelectedEntity = entity; if (entity != null && entity._t == vdConst.vdInsert_code && entity.BlockRef && entity.BlockRef.Name == "aaa") {//if the entity is the block that we want var minpt = [entity.BoundingBox[0], entity.BoundingBox[1], entity.BoundingBox[2]];//The lowest left corner of the boundingBox var maxpt = [entity.BoundingBox[3], entity.BoundingBox[4], entity.BoundingBox[5]]; //The upper right corner of the boundingBox var rect = vdcanvas.AddRect(minpt, maxpt, false, {});//We draw a rectangle in the size of the bounding box of the block //rect.HatchProperties = vdcanvas.createNewHatchProperties("solid", vdConst.colorFromString("byblock"), vdConst.colorFromString("255,0,0,50")); rect.HatchProperties = vdcanvas.createNewHatchProperties("u20", vdConst.colorFromString("255,255,255,50"), vdConst.colorFromString("255,255,255,255"), 1, vdgeo.DegreesToRadians(45));//We add hatch properties to the rect vdcanvas.Refresh(); vdcanvas.ActionDrawEntities([rect]);//We draw the rect } else { vdcanvas.ActionDrawEntities(null); } } function _vdmouseout(e) {//Incase cursor is out of the canvas if (!lastSelectedEntity) return; lastSelectedEntity = null; vdcanvas.ActionDrawEntities(null); } function test() { var blk = vdcanvas.AddBlockFromFile("ccc.vds", "aaa", true);//We load the block from ccc.vds vdcanvas.AddBlockSymbol("aaa", [0, 0, 0], 1, 0, true, null);//We draw the block vdcanvas.zoomExtents(); vdcanvas.redraw(); vdcanvas.vdmousemove = _vdmousemove; vdcanvas.vdmouseout = _vdmouseout;//Incase cursor is out of the canvas }
对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。
热门文章推荐:
如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系咨询相关问题。
关注慧聚IT微信公众号 ???,了解产品的最新动态及最新资讯。