Skip to content

Commit

Permalink
feat(gui): add download button to mask (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 14, 2023
1 parent c61f200 commit 3544e23
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions gui/src/components/input/MaskCanvas.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { doesExist, Maybe, mustExist } from '@apextoaster/js-utils';
import { FormatColorFill, Gradient, InvertColors, Undo } from '@mui/icons-material';
import { Download, FormatColorFill, Gradient, InvertColors, Save, Undo } from '@mui/icons-material';
import { Button, Stack, Typography } from '@mui/material';
import { throttle } from 'lodash';
import React, { RefObject, useContext, useEffect, useMemo, useRef } from 'react';
Expand Down Expand Up @@ -251,6 +251,27 @@ export function MaskCanvas(props: MaskCanvasProps) {
};

return <Stack spacing={2}>
<Stack direction='row' spacing={2}>
<Button
variant='outlined'
startIcon={<Download />}
onClick={() => {
if (doesExist(maskRef.current)) {
const data = maskRef.current.toDataURL('image/png');
const link = document.createElement('a');

link.setAttribute('download', 'mask.png');
link.setAttribute('href', data.replace('image/png', 'image/octet-stream'));
link.click();
}
}}
/>
<Button
variant='outlined'
startIcon={<Undo />}
onClick={() => drawUndo()}
/>
</Stack>
<canvas
ref={brushRef}
height={params.height.default}
Expand Down Expand Up @@ -326,11 +347,6 @@ export function MaskCanvas(props: MaskCanvasProps) {
/>
</Stack>
<Stack direction='row' spacing={2}>
<Button
variant='outlined'
startIcon={<Undo />}
onClick={() => drawUndo()}
/>
<Button
variant='outlined'
startIcon={<FormatColorFill />}
Expand Down

0 comments on commit 3544e23

Please sign in to comment.