forked from TurboWarp/scratch-paint
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmode-tools.jsx
More file actions
984 lines (970 loc) · 47.1 KB
/
mode-tools.jsx
File metadata and controls
984 lines (970 loc) · 47.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
/* eslint-disable no-case-declarations */
import classNames from 'classnames';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import React from 'react';
import Dropdown from '../dropdown/dropdown.jsx';
import MediaQuery from 'react-responsive';
import layout from '../../lib/layout-constants';
import { changeBrushSize, changeSimplifySize, setBrushType } from '../../reducers/brush-mode';
import { changeBrushSize as changeEraserSize, changeSimplifySize as changeEraserSimplifySize } from '../../reducers/eraser-mode';
import { changeSimplifySize as changePenSimplifySize } from '../../reducers/pen-mode';
import { changeRoundedRectCornerSize } from '../../reducers/rounded-rect-mode';
import { changeRoundedCornerSize } from '../../reducers/rect-mode';
import { changeTrianglePolyCount, changeTrianglePointCount } from '../../reducers/triangle-mode';
import { changeCurrentlySelectedShape } from '../../reducers/sussy-mode';
import { changeBitBrushSize } from '../../reducers/bit-brush-size';
import { changeBitEraserSize } from '../../reducers/bit-eraser-size';
import { setShapesFilled } from '../../reducers/fill-bitmap-shapes';
import { setTextAlignment } from '../../reducers/text-alignment';
import FontDropdown from '../../containers/font-dropdown.jsx';
import LiveInputHOC from '../forms/live-input-hoc.jsx';
import Label from '../forms/label.jsx';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
import Input from '../forms/input.jsx';
import InputGroup from '../input-group/input-group.jsx';
import ButtonGroup from '../button-group/button-group.jsx';
import Button from '../button/button.jsx';
import LabeledIconButton from '../labeled-icon-button/labeled-icon-button.jsx';
import Modes from '../../lib/modes';
import Formats, { isBitmap, isVector } from '../../lib/format';
import { hideLabel } from '../../lib/hide-label';
import styles from './mode-tools.css';
import { MAX_STROKE_WIDTH } from '../../reducers/stroke-width';
import {
selectableShapes as sussyToolShapes,
categories as sussyToolCategories,
generateShapeSVG as generateSussyShapeSVG,
categorizeShapes as categorizeSussyShapes,
} from '../../helper/selectable-shapes.js';
import copyIcon from './icons/copy.svg';
import cutIcon from './icons/cut.svg';
import pasteIcon from './icons/paste.svg';
import deleteIcon from './icons/delete.svg';
import roundLine from './icons/round-line.svg';
import squareLine from './icons/square-line.svg';
import miterLineJoin from './icons/miter-line-join.svg';
import roundLineJoin from './icons/round-line-join.svg';
import bevelLineJoin from './icons/bevel-line-join.svg';
import shapeMergeIcon from './icons/merge.svg';
import shapeMaskIcon from './icons/mask.svg';
import shapeSubtractIcon from './icons/subtract.svg';
import shapeFilterIcon from './icons/filter.svg';
import alignLeftIcon from './icons/alignLeft.svg';
import alignRightIcon from './icons/alignRight.svg';
import alignCenterIcon from './icons/alignCenter.svg';
import textToShapesIcon from './icons/text-to-shapes.svg';
import bitBrushIcon from '../bit-brush-mode/brush.svg';
import bitEraserIcon from '../bit-eraser-mode/eraser.svg';
import bitLineIcon from '../bit-line-mode/line.svg';
import brushIcon from '../brush-mode/brush.svg';
import curvedPointIcon from './icons/curved-point.svg';
import eraserIcon from '../eraser-mode/eraser.svg';
import roundedRectIcon from '../rounded-rect-mode/rounded-rectangle.svg';
import triangleIcon from '../triangle-mode/triangle.svg';
import triangleSpikeRatioIcon from './icons/triangle-spike-ratio.svg';
import flipHorizontalIcon from './icons/flip-horizontal.svg';
import flipVerticalIcon from './icons/flip-vertical.svg';
import centerSelectionIcon from './icons/centerSelection.svg';
import straightPointIcon from './icons/straight-point.svg';
import bitOvalIcon from '../bit-oval-mode/oval.svg';
import bitRectIcon from '../bit-rect-mode/rectangle.svg';
import bitOvalOutlinedIcon from '../bit-oval-mode/oval-outlined.svg';
import bitRectOutlinedIcon from '../bit-rect-mode/rectangle-outlined.svg';
const LiveInput = LiveInputHOC(Input);
const ModeToolsComponent = props => {
const messages = defineMessages({
brushSize: {
defaultMessage: 'Size',
description: 'Label for the brush size input',
id: 'paint.modeTools.brushSize'
},
brushSimplify: {
defaultMessage: 'Smoothing',
description: 'Label for the brush smoothing input, higher numbers control how much the drawn line will be corrected',
id: 'paint.modeTools.brushSimplify'
},
eraserSize: {
defaultMessage: 'Eraser size',
description: 'Label for the eraser size input',
id: 'paint.modeTools.eraserSize'
},
eraserSimplify: {
defaultMessage: 'Smoothing',
description: 'Label for the eraser smoothing input, higher numbers control how much the drawn line will be corrected',
id: 'paint.modeTools.eraserSimplify'
},
brushCircle: {
defaultMessage: 'Circle Brush',
description: 'Label for the circle brush shape',
id: 'paint.modeTools.circleSquare'
},
brushSquare: {
defaultMessage: 'Square Brush',
description: 'Label for the square brush shape',
id: 'paint.modeTools.brushSquare'
},
roundedCornerSize: {
defaultMessage: 'Rounded corner size',
description: 'Label for the Rounded corner size input',
id: 'paint.modeTools.roundedCornerSize'
},
currentSideCount: {
defaultMessage: 'Polygon side count',
description: 'Label for the Polygon side count input',
id: 'paint.modeTools.currentSideCount'
},
spokeRatio: {
defaultMessage: 'Star spoke ratio',
description: 'Label for the Star spoke ratio input, controls the size of the spokes on a star',
id: 'paint.modeTools.spikeRatio'
},
penSimplify: {
defaultMessage: 'Smoothing',
description: 'Label for the pen smoothing input, higher numbers control how much the drawn line will be corrected',
id: 'paint.modeTools.penSimplify'
},
copy: {
defaultMessage: 'Copy',
description: 'Label for the copy button',
id: 'paint.modeTools.copy'
},
cut: {
defaultMessage: 'Cut',
description: 'Label for the cut button',
id: 'paint.modeTools.cut'
},
paste: {
defaultMessage: 'Paste',
description: 'Label for the paste button',
id: 'paint.modeTools.paste'
},
delete: {
defaultMessage: 'Delete',
description: 'Label for the delete button',
id: 'paint.modeTools.delete'
},
curved: {
defaultMessage: 'Curved',
description: 'Label for the button that converts selected points to curves',
id: 'paint.modeTools.curved'
},
pointed: {
defaultMessage: 'Pointed',
description: 'Label for the button that converts selected points to sharp points',
id: 'paint.modeTools.pointed'
},
thickness: {
defaultMessage: 'Thickness',
description: 'Label for the number input to choose the line thickness',
id: 'paint.modeTools.thickness'
},
flipHorizontal: {
defaultMessage: 'Flip Horizontal',
description: 'Label for the button to flip the image horizontally',
id: 'paint.modeTools.flipHorizontal'
},
flipVertical: {
defaultMessage: 'Flip Vertical',
description: 'Label for the button to flip the image vertically',
id: 'paint.modeTools.flipVertical'
},
filled: {
defaultMessage: 'Filled',
description: 'Label for the button that sets the bitmap rectangle/oval mode to draw outlines',
id: 'paint.modeTools.filled'
},
outlined: {
defaultMessage: 'Outlined',
description: 'Label for the button that sets the bitmap rectangle/oval mode to draw filled-in shapes',
id: 'paint.modeTools.outlined'
},
movementCenter: {
defaultMessage: 'Center',
description: 'Label for the button that moves the selected objects to the center of the canvas',
id: 'paint.modeTools.movementCenter'
}
});
switch (props.mode) {
case Modes.BRUSH:
/* falls through */
case Modes.BIT_BRUSH:
/* falls through */
case Modes.BIT_LINE:
{
const currentIcon = isVector(props.format) ? brushIcon :
props.mode === Modes.BIT_LINE ? bitLineIcon : bitBrushIcon;
const currentBrushValue = isBitmap(props.format) ? props.bitBrushSize : props.brushValue;
const currentSimplifyValue = props.simplifyValue;
const changeFunction = isBitmap(props.format) ? props.onBitBrushSliderChange : props.onBrushSliderChange;
const changeFunctionSimplify = props.onSimplifySliderChange;
const currentMessage = props.mode === Modes.BIT_LINE ? messages.thickness : messages.brushSize;
const hasSimplifyOption = props.mode === Modes.BRUSH;
return (
<div className={classNames(props.className, styles.modeTools)}>
<div>
<img
alt={props.intl.formatMessage(currentMessage)}
title={props.intl.formatMessage(currentMessage)}
className={styles.modeToolsIcon}
draggable={false}
src={currentIcon}
/>
</div>
<LiveInput
range
small
max={MAX_STROKE_WIDTH}
min="1"
type="number"
value={currentBrushValue}
onSubmit={changeFunction}
/>
{hasSimplifyOption && (
<Label text={props.intl.formatMessage(messages.brushSimplify)} style={{ marginLeft: 'calc(2 * .25rem)' }}>
<LiveInput
range
small
max={1000}
min="0"
type="number"
value={currentSimplifyValue}
onSubmit={changeFunctionSimplify}
/>
</Label>
)}
{/* TODO replace this with a dropdown when we add more brush shapes */}
{hasSimplifyOption && (
<InputGroup>
<ButtonGroup>
<Button
className={
classNames(styles.buttonGroupButton)
}
onClick={() => props.onBrushChange("CIRCLE")}
>
<img
alt={props.intl.formatMessage(messages.brushCircle)}
className={styles.buttonGroupButtonIcon}
draggable={false}
src={"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCBmaWxsPSIjMDBjM2ZmIiB3aWR0aD0iMTUiIGhlaWdodD0iMTUiIHJ4PSIxMDAiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDIuNSAyLjUpIi8+PC9zdmc+"}
/>
</Button>
<Button
className={
classNames(styles.buttonGroupButton)
}
onClick={() => props.onBrushChange("SQUARE")}
>
<img
alt={props.intl.formatMessage(messages.brushSquare)}
className={styles.buttonGroupButtonIcon}
draggable={false}
src={"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCBmaWxsPSIjMDBjM2ZmIiB3aWR0aD0iMTUiIGhlaWdodD0iMTUiIHJ4PSIyIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgyLjUgMi41KSIvPjwvc3ZnPg=="}
/>
</Button>
</ButtonGroup>
</InputGroup>
)}
</div>
);
}
case Modes.BIT_ERASER:
/* falls through */
case Modes.ERASER:
{
const currentIcon = isVector(props.format) ? eraserIcon : bitEraserIcon;
const currentEraserValue = isBitmap(props.format) ? props.bitEraserSize : props.eraserValue;
const currentEraserSimplifyValue = props.eraserSimplifyValue;
const changeFunction = isBitmap(props.format) ? props.onBitEraserSliderChange : props.onEraserSliderChange;
const changeFunctionSimplify = props.onEraserSimplifySliderChange;
const hasSimplifyOption = props.mode === Modes.ERASER;
return (
<div className={classNames(props.className, styles.modeTools)}>
<div>
<img
alt={props.intl.formatMessage(messages.eraserSize)}
title={props.intl.formatMessage(messages.eraserSize)}
className={styles.modeToolsIcon}
draggable={false}
src={currentIcon}
/>
</div>
<LiveInput
range
small
max={MAX_STROKE_WIDTH}
min="1"
type="number"
value={currentEraserValue}
onSubmit={changeFunction}
/>
{hasSimplifyOption && (
<Label text={props.intl.formatMessage(messages.eraserSimplify)} style={{ marginLeft: 'calc(2 * .25rem)' }}>
<LiveInput
range
small
max={1000}
min="0"
type="number"
value={currentEraserSimplifyValue}
onSubmit={changeFunctionSimplify}
/>
</Label>
)}
{/* TODO replace this with a dropdown when we add more brush shapes */}
{hasSimplifyOption && (
<InputGroup>
<ButtonGroup>
<Button
className={
classNames(styles.buttonGroupButton)
}
onClick={() => props.onBrushChange("CIRCLE")}
>
<img
alt={props.intl.formatMessage(messages.brushCircle)}
className={styles.buttonGroupButtonIcon}
draggable={false}
src={"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCBmaWxsPSIjMDBjM2ZmIiB3aWR0aD0iMTUiIGhlaWdodD0iMTUiIHJ4PSIxMDAiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDIuNSAyLjUpIi8+PC9zdmc+"}
/>
</Button>
<Button
className={
classNames(styles.buttonGroupButton)
}
onClick={() => props.onBrushChange("SQUARE")}
>
<img
alt={props.intl.formatMessage(messages.brushSquare)}
className={styles.buttonGroupButtonIcon}
draggable={false}
src={"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCBmaWxsPSIjMDBjM2ZmIiB3aWR0aD0iMTUiIGhlaWdodD0iMTUiIHJ4PSIyIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgyLjUgMi41KSIvPjwvc3ZnPg=="}
/>
</Button>
</ButtonGroup>
</InputGroup>
)}
</div>
)
}
case Modes.ROUNDED_RECT:
/* falls through */
case Modes.RECT:
{
// NOTE: BIT_RECT doesnt use Path, so this can't be added there the same way as RECT has it.
const currentCornerValue = props.mode === Modes.ROUNDED_RECT ? props.roundedRectCornerValue : props.roundedCornerValue;
const changeFunction = props.mode === Modes.ROUNDED_RECT ? props.onRoundedRectCornerSliderChange : props.onRoundedCornerSliderChange;
return (
<div className={classNames(props.className, styles.modeTools)}>
<div>
<img
alt={props.intl.formatMessage(messages.roundedCornerSize)}
title={props.intl.formatMessage(messages.roundedCornerSize)}
className={styles.modeToolsIcon}
draggable={false}
src={roundedRectIcon}
/>
</div>
<LiveInput
range
small
min={0}
max={1000}
type="number"
value={currentCornerValue}
onSubmit={changeFunction}
/>
</div>
);
}
case Modes.TRIANGLE:
{
const currentSideValue = props.trianglePolyValue;
const currentPointValue = props.trianglePointValue;
const changeFunction = props.onPolyCountSliderChange;
const changeFunctionPoint = props.onPointCountSliderChange;
return (
<div className={classNames(props.className, styles.modeTools)}>
<div>
<img
alt={props.intl.formatMessage(messages.currentSideCount)}
title={props.intl.formatMessage(messages.currentSideCount)}
className={styles.modeToolsIcon}
draggable={false}
src={triangleIcon}
/>
</div>
<LiveInput
range
small
max={1000}
min="3"
type="number"
value={currentSideValue}
onSubmit={changeFunction}
/>
<div>
<img
alt={props.intl.formatMessage(messages.spokeRatio)}
title={props.intl.formatMessage(messages.spokeRatio)}
className={styles.modeToolsIcon}
draggable={false}
src={triangleSpikeRatioIcon}
/>
</div>
<LiveInput
range
small
max={1000}
min="0" // Spike ratio is limited to 0.01, but setting that here makes the number input arrows work really ugly
step="0.1"
type="number"
value={currentPointValue}
onSubmit={changeFunctionPoint}
/>
</div>
);
}
case Modes.SUSSY:
{
const currentlySelectedShape = props.currentlySelectedShape;
const changeFunction = props.onCurrentlySelectedShapeChange;
const selectedShapeObject = sussyToolShapes
.filter(shape => shape.id === currentlySelectedShape)[0];
const categorizedShapes = categorizeSussyShapes(sussyToolShapes);
const selectableShapesList = (
<InputGroup
className={classNames(
styles.modDashedBorder,
styles.dropItemShapeToolMenu,
styles.dropdownMaxItemList
)}
>
{Object.keys(categorizedShapes).map(categoryId => categorizedShapes[categoryId].length === 0 ?
(<React.Fragment key={categoryId} />) : (<React.Fragment key={categoryId}>
<p className={classNames(styles.dropItemShapeToolLabel)}>
{sussyToolCategories[categoryId]}
</p>
{categorizedShapes[categoryId].map(shape => (
<LabeledIconButton
key={shape.id}
className={classNames(styles.dropItemShapeTool)}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={`data:image/svg+xml,${encodeURIComponent(generateSussyShapeSVG(shape))}`}
title={shape.name}
onClick={() => changeFunction(shape.id)}
/>
))}
</React.Fragment>))}
</InputGroup>
);
return (
<div className={classNames(props.className, styles.modeTools)}>
<Dropdown
className={styles.modUnselect}
enterExitTransitionDurationMs={20}
popoverContent={
<InputGroup
className={styles.modContextMenu}
rtl={props.rtl}
>
{selectableShapesList}
</InputGroup>
}
tipSize={.01}
>
<img
src={`data:image/svg+xml,${encodeURIComponent(generateSussyShapeSVG(selectedShapeObject))}`}
alt={selectedShapeObject.name}
title={selectedShapeObject.name}
height={16}
/>
</Dropdown>
</div>
);
}
case Modes.PEN:
{
const currentPenSimplifyValue = props.penSimplifyValue;
const changeFunctionSimplify = props.onPenSimplifySliderChange;
return (
<div className={classNames(props.className, styles.modeTools)}>
<Label text={props.intl.formatMessage(messages.eraserSimplify)} style={{ marginLeft: 'calc(2 * .25rem)' }}>
<LiveInput
range
small
max={1000}
min="0"
type="number"
value={currentPenSimplifyValue}
onSubmit={changeFunctionSimplify}
/>
</Label>
</div>
);
}
case Modes.RESHAPE:
const lineJoinReshape = (
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
disabled={props.hasSelectedMiterLineJoin}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={miterLineJoin}
title={'Spiked'}
onClick={props.onMiterLineJoin}
/>
<LabeledIconButton
disabled={props.hasSelectedRoundLineJoin}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={roundLineJoin}
title={'Rounded'}
onClick={props.onRoundLineJoin}
/>
<LabeledIconButton
disabled={props.hasSelectedBevelLineJoin}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={bevelLineJoin}
title={'Beveled'}
onClick={props.onBevelLineJoin}
/>
</InputGroup>
);
const deleteSelectedNodes = (
<InputGroup className={classNames(styles.modLabeledIconHeight)}>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={deleteIcon}
title={props.intl.formatMessage(messages.delete)}
onClick={props.onDelete}
/>
</InputGroup>
);
return (
<div className={classNames(props.className, styles.modeTools)}>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
disabled={!props.hasSelectedUncurvedPoints}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={curvedPointIcon}
title={props.intl.formatMessage(messages.curved)}
onClick={props.onCurvePoints}
/>
<LabeledIconButton
disabled={!props.hasSelectedUnpointedPoints}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={straightPointIcon}
title={props.intl.formatMessage(messages.pointed)}
onClick={props.onPointPoints}
/>
</InputGroup>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
disabled={props.hasSelectedRoundEnds}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={roundLine}
title={'Rounded'}
onClick={props.onRoundEnds}
/>
<LabeledIconButton
disabled={props.hasSelectedSquareEnds}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={squareLine}
title={'Squared'}
onClick={props.onSquareEnds}
/>
</InputGroup>
<MediaQuery minWidth={layout.fullSizeEditorMinWidthExtraToolsCollapsed}>
{lineJoinReshape}
{deleteSelectedNodes}
</MediaQuery>
<MediaQuery maxWidth={layout.fullSizeEditorMinWidthExtraToolsCollapsed - 1}>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<Dropdown
className={styles.modUnselect}
enterExitTransitionDurationMs={20}
popoverContent={
<InputGroup
className={styles.modContextMenu}
rtl={props.rtl}
>
{lineJoinReshape}
{deleteSelectedNodes}
</InputGroup>
}
tipSize={.01}
>
More
</Dropdown>
</InputGroup>
</MediaQuery>
</div>
);
case Modes.BIT_SELECT:
/* falls through */
case Modes.SELECT:
const reshapingMethods = props.format.startsWith("BITMAP") ? null : (
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={shapeMergeIcon}
title={'Merge'}
onClick={props.onMergeShape}
/>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={shapeMaskIcon}
title={'Mask'}
onClick={props.onMaskShape}
/>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={shapeSubtractIcon}
title={'Subtract'}
onClick={props.onSubtractShape}
/>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={shapeFilterIcon}
title={'Filter'}
onClick={props.onExcludeShape}
/>
</InputGroup>
);
const flipOptions = (
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
hideLabel={props.intl.locale !== 'en'}
imgSrc={flipHorizontalIcon}
title={props.intl.formatMessage(messages.flipHorizontal)}
onClick={props.onFlipHorizontal}
/>
<LabeledIconButton
hideLabel={props.intl.locale !== 'en'}
imgSrc={flipVerticalIcon}
title={props.intl.formatMessage(messages.flipVertical)}
onClick={props.onFlipVertical}
/>
</InputGroup>
);
const movementOptions = (
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
hideLabel={props.intl.locale !== 'en'}
imgSrc={centerSelectionIcon}
title={props.intl.formatMessage(messages.movementCenter)}
onClick={props.onCenterSelection}
/>
</InputGroup>
);
return (
<div className={classNames(props.className, styles.modeTools)}>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={copyIcon}
title={props.intl.formatMessage(messages.copy)}
onClick={props.onCopyToClipboard}
/>
<LabeledIconButton
disabled={!(props.clipboardItems.length > 0)}
hideLabel={hideLabel(props.intl.locale)}
imgSrc={pasteIcon}
title={props.intl.formatMessage(messages.paste)}
onClick={props.onPasteFromClipboard}
/>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={cutIcon}
title={props.intl.formatMessage(messages.cut)}
onClick={props.onCutToClipboard}
/>
</InputGroup>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
hideLabel={hideLabel(props.intl.locale)}
imgSrc={deleteIcon}
title={props.intl.formatMessage(messages.delete)}
onClick={props.onDelete}
/>
</InputGroup>
<MediaQuery minWidth={layout.fullSizeEditorMinWidthExtraToolsCollapsed}>
{/* Flip Options */}
{flipOptions}
{/* Movement Options */}
{movementOptions}
{/* Reshaping Methods */}
{(props.mode === Modes.SELECT) ? (
<MediaQuery minWidth={layout.fullSizeEditorMinWidthExtraTools}>
{reshapingMethods}
</MediaQuery>
) : null}
{(props.mode === Modes.SELECT) ? (
<MediaQuery maxWidth={layout.fullSizeEditorMinWidthExtraTools - 1}>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<Dropdown
className={styles.modUnselect}
enterExitTransitionDurationMs={20}
popoverContent={
<InputGroup
className={styles.modContextMenu}
rtl={props.rtl}
>
{reshapingMethods}
</InputGroup>
}
tipSize={.01}
>
More
</Dropdown>
</InputGroup>
</MediaQuery>
) : null}
</MediaQuery>
<MediaQuery maxWidth={layout.fullSizeEditorMinWidthExtraToolsCollapsed - 1}>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<Dropdown
className={styles.modUnselect}
enterExitTransitionDurationMs={20}
popoverContent={
<InputGroup
className={styles.modContextMenu}
rtl={props.rtl}
>
{flipOptions}
{movementOptions}
{reshapingMethods}
</InputGroup>
}
tipSize={.01}
>
More
</Dropdown>
</InputGroup>
</MediaQuery>
</div>
);
case Modes.BIT_TEXT:
/* falls through */
case Modes.TEXT:
return (
<div className={classNames(props.className, styles.modeTools)}>
<InputGroup className={classNames(styles.modDashedBorder)}>
<FontDropdown
onUpdateImage={props.onUpdateImage}
onManageFonts={props.onManageFonts}
/>
</InputGroup>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
hideLabel
imgSrc={alignLeftIcon}
title={'Left Align'}
onClick={props.onTextAlignLeft}
/>
<LabeledIconButton
hideLabel
imgSrc={alignCenterIcon}
title={'Center Align'}
onClick={props.onTextAlignCenter}
/>
<LabeledIconButton
hideLabel
imgSrc={alignRightIcon}
title={'Right Align'}
onClick={props.onTextAlignRight}
/>
</InputGroup>
<InputGroup className={classNames(styles.modDashedBorder, styles.modLabeledIconHeight)}>
<LabeledIconButton
imgSrc={textToShapesIcon}
title={'Convert'}
onClick={props.onTextAlignLeft}
/>
</InputGroup>
</div>
);
case Modes.BIT_RECT:
/* falls through */
case Modes.BIT_OVAL:
{
const fillIcon = props.mode === Modes.BIT_RECT ? bitRectIcon : bitOvalIcon;
const outlineIcon = props.mode === Modes.BIT_RECT ? bitRectOutlinedIcon : bitOvalOutlinedIcon;
return (
<div className={classNames(props.className, styles.modeTools)}>
<InputGroup>
<LabeledIconButton
highlighted={props.fillBitmapShapes}
imgSrc={fillIcon}
title={props.intl.formatMessage(messages.filled)}
onClick={props.onFillShapes}
/>
</InputGroup>
<InputGroup>
<LabeledIconButton
highlighted={!props.fillBitmapShapes}
imgSrc={outlineIcon}
title={props.intl.formatMessage(messages.outlined)}
onClick={props.onOutlineShapes}
/>
</InputGroup>
{props.fillBitmapShapes ? null : (
<InputGroup>
<Label text={props.intl.formatMessage(messages.thickness)}>
<LiveInput
range
small
max={MAX_STROKE_WIDTH}
min="1"
type="number"
value={props.bitBrushSize}
onSubmit={props.onBitBrushSliderChange}
/>
</Label>
</InputGroup>)
}
</div>
);
}
case Modes.ARROW:
{
return (
<div className={classNames(props.className, styles.modeTools)}>
<span>{`Hold Alt + Shift to resize arrow tip`}</span>
</div>
);
}
default:
// Leave empty for now, if mode not supported
return (
<div className={classNames(props.className, styles.modeTools)} />
);
}
};
ModeToolsComponent.propTypes = {
bitBrushSize: PropTypes.number,
bitEraserSize: PropTypes.number,
brushValue: PropTypes.number,
simplifyValue: PropTypes.number,
className: PropTypes.string,
clipboardItems: PropTypes.arrayOf(PropTypes.array),
eraserValue: PropTypes.number,
eraserSimplifyValue: PropTypes.number,
brushType: PropTypes.string,
penSimplifyValue: PropTypes.number,
roundedCornerValue: PropTypes.number,
roundedRectCornerValue: PropTypes.number,
trianglePolyValue: PropTypes.number,
trianglePointValue: PropTypes.number,
currentlySelectedShape: PropTypes.string,
fillBitmapShapes: PropTypes.bool,
format: PropTypes.oneOf(Object.keys(Formats)),
hasSelectedUncurvedPoints: PropTypes.bool,
hasSelectedUnpointedPoints: PropTypes.bool,
intl: intlShape.isRequired,
mode: PropTypes.string.isRequired,
onBitBrushSliderChange: PropTypes.func.isRequired,
onBitEraserSliderChange: PropTypes.func.isRequired,
onBrushSliderChange: PropTypes.func.isRequired,
onSimplifySliderChange: PropTypes.func.isRequired,
onCopyToClipboard: PropTypes.func.isRequired,
onCutToClipboard: PropTypes.func.isRequired,
onCurvePoints: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
onEraserSliderChange: PropTypes.func,
onBrushChange: PropTypes.func,
onEraserSimplifySliderChange: PropTypes.func,
onPenSimplifySliderChange: PropTypes.func,
onFillShapes: PropTypes.func.isRequired,
onFlipHorizontal: PropTypes.func.isRequired,
onFlipVertical: PropTypes.func.isRequired,
onCenterSelection: PropTypes.func.isRequired,
onManageFonts: PropTypes.func,
onOutlineShapes: PropTypes.func.isRequired,
onPasteFromClipboard: PropTypes.func.isRequired,
onPointPoints: PropTypes.func.isRequired,
onUpdateImage: PropTypes.func.isRequired,
onMergeShape: PropTypes.func.isRequired,
onMaskShape: PropTypes.func.isRequired,
onSubtractShape: PropTypes.func.isRequired,
onExcludeShape: PropTypes.func.isRequired
};
const mapStateToProps = state => ({
mode: state.scratchPaint.mode,
format: state.scratchPaint.format,
fillBitmapShapes: state.scratchPaint.fillBitmapShapes,
bitBrushSize: state.scratchPaint.bitBrushSize,
bitEraserSize: state.scratchPaint.bitEraserSize,
brushValue: state.scratchPaint.brushMode.brushSize,
simplifyValue: state.scratchPaint.brushMode.simplifySize,
clipboardItems: state.scratchPaint.clipboard.items,
eraserValue: state.scratchPaint.eraserMode.brushSize,
eraserSimplifyValue: state.scratchPaint.eraserMode.simplifySize,
brushType: state.scratchPaint.brushType,
penSimplifyValue: state.scratchPaint.penMode.simplifySize,
roundedRectCornerValue: state.scratchPaint.roundedRectMode.roundedCornerSize,
roundedCornerValue: state.scratchPaint.rectMode.roundedCornerSize,
trianglePolyValue: state.scratchPaint.triangleMode.trianglePolyCount,
trianglePointValue: state.scratchPaint.triangleMode.trianglePointCount,
currentlySelectedShape: state.scratchPaint.sussyMode.shape
});
const mapDispatchToProps = dispatch => ({
onBrushSliderChange: brushSize => {
dispatch(changeBrushSize(brushSize));
},
onSimplifySliderChange: brushSize => {
dispatch(changeSimplifySize(brushSize));
},
onRoundedRectCornerSliderChange: roundedCornerSize => {
dispatch(changeRoundedRectCornerSize(roundedCornerSize));
},
onRoundedCornerSliderChange: roundedCornerSize => {
dispatch(changeRoundedCornerSize(roundedCornerSize));
},
onPolyCountSliderChange: polyCount => {
dispatch(changeTrianglePolyCount(polyCount));
},
onPointCountSliderChange: polyCount => {
dispatch(changeTrianglePointCount(polyCount));
},
onCurrentlySelectedShapeChange: shape => {
dispatch(changeCurrentlySelectedShape(shape));
},
onBitBrushSliderChange: bitBrushSize => {
dispatch(changeBitBrushSize(bitBrushSize));
},
onBitEraserSliderChange: eraserSize => {
dispatch(changeBitEraserSize(eraserSize));
},
onEraserSliderChange: eraserSize => {
dispatch(changeEraserSize(eraserSize));
},
onEraserSimplifySliderChange: eraserSize => {
dispatch(changeEraserSimplifySize(eraserSize));
},
onBrushChange: type => {
dispatch(setBrushType(type));
},
onPenSimplifySliderChange: eraserSize => {
dispatch(changePenSimplifySize(eraserSize));
},
onFillShapes: () => {
dispatch(setShapesFilled(true));
},
onOutlineShapes: () => {
dispatch(setShapesFilled(false));
},
onTextAlignLeft: () => {
dispatch(setTextAlignment("left"));
},
onTextAlignRight: () => {
dispatch(setTextAlignment("right"));
},
onTextAlignCenter: () => {
dispatch(setTextAlignment("center"));
},
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(injectIntl(ModeToolsComponent));