Skip to content

Commit 5e5890d

Browse files
committed
Gradients in line mode
The UX here isn't the best thing in the world but I think having the functionality is important judging from the playtest
1 parent 2f15090 commit 5e5890d

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/containers/line-mode.jsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ColorStyleProptype from '../lib/color-style-proptype';
88
import {clearSelection} from '../helper/selection';
99
import {endPointHit, touching} from '../helper/snapping';
1010
import {drawHitPoint, removeHitPoint} from '../helper/guides';
11-
import {stylePath} from '../helper/style-path';
11+
import {styleShape} from '../helper/style-path';
1212
import {changeStrokeColor, clearStrokeGradient} from '../reducers/stroke-style';
1313
import {changeStrokeWidth} from '../reducers/stroke-width';
1414
import {changeMode} from '../reducers/modes';
@@ -103,7 +103,11 @@ class LineMode extends React.Component {
103103
this.hitResult = endPointHit(event.point, LineMode.SNAP_TOLERANCE);
104104
if (this.hitResult) {
105105
this.path = this.hitResult.path;
106-
stylePath(this.path, this.props.colorState.strokeColor.primary, this.props.colorState.strokeWidth);
106+
styleShape(this.path, {
107+
fillColor: null,
108+
strokeColor: this.props.colorState.strokeColor,
109+
strokeWidth: this.props.colorState.strokeWidth
110+
});
107111
if (this.hitResult.isFirst) {
108112
this.path.reverse();
109113
}
@@ -116,7 +120,11 @@ class LineMode extends React.Component {
116120
if (!this.path) {
117121
this.path = new paper.Path();
118122
this.path.strokeCap = 'round';
119-
stylePath(this.path, this.props.colorState.strokeColor.primary, this.props.colorState.strokeWidth);
123+
styleShape(this.path, {
124+
fillColor: null,
125+
strokeColor: this.props.colorState.strokeColor,
126+
strokeWidth: this.props.colorState.strokeWidth
127+
});
120128

121129
this.path.add(event.point);
122130
this.path.add(event.point); // Add second point, which is what will move when dragged
@@ -188,6 +196,12 @@ class LineMode extends React.Component {
188196
} else {
189197
this.path.lastSegment.point = endPoint;
190198
}
199+
200+
styleShape(this.path, {
201+
fillColor: null,
202+
strokeColor: this.props.colorState.strokeColor,
203+
strokeWidth: this.props.colorState.strokeWidth
204+
});
191205
}
192206
onMouseUp (event) {
193207
if (event.event.button > 0 || !this.active) return; // only first mouse button
@@ -227,6 +241,12 @@ class LineMode extends React.Component {
227241
this.hitResult = null;
228242
}
229243

244+
styleShape(this.path, {
245+
fillColor: null,
246+
strokeColor: this.props.colorState.strokeColor,
247+
strokeWidth: this.props.colorState.strokeWidth
248+
});
249+
230250
if (this.path) {
231251
this.props.onUpdateImage();
232252
this.path = null;

src/helper/style-path.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,6 @@ const styleBlob = function (path, options) {
531531
}
532532
};
533533

534-
const stylePath = function (path, strokeColor, strokeWidth) {
535-
// Make sure a visible line is drawn
536-
path.setStrokeColor(
537-
(strokeColor === MIXED || strokeColor === null) ? 'black' : strokeColor);
538-
path.setStrokeWidth(
539-
strokeWidth === null || strokeWidth === 0 ? 1 : strokeWidth);
540-
};
541-
542534
const styleCursorPreview = function (path, options) {
543535
if (options.isEraser) {
544536
path.fillColor = 'white';
@@ -577,7 +569,6 @@ export {
577569
MIXED,
578570
styleBlob,
579571
styleShape,
580-
stylePath,
581572
styleCursorPreview,
582573
swapColorsInSelection
583574
};

src/lib/modes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const GradientToolsModes = keyMirror({
3232
RESHAPE: null,
3333
OVAL: null,
3434
RECT: null,
35+
LINE: null,
3536

3637
BIT_OVAL: null,
3738
BIT_RECT: null,

0 commit comments

Comments
 (0)