mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Implement SelectionState.js: bitwise flags for segment selection state.
This commit is contained in:
parent
7867a46c35
commit
d831d66758
5 changed files with 42 additions and 16 deletions
|
@ -44,6 +44,7 @@ var sources = [
|
|||
|
||||
'src/path/Segment.js',
|
||||
'src/path/SegmentPoint.js',
|
||||
'src/path/SelectionState.js',
|
||||
'src/path/Curve.js',
|
||||
'src/path/CurveLocation.js',
|
||||
'src/path/PathItem.js',
|
||||
|
|
|
@ -92,6 +92,7 @@ Base.inject({
|
|||
|
||||
//#include "path/Segment.js"
|
||||
//#include "path/SegmentPoint.js"
|
||||
//#include "path/SelectionState.js"
|
||||
//#include "path/Curve.js"
|
||||
//#include "path/CurveLocation.js"
|
||||
//#include "path/PathItem.js"
|
||||
|
|
|
@ -149,7 +149,8 @@ var Path = this.Path = PathItem.extend({
|
|||
}
|
||||
this._selectedSegmentCount = selected ? length : 0;
|
||||
for (var i = 0; i < length; i++)
|
||||
this._segments[i]._selectionState = selected ? 'point' : null;
|
||||
this._segments[i]._selectionState = selected
|
||||
? SelectionState.POINT : null;
|
||||
},
|
||||
|
||||
isFullySelected: function() {
|
||||
|
@ -287,7 +288,7 @@ var Path = this.Path = PathItem.extend({
|
|||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
var segment = segments[i],
|
||||
point = segment._point,
|
||||
pointSelected = segment._selectionState == 'point';
|
||||
pointSelected = segment._selectionState == SelectionState.POINT;
|
||||
// TODO: draw handles depending on selection state of
|
||||
// segment.point and neighbouring segments.
|
||||
if (pointSelected || segment.getSelected(segment._handleIn))
|
||||
|
|
|
@ -129,11 +129,13 @@ var Segment = this.Segment = Base.extend({
|
|||
var point = arguments.length ? arguments[0] : this.point;
|
||||
var state = this._selectionState;
|
||||
if (point == this.point) {
|
||||
return state == 'point';
|
||||
return state == SelectionState.POINT;
|
||||
} else if (point == this.handleIn) {
|
||||
return state == 'handle-in' || state == 'handle-both';
|
||||
return (state & SelectionState.HANDLE_IN)
|
||||
== SelectionState.HANDLE_IN;
|
||||
} else if (point == this.handleOut) {
|
||||
return state == 'handle-out' || state == 'handle-both';
|
||||
return (state & SelectionState.HANDLE_OUT)
|
||||
== SelectionState.HANDLE_OUT;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
@ -153,11 +155,11 @@ var Segment = this.Segment = Base.extend({
|
|||
return;
|
||||
var wasSelected = !!this._selectionState;
|
||||
var state = this._selectionState,
|
||||
pointSelected = state == 'point',
|
||||
handleInSelected = state == 'handle-in'
|
||||
|| state == 'handle-both',
|
||||
handleOutSelected = state == 'handle-out'
|
||||
|| state == 'handle-both',
|
||||
pointSelected = state == SelectionState.POINT,
|
||||
handleInSelected = (state & SelectionState.HANDLE_IN)
|
||||
== SelectionState.HANDLE_IN,
|
||||
handleOutSelected = (state & SelectionState.HANDLE_OUT)
|
||||
== SelectionState.HANDLE_OUT,
|
||||
previous = this.getPrevious(),
|
||||
next = this.getNext(),
|
||||
closed = this._path.closed,
|
||||
|
@ -202,13 +204,13 @@ var Segment = this.Segment = Base.extend({
|
|||
}
|
||||
}
|
||||
this._selectionState = pointSelected
|
||||
? 'point'
|
||||
? SelectionState.POINT
|
||||
: handleInSelected
|
||||
? handleOutSelected
|
||||
? 'handle-both'
|
||||
: 'handle-in'
|
||||
? SelectionState.HANDLE_BOTH
|
||||
: SelectionState.HANDLE_IN
|
||||
: handleOutSelected
|
||||
? 'handle-out'
|
||||
? SelectionState.HANDLE_OUT
|
||||
: null;
|
||||
// If the selection state of the segment has changed, we need to let
|
||||
// it's path know and possibly add or remove it from
|
||||
|
@ -228,8 +230,7 @@ var Segment = this.Segment = Base.extend({
|
|||
selectedItems.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
reverse: function() {
|
||||
|
|
22
src/path/SelectionState.js
Normal file
22
src/path/SelectionState.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Paper.js
|
||||
*
|
||||
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
||||
* based on Scriptographer.org and designed to be largely API compatible.
|
||||
* http://paperjs.org/
|
||||
* http://scriptographer.org/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
var SelectionState = {
|
||||
POINT: 1,
|
||||
HANDLE_IN: 2,
|
||||
HANDLE_OUT: 4,
|
||||
HANDLE_BOTH: 6
|
||||
};
|
Loading…
Reference in a new issue