Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jan 18, 2021
1 parent ef98110 commit fbfdc2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
21 changes: 8 additions & 13 deletions src/components/Artboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React, {
ForwardedRef,
forwardRef,
useCallback,
useEffect,
useImperativeHandle,
useRef,
useState,
} from "react";

Expand Down Expand Up @@ -127,7 +125,7 @@ export const Artboard = forwardRef(function Artboard(
if (canvas && history) {
history.pushState(canvas);
}
}, [context, canvas]);
}, [context, canvas, history]);

const gotRef = useCallback(
(canvasRef: HTMLCanvasElement) => {
Expand All @@ -139,12 +137,9 @@ export const Artboard = forwardRef(function Artboard(
const ctx = canvasRef.getContext("2d");
setCanvas(canvasRef);
setContext(ctx);
if (ctx) {
if (history) {
console.log("setting context");
history.setContext(ctx);
history.pushState(canvasRef);
}
if (ctx && history) {
history.setContext(ctx);
history.pushState(canvasRef);
}
},
[history]
Expand All @@ -158,7 +153,7 @@ export const Artboard = forwardRef(function Artboard(
endStroke();
}
},
[mouseMove, drawing]
[drawing, mouseDown, endStroke]
);

const mouseLeave = useCallback(
Expand All @@ -169,13 +164,13 @@ export const Artboard = forwardRef(function Artboard(
continueStroke(getMousePoint(event));
endStroke();
},
[drawing]
[continueStroke, drawing, endStroke]
);

useImperativeHandle(
ref,
() => ({
download: (filename: string = "image.png", type?: string) => {
download: (filename = "image.png", type?: string) => {
if (!canvas) {
return;
}
Expand All @@ -187,7 +182,7 @@ export const Artboard = forwardRef(function Artboard(
clear,
getImageAsDataUri: (type?: string) => canvas?.toDataURL(type),
}),
[canvas]
[canvas, clear]
);

return (
Expand Down
8 changes: 3 additions & 5 deletions src/tools/brush/useBrush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function makeBrush(
varyBrightness: number
): Brush {
const brush: Brush = [];
let bristleCount = Math.round(strokeWidth / 3);
const bristleCount = Math.round(strokeWidth / 3);
const gap = strokeWidth / bristleCount;
for (let i = 0; i < bristleCount; i++) {
const distance =
Expand Down Expand Up @@ -106,14 +106,12 @@ export function useBrush({
const lastPoint = useRef<Point>();

const startStroke = useCallback(
(point: Point, context: CanvasRenderingContext2D) => {
// context.globalCompositeOperation = "darken";

(point: Point) => {
currentAngle.current = undefined;
setBrush(makeBrush(strokeWidth, color, varyBrightness));
lastPoint.current = point;
},
[setBrush, strokeWidth, color]
[setBrush, strokeWidth, color, varyBrightness]
);

const continueStroke = useCallback(
Expand Down

0 comments on commit fbfdc2f

Please sign in to comment.