Add fabric.Object#selectable Boolean property (true by default), which can be used to control object selection.

This commit is contained in:
kangax 2011-05-11 15:56:49 -04:00
parent 7041b64ad6
commit 79e37bbf30
5 changed files with 31 additions and 9 deletions

14
dist/all.js vendored
View file

@ -4873,10 +4873,13 @@ fabric.util.animate = animate;
if (currentObject.intersectsWithRect(selectionX1Y1, selectionX2Y2) ||
currentObject.isContainedWithinRect(selectionX1Y1, selectionX2Y2)) {
currentObject.setActive(true);
group.push(currentObject);
if (currentObject.selectable) {
currentObject.setActive(true);
group.push(currentObject);
}
}
}
if (group.length === 1) {
this.setActiveObject(group[0]);
fireEvent('object:selected', {
@ -4889,6 +4892,7 @@ fabric.util.animate = animate;
group.saveCoords();
fireEvent('group:selected', { target: group });
}
this.renderAll();
},
@ -5107,6 +5111,7 @@ fabric.util.animate = animate;
* @param {Boolean} skipGroup when true, group is skipped and only objects are traversed through
*/
findTarget: function (e, skipGroup) {
var target,
pointer = this.getPointer(e);
@ -5124,7 +5129,9 @@ fabric.util.animate = animate;
break;
}
}
return target;
if (target && target.selectable) {
return target;
}
},
/**
@ -6233,6 +6240,7 @@ fabric.util.animate = animate;
borderOpacityWhenMoving: 0.4,
borderScaleFactor: 1,
transformMatrix: null,
selectable: true,
/**
* @method callSuper

View file

@ -1,6 +1,6 @@
/*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */
var fabric = fabric || { version: "0.2.2" };
var fabric = fabric || { version: "0.2.3" };
/**
* Wrapper around `console.log` (when available)

View file

@ -1077,11 +1077,14 @@
if (currentObject.intersectsWithRect(selectionX1Y1, selectionX2Y2) ||
currentObject.isContainedWithinRect(selectionX1Y1, selectionX2Y2)) {
currentObject.setActive(true);
group.push(currentObject);
if (currentObject.selectable) {
currentObject.setActive(true);
group.push(currentObject);
}
}
}
// do not create group for 1 element only
if (group.length === 1) {
this.setActiveObject(group[0]);
@ -1095,6 +1098,7 @@
group.saveCoords();
fireEvent('group:selected', { target: group });
}
this.renderAll();
},
@ -1322,6 +1326,7 @@
* @param {Boolean} skipGroup when true, group is skipped and only objects are traversed through
*/
findTarget: function (e, skipGroup) {
var target,
pointer = this.getPointer(e);
@ -1341,7 +1346,9 @@
break;
}
}
return target;
if (target && target.selectable) {
return target;
}
},
/**

View file

@ -91,6 +91,13 @@
borderScaleFactor: 1,
transformMatrix: null,
/**
* When set to `false`, an object can not be selected for modification (using either point-click-based or group-based selection)
* @property
* @type Boolean
*/
selectable: true,
/**
* @method callSuper
* @param {String} methodName

View file

@ -10,7 +10,7 @@
<script src="../../lib/excanvas.js" type="text/javascript"></script>
<![endif]-->
<script src="../../dist/all.min.js" type="text/javascript"></script>
<script src="../../dist/all.js" type="text/javascript"></script>
<script src="../fonts/Delicious_500.font.js"></script>
<link rel="stylesheet" href="demo.css" type="text/css">