From 6f6ae9dd4b3aca1295b4ea781cbadc7c53c96250 Mon Sep 17 00:00:00 2001 From: kekee000 Date: Tue, 23 Sep 2014 21:12:30 +0800 Subject: [PATCH] add point size --- src/editor/group/updateControls.js | 9 ++++++++- src/render/shape/CirclePoint.js | 18 ++++++++++-------- src/render/shape/Point.js | 19 +++++++++++-------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/editor/group/updateControls.js b/src/editor/group/updateControls.js index a151b83..743142f 100644 --- a/src/editor/group/updateControls.js +++ b/src/editor/group/updateControls.js @@ -61,7 +61,14 @@ define( points.forEach(function(p, i) { lang.extend(controls[i], p); if (i > 0) { - controls[i].type = mode == 'rotate' && i <= 4 ? 'cpoint' : 'point'; + if (mode == 'rotate' && i <= 4) { + controls[i].type = 'cpoint'; + controls[i].size = 3; + } + else { + controls[i].type = 'point'; + controls[i].size = 6; + } } }); diff --git a/src/render/shape/CirclePoint.js b/src/render/shape/CirclePoint.js index acdd40c..ab4aecb 100644 --- a/src/render/shape/CirclePoint.js +++ b/src/render/shape/CirclePoint.js @@ -23,11 +23,12 @@ define( * @param {Object} 矩形区域 */ getRect: function(shape) { + var size = shape.size || POINT_SIZE; return { - x: shape.x - POINT_SIZE, - y: shape.y - POINT_SIZE, - width: 2 * POINT_SIZE, - height: 2 * POINT_SIZE + x: shape.x - size, + y: shape.y - size, + width: 2 * size, + height: 2 * size }; }, @@ -40,7 +41,8 @@ define( * @param {boolean} 是否 */ isIn: function(shape, x, y) { - return Math.pow(shape.x - x, 2) + Math.pow(shape.y - y, 2) <= Math.pow(POINT_SIZE * 2, 2); + var size = shape.size || POINT_SIZE; + return Math.pow(shape.x - x, 2) + Math.pow(shape.y - y, 2) <= Math.pow(size * 2, 2); }, /** @@ -50,12 +52,12 @@ define( * @param {Object} shape shape数据 */ draw: function(ctx, shape) { - + var size = shape.size || POINT_SIZE; var x = Math.round(shape.x); var y = Math.round(shape.y); - ctx.moveTo(x + POINT_SIZE, y); - ctx.arc(x, y, POINT_SIZE, 0, Math.PI * 2, true); + ctx.moveTo(x + size, y); + ctx.arc(x, y, size, 0, Math.PI * 2, true); } }; diff --git a/src/render/shape/Point.js b/src/render/shape/Point.js index 20520a7..55c2078 100644 --- a/src/render/shape/Point.js +++ b/src/render/shape/Point.js @@ -23,11 +23,12 @@ define( * @param {Object} 矩形区域 */ getRect: function(shape) { + var size = shape.size || POINT_SIZE; return { - x: shape.x - POINT_SIZE / 2 , - y: shape.y - POINT_SIZE / 2, - width: POINT_SIZE, - height: POINT_SIZE + x: shape.x - size / 2 , + y: shape.y - size / 2, + width: size, + height: size }; }, @@ -40,8 +41,9 @@ define( * @param {boolean} 是否 */ isIn: function(shape, x, y) { - var w = POINT_SIZE; - var h = POINT_SIZE; + var size = shape.size || POINT_SIZE; + var w = size; + var h = size; return x <= shape.x + w && x >= shape.x - w && y <= shape.y + h @@ -58,8 +60,9 @@ define( var x = Math.round(shape.x); var y = Math.round(shape.y); - var w = POINT_SIZE / 2; - var h = POINT_SIZE / 2; + var size = shape.size || POINT_SIZE; + var w = size / 2; + var h = size / 2; ctx.moveTo(x - w, y - h); ctx.lineTo(x + w, y - h); ctx.lineTo(x + w, y + h);