VDF常见问题整理(三十九):如何提示用户插入和旋转实体数组?

VectorDraw Developer Framework试用版下载


问:

    在使用VDF的过程中,怎样才能提示用户插入和旋转实体数组否存在什么代码来实现此操作/p>

答:

    这是一个示例,提示用户设置矩形的宽度和高度以及行和列的数量以及它们之间的边距。当用户设置所有这些并单击按钮时,阵列将被淹没,用户可以根据需要放置并旋转它。

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 rotationvar oldcolor = vdcanvas.SetActionLineColor([0, 0, 0, 0]);                   //empty the existing selection of scriptCommandvdcanvas.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 objectsvar origin = [1000000, 1000000, 0];                   //additional space between items in arrayvar marginPercent = 0.1;                   //calculate the column and row distancesvar 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 groupif (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       }

    对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。

热门文章推荐:

  • 如何排除GroundSurface对象的三角形区域/strong>

  • 复杂自定义对象的入门指南


    如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系在线客服>>咨询相关问题。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年10月18日
下一篇 2019年10月18日

相关推荐

发表回复

登录后才能评论