use of com.helospark.tactview.ui.javafx.JavaDisplayableAudioVideoFragment in project tactview by helospark.
the class InputModeRepository method createMouseHandler.
private EventHandler<? super MouseEvent> createMouseHandler(Consumer<StrategyMouseInput> function, Consumer<GeneralCanvasOperationsMouseRequest> fallbackHandler) {
return e -> {
JavaDisplayableAudioVideoFragment cacheCurrentImage = displayUpdaterService.getCacheCurrentImage();
double unmodifiedX = e.getX() - canvasStateHolder.getTranslateX();
double unmodifiedY = e.getY() - canvasStateHolder.getTranslateY();
if (inputModeInput != null) {
double x = (sizeFunctionImplementation.scalePreviewDataUsingSizeFunction(unmodifiedX, inputModeInput.sizeFunction, projectRepository.getPreviewWidth()));
double y = (sizeFunctionImplementation.scalePreviewDataUsingSizeFunction(unmodifiedY, inputModeInput.sizeFunction, projectRepository.getPreviewHeight()));
StrategyMouseInput strategyInput = StrategyMouseInput.builder().withx(x).withy(y).withMouseEvent(e).withUnscaledX(unmodifiedX).withUnscaledY(unmodifiedY).withCanvasImage(() -> {
return playbackController.getVideoFrameAt(timelineManager.getCurrentPosition(), Optional.empty()).getImage();
}).withCurrentlyPressedKeyRepository(currentlyPressedKeyRepository).build();
function.accept(strategyInput);
if (inputModeInput.currentStrategy.getResultType() == ResultType.PARTIAL) {
handleStrategyHasResult();
}
if (inputModeInput.currentStrategy.getResultType() == ResultType.DONE) {
handleStrategyHasResult();
reset();
}
updateCanvas(e);
} else if (cacheCurrentImage != null) {
Map<String, RegularRectangle> filteredRectangles = cacheCurrentImage.getClipRectangle().entrySet().stream().filter(entry -> selectedNodeRepository.getSelectedClipIds().contains(entry.getKey())).collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));
GeneralCanvasOperationsMouseRequest fallbackRequest = GeneralCanvasOperationsMouseRequest.builder().withCanvas(canvas).withUnscaledX(unmodifiedX).withUnscaledY(unmodifiedY).withCanvasRelativeX(e.getX()).withCanvasRelativeY(e.getY()).withx(unmodifiedX / projectRepository.getPreviewWidth()).withy(unmodifiedY / projectRepository.getPreviewHeight()).withMouseEvent(e).withRectangles(filteredRectangles).build();
fallbackHandler.accept(fallbackRequest);
}
};
}
Aggregations