show prev mask when dream again
This commit is contained in:
parent
f4eedbe3b1
commit
f5247c89b2
@ -62,6 +62,8 @@ import emitter, {
|
|||||||
EVENT_CUSTOM_MASK,
|
EVENT_CUSTOM_MASK,
|
||||||
EVENT_PAINT_BY_EXAMPLE,
|
EVENT_PAINT_BY_EXAMPLE,
|
||||||
RERUN_LAST_MASK,
|
RERUN_LAST_MASK,
|
||||||
|
DREAM_BUTTON_MOUSE_ENTER,
|
||||||
|
DREAM_BUTTON_MOUSE_LEAVE,
|
||||||
} from '../../event'
|
} from '../../event'
|
||||||
import FileSelect from '../FileSelect/FileSelect'
|
import FileSelect from '../FileSelect/FileSelect'
|
||||||
import InteractiveSeg from '../InteractiveSeg/InteractiveSeg'
|
import InteractiveSeg from '../InteractiveSeg/InteractiveSeg'
|
||||||
@ -130,15 +132,24 @@ export default function Editor() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const [showInteractiveSegModal, setShowInteractiveSegModal] = useState(false)
|
const [showInteractiveSegModal, setShowInteractiveSegModal] = useState(false)
|
||||||
const [interactiveSegMask, setInteractiveSegMask] =
|
const [interactiveSegMask, setInteractiveSegMask] = useState<
|
||||||
useState<HTMLImageElement | null>(null)
|
HTMLImageElement | null | undefined
|
||||||
|
>(null)
|
||||||
// only used while interactive segmentation is on
|
// only used while interactive segmentation is on
|
||||||
const [tmpInteractiveSegMask, setTmpInteractiveSegMask] =
|
const [tmpInteractiveSegMask, setTmpInteractiveSegMask] = useState<
|
||||||
useState<HTMLImageElement | null>(null)
|
HTMLImageElement | null | undefined
|
||||||
|
>(null)
|
||||||
const [prevInteractiveSegMask, setPrevInteractiveSegMask] = useState<
|
const [prevInteractiveSegMask, setPrevInteractiveSegMask] = useState<
|
||||||
HTMLImageElement | null | undefined
|
HTMLImageElement | null | undefined
|
||||||
>(null)
|
>(null)
|
||||||
|
|
||||||
|
// 仅用于在 dream button hover 时显示提示
|
||||||
|
const [dreamButtonHoverSegMask, setDreamButtonHoverSegMask] = useState<
|
||||||
|
HTMLImageElement | null | undefined
|
||||||
|
>(null)
|
||||||
|
const [dreamButtonHoverLineGroup, setDreamButtonHoverLineGroup] =
|
||||||
|
useState<LineGroup>([])
|
||||||
|
|
||||||
const [clicks, setClicks] = useRecoilState(interactiveSegClicksState)
|
const [clicks, setClicks] = useRecoilState(interactiveSegClicksState)
|
||||||
|
|
||||||
const [brushSize, setBrushSize] = useRecoilState(brushSizeState)
|
const [brushSize, setBrushSize] = useRecoilState(brushSizeState)
|
||||||
@ -202,21 +213,33 @@ export default function Editor() {
|
|||||||
|
|
||||||
context.clearRect(0, 0, context.canvas.width, context.canvas.height)
|
context.clearRect(0, 0, context.canvas.width, context.canvas.height)
|
||||||
context.drawImage(render, 0, 0, imageWidth, imageHeight)
|
context.drawImage(render, 0, 0, imageWidth, imageHeight)
|
||||||
if (isInteractiveSeg && tmpInteractiveSegMask !== null) {
|
if (isInteractiveSeg && tmpInteractiveSegMask) {
|
||||||
context.drawImage(tmpInteractiveSegMask, 0, 0, imageWidth, imageHeight)
|
context.drawImage(tmpInteractiveSegMask, 0, 0, imageWidth, imageHeight)
|
||||||
}
|
}
|
||||||
if (!isInteractiveSeg && interactiveSegMask !== null) {
|
if (!isInteractiveSeg && interactiveSegMask) {
|
||||||
context.drawImage(interactiveSegMask, 0, 0, imageWidth, imageHeight)
|
context.drawImage(interactiveSegMask, 0, 0, imageWidth, imageHeight)
|
||||||
}
|
}
|
||||||
|
if (dreamButtonHoverSegMask) {
|
||||||
|
context.drawImage(
|
||||||
|
dreamButtonHoverSegMask,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
imageWidth,
|
||||||
|
imageHeight
|
||||||
|
)
|
||||||
|
}
|
||||||
drawLines(context, lineGroup)
|
drawLines(context, lineGroup)
|
||||||
|
drawLines(context, dreamButtonHoverLineGroup)
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
context,
|
context,
|
||||||
isInteractiveSeg,
|
isInteractiveSeg,
|
||||||
tmpInteractiveSegMask,
|
tmpInteractiveSegMask,
|
||||||
|
dreamButtonHoverSegMask,
|
||||||
interactiveSegMask,
|
interactiveSegMask,
|
||||||
imageHeight,
|
imageHeight,
|
||||||
imageWidth,
|
imageWidth,
|
||||||
|
dreamButtonHoverLineGroup,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -277,6 +300,7 @@ export default function Editor() {
|
|||||||
|
|
||||||
const drawOnCurrentRender = useCallback(
|
const drawOnCurrentRender = useCallback(
|
||||||
(lineGroup: LineGroup) => {
|
(lineGroup: LineGroup) => {
|
||||||
|
console.log('[drawOnCurrentRender] draw on current render')
|
||||||
if (renders.length === 0) {
|
if (renders.length === 0) {
|
||||||
draw(original, lineGroup)
|
draw(original, lineGroup)
|
||||||
} else {
|
} else {
|
||||||
@ -459,6 +483,53 @@ export default function Editor() {
|
|||||||
prevInteractiveSegMask,
|
prevInteractiveSegMask,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
emitter.on(DREAM_BUTTON_MOUSE_ENTER, () => {
|
||||||
|
// 当前 canvas 上没有手绘 mask 或者 interactiveSegMask 时,显示上一次的 mask
|
||||||
|
if (!hadDrawSomething() && !interactiveSegMask) {
|
||||||
|
if (prevInteractiveSegMask) {
|
||||||
|
setDreamButtonHoverSegMask(prevInteractiveSegMask)
|
||||||
|
}
|
||||||
|
let lineGroup2Show: LineGroup = []
|
||||||
|
if (redoLineGroups.length !== 0) {
|
||||||
|
lineGroup2Show = redoLineGroups[redoLineGroups.length - 1]
|
||||||
|
} else if (lineGroups.length !== 0) {
|
||||||
|
lineGroup2Show = lineGroups[lineGroups.length - 1]
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`[DREAM_BUTTON_MOUSE_ENTER], prevInteractiveSegMask: ${prevInteractiveSegMask} lineGroup2Show: ${lineGroup2Show.length}`
|
||||||
|
)
|
||||||
|
if (lineGroup2Show) {
|
||||||
|
setDreamButtonHoverLineGroup(lineGroup2Show)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return () => {
|
||||||
|
emitter.off(DREAM_BUTTON_MOUSE_ENTER)
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
hadDrawSomething,
|
||||||
|
interactiveSegMask,
|
||||||
|
prevInteractiveSegMask,
|
||||||
|
drawOnCurrentRender,
|
||||||
|
lineGroups,
|
||||||
|
redoLineGroups,
|
||||||
|
])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
emitter.on(DREAM_BUTTON_MOUSE_LEAVE, () => {
|
||||||
|
// 当前 canvas 上没有手绘 mask 或者 interactiveSegMask 时,显示上一次的 mask
|
||||||
|
if (!hadDrawSomething() && !interactiveSegMask) {
|
||||||
|
setDreamButtonHoverSegMask(null)
|
||||||
|
setDreamButtonHoverLineGroup([])
|
||||||
|
drawOnCurrentRender([])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return () => {
|
||||||
|
emitter.off(DREAM_BUTTON_MOUSE_LEAVE)
|
||||||
|
}
|
||||||
|
}, [hadDrawSomething, interactiveSegMask, drawOnCurrentRender])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
emitter.on(EVENT_CUSTOM_MASK, (data: any) => {
|
emitter.on(EVENT_CUSTOM_MASK, (data: any) => {
|
||||||
// TODO: not work with paint by example
|
// TODO: not work with paint by example
|
||||||
@ -743,7 +814,7 @@ export default function Editor() {
|
|||||||
setInitialCentered(true)
|
setInitialCentered(true)
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
context?.canvas,
|
// context?.canvas,
|
||||||
viewportRef,
|
viewportRef,
|
||||||
original,
|
original,
|
||||||
isOriginalLoaded,
|
isOriginalLoaded,
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import React, { FormEvent, useRef, useState } from 'react'
|
import React, { FormEvent, useRef, useState } from 'react'
|
||||||
import { useClickAway } from 'react-use'
|
import { useClickAway } from 'react-use'
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil'
|
import { useRecoilState, useRecoilValue } from 'recoil'
|
||||||
import emitter, { EVENT_PROMPT } from '../../event'
|
import emitter, {
|
||||||
|
DREAM_BUTTON_MOUSE_ENTER,
|
||||||
|
DREAM_BUTTON_MOUSE_LEAVE,
|
||||||
|
EVENT_PROMPT,
|
||||||
|
} from '../../event'
|
||||||
import { appState, isInpaintingState, propmtState } from '../../store/Atoms'
|
import { appState, isInpaintingState, propmtState } from '../../store/Atoms'
|
||||||
import Button from '../shared/Button'
|
import Button from '../shared/Button'
|
||||||
import TextInput from '../shared/Input'
|
import TextInput from '../shared/Input'
|
||||||
|
|
||||||
// TODO: show progress in input
|
// TODO: show progress in input
|
||||||
const PromptInput = () => {
|
const PromptInput = () => {
|
||||||
const [app, setAppState] = useRecoilState(appState)
|
const app = useRecoilValue(appState)
|
||||||
const [prompt, setPrompt] = useRecoilState(propmtState)
|
const [prompt, setPrompt] = useRecoilState(propmtState)
|
||||||
const isInpainting = useRecoilValue(isInpaintingState)
|
const isInpainting = useRecoilValue(isInpaintingState)
|
||||||
const ref = useRef(null)
|
const ref = useRef(null)
|
||||||
@ -39,6 +43,14 @@ const PromptInput = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onMouseEnter = () => {
|
||||||
|
emitter.emit(DREAM_BUTTON_MOUSE_ENTER)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onMouseLeave = () => {
|
||||||
|
emitter.emit(DREAM_BUTTON_MOUSE_LEAVE)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="prompt-wrapper">
|
<div className="prompt-wrapper">
|
||||||
<TextInput
|
<TextInput
|
||||||
@ -52,6 +64,8 @@ const PromptInput = () => {
|
|||||||
border
|
border
|
||||||
onClick={handleRepaintClick}
|
onClick={handleRepaintClick}
|
||||||
disabled={prompt.length === 0 || app.isInpainting}
|
disabled={prompt.length === 0 || app.isInpainting}
|
||||||
|
onMouseEnter={onMouseEnter}
|
||||||
|
onMouseLeave={onMouseLeave}
|
||||||
>
|
>
|
||||||
Dream
|
Dream
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -12,6 +12,8 @@ interface ButtonProps {
|
|||||||
onClick?: () => void
|
onClick?: () => void
|
||||||
onDown?: (ev: PointerEvent) => void
|
onDown?: (ev: PointerEvent) => void
|
||||||
onUp?: (ev: PointerEvent) => void
|
onUp?: (ev: PointerEvent) => void
|
||||||
|
onMouseEnter?: () => void
|
||||||
|
onMouseLeave?: () => void
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +29,8 @@ const Button: React.FC<ButtonProps> = props => {
|
|||||||
onClick,
|
onClick,
|
||||||
onDown,
|
onDown,
|
||||||
onUp,
|
onUp,
|
||||||
|
onMouseEnter,
|
||||||
|
onMouseLeave,
|
||||||
style,
|
style,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
@ -42,6 +46,8 @@ const Button: React.FC<ButtonProps> = props => {
|
|||||||
style={style}
|
style={style}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onClick={blurOnClick}
|
onClick={blurOnClick}
|
||||||
|
onMouseEnter={onMouseEnter}
|
||||||
|
onMouseLeave={onMouseLeave}
|
||||||
onPointerDown={(ev: React.PointerEvent<HTMLDivElement>) => {
|
onPointerDown={(ev: React.PointerEvent<HTMLDivElement>) => {
|
||||||
onDown?.(ev.nativeEvent)
|
onDown?.(ev.nativeEvent)
|
||||||
}}
|
}}
|
||||||
|
@ -14,6 +14,9 @@ export interface PaintByExampleEventData {
|
|||||||
|
|
||||||
export const RERUN_LAST_MASK = 'rerun_last_mask'
|
export const RERUN_LAST_MASK = 'rerun_last_mask'
|
||||||
|
|
||||||
|
export const DREAM_BUTTON_MOUSE_ENTER = 'dream_button_mouse_enter'
|
||||||
|
export const DREAM_BUTTON_MOUSE_LEAVE = 'dream_btoon_mouse_leave'
|
||||||
|
|
||||||
const emitter = mitt()
|
const emitter = mitt()
|
||||||
|
|
||||||
export default emitter
|
export default emitter
|
||||||
|
Loading…
Reference in New Issue
Block a user