Search in sources :

Example 1 with ScaleEffect

use of com.helospark.tactview.core.timeline.effect.scale.ScaleEffect in project tactview by helospark.

the class GeneralCanvasOperationStrategy method findDragData.

private DragData findDragData(GeneralCanvasOperationsMouseRequest input) {
    String draggedClip = null;
    DragPointType dragPointType = null;
    for (var entry : input.rectangles.entrySet()) {
        RegularRectangle rectangle = entry.getValue();
        if (isPointClose(input.unscaledX, input.unscaledY, rectangle.getX(), rectangle.getY())) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.TOP_LEFT;
            break;
        }
        if (isPointClose(input.unscaledX, input.unscaledY, rectangle.getX() + rectangle.getWidth(), rectangle.getY())) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.TOP_RIGHT;
            break;
        }
        if (isPointClose(input.unscaledX, input.unscaledY, rectangle.getX(), rectangle.getY() + rectangle.getHeight())) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.BOTTOM_LEFT;
            break;
        }
        if (isPointClose(input.unscaledX, input.unscaledY, rectangle.getX() + rectangle.getWidth(), rectangle.getY() + rectangle.getHeight())) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.BOTTOM_RIGHT;
            break;
        }
        if (Math.abs(input.unscaledX - rectangle.getX()) < CLOSE_THRESHOLD && isYWithinRectangleRange(input.unscaledY, rectangle)) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.LEFT;
            break;
        }
        if (Math.abs(input.unscaledX - (rectangle.getX() + rectangle.getWidth())) < CLOSE_THRESHOLD && isYWithinRectangleRange(input.unscaledY, rectangle)) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.RIGHT;
            break;
        }
        if (Math.abs(input.unscaledY - (rectangle.getY() + rectangle.getHeight())) < CLOSE_THRESHOLD && isXWithinRectangleRange(input.unscaledX, rectangle)) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.BOTTOM;
            break;
        }
        if (Math.abs(input.unscaledY - rectangle.getY()) < CLOSE_THRESHOLD && isXWithinRectangleRange(input.unscaledX, rectangle)) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.TOP;
            break;
        }
        if (isPointInRectangle(input.unscaledX, input.unscaledY, rectangle)) {
            draggedClip = entry.getKey();
            dragPointType = DragPointType.CENTER;
            break;
        }
    }
    if (draggedClip != null && dragPointType != null) {
        ValueProviderDescriptor translateElement = effectParametersRepository.findDescriptorForLabelAndClipId(draggedClip, "translate").get();
        Point originalPosition = ((PointProvider) translateElement.getKeyframeableEffect()).getValueAt(uiTimelineManager.getCurrentPosition());
        Point lastScale = new Point(1.0, 1.0);
        ScaleEffect scaleEffect = findOptionalScale(draggedClip);
        if (scaleEffect != null) {
            double xScale = (double) effectParametersRepository.findDescriptorForLabelAndClipId(scaleEffect.getId(), "width scale").get().getKeyframeableEffect().getValueAt(uiTimelineManager.getCurrentPosition());
            double yScale = (double) effectParametersRepository.findDescriptorForLabelAndClipId(scaleEffect.getId(), "height scale").get().getKeyframeableEffect().getValueAt(uiTimelineManager.getCurrentPosition());
            lastScale = new Point(xScale, yScale);
        }
        return new DragData(draggedClip, dragPointType, originalPosition, lastScale, input.rectangles.get(draggedClip));
    } else {
        return null;
    }
}
Also used : ScaleEffect(com.helospark.tactview.core.timeline.effect.scale.ScaleEffect) PointProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.PointProvider) ValueProviderDescriptor(com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) RegularRectangle(com.helospark.tactview.core.timeline.TimelineRenderResult.RegularRectangle)

Example 2 with ScaleEffect

use of com.helospark.tactview.core.timeline.effect.scale.ScaleEffect in project tactview by helospark.

the class GeneralCanvasOperationStrategy method getOrAddScaleEffect.

private String getOrAddScaleEffect(String draggedClip) {
    ScaleEffect optionalScale = findOptionalScale(draggedClip);
    if (optionalScale != null) {
        return optionalScale.getId();
    }
    AddEffectCommand addEffectCommand = new AddEffectCommand(draggedClip, "scale", TimelinePosition.ofZero(), timelineManagerAccessor);
    return commandInterpreterService.sendWithResult(addEffectCommand).join().getAddedEffectId();
}
Also used : ScaleEffect(com.helospark.tactview.core.timeline.effect.scale.ScaleEffect) AddEffectCommand(com.helospark.tactview.ui.javafx.commands.impl.AddEffectCommand)

Aggregations

ScaleEffect (com.helospark.tactview.core.timeline.effect.scale.ScaleEffect)2 RegularRectangle (com.helospark.tactview.core.timeline.TimelineRenderResult.RegularRectangle)1 ValueProviderDescriptor (com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor)1 Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)1 PointProvider (com.helospark.tactview.core.timeline.effect.interpolation.provider.PointProvider)1 AddEffectCommand (com.helospark.tactview.ui.javafx.commands.impl.AddEffectCommand)1