use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle in project tactview by helospark.
the class DrawnRectangleHighlightProceduralEffect method createProceduralFrame.
@Override
public ClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
ClipImage result = ClipImage.fromSize(request.getExpectedWidth(), request.getExpectedHeight());
double progress;
double endSeconds = endPositionProvider.getValueAt(relativePosition);
double actualSeconds = relativePosition.getSeconds().doubleValue();
if (endSeconds > actualSeconds) {
progress = actualSeconds / endSeconds;
} else {
progress = 1.0;
}
Rectangle rectangle = rectangleProvider.getValueAt(relativePosition);
double overshoot = overshootProvider.getValueAt(relativePosition);
double totalLength = rectangle.getLength() * (1.0 + overshoot * 2 * 4);
double lengthToDraw = progress * totalLength;
int brushSize = (int) (brushSizeProvider.getValueAt(relativePosition) * request.getScale());
if (brushSize < 1) {
brushSize = 1;
}
String brushFilePath = brushFileProvider.getValueOrDefault(relativePosition, "classpath:/brushes/Sponge-02.gbr");
Point brushHalfSize = new Point((double) brushSize / request.getExpectedWidth() / 2.0, (double) brushSize / request.getExpectedHeight() / 2.0);
Color color = colorProvider.getValueAt(relativePosition);
for (int i = 0; i < 4 && lengthToDraw > 0.0; ++i) {
// 0->1, 1->2, 2->3, 3->0
Point start = rectangle.points.get(i).subtract(brushHalfSize);
Point end = rectangle.points.get((i + 1) % 4).subtract(brushHalfSize);
Point overshootOffsetVector = end.subtract(start).normalize().scalarMultiply(overshoot);
start = start.subtract(overshootOffsetVector);
end = end.add(overshootOffsetVector);
double distance = start.distanceFrom(end);
double lineProgress = lengthToDraw > distance ? 1.0 : lengthToDraw / distance;
Point startInPixels = start.multiply(request.getExpectedWidth(), request.getExpectedHeight());
Point endInPixels = end.multiply(request.getExpectedWidth(), request.getExpectedHeight());
DrawLineRequest drawLineRequest = DrawLineRequest.builder().withBrushFilePath(brushFilePath).withBrushSize(brushSize).withColor(color).withPixels(bresenhemPixelProvider.linePixels(startInPixels, endInPixels)).withProgress(lineProgress).withResult(result).build();
drawLineService.drawLine(drawLineRequest);
lengthToDraw -= distance;
}
return result;
}
use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle in project tactview by helospark.
the class RectangleProviderValueSetterChainItem method handle.
@Override
protected EffectLine handle(RectangleProvider rectangleProvider, ValueProviderDescriptor descriptor) {
List<EffectLine> pointProviders = new ArrayList<>();
for (int i = 0; i < 4; ++i) {
pointProviders.add(pointProviderValueSetterChainItem.create(descriptor, rectangleProvider.getChildren().get(i)));
}
Button button = new Button("", new Glyph("FontAwesome", FontAwesome.Glyph.SQUARE));
VBox vbox = new VBox();
pointProviders.stream().forEach(a -> vbox.getChildren().add(a.visibleNode));
HBox hbox = new HBox();
hbox.getChildren().add(vbox);
hbox.getChildren().add(button);
CompositeEffectLine result = CompositeEffectLine.builder().withVisibleNode(hbox).withValues(pointProviders).withDescriptorId(rectangleProvider.getId()).withEffectParametersRepository(effectParametersRepository).withCommandInterpreter(commandInterpreter).withDescriptor(descriptor).withUpdateFromValue(value -> {
Rectangle line = (Rectangle) value;
for (int i = 0; i < 4; ++i) {
pointProviders.get(i).getUpdateFromValue().accept(line.points.get(i));
}
}).build();
button.setOnMouseClicked(event -> {
if (event.getButton() == MouseButton.PRIMARY) {
Rectangle previousValue = rectangleProvider.getValueAt(uiTimelineManager.getCurrentPosition());
inputModeRepository.requestRectangle(rectangle -> {
boolean revertable = this.inputModeRepository.getResultType().equals(ResultType.DONE);
KeyframeAddedRequest keyframeRequest = KeyframeAddedRequest.builder().withDescriptorId(rectangleProvider.getId()).withGlobalTimelinePosition(uiTimelineManager.getCurrentPosition()).withValue(rectangle).withPreviousValue(Optional.ofNullable(previousValue)).withRevertable(revertable).build();
commandInterpreter.sendWithResult(new AddKeyframeForPropertyCommand(effectParametersRepository, keyframeRequest));
}, getCurrentValue(pointProviders), rectangleProvider.getSizeFunction());
}
});
contextMenuAppender.addContextMenu(result, rectangleProvider, descriptor, button);
return result;
}
use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle in project tactview by helospark.
the class RectangleWarpEffect method createFrame.
@Override
public ReadOnlyClipImage createFrame(StatelessEffectRequest request) {
ClipImage result = ClipImage.fromSize(request.getCanvasWidth(), request.getCanvasHeight());
Rectangle rectangle = rectangleProvider.getValueAt(request.getEffectPosition());
List<Point> points = rectangle.points.stream().map(a -> a.multiply(request.getCurrentFrame().getWidth(), request.getCurrentFrame().getHeight())).collect(Collectors.toList());
SimpleVertex a = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(0).x, points.get(0).y)).withTextureCoordinates(new Vector2D(0, 0)).build();
SimpleVertex b = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(1).x, points.get(1).y)).withTextureCoordinates(new Vector2D(1, 0)).build();
SimpleVertex c = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(2).x, points.get(2).y)).withTextureCoordinates(new Vector2D(1, 1)).build();
SimpleVertex d = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(3).x, points.get(3).y)).withTextureCoordinates(new Vector2D(0, 1)).build();
drawTriangle(request, result, a, c, b);
drawTriangle(request, result, a, d, c);
return result;
}
Aggregations