Force a real color when activating brush, pen and line mode.

This commit is contained in:
Paul Kaplan 2017-10-26 17:09:44 -04:00
parent d98a493954
commit 40ec57fbf1
3 changed files with 45 additions and 2 deletions

View file

@ -4,7 +4,9 @@ import {connect} from 'react-redux';
import bindAll from 'lodash.bindall'; import bindAll from 'lodash.bindall';
import Modes from '../modes/modes'; import Modes from '../modes/modes';
import Blobbiness from '../helper/blob-tools/blob'; import Blobbiness from '../helper/blob-tools/blob';
import {MIXED} from '../helper/style-path';
import {changeFillColor} from '../reducers/fill-color';
import {changeBrushSize} from '../reducers/brush-mode'; import {changeBrushSize} from '../reducers/brush-mode';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
@ -13,6 +15,9 @@ import {clearSelection} from '../helper/selection';
import BrushModeComponent from '../components/brush-mode/brush-mode.jsx'; import BrushModeComponent from '../components/brush-mode/brush-mode.jsx';
class BrushMode extends React.Component { class BrushMode extends React.Component {
static get DEFAULT_COLOR () {
return '#9966FF';
}
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
@ -49,6 +54,12 @@ class BrushMode extends React.Component {
// analogous to how selection works with eraser // analogous to how selection works with eraser
clearSelection(this.props.clearSelectedItems); clearSelection(this.props.clearSelectedItems);
// Force the default brush color if fill is MIXED or transparent
const {fillColor} = this.props.colorState;
if (fillColor === MIXED || fillColor === null) {
this.props.onChangeFillColor(BrushMode.DEFAULT_COLOR);
}
// TODO: This is temporary until a component that provides the brush size is hooked up // TODO: This is temporary until a component that provides the brush size is hooked up
this.props.canvas.addEventListener('mousewheel', this.onScroll); this.props.canvas.addEventListener('mousewheel', this.onScroll);
this.blob.activateTool({ this.blob.activateTool({
@ -93,6 +104,7 @@ BrushMode.propTypes = {
}).isRequired, }).isRequired,
handleMouseDown: PropTypes.func.isRequired, handleMouseDown: PropTypes.func.isRequired,
isBrushModeActive: PropTypes.bool.isRequired, isBrushModeActive: PropTypes.bool.isRequired,
onChangeFillColor: PropTypes.func.isRequired,
onUpdateSvg: PropTypes.func.isRequired onUpdateSvg: PropTypes.func.isRequired
}; };
@ -110,6 +122,9 @@ const mapDispatchToProps = dispatch => ({
}, },
handleMouseDown: () => { handleMouseDown: () => {
dispatch(changeMode(Modes.BRUSH)); dispatch(changeMode(Modes.BRUSH));
},
onChangeFillColor: fillColor => {
dispatch(changeFillColor(fillColor));
} }
}); });

View file

@ -8,8 +8,10 @@ import {clearSelection} from '../helper/selection';
import {endPointHit, touching} from '../helper/snapping'; import {endPointHit, touching} from '../helper/snapping';
import {drawHitPoint, removeHitPoint} from '../helper/guides'; import {drawHitPoint, removeHitPoint} from '../helper/guides';
import {stylePath} from '../helper/style-path'; import {stylePath} from '../helper/style-path';
import {changeStrokeColor} from '../reducers/stroke-color';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
import {MIXED} from '../helper/style-path';
import LineModeComponent from '../components/line-mode/line-mode.jsx'; import LineModeComponent from '../components/line-mode/line-mode.jsx';
@ -17,6 +19,9 @@ class LineMode extends React.Component {
static get SNAP_TOLERANCE () { static get SNAP_TOLERANCE () {
return 6; return 6;
} }
static get DEFAULT_COLOR () {
return '#000000';
}
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
@ -46,8 +51,15 @@ class LineMode extends React.Component {
} }
activateTool () { activateTool () {
clearSelection(this.props.clearSelectedItems); clearSelection(this.props.clearSelectedItems);
// Force the default line color if stroke is MIXED or transparent
const {strokeColor} = this.props.colorState;
if (strokeColor === MIXED || strokeColor === null) {
this.props.onChangeStrokeColor(LineMode.DEFAULT_COLOR);
}
this.tool = new paper.Tool(); this.tool = new paper.Tool();
this.path = null; this.path = null;
this.hitResult = null; this.hitResult = null;
@ -182,7 +194,7 @@ class LineMode extends React.Component {
removeHitPoint(); removeHitPoint();
this.hitResult = null; this.hitResult = null;
} }
if (this.path) { if (this.path) {
this.props.onUpdateSvg(); this.props.onUpdateSvg();
this.path = null; this.path = null;
@ -233,6 +245,9 @@ const mapDispatchToProps = dispatch => ({
}, },
handleMouseDown: () => { handleMouseDown: () => {
dispatch(changeMode(Modes.LINE)); dispatch(changeMode(Modes.LINE));
},
onChangeStrokeColor: strokeColor => {
dispatch(changeStrokeColor(strokeColor));
} }
}); });

View file

@ -4,14 +4,19 @@ import {connect} from 'react-redux';
import bindAll from 'lodash.bindall'; import bindAll from 'lodash.bindall';
import Modes from '../modes/modes'; import Modes from '../modes/modes';
import {changeStrokeColor} from '../reducers/stroke-color';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
import {MIXED} from '../helper/style-path';
import {clearSelection} from '../helper/selection'; import {clearSelection} from '../helper/selection';
import PenTool from '../helper/tools/pen-tool'; import PenTool from '../helper/tools/pen-tool';
import PenModeComponent from '../components/pen-mode/pen-mode.jsx'; import PenModeComponent from '../components/pen-mode/pen-mode.jsx';
class PenMode extends React.Component { class PenMode extends React.Component {
static get DEFAULT_COLOR () {
return '#000000';
}
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
@ -42,6 +47,11 @@ class PenMode extends React.Component {
} }
activateTool () { activateTool () {
clearSelection(this.props.clearSelectedItems); clearSelection(this.props.clearSelectedItems);
// Force the default pen color if stroke is MIXED or transparent
const {strokeColor} = this.props.colorState;
if (strokeColor === MIXED || strokeColor === null) {
this.props.onChangeStrokeColor(PenMode.DEFAULT_COLOR)
}
this.tool = new PenTool( this.tool = new PenTool(
this.props.clearSelectedItems, this.props.clearSelectedItems,
this.props.onUpdateSvg this.props.onUpdateSvg
@ -89,6 +99,9 @@ const mapDispatchToProps = dispatch => ({
dispatch(changeMode(Modes.PEN)); dispatch(changeMode(Modes.PEN));
}, },
deactivateTool () { deactivateTool () {
},
onChangeStrokeColor: strokeColor => {
dispatch(changeStrokeColor(strokeColor));
} }
}); });