forked from invoke-ai/InvokeAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/raster blend boolean #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dunkeroni
wants to merge
16
commits into
main
Choose a base branch
from
feature/raster-blend-boolean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+327
−6
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d9dea78
feat(canvas): add raster layer blend modes and boolean operations sub…
dunkeroni 7a4c87a
feat(canvas): boolean ops submenu and UI polish
dunkeroni de37f87
(chore): prettier lint
dunkeroni f3d9323
add icons to boolean submenu items
dunkeroni 4adaa70
add delete button for color blend operations
dunkeroni 0e535ff
move composite operation type and imports
dunkeroni 47a6092
chore: pnpm eslint
dunkeroni 4484346
update blend modes order
dunkeroni a006619
update default blend mode to 'color'
dunkeroni b6a89bd
add i18n for blend modes
dunkeroni 5cd6183
actually use translations for blend modes now
dunkeroni edcf922
move composite options into types.ts
dunkeroni 8a00690
cleanup and comments
dunkeroni 03f7627
update names
dunkeroni 7c4737f
move constant mapping out of function
dunkeroni 31d7cfc
Merge branch 'main' into feature/raster-blend-boolean
dunkeroni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...c/features/controlLayers/components/RasterLayer/RasterLayerCompositeOperationSettings.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { Flex, FormControl, FormLabel, Select } from '@invoke-ai/ui-library'; | ||
| import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; | ||
| import { InpaintMaskDeleteModifierButton } from 'features/controlLayers/components/InpaintMask/InpaintMaskDeleteModifierButton'; | ||
| import { useEntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext'; | ||
| import { rasterLayerGlobalCompositeOperationChanged } from 'features/controlLayers/store/canvasSlice'; | ||
| import { COLOR_BLEND_MODES, type CompositeOperation } from 'features/controlLayers/store/compositeOperations'; | ||
| import type { CanvasRasterLayerState } from 'features/controlLayers/store/types'; | ||
| import type { ChangeEvent } from 'react'; | ||
| import { memo, useCallback, useMemo } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| export const RasterLayerCompositeOperationSettings = memo(() => { | ||
| const { t } = useTranslation(); | ||
| const dispatch = useAppDispatch(); | ||
| const entityIdentifier = useEntityIdentifierContext<'raster_layer'>(); | ||
|
|
||
| const layer = useAppSelector((s) => | ||
| s.canvas.present.rasterLayers.entities.find((e: CanvasRasterLayerState) => e.id === entityIdentifier.id) | ||
| ); | ||
|
|
||
| const showSettings = useMemo(() => { | ||
| return layer?.globalCompositeOperation !== undefined; | ||
| }, [layer]); | ||
|
|
||
| const currentOperation = useMemo(() => { | ||
| return layer?.globalCompositeOperation ?? 'source-over'; | ||
| }, [layer]); | ||
|
|
||
| const onChange = useCallback( | ||
| (e: ChangeEvent<HTMLSelectElement>) => { | ||
| const value = e.target.value as CompositeOperation; | ||
| dispatch(rasterLayerGlobalCompositeOperationChanged({ entityIdentifier, globalCompositeOperation: value })); | ||
| }, | ||
| [dispatch, entityIdentifier] | ||
| ); | ||
|
|
||
| const onDelete = useCallback(() => { | ||
| dispatch( | ||
| rasterLayerGlobalCompositeOperationChanged({ | ||
| entityIdentifier, | ||
| globalCompositeOperation: undefined, | ||
| }) | ||
| ); | ||
| }, [dispatch, entityIdentifier]); | ||
|
|
||
| if (!showSettings) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Flex px={2} pb={2}> | ||
| <FormControl> | ||
| <FormLabel m={0}>{t('controlLayers.compositeOperation.label')}</FormLabel> | ||
| <Flex alignItems="center" mb={1}> | ||
| <Select value={currentOperation} onChange={onChange} size="sm" flex={1} mr={2}> | ||
| {COLOR_BLEND_MODES.map((op) => ( | ||
| <option key={op} value={op}> | ||
| {op} | ||
| </option> | ||
| ))} | ||
| </Select> | ||
| <InpaintMaskDeleteModifierButton onDelete={onDelete} /> | ||
| </Flex> | ||
| </FormControl> | ||
| </Flex> | ||
| ); | ||
| }); | ||
|
|
||
| RasterLayerCompositeOperationSettings.displayName = 'RasterLayerCompositeOperationSettings'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../src/features/controlLayers/components/RasterLayer/RasterLayerMenuItemsBooleanSubMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { Menu, MenuButton, MenuItem, MenuList } from '@invoke-ai/ui-library'; | ||
| import { useAppDispatch } from 'app/store/storeHooks'; | ||
| import { SubMenuButtonContent, useSubMenu } from 'common/hooks/useSubMenu'; | ||
| import { useCanvasManager } from 'features/controlLayers/contexts/CanvasManagerProviderGate'; | ||
| import { useEntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext'; | ||
| import { useCanvasIsBusy } from 'features/controlLayers/hooks/useCanvasIsBusy'; | ||
| import { useEntityIdentifierBelowThisOne } from 'features/controlLayers/hooks/useNextRenderableEntityIdentifier'; | ||
| import { rasterLayerGlobalCompositeOperationChanged } from 'features/controlLayers/store/canvasSlice'; | ||
| import type { CompositeOperation } from 'features/controlLayers/store/compositeOperations'; | ||
| import type { CanvasEntityIdentifier } from 'features/controlLayers/store/types'; | ||
| import { memo, useCallback } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { CgPathBack, CgPathCrop, CgPathExclude, CgPathFront, CgPathIntersect } from 'react-icons/cg'; | ||
|
|
||
| export const RasterLayerMenuItemsBooleanSubMenu = memo(() => { | ||
| const { t } = useTranslation(); | ||
| const subMenu = useSubMenu(); | ||
| const canvasManager = useCanvasManager(); | ||
| const isBusy = useCanvasIsBusy(); | ||
| const dispatch = useAppDispatch(); | ||
| const entityIdentifier = useEntityIdentifierContext<'raster_layer'>(); | ||
| const entityIdentifierBelowThisOne = useEntityIdentifierBelowThisOne(entityIdentifier as CanvasEntityIdentifier); | ||
|
|
||
| const perform = useCallback( | ||
| async (op: CompositeOperation) => { | ||
| if (!entityIdentifierBelowThisOne) { | ||
| return; | ||
| } | ||
| dispatch(rasterLayerGlobalCompositeOperationChanged({ entityIdentifier, globalCompositeOperation: op })); | ||
| try { | ||
| await canvasManager.compositor.mergeByEntityIdentifiers([entityIdentifierBelowThisOne, entityIdentifier], true); | ||
| } finally { | ||
| dispatch(rasterLayerGlobalCompositeOperationChanged({ entityIdentifier, globalCompositeOperation: undefined })); | ||
| } | ||
| }, | ||
| [canvasManager.compositor, dispatch, entityIdentifier, entityIdentifierBelowThisOne] | ||
| ); | ||
|
|
||
| const onIntersection = useCallback(() => perform('source-in'), [perform]); | ||
| const onCutout = useCallback(() => perform('destination-in'), [perform]); | ||
| const onCutAway = useCallback(() => perform('source-out'), [perform]); | ||
| const onExclude = useCallback(() => perform('xor'), [perform]); | ||
|
|
||
| const disabled = isBusy || !entityIdentifierBelowThisOne; | ||
|
|
||
| return ( | ||
| <MenuItem {...subMenu.parentMenuItemProps} isDisabled={disabled} icon={<CgPathCrop size={18} />}> | ||
| <Menu {...subMenu.menuProps}> | ||
| <MenuButton {...subMenu.menuButtonProps}> | ||
| <SubMenuButtonContent label={t('controlLayers.booleanOps.label')} /> | ||
| </MenuButton> | ||
| <MenuList {...subMenu.menuListProps}> | ||
| <MenuItem onClick={onIntersection} isDisabled={disabled} icon={<CgPathIntersect size={18} />}> | ||
| {t('controlLayers.booleanOps.intersection')} | ||
| </MenuItem> | ||
| <MenuItem onClick={onCutout} isDisabled={disabled} icon={<CgPathBack size={18} />}> | ||
| {t('controlLayers.booleanOps.cutout')} | ||
| </MenuItem> | ||
| <MenuItem onClick={onCutAway} isDisabled={disabled} icon={<CgPathFront size={18} />}> | ||
| {t('controlLayers.booleanOps.cutAway')} | ||
| </MenuItem> | ||
| <MenuItem onClick={onExclude} isDisabled={disabled} icon={<CgPathExclude size={18} />}> | ||
| {t('controlLayers.booleanOps.exclude')} | ||
| </MenuItem> | ||
| </MenuList> | ||
| </Menu> | ||
| </MenuItem> | ||
| ); | ||
| }); | ||
|
|
||
| RasterLayerMenuItemsBooleanSubMenu.displayName = 'RasterLayerMenuItemsBooleanSubMenu'; |
35 changes: 35 additions & 0 deletions
35
.../features/controlLayers/components/RasterLayer/RasterLayerMenuItemsCompositeOperation.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { MenuItem } from '@invoke-ai/ui-library'; | ||
| import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; | ||
| import { useEntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext'; | ||
| import { rasterLayerGlobalCompositeOperationChanged } from 'features/controlLayers/store/canvasSlice'; | ||
| import type { CanvasRasterLayerState } from 'features/controlLayers/store/types'; | ||
| import { memo, useCallback } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { PiDropHalfBold } from 'react-icons/pi'; | ||
|
|
||
| export const RasterLayerMenuItemsCompositeOperation = memo(() => { | ||
| const dispatch = useAppDispatch(); | ||
| const entityIdentifier = useEntityIdentifierContext<'raster_layer'>(); | ||
| const { t } = useTranslation(); | ||
| const layer = useAppSelector((s) => | ||
| s.canvas.present.rasterLayers.entities.find((e: CanvasRasterLayerState) => e.id === entityIdentifier.id) | ||
| ); | ||
| const hasCompositeOperation = layer?.globalCompositeOperation !== undefined; | ||
|
|
||
| const onToggleCompositeOperationPresence = useCallback(() => { | ||
| if (hasCompositeOperation) { | ||
| dispatch(rasterLayerGlobalCompositeOperationChanged({ entityIdentifier, globalCompositeOperation: undefined })); | ||
| } else { | ||
| // default to color when enabling blend modes | ||
| dispatch(rasterLayerGlobalCompositeOperationChanged({ entityIdentifier, globalCompositeOperation: 'color' })); | ||
| } | ||
| }, [dispatch, entityIdentifier, hasCompositeOperation]); | ||
|
|
||
| return ( | ||
| <MenuItem onClick={onToggleCompositeOperationPresence} icon={<PiDropHalfBold />}> | ||
| {hasCompositeOperation ? t('controlLayers.compositeOperation.remove') : t('controlLayers.compositeOperation.add')} | ||
| </MenuItem> | ||
| ); | ||
| }); | ||
|
|
||
| RasterLayerMenuItemsCompositeOperation.displayName = 'RasterLayerMenuItemsCompositeOperation'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.