Optimize and fix code that draws selections and handles.

This commit is contained in:
Jürg Lehni 2014-03-04 09:26:55 +01:00
parent dad17ba28e
commit 763fd5b6a3
2 changed files with 10 additions and 14 deletions

View file

@ -1929,19 +1929,15 @@ var Path = PathItem.extend(/** @lends Path# */{
if (state & /*#=*/ SelectionState.HANDLE_OUT) if (state & /*#=*/ SelectionState.HANDLE_OUT)
drawHandle(4); drawHandle(4);
// Draw a rectangle at segment.point: // Draw a rectangle at segment.point:
ctx.save(); ctx.fillRect(pX - half, pY - half, size, size);
ctx.beginPath();
ctx.rect(pX - half, pY - half, size, size);
ctx.fill();
// If the point is not selected, draw a white square that is 1 px // If the point is not selected, draw a white square that is 1 px
// smaller on all sides: // smaller on all sides:
if (!(state & /*#=*/ SelectionState.POINT)) { if (!(state & /*#=*/ SelectionState.POINT)) {
ctx.beginPath(); var fillStyle = ctx.fillStyle;
ctx.rect(pX - half + 1, pY - half + 1, size - 2, size - 2);
ctx.fillStyle = '#ffffff'; ctx.fillStyle = '#ffffff';
ctx.fill(); ctx.fillRect(pX - half + 1, pY - half + 1, size - 2, size - 2);
ctx.fillStyle = fillStyle;
} }
ctx.restore();
} }
} }

View file

@ -450,7 +450,9 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
ctx.save(); ctx.save();
ctx.strokeWidth = 1; ctx.strokeWidth = 1;
for (var id in this._selectedItems) { for (var id in this._selectedItems) {
var item = this._selectedItems[id]; var item = this._selectedItems[id],
size = this.options.handleSize || 4;
half = size / 2;
if (item._updateVersion === this._updateVersion if (item._updateVersion === this._updateVersion
&& (item._drawSelected || item._boundsSelected)) { && (item._drawSelected || item._boundsSelected)) {
// Allow definition of selected color on a per item and per // Allow definition of selected color on a per item and per
@ -473,11 +475,9 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
coords[i], coords[++i]); coords[i], coords[++i]);
ctx.closePath(); ctx.closePath();
ctx.stroke(); ctx.stroke();
for (var i = 0; i < 8; i++) { for (var i = 0; i < 8; i++)
ctx.beginPath(); ctx.fillRect(coords[i] - half, coords[++i] - half,
ctx.rect(coords[i] - 2, coords[++i] - 2, 4, 4); size, size);
ctx.fill();
}
} }
} }
} }