VDF常見(jiàn)問(wèn)題整理(三十九):如何提示用戶插入和旋轉(zhuǎn)實(shí)體數(shù)組?
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫(kù)。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問(wèn):
在使用VDF的過(guò)程中,怎樣才能提示用戶插入和旋轉(zhuǎn)實(shí)體數(shù)組?是否存在什么代碼來(lái)實(shí)現(xiàn)此操作?
答:
這是一個(gè)示例,提示用戶設(shè)置矩形的寬度和高度以及行和列的數(shù)量以及它們之間的邊距。當(dāng)用戶設(shè)置所有這些并單擊按鈕時(shí),陣列將被淹沒(méi),用戶可以根據(jù)需要放置并旋轉(zhuǎn)它。
function array(){ var rectwidth = Number(document.getElementById('width').value); var rectheight = Number(document.getElementById('height').value); var nrows = Number(document.getElementById('rows').value); var ncolums = Number(document.getElementById('colums').value); //set the action line color alha to 0 in order to ruber line to be invisible durring move and rotation var oldcolor = vdcanvas.SetActionLineColor([0, 0, 0, 0]); //empty the existing selection of scriptCommand vdcanvas.scriptCommand.clearSelection(); //begin an undo group to enclose all next commands vdcanvas.scriptCommand.undogroup('begin'); //initially set the origin of the drawing into a big value outside the screen in order the first created items to be invisible and display only the moved objects var origin = [1000000, 1000000, 0]; //additional space between items in array var marginPercent = 0.1; //calculate the column and row distances var colomndist = rectwidth * (1 + marginPercent); var rowdist = rectheight * (1 + marginPercent); //create the objects array in the initial origin for (var r = 0; r < nrows; r++) { for (var c = 0; c < ncolums; c++) { vdcanvas.scriptCommand.rect([[origin[0] + c * colomndist, origin[1] + r * rowdist, 0], rectwidth, rectheight, 0], actionentityadded); } } //add each created item to the scriptCommand selection function actionentityadded(vdraw, entity) { vdcanvas.scriptCommand.parseCommands(['select h_' + entity.HandleId.toString()]); setTimeout(vdcanvas.redraw); } //begin a user move command vdcanvas.scriptCommand.move(origin, null, _rotateCallback); //callback of the move finish that begins a rotate command function _rotateCallback() { if (!vdcanvas.ActiveAction().IsCanceled()) vdcanvas.scriptCommand.rotate(vdcanvas.ActiveAction().ResValue[1], null, _finishCallback); else _finishCallback(); } //finished callback function _finishCallback() { vdcanvas.SetActionLineColor(oldcolor);//restore the action line color vdcanvas.scriptCommand.undogroup('close');//close the undo group if (vdcanvas.ActiveAction().IsCanceled()) {//implement the user cancel (right-click or esc) vdcanvas.scriptCommand.undo();//undo all actions from the group begin setTimeout(vdcanvas.redraw);//post a redraw to refresh clear the screen from created items }//else not need to do anything }
對(duì)于以上問(wèn)答,如果您有任何的疑惑都可以在評(píng)論區(qū)留言,我們會(huì)及時(shí)回復(fù)。此系列的問(wèn)答教程我們會(huì)持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門文章推薦:
如果您對(duì)想要購(gòu)買正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關(guān)問(wèn)題。
關(guān)注慧聚IT微信公眾號(hào) ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。