add point size

This commit is contained in:
kekee000
2014-09-23 21:12:30 +08:00
parent 336a49919f
commit 6f6ae9dd4b
3 changed files with 29 additions and 17 deletions

View File

@@ -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;
}
}
});

View File

@@ -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);
}
};

View File

@@ -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);