首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PaperJS拖放圆圈

PaperJS拖放圆圈
EN

Stack Overflow用户
提问于 2013-06-02 03:05:58
回答 1查看 5K关注 0票数 1

如何对使用onMouseDrag绘制的圆应用拖放。Look at the fiddle

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-02 04:57:47

带有粗略的拖放演示的Here is a fiddle。通常,鼠标工具有两种模式:绘制和拖动。小提琴中的状态管理很弱,编写一个合适的鼠标工具需要更深入地了解paper.js。

代码语言:javascript
复制
<script type="text/paperscript" canvas="canvas">
        var path = null;
        var circles = [];

        // Mouse tool state
        var isDrawing = false;
        var draggingIndex = -1;

        function onMouseDrag(event) {

            // Maybe hit test to see if we are on top of a circle
            if (!isDrawing && circles.length > 0) {
                for (var ix = 0; ix < circles.length; ix++) {
                    if (circles[ix].contains(event.point)) {
                        draggingIndex = ix;
                        break;
                    }
                }
            }

            // Should we be dragging something?
            if (draggingIndex > -1) {
                circles[draggingIndex].position = event.point;
            } else {
                 // We are drawing
                    path = new Path.Circle({
                        center: event.downPoint,
                        radius: (event.downPoint - event.point).length,
                        fillColor: null,
                        strokeColor: 'black',
                        strokeWidth: 10
                    });

                  path.removeOnDrag();
                  isDrawing = true;
            }
        };

        function onMouseUp(event) {
            if (isDrawing) {
                circles.push(path);
            }

            // Reset the tool state
            isDrawing = false;
            draggingIndex = -1;
        };
</script>
<canvas id="canvas"></canvas>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16876253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档