VDF常見問題整理(四十一):如何突出顯示vdInsert?
VectorDraw Developer Framework(VDF)是一個用于應用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如果想要實現(xiàn)當將鼠標懸停在一些元素上時,它們突出顯示,或者是能夠在內(nèi)部繪制陰影線。這能夠?qū)崿F(xiàn)嗎?當然,也有可能不可能實現(xiàn),因為這是vdInsert而不是像rect這樣的標準形狀。
答:
突出顯示Insert對象是無法實現(xiàn)的,但是我們可以以塊的邊界框的大小創(chuàng)建一個新的矩形,而不是突出顯示該矩形。
下面是一個使用AddBlockFromFile(ccc.vds)方法加載vds文件并創(chuàng)建一個新塊(aaa)的示例,之后我們調(diào)用vdmousemove和vdmouseout方法,當光標在包含該塊的矩形上方時,需要依次調(diào)用該vdmousemove和vdmouseout方法,然后將該矩形突出顯示。當光標移出該矩形區(qū)域之外時,使用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 }
對于以上問答,如果您有任何的疑惑都可以在評論區(qū)留言,我們會及時回復。此系列的問答教程我們會持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門文章推薦:
如果您對想要購買正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關(guān)問題。
關(guān)注慧聚IT微信公眾號 ???,了解產(chǎn)品的最新動態(tài)及最新資訊。