fix(style): brush can not fully paint the image
This commit is contained in:
@@ -20,6 +20,7 @@ type CanvasImageEditorProps = {
|
|||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
imguid: string | number;
|
imguid: string | number;
|
||||||
onSave: (imageData: { mask: string | null; img: string }) => void;
|
onSave: (imageData: { mask: string | null; img: string }) => void;
|
||||||
|
onScaleImageSize?: (data: { width: number; height: number }) => void;
|
||||||
uploadButton: React.ReactNode;
|
uploadButton: React.ReactNode;
|
||||||
imageStatus: {
|
imageStatus: {
|
||||||
isOriginal: boolean;
|
isOriginal: boolean;
|
||||||
@@ -34,6 +35,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
disabled,
|
disabled,
|
||||||
imageStatus,
|
imageStatus,
|
||||||
onSave,
|
onSave,
|
||||||
|
onScaleImageSize,
|
||||||
imguid,
|
imguid,
|
||||||
uploadButton
|
uploadButton
|
||||||
}) => {
|
}) => {
|
||||||
@@ -110,8 +112,8 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
}
|
}
|
||||||
overlayCanvasRef.current!.style.cursor = 'none';
|
overlayCanvasRef.current!.style.cursor = 'none';
|
||||||
cursorRef.current!.style.display = 'block';
|
cursorRef.current!.style.display = 'block';
|
||||||
cursorRef.current!.style.top = `${e.clientY}px`;
|
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
||||||
cursorRef.current!.style.left = `${e.clientX}px`;
|
cursorRef.current!.style.left = `${e.clientX - (lineWidth / 2) * autoScale.current}px`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
@@ -120,8 +122,8 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
}
|
}
|
||||||
overlayCanvasRef.current!.style.cursor = 'none';
|
overlayCanvasRef.current!.style.cursor = 'none';
|
||||||
cursorRef.current!.style.display = 'block';
|
cursorRef.current!.style.display = 'block';
|
||||||
cursorRef.current!.style.top = `${e.clientY}px`;
|
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
||||||
cursorRef.current!.style.left = `${e.clientX}px`;
|
cursorRef.current!.style.left = `${e.clientX - (lineWidth / 2) * autoScale.current}px`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMouseLeave = () => {
|
const handleMouseLeave = () => {
|
||||||
@@ -300,8 +302,8 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
if (!isDrawing.current) return;
|
if (!isDrawing.current) return;
|
||||||
|
|
||||||
const { offsetX, offsetY } = e.nativeEvent;
|
const { offsetX, offsetY } = e.nativeEvent;
|
||||||
const currentX = offsetX + lineWidth / 2;
|
const currentX = offsetX;
|
||||||
const currentY = offsetY + lineWidth / 2;
|
const currentY = offsetY;
|
||||||
|
|
||||||
currentStroke.current.push({
|
currentStroke.current.push({
|
||||||
x: currentX,
|
x: currentX,
|
||||||
@@ -336,8 +338,8 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
currentStroke.current = [];
|
currentStroke.current = [];
|
||||||
const { offsetX, offsetY } = e.nativeEvent;
|
const { offsetX, offsetY } = e.nativeEvent;
|
||||||
|
|
||||||
const currentX = offsetX + lineWidth / 2;
|
const currentX = offsetX;
|
||||||
const currentY = offsetY + lineWidth / 2;
|
const currentY = offsetY;
|
||||||
|
|
||||||
currentStroke.current.push({
|
currentStroke.current.push({
|
||||||
x: currentX,
|
x: currentX,
|
||||||
@@ -530,6 +532,10 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
|
|
||||||
setImgLoaded(false);
|
setImgLoaded(false);
|
||||||
await drawImage();
|
await drawImage();
|
||||||
|
onScaleImageSize?.({
|
||||||
|
width: canvasRef.current!.width,
|
||||||
|
height: canvasRef.current!.height
|
||||||
|
});
|
||||||
setImgLoaded(true);
|
setImgLoaded(true);
|
||||||
|
|
||||||
if (strokeCache.current[imguid]) {
|
if (strokeCache.current[imguid]) {
|
||||||
@@ -586,9 +592,15 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
canvasRef.current!.style.transform = `scale(${autoScale.current})`;
|
canvasRef.current!.style.transform = `scale(${autoScale.current})`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateCursorPosOnZoom = (e: any) => {
|
||||||
|
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
cursorRef.current!.style.left = `${e.clientX - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
};
|
||||||
|
|
||||||
const handleOnWheel = (event: any) => {
|
const handleOnWheel = (event: any) => {
|
||||||
handleZoom(event);
|
handleZoom(event);
|
||||||
updateCursorSize();
|
updateCursorSize();
|
||||||
|
updateCursorPosOnZoom(event);
|
||||||
setActiveScale(autoScale.current);
|
setActiveScale(autoScale.current);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -370,7 +370,10 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setTokenResult({
|
setTokenResult({
|
||||||
error: true,
|
error: true,
|
||||||
errorMessage:
|
errorMessage:
|
||||||
result?.data?.error?.message || result?.data?.error || ''
|
result?.data?.data?.detail ||
|
||||||
|
result?.data?.error?.message ||
|
||||||
|
result?.data?.error ||
|
||||||
|
''
|
||||||
});
|
});
|
||||||
setImageList([]);
|
setImageList([]);
|
||||||
return;
|
return;
|
||||||
@@ -627,6 +630,31 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
[modelList, isOpenaiCompatible]
|
[modelList, isOpenaiCompatible]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleOnScaleImageSize = useCallback(
|
||||||
|
(data: { width: number; height: number }) => {
|
||||||
|
const { width, height } = data;
|
||||||
|
form.current?.form?.setFieldsValue({
|
||||||
|
size: 'custom',
|
||||||
|
width: width || 512,
|
||||||
|
height: height || 512
|
||||||
|
});
|
||||||
|
setParams((pre: object) => {
|
||||||
|
return {
|
||||||
|
...pre,
|
||||||
|
size: 'custom',
|
||||||
|
width: width || 512,
|
||||||
|
height: height || 512
|
||||||
|
};
|
||||||
|
});
|
||||||
|
updateCacheFormData({
|
||||||
|
size: 'custom',
|
||||||
|
width: width || 512,
|
||||||
|
height: height || 512
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const handleUpdateImageList = useCallback((base64List: any) => {
|
const handleUpdateImageList = useCallback((base64List: any) => {
|
||||||
console.log('updateimagelist=========', base64List);
|
console.log('updateimagelist=========', base64List);
|
||||||
const currentImg = _.get(base64List, '[0]', {});
|
const currentImg = _.get(base64List, '[0]', {});
|
||||||
@@ -639,24 +667,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
isResetNeeded: true
|
isResetNeeded: true
|
||||||
});
|
});
|
||||||
setImageList([]);
|
setImageList([]);
|
||||||
form.current?.form?.setFieldsValue({
|
|
||||||
size: 'custom',
|
|
||||||
width: currentImg.rawWidth || 512,
|
|
||||||
height: currentImg.rawHeight || 512
|
|
||||||
});
|
|
||||||
setParams((pre: object) => {
|
|
||||||
return {
|
|
||||||
...pre,
|
|
||||||
size: 'custom',
|
|
||||||
width: currentImg.rawWidth || 512,
|
|
||||||
height: currentImg.rawHeight || 512
|
|
||||||
};
|
|
||||||
});
|
|
||||||
updateCacheFormData({
|
|
||||||
size: 'custom',
|
|
||||||
width: currentImg.rawWidth || 512,
|
|
||||||
height: currentImg.rawHeight || 512
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleOnSave = useCallback(
|
const handleOnSave = useCallback(
|
||||||
@@ -859,9 +869,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
height: 125,
|
height: 125,
|
||||||
maxWidth: 125,
|
maxHeight: 125
|
||||||
maxHeight: 125,
|
|
||||||
overflow: 'hidden'
|
|
||||||
}}
|
}}
|
||||||
key={item.uid}
|
key={item.uid}
|
||||||
>
|
>
|
||||||
@@ -869,7 +877,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
{...item}
|
{...item}
|
||||||
height={125}
|
height={125}
|
||||||
maxHeight={125}
|
maxHeight={125}
|
||||||
maxWidth={125}
|
|
||||||
preview={item.preview}
|
preview={item.preview}
|
||||||
loading={item.loading}
|
loading={item.loading}
|
||||||
autoSize={false}
|
autoSize={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user