Skip to content

Commit 2a8e4c4

Browse files
committed
move shapes into a shape tool
1 parent ea28158 commit 2a8e4c4

File tree

12 files changed

+276
-24
lines changed

12 files changed

+276
-24
lines changed

src/components/mode-tools/mode-tools.jsx

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {changeBrushSize} from '../../reducers/brush-mode';
1111
import {changeBrushSize as changeEraserSize} from '../../reducers/eraser-mode';
1212
import {changeRoundedCornerSize} from '../../reducers/rounded-rect-mode';
1313
import {changeTrianglePolyCount} from '../../reducers/triangle-mode';
14+
import {changeCurrentlySelectedShape} from '../../reducers/sussy-mode';
1415
import {changeBitBrushSize} from '../../reducers/bit-brush-size';
1516
import {changeBitEraserSize} from '../../reducers/bit-eraser-size';
1617
import {setShapesFilled} from '../../reducers/fill-bitmap-shapes';
@@ -60,6 +61,8 @@ import bitRectOutlinedIcon from '../bit-rect-mode/rectangle-outlined.svg';
6061

6162
import {MAX_STROKE_WIDTH} from '../../reducers/stroke-width';
6263

64+
import selectableShapes from '../../helper/selectable-shapes.js';
65+
6366
const LiveInput = LiveInputHOC(Input);
6467
const ModeToolsComponent = props => {
6568
const messages = defineMessages({
@@ -262,6 +265,73 @@ const ModeToolsComponent = props => {
262265
</div>
263266
);
264267
}
268+
case Modes.SUSSY:
269+
{
270+
const currentlySelectedShape = props.currentlySelectedShape;
271+
const changeFunction = props.onCurrentlySelectedShapeChange;
272+
const selectedShapeObject = selectableShapes
273+
.filter(shape => shape.id === currentlySelectedShape)[0];
274+
const generateShapeSVG = (shapeObject) => {
275+
return `<svg
276+
version="1.1"
277+
xmlns="http://www.w3.org/2000/svg"
278+
xmlns:xlink="http://www.w3.org/1999/xlink"
279+
280+
width="${shapeObject.icon.width}"
281+
height="${shapeObject.icon.height}"
282+
viewBox="${shapeObject.icon.viewBox}"
283+
284+
>
285+
<g transform="translate(${shapeObject.icon.x},${shapeObject.icon.y})">
286+
<g data-paper-data="{&quot;isPaintingLayer&quot;:true}"
287+
fill="none" fill-rule="nonzero" stroke="#575E75"
288+
289+
stroke-width="${shapeObject.icon.strokeWidth}"
290+
291+
stroke-linecap="butt"
292+
stroke-linejoin="round" stroke-dashoffset="0" style="mix-blend-mode: normal">
293+
294+
<path d="${shapeObject.path}"/>
295+
296+
</g></g></svg>`
297+
};
298+
const selectableShapesList = (
299+
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
300+
{selectableShapes.map(shape => {
301+
return (<LabeledIconButton
302+
hideLabel={hideLabel(props.intl.locale)}
303+
imgSrc={`data:image/svg+xml,${encodeURIComponent(generateShapeSVG(shape))}`}
304+
title={shape.name}
305+
onClick={() => changeFunction(shape.id)}
306+
/>)
307+
})}
308+
</InputGroup>
309+
)
310+
return (
311+
<div className={classNames(props.className, styles.modeTools)}>
312+
<Dropdown
313+
className={styles.modUnselect}
314+
enterExitTransitionDurationMs={20}
315+
popoverContent={
316+
<InputGroup
317+
className={styles.modContextMenu}
318+
rtl={props.rtl}
319+
>
320+
{selectableShapesList}
321+
</InputGroup>
322+
}
323+
tipSize={.01}
324+
>
325+
<img
326+
src={`data:image/svg+xml,${encodeURIComponent(generateShapeSVG(selectedShapeObject))}`}
327+
alt={selectedShapeObject.name}
328+
title={selectedShapeObject.name}
329+
height={16}
330+
/>
331+
</Dropdown>
332+
</div>
333+
);
334+
}
265335
case Modes.RESHAPE:
266336
return (
267337
<div className={classNames(props.className, styles.modeTools)}>
@@ -527,6 +597,7 @@ ModeToolsComponent.propTypes = {
527597
eraserValue: PropTypes.number,
528598
roundedCornerValue: PropTypes.number,
529599
trianglePolyValue: PropTypes.number,
600+
currentlySelectedShape: PropTypes.string,
530601
fillBitmapShapes: PropTypes.bool,
531602
format: PropTypes.oneOf(Object.keys(Formats)),
532603
hasSelectedUncurvedPoints: PropTypes.bool,
@@ -571,7 +642,8 @@ const mapStateToProps = state => ({
571642
clipboardItems: state.scratchPaint.clipboard.items,
572643
eraserValue: state.scratchPaint.eraserMode.brushSize,
573644
roundedCornerValue: state.scratchPaint.roundedRectMode.roundedCornerSize,
574-
trianglePolyValue: state.scratchPaint.triangleMode.trianglePolyCount
645+
trianglePolyValue: state.scratchPaint.triangleMode.trianglePolyCount,
646+
currentlySelectedShape: state.scratchPaint.sussyMode.currentlySelectedShape
575647
});
576648
const mapDispatchToProps = dispatch => ({
577649
onBrushSliderChange: brushSize => {
@@ -583,6 +655,9 @@ const mapDispatchToProps = dispatch => ({
583655
onPolyCountSliderChange: polyCount => {
584656
dispatch(changeTrianglePolyCount(polyCount));
585657
},
658+
onCurrentlySelectedShapeChange: shape => {
659+
dispatch(changeCurrentlySelectedShape(shape));
660+
},
586661
onBitBrushSliderChange: bitBrushSize => {
587662
dispatch(changeBitBrushSize(bitBrushSize));
588663
},

src/components/paint-editor/paint-editor.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import OvalMode from '../../containers/oval-mode.jsx';
3030
import RectMode from '../../containers/rect-mode.jsx';
3131
import RoundedRectMode from '../../containers/rounded-rect-mode.jsx';
3232
import SussyMode from '../../containers/sussy-mode.jsx';
33-
import DragonMode from '../../containers/dragon-mode.jsx';
3433
import TriangleMode from '../../containers/triangle-mode.jsx';
3534
import ArrowMode from '../../containers/arrow-mode.jsx';
3635
import ReshapeMode from '../../containers/reshape-mode.jsx';
@@ -184,9 +183,6 @@ const PaintEditorComponent = props => (
184183
<SussyMode
185184
onUpdateImage={props.onUpdateImage}
186185
/>
187-
<DragonMode
188-
onUpdateImage={props.onUpdateImage}
189-
/>
190186
<ArrowMode
191187
onUpdateImage={props.onUpdateImage}
192188
/>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="15.89412"
2+
height="15.89412" viewBox="-2,-2,19.89412,19.89412">
3+
<g transform="translate(-232.05294,-172.05294)">
4+
<g data-paper-data="{&quot;isPaintingLayer&quot;:true}" stroke-linecap="butt" stroke-linejoin="miter"
5+
stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" style="mix-blend-mode: normal">
6+
<path
7+
d="M232.80294,180c0,-3.97483 3.22223,-7.19706 7.19706,-7.19706c3.97483,0 7.19706,3.22223 7.19706,7.19706c0,3.97483 -3.22223,7.19706 -7.19706,7.19706c-3.97483,0 -7.19706,-3.22223 -7.19706,-7.19706z"
8+
fill="none" fill-rule="evenodd" stroke="#575e75" stroke-width="1.5" />
9+
<path
10+
d="M237.08478,178.21688c0,-0.41421 0.33579,-0.75 0.75,-0.75c0.41421,0 0.75,0.33579 0.75,0.75c0,0.41421 -0.33579,0.75 -0.75,0.75c-0.41421,0 -0.75,-0.33579 -0.75,-0.75z"
11+
fill="#575e75" fill-rule="nonzero" stroke="none" stroke-width="0.5" />
12+
<path
13+
d="M241.41522,178.21688c0,-0.41421 0.33579,-0.75 0.75,-0.75c0.41421,0 0.75,0.33579 0.75,0.75c0,0.41421 -0.33579,0.75 -0.75,0.75c-0.41421,0 -0.75,-0.33579 -0.75,-0.75z"
14+
fill="#575e75" fill-rule="nonzero" stroke="none" stroke-width="0.5" />
15+
<path
16+
d="M236.07461,181.52292c0,-0.00043 3.92539,0.00434 3.92539,0.00434c0,0 3.92539,-0.00477 3.92539,-0.00434c0,2.11928 -1.75746,3.83729 -3.92539,3.83729c-2.16793,0 -3.92539,-1.71801 -3.92539,-3.83729z"
17+
fill="none" fill-rule="nonzero" stroke="#575e75" stroke-width="1" />
18+
</g>
19+
</g>
20+
</svg><!--rotationCenter:7.947057591364199:7.947057591364143-->
Lines changed: 20 additions & 9 deletions
Loading

src/containers/paint-editor.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ class PaintEditor extends React.Component {
197197
case Modes.LINE:
198198
this.props.changeMode(Modes.BIT_LINE);
199199
break;
200-
case Modes.DRAGON:
201-
/* falls through */
202200
case Modes.OVAL:
203201
this.props.changeMode(Modes.BIT_OVAL);
204202
break;

src/helper/selectable-shapes.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
const selectablePaths = {
2+
dragon: 'M169.19262,341.94408c-5.80616,2.17958 -21.17199,0.24298 -33.38995,1.0916c-7.25679,0 -9.67935,-0.84862 -15.72487,-5.20415c-7.74276,-11.732 -18.51008,-29.51676 -23.10859,-48.2662c-1.20765,-6.17244 9.43637,-6.77446 4.23585,-12.70392c-5.32382,-8.95041 0.9683,-11.49264 3.26392,-11.97498c9.31669,0.23935 3.02457,20.92901 26.00986,15.36221c2.29925,-9.79903 -1.33096,-32.17867 4.71818,-38.95313c3.02457,19.96071 0.72532,26.25284 3.74989,32.29835c8.95403,-3.86956 12.09828,0.48596 14.87987,1.45426c2.54223,6.16882 7.98574,3.26392 8.71105,0.23935c-0.11968,-10.16169 -0.84499,-27.82315 0.60564,-39.55877c-3.14425,-1.93297 -5.80616,-7.86243 -3.50691,-18.2671c-0.36266,-0.9683 8.70743,-23.22464 -1.21128,-25.76687c-8.10541,2.54223 -11.61232,14.39754 -16.1528,19.33332c-3.77165,-11.7864 -7.26042,-25.55291 -7.97123,-44.80644c1.39623,-28.10239 14.28149,-28.10239 24.68253,-27.17036c-2.48421,-4.81248 -6.36465,-9.7809 -6.65841,-17.67234c-1.70812,-29.19037 5.90045,-48.59984 22.04963,-54.96812c-4.65653,7.60857 -4.96842,20.03325 -4.65653,24.06963c4.19233,15.99323 14.90526,28.87848 22.82209,30.74255c9.16438,-5.12436 13.82091,-13.81728 19.72136,-25.93007c2.17232,-4.50422 -2.02001,-24.68978 -0.15594,-36.79894c7.45263,-23.44586 28.41428,-34.47067 38.04286,-44.87534c-5.74451,15.68497 -11.49264,37.11083 -9.78452,42.85533c7.14437,18.01324 12.73293,31.67821 22.20557,47.04767c6.21234,-0.93203 11.02481,-6.98843 17.23352,-8.5406c-16.76932,25.30992 -3.10436,55.27638 -2.79247,57.45233c20.33788,-20.02962 35.24676,-43.94331 56.67262,-53.56826c25.62181,-25.93007 41.30316,-55.58827 65.83699,-89.12691c-2.7961,27.63819 -19.25353,67.23323 -29.50226,85.71067c-9.7809,20.64977 -19.25353,36.33111 -33.85053,58.92473c-17.90807,20.81296 -20.18556,24.60999 -26.83672,48.36411c0.23935,3.38723 4.23222,5.92946 7.01381,8.46807c-7.25679,1.81329 -8.70743,5.56681 -9.07371,11.37297c0,41.61504 5.32382,45.24525 5.20052,56.37524c-15.36221,32.41803 -28.67177,42.46004 -60.2448,65.565c-76.33595,21.41497 -51.90003,3.86956 -76.45563,-3.63021zM242.45,269.99185c3.089,-2.18347 3.8336,-19.71382 1.23123,-26.15118c-3.41142,-8.43867 -9.64814,-22.47456 -13.03123,-22.04882c-8.4,0.67715 -6.47716,12 -26,17.4c-2.36136,1.15845 -17.23312,6.73679 -30.28301,6.53392c-4.23102,-0.06578 -2.26453,29.16099 -0.51699,31.46608c5.4,7.12284 58.90584,-0.34765 68.6,-7.2z',
3+
sussy: 'm 77 0 h 28 a 20 20 0 0 1 20 20 v 0 a 20 20 0 0 1 -20 20 V 40 H 77 V 112 A 1 1 0 0 1 42 111 A 1 1 0 0 0 16 112 A 1 1 0 0 1 -18 111 V 74 H -29 C -35 74 -36 73 -36 67 V 5 C -36 -1 -35 -2 -29 -2 H -18 A 1 1 0 0 1 76 0',
4+
speechBubble: 'M204.14966,175.04472c-0.31482,-15.49173 8.58161,-20.45314 15.2824,-20.45314c8.15418,0 26.20534,-0.47063 40.10194,0c6.7857,0.22981 16.64329,5.37466 16.31655,20.45314c-0.30922,14.27018 -11.32079,18.61465 -16.43145,18.61465c-4.65217,0 -12.43125,0 -21.25748,0c-2.33362,0 -8.8706,12.31777 -19.5339,11.95015c-7.56289,-0.26073 4.2991,-11.95015 1.26396,-11.95015c-9.00032,0 -15.52291,-7.83267 -15.74202,-18.61465z',
5+
smile: 'M218.60708,180c0,-11.81499 9.57794,-21.39292 21.39292,-21.39292c11.81499,0 21.39292,9.57794 21.39292,21.39292c0,11.81499 -9.57794,21.39293 -21.39292,21.39293c-11.81499,0 -21.39292,-9.57794 -21.39292,-21.39293zM239.89701,196.60775c14.70959,0.07281 16.22782,-13.7612 16.22782,-13.7612h-31.54689c0,0 1.12947,13.69096 15.31907,13.7612zM247.80316,176.22994c1.59793,0 2.8933,-1.29538 2.8933,-2.8933c0,-1.59793 -1.29538,-2.8933 -2.8933,-2.8933c-1.59793,0 -2.8933,1.29538 -2.8933,2.8933c0,1.59793 1.29538,2.8933 2.8933,2.8933zM232.19685,176.22994c1.59793,0 2.8933,-1.29538 2.8933,-2.8933c0,-1.59793 -1.29538,-2.8933 -2.8933,-2.8933c-1.59793,0 -2.8933,1.29538 -2.8933,2.8933c0,1.59793 1.29538,2.8933 2.8933,2.8933z',
6+
frown: 'M218.60708,180c0,-11.81499 9.57794,-21.39292 21.39292,-21.39292c11.81499,0 21.39293,9.57794 21.39293,21.39292c0,11.81499 -9.57794,21.39292 -21.39293,21.39292c-11.81498,0 -21.39292,-9.57794 -21.39292,-21.39292zM247.80316,176.22993c1.59793,0 2.89331,-1.29538 2.89331,-2.8933c0,-1.59793 -1.29537,-2.89331 -2.89331,-2.89331c-1.59793,0 -2.8933,1.29538 -2.8933,2.89331c0,1.59793 1.29537,2.8933 2.8933,2.8933zM232.19685,176.22993c1.59793,0 2.8933,-1.29538 2.8933,-2.8933c0,-1.59793 -1.29538,-2.89331 -2.8933,-2.89331c-1.59793,0 -2.8933,1.29538 -2.8933,2.89331c0,1.59793 1.29538,2.8933 2.8933,2.8933zM226.26564,193.49228h28.1715c0,0 -1.35578,-10.96285 -14.49151,-10.90515c-12.67137,0.05566 -13.67999,10.90515 -13.67999,10.90515z',
7+
thinkingBubble: 'M181.625,163.75c0,-9.03599 8.31115,-16.7148 19.88037,-19.50356c3.78813,-8.33365 14.94537,-14.37144 28.11963,-14.37144c10.60583,0 19.90445,3.91305 25.10344,9.78682c1.5942,-0.18873 3.22977,-0.28682 4.89656,-0.28682c7.20482,0 13.82617,1.83268 19.04507,4.89724c0.96891,-0.09722 1.95499,-0.14724 2.95493,-0.14724c13.66905,0 24.75,9.34606 24.75,20.875c0,6.80117 -3.85625,12.84269 -9.82521,16.65396c2.12223,2.1898 3.32521,4.69056 3.32521,7.34604c0,8.62945 -12.70392,15.625 -28.375,15.625c-5.79983,0 -11.19324,-0.9582 -15.68664,-2.60279c-5.37837,3.48673 -12.44651,5.60279 -20.18836,5.60279c-2.14277,0 -4.23392,-0.1621 -6.25193,-0.4705c0.00128,0.04563 0.00193,0.09136 0.00193,0.13717c0,4.55635 -6.37994,8.25 -14.25,8.25c-7.87006,0 -14.25,-3.69365 -14.25,-8.25c0,-1.85573 1.0583,-3.56835 2.84455,-4.9466c-12.33446,-0.48405 -22.09455,-6.7775 -22.09455,-14.47006c0,-4.13493 2.81999,-7.8656 7.34397,-10.50709c-4.57145,-3.63277 -7.34397,-8.39897 -7.34397,-13.61791zM202.125,220.66667c0,2.96853 -3.52576,5.375 -7.875,5.375c-4.34924,0 -7.875,-2.40647 -7.875,-5.375c0,-2.96853 3.52576,-5.375 7.875,-5.375c4.34924,0 7.875,2.40647 7.875,5.375zM183.375,226c0,2.27818 -2.18261,4.125 -4.875,4.125c-2.69239,0 -4.875,-1.84682 -4.875,-4.125c0,-2.27818 2.18261,-4.125 4.875,-4.125c2.69239,0 4.875,1.84682 4.875,4.125z',
8+
codeblock: '',
9+
cloud: '',
10+
heart: '',
11+
check: '',
12+
cross: '',
13+
blank: '',
14+
};
15+
16+
// TODO: make icons easier to add
17+
const selectableShapes = [
18+
{
19+
id: "smile",
20+
name: "Smile",
21+
path: selectablePaths.smile,
22+
size: 37,
23+
icon: {
24+
x: -218.60707,
25+
y: -158.60707,
26+
width: 42.78585,
27+
height: 42.78585,
28+
viewBox: "-1,-1,44.78585,44.78585",
29+
strokeWidth: 3
30+
}
31+
},
32+
{
33+
id: "frown",
34+
name: "Frown",
35+
path: selectablePaths.frown,
36+
size: 37,
37+
icon: {
38+
x: -218.60707,
39+
y: -158.60707,
40+
width: 42.78585,
41+
height: 42.78585,
42+
viewBox: "-1,-1,44.78585,44.78585",
43+
strokeWidth: 3
44+
}
45+
},
46+
{
47+
id: "speechBubble",
48+
name: "Speech Bubble",
49+
path: selectablePaths.speechBubble,
50+
size: 50,
51+
icon: {
52+
x: -204.14153,
53+
y: -154.38241,
54+
width: 71.71694,
55+
height: 51.23518,
56+
viewBox: "-2,2,75.71694,55.23518",
57+
strokeWidth: 7
58+
}
59+
},
60+
{
61+
id: "thinkingBubble",
62+
name: "Thinking Bubble",
63+
path: selectablePaths.thinkingBubble,
64+
size: 65,
65+
icon: {
66+
x: -173.625,
67+
y: -129.875,
68+
width: 132.75,
69+
height: 100.25,
70+
viewBox: "0,0,132.75,100.25",
71+
strokeWidth: 8
72+
}
73+
},
74+
{
75+
id: "sussy",
76+
name: "Sussy",
77+
path: selectablePaths.sussy,
78+
size: 100,
79+
icon: {
80+
x: 0,
81+
y: 0,
82+
width: 20,
83+
height: 20,
84+
viewBox: "-36 -55 161 192",
85+
strokeWidth: 14
86+
}
87+
},
88+
{
89+
id: "dragon",
90+
name: "Dragon",
91+
path: selectablePaths.dragon,
92+
size: 100,
93+
icon: {
94+
x: -82.87288,
95+
y: -3,
96+
width: 302.64767,
97+
height: 345.05044,
98+
viewBox: "0,0,330.64767,360.05044",
99+
strokeWidth: 26
100+
}
101+
},
102+
];
103+
104+
export default selectableShapes;

0 commit comments

Comments
 (0)