HudCanvas: handle select-nothing
This commit is contained in:
parent
50e68f4792
commit
545ac72faa
|
@ -1,4 +1,4 @@
|
||||||
import { useState, useEffect, useRef, MouseEvent } from 'react';
|
import { useState, useEffect, useRef, useCallback, MouseEvent } from 'react';
|
||||||
|
|
||||||
interface Styles {
|
interface Styles {
|
||||||
borderLineWidth: number;
|
borderLineWidth: number;
|
||||||
|
@ -11,6 +11,7 @@ interface Props {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
zIndex: number;
|
zIndex: number;
|
||||||
|
emptySelectionAction: EmptySelectionAction;
|
||||||
styles: Styles;
|
styles: Styles;
|
||||||
position: number | null;
|
position: number | null;
|
||||||
selection: Selection;
|
selection: Selection;
|
||||||
|
@ -32,6 +33,11 @@ enum HoverState {
|
||||||
OverSelection,
|
OverSelection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum EmptySelectionAction {
|
||||||
|
SelectNothing,
|
||||||
|
SelectPrevious,
|
||||||
|
}
|
||||||
|
|
||||||
export interface Selection {
|
export interface Selection {
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
|
@ -43,6 +49,7 @@ export const HudCanvas: React.FC<Props> = ({
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
zIndex,
|
zIndex,
|
||||||
|
emptySelectionAction,
|
||||||
styles: {
|
styles: {
|
||||||
borderLineWidth,
|
borderLineWidth,
|
||||||
borderStrokeStyle,
|
borderStrokeStyle,
|
||||||
|
@ -271,13 +278,24 @@ export const HudCanvas: React.FC<Props> = ({
|
||||||
setCursor('auto');
|
setCursor('auto');
|
||||||
|
|
||||||
if (newSelection.start == newSelection.end) {
|
if (newSelection.start == newSelection.end) {
|
||||||
setNewSelection({ start: 0, end: 0 });
|
handleEmptySelectionAction();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectionChange({ ...newSelection });
|
onSelectionChange({ ...newSelection });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleEmptySelectionAction = useCallback(() => {
|
||||||
|
switch (emptySelectionAction) {
|
||||||
|
case EmptySelectionAction.SelectPrevious:
|
||||||
|
setNewSelection({ ...selection });
|
||||||
|
break;
|
||||||
|
case EmptySelectionAction.SelectNothing:
|
||||||
|
onSelectionChange({ start: 0, end: 0 });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, [selection]);
|
||||||
|
|
||||||
const handleMouseLeave = (_evt: MouseEvent<HTMLCanvasElement>) => {
|
const handleMouseLeave = (_evt: MouseEvent<HTMLCanvasElement>) => {
|
||||||
setHoverState(HoverState.Normal);
|
setHoverState(HoverState.Normal);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
|
||||||
import { MediaSet } from './generated/media_set';
|
import { MediaSet } from './generated/media_set';
|
||||||
import { Frames, VideoPosition } from './App';
|
import { Frames, VideoPosition } from './App';
|
||||||
import { WaveformCanvas } from './WaveformCanvas';
|
import { WaveformCanvas } from './WaveformCanvas';
|
||||||
import { HudCanvas } from './HudCanvas';
|
import { HudCanvas, EmptySelectionAction } from './HudCanvas';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
export interface Selection {
|
export interface Selection {
|
||||||
|
@ -103,6 +103,7 @@ export const Overview: React.FC<Props> = ({
|
||||||
width={CanvasLogicalWidth}
|
width={CanvasLogicalWidth}
|
||||||
height={CanvasLogicalHeight}
|
height={CanvasLogicalHeight}
|
||||||
zIndex={1}
|
zIndex={1}
|
||||||
|
emptySelectionAction={EmptySelectionAction.SelectPrevious}
|
||||||
styles={hudStyles}
|
styles={hudStyles}
|
||||||
position={positionPixels}
|
position={positionPixels}
|
||||||
selection={selectedPixels}
|
selection={selectedPixels}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { useEffect, useState, useCallback } from 'react';
|
||||||
import { Frames, VideoPosition, newRPC } from './App';
|
import { Frames, VideoPosition, newRPC } from './App';
|
||||||
import { MediaSetServiceClientImpl, MediaSet } from './generated/media_set';
|
import { MediaSetServiceClientImpl, MediaSet } from './generated/media_set';
|
||||||
import { WaveformCanvas } from './WaveformCanvas';
|
import { WaveformCanvas } from './WaveformCanvas';
|
||||||
import { Selection, HudCanvas } from './HudCanvas';
|
import { Selection, HudCanvas, EmptySelectionAction } from './HudCanvas';
|
||||||
import { from, Observable } from 'rxjs';
|
import { from, Observable } from 'rxjs';
|
||||||
import { bufferCount } from 'rxjs/operators';
|
import { bufferCount } from 'rxjs/operators';
|
||||||
|
|
||||||
|
@ -167,6 +167,7 @@ export const Waveform: React.FC<Props> = ({
|
||||||
width={CanvasLogicalWidth}
|
width={CanvasLogicalWidth}
|
||||||
height={CanvasLogicalHeight}
|
height={CanvasLogicalHeight}
|
||||||
zIndex={1}
|
zIndex={1}
|
||||||
|
emptySelectionAction={EmptySelectionAction.SelectNothing}
|
||||||
styles={hudStyles}
|
styles={hudStyles}
|
||||||
position={positionPixels}
|
position={positionPixels}
|
||||||
selection={selectedPixels}
|
selection={selectedPixels}
|
||||||
|
|
Loading…
Reference in New Issue