Skip to content

Commit

Permalink
fix: improve line drawing code
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Jul 16, 2024
1 parent 16ea484 commit 551a660
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package software.coley.recaf.ui.control.richtext.problem;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import software.coley.recaf.ui.control.richtext.linegraphics.AbstractTextBoundLineGraphicFactory;
Expand All @@ -15,9 +14,7 @@
* @see ProblemTracking
*/
public class ProblemGraphicFactory extends AbstractTextBoundLineGraphicFactory {
/**
* New graphic factory.
*/

public ProblemGraphicFactory() {
super(LineGraphicFactory.P_LINE_PROBLEMS);
}
Expand Down Expand Up @@ -61,22 +58,23 @@ private void drawWaves(Canvas canvas, double errorWidth) {
gc.beginPath();

final double scalingFactor = .7;
final double waveUp = 3 * scalingFactor;
final double waveDown = 6 * scalingFactor;
final double stop = errorWidth - scalingFactor;

// draw sawtooth pattern
for (double offset = 0; offset < stop; offset += waveDown) {
gc.moveTo(offset, containerHeight - waveUp);
if (offset + waveUp < stop)
gc.lineTo(offset + waveUp, containerHeight - waveDown);
if (offset + waveDown < stop)
gc.lineTo(offset + waveDown, containerHeight - waveUp);
// heights
final double waveUp = containerHeight - 3 * scalingFactor;
final double waveDown = containerHeight - 6 * scalingFactor;

final double stepScale = .6;
final double step = waveDown * stepScale;
final double halfStep = step / 2;

// we want to draw waves such that the last wave is on the border of the errorWidth
for (double x = 0; x < errorWidth; x += step) {
gc.moveTo(x, waveUp);
if (x < errorWidth - halfStep)
gc.lineTo(x + halfStep, waveDown);
if (x < errorWidth - step)
gc.lineTo(x + step, waveUp);
}

// draw one last wave up
gc.lineTo(stop, containerHeight - waveUp);

gc.stroke();
gc.closePath();
}
Expand Down

0 comments on commit 551a660

Please sign in to comment.