diff --git a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/DefaultFrameRenderer.java b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/DefaultFrameRenderer.java index a4a35ef..f9b1ede 100644 --- a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/DefaultFrameRenderer.java +++ b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/DefaultFrameRenderer.java @@ -100,9 +100,8 @@ public DefaultFrameRenderer( @Override public void paintFrame( @NotNull Graphics2D g2, - @NotNull FrameModel<@NotNull T> frameModel, + @NotNull FrameBox<@NotNull T> frame, @NotNull FrameModel<@NotNull T> frameModel, @NotNull RectangularShape frameRect, - @NotNull FrameBox<@NotNull T> frame, @NotNull Rectangle2D paintableIntersection, int renderFlags ) { @@ -264,7 +263,7 @@ private String calculateFrameText( } @Override - public RectangularShape reusableFrameRect() { + public RectangularShape reusableFrameShape() { return roundedFrame ? new RoundRectangle2D.Double( 0, 0, 0, 0, 5, 5 ) : new Rectangle2D.Double(); diff --git a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphRenderEngine.java b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphRenderEngine.java index 140ea1e..30b2f14 100644 --- a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphRenderEngine.java +++ b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphRenderEngine.java @@ -307,7 +307,7 @@ private void internalPaint( var frames = frameModel.frames; // paint root { - var rootFrameShape = frameRenderer.reusableFrameRect(); // reusable rectangle + var rootFrameShape = frameRenderer.reusableFrameShape(); // reusable rectangle var rootFrame = frames.get(0); int internalPadding = 0; // Remove ? @@ -321,9 +321,8 @@ private void internalPaint( if (!paintableIntersection.isEmpty()) { frameRenderer.paintFrame( g2d, - frameModel, + rootFrame, frameModel, rootFrameShape, - rootFrame, paintableIntersection, FrameRenderingFlags.toFlags( minimapMode, @@ -340,7 +339,7 @@ private void internalPaint( } // paint real flames - var frameShape = frameRenderer.reusableFrameRect(); // reusable rectangle + var frameShape = frameRenderer.reusableFrameShape(); // reusable rectangle for (int i = 1; i < frames.size(); i++) { var frame = frames.get(i); @@ -359,9 +358,8 @@ private void internalPaint( if (!paintableIntersection.isEmpty()) { frameRenderer.paintFrame( g2d, - frameModel, + frame, frameModel, frameShape, - frame, paintableIntersection, // choose font depending on whether the left-side of the frame is clipped FrameRenderingFlags.toFlags( diff --git a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FrameRenderer.java b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FrameRenderer.java index 269ac04..34bccdb 100644 --- a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FrameRenderer.java +++ b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FrameRenderer.java @@ -1,5 +1,6 @@ package io.github.bric3.fireplace.flamegraph; +import org.jetbrains.annotations.ApiStatus.Experimental; import org.jetbrains.annotations.NotNull; import java.awt.*; @@ -13,6 +14,7 @@ * @see FlamegraphView */ // TODO root frame renderer ? +@Experimental public interface FrameRenderer { /** * The size of the gap at between each side of a frame. @@ -46,9 +48,9 @@ public interface FrameRenderer { * using the {@link FrameRenderingFlags} methods. * * @param g2 the graphics context + * @param frame the frame to paint * @param frameModel the frame model * @param frameRect the frame region (may fall outside visible area). - * @param frame the frame to paint * @param paintableIntersection the intersection between the frame rectangle and the visible region * (can be used to position the text label). * @param renderFlags the rendering flags (minimap, selection, hovered, highlight, etc.) @@ -56,14 +58,21 @@ public interface FrameRenderer { */ void paintFrame( @NotNull Graphics2D g2, + @NotNull FrameBox frame, @NotNull FrameModel frameModel, @NotNull RectangularShape frameRect, - @NotNull FrameBox frame, @NotNull Rectangle2D paintableIntersection, int renderFlags ); - default RectangularShape reusableFrameRect() { + /** + * A factory for the frame rectangle shape, this shape is reused. + * Usually the frame will be a standard rectangle; however, the implementation may want to + * use a different shape (e.g., a rounded rectangle). + * This instance is likely to be reused for each frame. + * @return a new instance of the frame shape. + */ + default RectangularShape reusableFrameShape() { return new Rectangle2D.Double(); } }