Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.3 KB
Raw Blame
import { useAppSelector } from 'app/store/storeHooks';
import { useAssertSingleton } from 'common/hooks/useAssertSingleton';
import { useCanvasIsBusy } from 'features/controlLayers/hooks/useCanvasIsBusy';
import { useInvertMask } from 'features/controlLayers/hooks/useInvertMask';
import { selectSelectedEntityIdentifier } from 'features/controlLayers/store/selectors';
import { isMaskEntityIdentifier } from 'features/controlLayers/store/types';
import { useRegisteredHotkeys } from 'features/system/components/HotkeysModal/useHotkeyData';
import { useMemo } from 'react';

export const useCanvasInvertMaskHotkey = () => {
  useAssertSingleton('useCanvasInvertMaskHotkey');
  const selectedEntityIdentifier = useAppSelector(selectSelectedEntityIdentifier);
  const isBusy = useCanvasIsBusy();
  const invertMask = useInvertMask();

  const isEnabled = useMemo(() => {
    if (!selectedEntityIdentifier) {
      return false;
    }
    if (!isMaskEntityIdentifier(selectedEntityIdentifier)) {
      return false;
    }
    if (isBusy) {
      return false;
    }
    return true;
  }, [selectedEntityIdentifier, isBusy]);

  useRegisteredHotkeys({
    id: 'invertMask',
    category: 'canvas',
    callback: invertMask,
    options: { enabled: isEnabled, preventDefault: true },
    dependencies: [invertMask, isEnabled],
  });
};