forked from extern/easydiffusion
organize the inpainting display
This commit is contained in:
parent
64d97a3232
commit
8b48ad77e8
@ -12,7 +12,9 @@ import {
|
|||||||
} from "./drawImage.css.ts";
|
} from "./drawImage.css.ts";
|
||||||
|
|
||||||
export default function DrawImage({ imageData }: DrawImageProps) {
|
export default function DrawImage({ imageData }: DrawImageProps) {
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
||||||
|
const drawingRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
const cursorRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
|
||||||
const [isDrawing, setIsDrawing] = useState(false);
|
const [isDrawing, setIsDrawing] = useState(false);
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ export default function DrawImage({ imageData }: DrawImageProps) {
|
|||||||
) => {
|
) => {
|
||||||
setIsDrawing(false);
|
setIsDrawing(false);
|
||||||
|
|
||||||
const canvas = canvasRef.current;
|
const canvas = drawingRef.current;
|
||||||
if (canvas) {
|
if (canvas) {
|
||||||
const data = canvas.toDataURL();
|
const data = canvas.toDataURL();
|
||||||
console.log("data", data);
|
console.log("data", data);
|
||||||
@ -44,7 +46,7 @@ export default function DrawImage({ imageData }: DrawImageProps) {
|
|||||||
e: React.MouseEvent<HTMLCanvasElement, MouseEvent>
|
e: React.MouseEvent<HTMLCanvasElement, MouseEvent>
|
||||||
) => {
|
) => {
|
||||||
if (isDrawing) {
|
if (isDrawing) {
|
||||||
const canvas = canvasRef.current;
|
const canvas = drawingRef.current;
|
||||||
if (canvas) {
|
if (canvas) {
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
ctx.strokeStyle = "red";
|
ctx.strokeStyle = "red";
|
||||||
@ -75,17 +77,64 @@ export default function DrawImage({ imageData }: DrawImageProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _handleCursorMove = (
|
||||||
|
e: React.MouseEvent<HTMLCanvasElement, MouseEvent>
|
||||||
|
) => {
|
||||||
|
console.log("cursor move");
|
||||||
|
|
||||||
|
|
||||||
|
const canvas = cursorRef.current;
|
||||||
|
if (canvas) {
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
ctx.strokeStyle = "red";
|
||||||
|
const {
|
||||||
|
nativeEvent: { offsetX, offsetY },
|
||||||
|
} = e;
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
|
||||||
|
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
ctx.lineWidth = 20;
|
||||||
|
|
||||||
|
// Sets the end of the lines drawn
|
||||||
|
// to a round shape.
|
||||||
|
ctx.lineCap = "round";
|
||||||
|
|
||||||
|
ctx.strokeStyle = "white";
|
||||||
|
// The cursor to start drawing
|
||||||
|
// moves to this coordinate
|
||||||
|
ctx.moveTo(offsetX, offsetY);
|
||||||
|
|
||||||
|
// A line is traced from start
|
||||||
|
// coordinate to this coordinate
|
||||||
|
ctx.lineTo(offsetX, offsetY);
|
||||||
|
|
||||||
|
// Draws the line.
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={DrawImageMain}>
|
<div className={DrawImageMain}>
|
||||||
<img src={imageData} />
|
<img src={imageData} />
|
||||||
<canvas
|
<canvas
|
||||||
ref={canvasRef}
|
ref={drawingRef}
|
||||||
width={512}
|
width={512}
|
||||||
height={512}
|
height={512}
|
||||||
onMouseDown={_handleMouseDown}
|
onMouseDown={_handleMouseDown}
|
||||||
onMouseMove={_handleMouseMove}
|
onMouseMove={_handleMouseMove}
|
||||||
onMouseUp={_handleMouseUp}
|
onMouseUp={_handleMouseUp}
|
||||||
></canvas>
|
></canvas>
|
||||||
|
<canvas
|
||||||
|
ref={cursorRef}
|
||||||
|
width={512}
|
||||||
|
height={512}
|
||||||
|
onMouseMove={_handleCursorMove}
|
||||||
|
></canvas>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,4 +5,15 @@ export const CreationPaneMain = style({
|
|||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
padding: "0 10px",
|
padding: "0 10px",
|
||||||
|
overflowY: "auto",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const InpaintingSlider = style({
|
||||||
|
position: "absolute",
|
||||||
|
top: "10px",
|
||||||
|
left: "400px",
|
||||||
|
width: "200px",
|
||||||
|
height: "20px",
|
||||||
|
zIndex: 1,
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
||||||
});
|
});
|
||||||
|
@ -1,22 +1,39 @@
|
|||||||
import React, { ChangeEvent } from "react";
|
import React, { ChangeEvent } from "react";
|
||||||
|
|
||||||
import MakeButton from "./basicCreation/makeButton";
|
|
||||||
import AdvancedSettings from "./advancedSettings";
|
import AdvancedSettings from "./advancedSettings";
|
||||||
import ImageModifiers from "./imageModifiers";
|
import ImageModifiers from "./imageModifiers";
|
||||||
|
import InpaintingPanel from "./inpaintingPanel";
|
||||||
|
|
||||||
|
import { useImageCreate } from "../../../stores/imageCreateStore";
|
||||||
|
|
||||||
import "./creationPanel.css";
|
import "./creationPanel.css";
|
||||||
|
|
||||||
// @ts-ignore
|
import {
|
||||||
import { CreationPaneMain } from "./creationpane.css.ts";
|
CreationPaneMain,
|
||||||
|
InpaintingSlider
|
||||||
|
} from // @ts-ignore
|
||||||
|
"./creationpane.css.ts";
|
||||||
|
|
||||||
import BasicCreation from "./basicCreation";
|
import BasicCreation from "./basicCreation";
|
||||||
|
|
||||||
export default function CreationPanel() {
|
export default function CreationPanel() {
|
||||||
|
|
||||||
|
|
||||||
|
const isInPaintingMode = useImageCreate((state) => state.isInpainting);
|
||||||
return (
|
return (
|
||||||
<div className={CreationPaneMain}>
|
<>
|
||||||
<BasicCreation></BasicCreation>
|
<div className={CreationPaneMain}>
|
||||||
<AdvancedSettings></AdvancedSettings>
|
<BasicCreation></BasicCreation>
|
||||||
<ImageModifiers></ImageModifiers>
|
<AdvancedSettings></AdvancedSettings>
|
||||||
</div>
|
<ImageModifiers></ImageModifiers>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isInPaintingMode && (
|
||||||
|
|
||||||
|
<div className={InpaintingSlider}>
|
||||||
|
<InpaintingPanel></InpaintingPanel>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
import React from "react";
|
||||||
|
import DrawImage from "../../../molecules/drawImage";
|
||||||
|
|
||||||
|
import { useImageCreate } from "../../../../stores/imageCreateStore";
|
||||||
|
|
||||||
|
export default function InpaintingPanel() {
|
||||||
|
|
||||||
|
|
||||||
|
const init_image = useImageCreate((state) =>
|
||||||
|
state.getValueForRequestKey("init_image")
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<DrawImage imageData={init_image} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -10,7 +10,7 @@ import { doMakeImage, MakeImageKey } from "../../../api";
|
|||||||
import AudioDing from "./audioDing";
|
import AudioDing from "./audioDing";
|
||||||
|
|
||||||
import GeneratedImage from "../../molecules/generatedImage";
|
import GeneratedImage from "../../molecules/generatedImage";
|
||||||
import DrawImage from "../../molecules/drawImage";
|
// import DrawImage from "../../molecules/drawImage";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
displayPanel,
|
displayPanel,
|
||||||
@ -25,6 +25,8 @@ type CompletedImagesType = {
|
|||||||
data: string;
|
data: string;
|
||||||
info: ImageRequest;
|
info: ImageRequest;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default function DisplayPanel() {
|
export default function DisplayPanel() {
|
||||||
const dingRef = useRef<HTMLAudioElement>(null);
|
const dingRef = useRef<HTMLAudioElement>(null);
|
||||||
const isSoundEnabled = useImageCreate((state) => state.isSoundEnabled());
|
const isSoundEnabled = useImageCreate((state) => state.isSoundEnabled());
|
||||||
@ -105,7 +107,7 @@ export default function DisplayPanel() {
|
|||||||
<div className={displayPanel}>
|
<div className={displayPanel}>
|
||||||
<AudioDing ref={dingRef}></AudioDing>
|
<AudioDing ref={dingRef}></AudioDing>
|
||||||
<div className={displayContainer}>
|
<div className={displayContainer}>
|
||||||
{isInPaintingMode && <DrawImage imageData={init_image}></DrawImage>}
|
{/* {isInPaintingMode && <DrawImage imageData={init_image}></DrawImage>} */}
|
||||||
|
|
||||||
{completedImages.length > 0 && (
|
{completedImages.length > 0 && (
|
||||||
<>
|
<>
|
||||||
|
@ -35,7 +35,7 @@ export const HeaderLayout = style({
|
|||||||
|
|
||||||
export const CreateLayout = style({
|
export const CreateLayout = style({
|
||||||
gridArea: "create",
|
gridArea: "create",
|
||||||
overflow: "auto",
|
position: "relative",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const DisplayLayout = style({
|
export const DisplayLayout = style({
|
||||||
|
Loading…
Reference in New Issue
Block a user