Skip to content

Commit

Permalink
chore: Reorder paintFrame args
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed May 21, 2024
1 parent bb2feda commit 4b89d00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Expand All @@ -321,9 +321,8 @@ private void internalPaint(
if (!paintableIntersection.isEmpty()) {
frameRenderer.paintFrame(
g2d,
frameModel,
rootFrame, frameModel,
rootFrameShape,
rootFrame,
paintableIntersection,
FrameRenderingFlags.toFlags(
minimapMode,
Expand All @@ -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);

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.bric3.fireplace.flamegraph;

import org.jetbrains.annotations.ApiStatus.Experimental;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
Expand All @@ -13,6 +14,7 @@
* @see FlamegraphView
*/
// TODO root frame renderer ?
@Experimental
public interface FrameRenderer<T> {
/**
* The size of the gap at between each side of a frame.
Expand Down Expand Up @@ -46,24 +48,31 @@ public interface FrameRenderer<T> {
* 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.)
* @see FrameRenderingFlags
*/
void paintFrame(
@NotNull Graphics2D g2,
@NotNull FrameBox<T> frame,
@NotNull FrameModel<T> frameModel,
@NotNull RectangularShape frameRect,
@NotNull FrameBox<T> 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();
}
}

0 comments on commit 4b89d00

Please sign in to comment.