color -> style, move selection gradient into it

A "style" refers to something that can fill/stroke a shape.
Currently that's either a solid color or a gradient of some orientation.
The selection gradient type reducer has been removed and folded into the
"fill style" reducer.
This commit is contained in:
adroitwhiz 2020-04-15 05:13:59 -04:00
parent 7bab4d5ed8
commit 1017911fd4
20 changed files with 129 additions and 141 deletions

View file

@ -5,11 +5,10 @@ import bindAll from 'lodash.bindall';
import Modes from '../lib/modes'; import Modes from '../lib/modes';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
import {clearSelection} from '../helper/selection'; import {clearSelection} from '../helper/selection';
import {clearGradient} from '../reducers/selection-gradient-type';
import BitBrushModeComponent from '../components/bit-brush-mode/bit-brush-mode.jsx'; import BitBrushModeComponent from '../components/bit-brush-mode/bit-brush-mode.jsx';
import BitBrushTool from '../helper/bit-tools/brush-tool'; import BitBrushTool from '../helper/bit-tools/brush-tool';
@ -102,7 +101,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
handleMouseDown: () => { handleMouseDown: () => {
dispatch(changeMode(Modes.BIT_BRUSH)); dispatch(changeMode(Modes.BIT_BRUSH));

View file

@ -7,7 +7,7 @@ import GradientTypes from '../lib/gradient-types';
import FillModeComponent from '../components/bit-fill-mode/bit-fill-mode.jsx'; import FillModeComponent from '../components/bit-fill-mode/bit-fill-mode.jsx';
import {changeFillColor, changeFillColor2, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, changeFillColor2, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
import {changeGradientType} from '../reducers/fill-mode-gradient-type'; import {changeGradientType} from '../reducers/fill-mode-gradient-type';
@ -65,10 +65,10 @@ class BitFillMode extends React.Component {
this.props.onChangeFillColor(DEFAULT_COLOR, 0); this.props.onChangeFillColor(DEFAULT_COLOR, 0);
} }
const gradientType = this.props.fillModeGradientType ? const gradientType = this.props.fillModeGradientType ?
this.props.fillModeGradientType : this.props.selectModeGradientType; this.props.fillModeGradientType : this.props.styleGradientType;
let color2 = this.props.color2; let color2 = this.props.color2;
if (gradientType !== this.props.selectModeGradientType) { if (gradientType !== this.props.styleGradientType) {
if (this.props.selectModeGradientType === GradientTypes.SOLID) { if (this.props.styleGradientType === GradientTypes.SOLID) {
color2 = getRotatedColor(color); color2 = getRotatedColor(color);
this.props.onChangeFillColor(color2, 1); this.props.onChangeFillColor(color2, 1);
} }
@ -104,20 +104,20 @@ BitFillMode.propTypes = {
clearSelectedItems: PropTypes.func.isRequired, clearSelectedItems: PropTypes.func.isRequired,
color: PropTypes.string, color: PropTypes.string,
color2: PropTypes.string, color2: PropTypes.string,
styleGradientType: PropTypes.oneOf(Object.keys(GradientTypes)).isRequired,
fillModeGradientType: PropTypes.oneOf(Object.keys(GradientTypes)), fillModeGradientType: PropTypes.oneOf(Object.keys(GradientTypes)),
handleMouseDown: PropTypes.func.isRequired, handleMouseDown: PropTypes.func.isRequired,
isFillModeActive: PropTypes.bool.isRequired, isFillModeActive: PropTypes.bool.isRequired,
onChangeFillColor: PropTypes.func.isRequired, onChangeFillColor: PropTypes.func.isRequired,
onUpdateImage: PropTypes.func.isRequired, onUpdateImage: PropTypes.func.isRequired
selectModeGradientType: PropTypes.oneOf(Object.keys(GradientTypes)).isRequired
}; };
const mapStateToProps = state => ({ const mapStateToProps = state => ({
fillModeGradientType: state.scratchPaint.fillMode.gradientType, // Last user-selected gradient type fillModeGradientType: state.scratchPaint.fillMode.gradientType, // Last user-selected gradient type
color: state.scratchPaint.color.fillColor.primary, color: state.scratchPaint.color.fillColor.primary,
color2: state.scratchPaint.color.fillColor.secondary, color2: state.scratchPaint.color.fillColor.secondary,
isFillModeActive: state.scratchPaint.mode === Modes.BIT_FILL, styleGradientType: state.scratchPaint.color.fillColor.gradientType,
selectModeGradientType: state.scratchPaint.color.gradientType isFillModeActive: state.scratchPaint.mode === Modes.BIT_FILL
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
clearSelectedItems: () => { clearSelectedItems: () => {

View file

@ -5,11 +5,10 @@ import bindAll from 'lodash.bindall';
import Modes from '../lib/modes'; import Modes from '../lib/modes';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
import {clearSelection} from '../helper/selection'; import {clearSelection} from '../helper/selection';
import {clearGradient} from '../reducers/selection-gradient-type';
import BitLineModeComponent from '../components/bit-line-mode/bit-line-mode.jsx'; import BitLineModeComponent from '../components/bit-line-mode/bit-line-mode.jsx';
import BitLineTool from '../helper/bit-tools/line-tool'; import BitLineTool from '../helper/bit-tools/line-tool';
@ -102,7 +101,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
handleMouseDown: () => { handleMouseDown: () => {
dispatch(changeMode(Modes.BIT_LINE)); dispatch(changeMode(Modes.BIT_LINE));

View file

@ -6,10 +6,9 @@ import bindAll from 'lodash.bindall';
import Modes from '../lib/modes'; import Modes from '../lib/modes';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
import {clearGradient} from '../reducers/selection-gradient-type';
import {setCursor} from '../reducers/cursor'; import {setCursor} from '../reducers/cursor';
import {clearSelection, getSelectedLeafItems} from '../helper/selection'; import {clearSelection, getSelectedLeafItems} from '../helper/selection';
@ -123,7 +122,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
setCursor: cursorString => { setCursor: cursorString => {
dispatch(setCursor(cursorString)); dispatch(setCursor(cursorString));

View file

@ -6,10 +6,9 @@ import bindAll from 'lodash.bindall';
import Modes from '../lib/modes'; import Modes from '../lib/modes';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
import {clearGradient} from '../reducers/selection-gradient-type';
import {setCursor} from '../reducers/cursor'; import {setCursor} from '../reducers/cursor';
import {clearSelection, getSelectedLeafItems} from '../helper/selection'; import {clearSelection, getSelectedLeafItems} from '../helper/selection';
@ -123,7 +122,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
setCursor: cursorString => { setCursor: cursorString => {
dispatch(setCursor(cursorString)); dispatch(setCursor(cursorString));

View file

@ -5,9 +5,9 @@ import {connect} from 'react-redux';
import bindAll from 'lodash.bindall'; import bindAll from 'lodash.bindall';
import Modes from '../lib/modes'; import Modes from '../lib/modes';
import {clearFillGradient} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
import {clearGradient} from '../reducers/selection-gradient-type';
import {setCursor} from '../reducers/cursor'; import {setCursor} from '../reducers/cursor';
import {getSelectedLeafItems} from '../helper/selection'; import {getSelectedLeafItems} from '../helper/selection';
@ -88,7 +88,7 @@ const mapStateToProps = state => ({
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
clearSelectedItems: () => { clearSelectedItems: () => {
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());

View file

@ -6,10 +6,9 @@ import Modes from '../lib/modes';
import Blobbiness from '../helper/blob-tools/blob'; import Blobbiness from '../helper/blob-tools/blob';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
import {clearGradient} from '../reducers/selection-gradient-type';
import {clearSelection} from '../helper/selection'; import {clearSelection} from '../helper/selection';
import BrushModeComponent from '../components/brush-mode/brush-mode.jsx'; import BrushModeComponent from '../components/brush-mode/brush-mode.jsx';
@ -112,7 +111,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
handleMouseDown: () => { handleMouseDown: () => {
dispatch(changeMode(Modes.BRUSH)); dispatch(changeMode(Modes.BRUSH));

View file

@ -5,7 +5,7 @@ import bindAll from 'lodash.bindall';
import parseColor from 'parse-color'; import parseColor from 'parse-color';
import {changeColorIndex} from '../reducers/color-index'; import {changeColorIndex} from '../reducers/color-index';
import {changeFillColor, changeFillColor2} from '../reducers/fill-color'; import {changeFillColor, changeFillColor2} from '../reducers/fill-style';
import {changeGradientType} from '../reducers/fill-mode-gradient-type'; import {changeGradientType} from '../reducers/fill-mode-gradient-type';
import {openFillColor, closeFillColor} from '../reducers/modals'; import {openFillColor, closeFillColor} from '../reducers/modals';
import {getSelectedLeafItems} from '../helper/selection'; import {getSelectedLeafItems} from '../helper/selection';
@ -124,7 +124,7 @@ const mapStateToProps = state => ({
fillColor2: state.scratchPaint.color.fillColor.secondary, fillColor2: state.scratchPaint.color.fillColor.secondary,
fillColorModalVisible: state.scratchPaint.modals.fillColor, fillColorModalVisible: state.scratchPaint.modals.fillColor,
format: state.scratchPaint.format, format: state.scratchPaint.format,
gradientType: state.scratchPaint.color.gradientType, gradientType: state.scratchPaint.color.fillColor.gradientType,
isEyeDropping: state.scratchPaint.color.eyeDropper.active, isEyeDropping: state.scratchPaint.color.eyeDropper.active,
mode: state.scratchPaint.mode, mode: state.scratchPaint.mode,
shouldShowGradientTools: state.scratchPaint.mode === Modes.SELECT || shouldShowGradientTools: state.scratchPaint.mode === Modes.SELECT ||

View file

@ -7,7 +7,7 @@ import GradientTypes from '../lib/gradient-types';
import FillTool from '../helper/tools/fill-tool'; import FillTool from '../helper/tools/fill-tool';
import {getRotatedColor, MIXED} from '../helper/style-path'; import {getRotatedColor, MIXED} from '../helper/style-path';
import {changeFillColor, changeFillColor2, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, changeFillColor2, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems} from '../reducers/selected-items';
import {clearSelection} from '../helper/selection'; import {clearSelection} from '../helper/selection';
@ -69,10 +69,10 @@ class FillMode extends React.Component {
this.props.onChangeFillColor(DEFAULT_COLOR, 0); this.props.onChangeFillColor(DEFAULT_COLOR, 0);
} }
const gradientType = this.props.fillModeGradientType ? const gradientType = this.props.fillModeGradientType ?
this.props.fillModeGradientType : this.props.selectModeGradientType; this.props.fillModeGradientType : this.props.fillStyleGradientType;
let fillColor2 = this.props.fillColor2; let fillColor2 = this.props.fillColor2;
if (gradientType !== this.props.selectModeGradientType) { if (gradientType !== this.props.fillStyleGradientType) {
if (this.props.selectModeGradientType === GradientTypes.SOLID) { if (this.props.fillStyleGradientType === GradientTypes.SOLID) {
fillColor2 = getRotatedColor(fillColor); fillColor2 = getRotatedColor(fillColor);
this.props.onChangeFillColor(fillColor2, 1); this.props.onChangeFillColor(fillColor2, 1);
} }
@ -114,13 +114,13 @@ FillMode.propTypes = {
clearSelectedItems: PropTypes.func.isRequired, clearSelectedItems: PropTypes.func.isRequired,
fillColor: PropTypes.string, fillColor: PropTypes.string,
fillColor2: PropTypes.string, fillColor2: PropTypes.string,
fillStyleGradientType: PropTypes.oneOf(Object.keys(GradientTypes)).isRequired,
fillModeGradientType: PropTypes.oneOf(Object.keys(GradientTypes)), fillModeGradientType: PropTypes.oneOf(Object.keys(GradientTypes)),
handleMouseDown: PropTypes.func.isRequired, handleMouseDown: PropTypes.func.isRequired,
hoveredItemId: PropTypes.number, hoveredItemId: PropTypes.number,
isFillModeActive: PropTypes.bool.isRequired, isFillModeActive: PropTypes.bool.isRequired,
onChangeFillColor: PropTypes.func.isRequired, onChangeFillColor: PropTypes.func.isRequired,
onUpdateImage: PropTypes.func.isRequired, onUpdateImage: PropTypes.func.isRequired,
selectModeGradientType: PropTypes.oneOf(Object.keys(GradientTypes)).isRequired,
setHoveredItem: PropTypes.func.isRequired setHoveredItem: PropTypes.func.isRequired
}; };
@ -128,9 +128,9 @@ const mapStateToProps = state => ({
fillModeGradientType: state.scratchPaint.fillMode.gradientType, // Last user-selected gradient type fillModeGradientType: state.scratchPaint.fillMode.gradientType, // Last user-selected gradient type
fillColor: state.scratchPaint.color.fillColor.primary, fillColor: state.scratchPaint.color.fillColor.primary,
fillColor2: state.scratchPaint.color.fillColor.secondary, fillColor2: state.scratchPaint.color.fillColor.secondary,
fillStyleGradientType: state.scratchPaint.color.fillColor.gradientType, // Selected item(s)' gradient type
hoveredItemId: state.scratchPaint.hoveredItemId, hoveredItemId: state.scratchPaint.hoveredItemId,
isFillModeActive: state.scratchPaint.mode === Modes.FILL, isFillModeActive: state.scratchPaint.mode === Modes.FILL
selectModeGradientType: state.scratchPaint.color.gradientType
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
setHoveredItem: hoveredItemId => { setHoveredItem: hoveredItemId => {

View file

@ -6,11 +6,10 @@ import bindAll from 'lodash.bindall';
import Modes from '../lib/modes'; import Modes from '../lib/modes';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeStrokeColor} from '../reducers/stroke-color'; import {changeStrokeColor} from '../reducers/stroke-color';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
import {clearGradient} from '../reducers/selection-gradient-type';
import {setCursor} from '../reducers/cursor'; import {setCursor} from '../reducers/cursor';
import {clearSelection, getSelectedLeafItems} from '../helper/selection'; import {clearSelection, getSelectedLeafItems} from '../helper/selection';
@ -126,7 +125,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
setCursor: cursorString => { setCursor: cursorString => {
dispatch(setCursor(cursorString)); dispatch(setCursor(cursorString));

View file

@ -6,11 +6,10 @@ import bindAll from 'lodash.bindall';
import Modes from '../lib/modes'; import Modes from '../lib/modes';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeStrokeColor} from '../reducers/stroke-color'; import {changeStrokeColor} from '../reducers/stroke-color';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
import {clearGradient} from '../reducers/selection-gradient-type';
import {setCursor} from '../reducers/cursor'; import {setCursor} from '../reducers/cursor';
import {clearSelection, getSelectedLeafItems} from '../helper/selection'; import {clearSelection, getSelectedLeafItems} from '../helper/selection';
@ -126,7 +125,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
setSelectedItems: () => { setSelectedItems: () => {
dispatch(setSelectedItems(getSelectedLeafItems(), false /* bitmapMode */)); dispatch(setSelectedItems(getSelectedLeafItems(), false /* bitmapMode */));

View file

@ -8,12 +8,11 @@ import Modes from '../lib/modes';
import {MIXED} from '../helper/style-path'; import {MIXED} from '../helper/style-path';
import {changeFont} from '../reducers/font'; import {changeFont} from '../reducers/font';
import {changeFillColor, DEFAULT_COLOR} from '../reducers/fill-color'; import {changeFillColor, clearFillGradient, DEFAULT_COLOR} from '../reducers/fill-style';
import {changeStrokeColor} from '../reducers/stroke-color'; import {changeStrokeColor} from '../reducers/stroke-color';
import {changeMode} from '../reducers/modes'; import {changeMode} from '../reducers/modes';
import {setTextEditTarget} from '../reducers/text-edit-target'; import {setTextEditTarget} from '../reducers/text-edit-target';
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
import {clearGradient} from '../reducers/selection-gradient-type';
import {setCursor} from '../reducers/cursor'; import {setCursor} from '../reducers/cursor';
import {clearSelection, getSelectedLeafItems} from '../helper/selection'; import {clearSelection, getSelectedLeafItems} from '../helper/selection';
@ -188,7 +187,7 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());
}, },
clearGradient: () => { clearGradient: () => {
dispatch(clearGradient()); dispatch(clearFillGradient());
}, },
handleChangeModeBitText: () => { handleChangeModeBitText: () => {
dispatch(changeMode(Modes.BIT_TEXT)); dispatch(changeMode(Modes.BIT_TEXT));

View file

@ -5,7 +5,7 @@ import {isGroup} from './group';
import {getItems} from './selection'; import {getItems} from './selection';
import GradientTypes from '../lib/gradient-types'; import GradientTypes from '../lib/gradient-types';
import parseColor from 'parse-color'; import parseColor from 'parse-color';
import {DEFAULT_COLOR} from '../reducers/fill-color'; import {DEFAULT_COLOR} from '../reducers/fill-style';
import {isCompoundPathChild} from '../helper/compound-path'; import {isCompoundPathChild} from '../helper/compound-path';
const MIXED = 'scratch-paint/style-path/mixed'; const MIXED = 'scratch-paint/style-path/mixed';

View file

@ -1,6 +1,5 @@
import log from '../log/log'; import log from '../log/log';
import {CHANGE_SELECTED_ITEMS} from '../reducers/selected-items'; import {CHANGE_SELECTED_ITEMS} from '../reducers/selected-items';
import {CLEAR_GRADIENT} from '../reducers/selection-gradient-type';
import {getColorsFromSelection, MIXED} from '../helper/style-path'; import {getColorsFromSelection, MIXED} from '../helper/style-path';
import GradientTypes from './gradient-types'; import GradientTypes from './gradient-types';
@ -15,18 +14,32 @@ const isValidHexColor = color => {
return true; return true;
}; };
const makeColorReducer = ({ const makeColorStyleReducer = ({
// Action name for changing the primary color
changePrimaryColorAction, changePrimaryColorAction,
// Action name for changing the secondary color
changeSecondaryColorAction, changeSecondaryColorAction,
// Action name for changing the gradient type
changeGradientTypeAction,
// Action name for clearing the gradient
clearGradientAction,
// Initial color when not set
defaultColor, defaultColor,
// The name of the property read from getColorsFromSelection to get the primary color.
// e.g. `fillColor` or `strokeColor`.
selectionPrimaryColorKey, selectionPrimaryColorKey,
// The name of the property read from getColorsFromSelection to get the secondary color.
// e.g. `fillColor2` or `strokeColor2`.
selectionSecondaryColorKey, selectionSecondaryColorKey,
// The name of the property read from getColorsFromSelection to get the gradient type.
// e.g. `fillGradientType` or `strokeGradientType`.
selectionGradientTypeKey selectionGradientTypeKey
}) => function colorReducer (state, action) { }) => function colorReducer (state, action) {
if (typeof state === 'undefined') { if (typeof state === 'undefined') {
state = { state = {
primary: defaultColor, primary: defaultColor,
secondary: null secondary: null,
gradientType: GradientTypes.SOLID
}; };
} }
switch (action.type) { switch (action.type) {
@ -43,7 +56,11 @@ const makeColorReducer = ({
} }
const colors = getColorsFromSelection(action.selectedItems, action.bitmapMode); const colors = getColorsFromSelection(action.selectedItems, action.bitmapMode);
const newState = {...state, primary: colors[selectionPrimaryColorKey]}; const newState = {
...state,
primary: colors[selectionPrimaryColorKey],
gradientType: colors[selectionGradientTypeKey]
};
// Gradient type may be solid when multiple gradient types are selected. // Gradient type may be solid when multiple gradient types are selected.
// In this case, changing the first color should not change the second color. // In this case, changing the first color should not change the second color.
@ -52,11 +69,17 @@ const makeColorReducer = ({
} }
return newState; return newState;
} }
case CLEAR_GRADIENT: case changeGradientTypeAction:
return {...state, secondary: null}; if (action.gradientType in GradientTypes) {
return {...state, gradientType: action.gradientType};
}
log.warn(`Gradient type does not exist: ${action.gradientType}`);
return state;
case clearGradientAction:
return {...state, secondary: null, gradientType: GradientTypes.SOLID};
default: default:
return state; return state;
} }
}; };
export default makeColorReducer; export default makeColorStyleReducer;

View file

@ -1,5 +1,5 @@
import log from '../log/log'; import log from '../log/log';
import {CHANGE_GRADIENT_TYPE} from './fill-mode-gradient-type'; import {CHANGE_FILL_GRADIENT_TYPE} from './fill-style';
import GradientTypes from '../lib/gradient-types'; import GradientTypes from '../lib/gradient-types';
const CHANGE_COLOR_INDEX = 'scratch-paint/color-index/CHANGE_COLOR_INDEX'; const CHANGE_COLOR_INDEX = 'scratch-paint/color-index/CHANGE_COLOR_INDEX';
@ -14,7 +14,7 @@ const reducer = function (state, action) {
return state; return state;
} }
return action.index; return action.index;
case CHANGE_GRADIENT_TYPE: case CHANGE_FILL_GRADIENT_TYPE:
if (action.gradientType === GradientTypes.SOLID) return 0; if (action.gradientType === GradientTypes.SOLID) return 0;
/* falls through */ /* falls through */
default: default:

View file

@ -1,14 +1,12 @@
import {combineReducers} from 'redux'; import {combineReducers} from 'redux';
import eyeDropperReducer from './eye-dropper'; import eyeDropperReducer from './eye-dropper';
import fillColorReducer from './fill-color'; import fillColorReducer from './fill-style';
import gradientTypeReducer from './selection-gradient-type';
import strokeColorReducer from './stroke-color'; import strokeColorReducer from './stroke-color';
import strokeWidthReducer from './stroke-width'; import strokeWidthReducer from './stroke-width';
export default combineReducers({ export default combineReducers({
eyeDropper: eyeDropperReducer, eyeDropper: eyeDropperReducer,
fillColor: fillColorReducer, fillColor: fillColorReducer,
gradientType: gradientTypeReducer,
strokeColor: strokeColorReducer, strokeColor: strokeColorReducer,
strokeWidth: strokeWidthReducer strokeWidth: strokeWidthReducer
}); });

View file

@ -1,36 +0,0 @@
import makeColorReducer from '../lib/make-color-reducer';
const CHANGE_FILL_COLOR = 'scratch-paint/fill-color/CHANGE_FILL_COLOR';
const CHANGE_FILL_COLOR_2 = 'scratch-paint/fill-color/CHANGE_FILL_COLOR_2';
const DEFAULT_COLOR = '#9966FF';
const reducer = makeColorReducer({
changePrimaryColorAction: CHANGE_FILL_COLOR,
changeSecondaryColorAction: CHANGE_FILL_COLOR_2,
defaultColor: DEFAULT_COLOR,
selectionPrimaryColorKey: 'fillColor',
selectionSecondaryColorKey: 'fillColor2',
selectionGradientTypeKey: 'gradientType'
});
// Action creators ==================================
const changeFillColor = function (fillColor) {
return {
type: CHANGE_FILL_COLOR,
color: fillColor
};
};
const changeFillColor2 = function (fillColor) {
return {
type: CHANGE_FILL_COLOR_2,
color: fillColor
};
};
export {
reducer as default,
changeFillColor,
changeFillColor2,
DEFAULT_COLOR
};

View file

@ -2,14 +2,14 @@
// and isn't overwritten by changing the selection. // and isn't overwritten by changing the selection.
import GradientTypes from '../lib/gradient-types'; import GradientTypes from '../lib/gradient-types';
import log from '../log/log'; import log from '../log/log';
import {CHANGE_FILL_GRADIENT_TYPE} from './fill-style';
const CHANGE_GRADIENT_TYPE = 'scratch-paint/fill-mode-gradient-type/CHANGE_GRADIENT_TYPE';
const initialState = null; const initialState = null;
const reducer = function (state, action) { const reducer = function (state, action) {
if (typeof state === 'undefined') state = initialState; if (typeof state === 'undefined') state = initialState;
switch (action.type) { switch (action.type) {
case CHANGE_GRADIENT_TYPE: case CHANGE_FILL_GRADIENT_TYPE:
if (action.gradientType in GradientTypes) { if (action.gradientType in GradientTypes) {
return action.gradientType; return action.gradientType;
} }
@ -22,16 +22,15 @@ const reducer = function (state, action) {
// Action creators ================================== // Action creators ==================================
// Use this for user-initiated gradient type selections only. // Use this for user-initiated gradient type selections only.
// See reducers/selection-gradient-type.js for other ways gradient type changes. // See reducers/fill-style.js for other ways gradient type changes.
const changeGradientType = function (gradientType) { const changeGradientType = function (gradientType) {
return { return {
type: CHANGE_GRADIENT_TYPE, type: CHANGE_FILL_GRADIENT_TYPE,
gradientType: gradientType gradientType: gradientType
}; };
}; };
export { export {
reducer as default, reducer as default,
CHANGE_GRADIENT_TYPE,
changeGradientType changeGradientType
}; };

View file

@ -0,0 +1,56 @@
import makeColorStyleReducer from '../lib/make-color-style-reducer';
const CHANGE_FILL_COLOR = 'scratch-paint/fill-style/CHANGE_FILL_COLOR';
const CHANGE_FILL_COLOR_2 = 'scratch-paint/fill-style/CHANGE_FILL_COLOR_2';
const CHANGE_FILL_GRADIENT_TYPE = 'scratch-paint/fill-style/CHANGE_FILL_GRADIENT_TYPE';
const CLEAR_FILL_GRADIENT = 'scratch-paint/fill-style/CLEAR_FILL_GRADIENT';
const DEFAULT_COLOR = '#9966FF';
const reducer = makeColorStyleReducer({
changePrimaryColorAction: CHANGE_FILL_COLOR,
changeSecondaryColorAction: CHANGE_FILL_COLOR_2,
changeGradientTypeAction: CHANGE_FILL_GRADIENT_TYPE,
clearGradientAction: CLEAR_FILL_GRADIENT,
defaultColor: DEFAULT_COLOR,
selectionPrimaryColorKey: 'fillColor',
selectionSecondaryColorKey: 'fillColor2',
selectionGradientTypeKey: 'gradientType'
});
// Action creators ==================================
const changeFillColor = function (fillColor) {
return {
type: CHANGE_FILL_COLOR,
color: fillColor
};
};
const changeFillColor2 = function (fillColor) {
return {
type: CHANGE_FILL_COLOR_2,
color: fillColor
};
};
const changeFillGradientType = function (gradientType) {
return {
type: CHANGE_FILL_GRADIENT_TYPE,
gradientType: gradientType
};
};
const clearFillGradient = function () {
return {
type: CLEAR_FILL_GRADIENT
};
};
export {
reducer as default,
changeFillColor,
changeFillColor2,
changeFillGradientType,
clearFillGradient,
DEFAULT_COLOR,
CHANGE_FILL_GRADIENT_TYPE
};

View file

@ -1,44 +0,0 @@
// Gradient type shown in the select tool
import GradientTypes from '../lib/gradient-types';
import {getColorsFromSelection} from '../helper/style-path';
import {CHANGE_SELECTED_ITEMS} from './selected-items';
import {CHANGE_GRADIENT_TYPE} from './fill-mode-gradient-type';
import log from '../log/log';
const CLEAR_GRADIENT = 'scratch-paint/selection-gradient-type/CLEAR_GRADIENT';
const initialState = GradientTypes.SOLID;
const reducer = function (state, action) {
if (typeof state === 'undefined') state = initialState;
switch (action.type) {
case CHANGE_GRADIENT_TYPE:
if (action.gradientType in GradientTypes) {
return action.gradientType;
}
log.warn(`Gradient type does not exist: ${action.gradientType}`);
return state;
case CLEAR_GRADIENT:
return GradientTypes.SOLID;
case CHANGE_SELECTED_ITEMS:
// Don't change state if no selection
if (!action.selectedItems || !action.selectedItems.length) {
return state;
}
return getColorsFromSelection(action.selectedItems, action.bitmapMode).gradientType;
default:
return state;
}
};
// Action creators ==================================
const clearGradient = function () {
return {
type: CLEAR_GRADIENT
};
};
export {
reducer as default,
CLEAR_GRADIENT,
clearGradient
};