I am working on a personal project and I want the user to be able to use a simple version of a radial menu. I have been trying to create a ring that is made up of N arcs (or another shape) I want it to look similar to a donut/ring. Where the number of pieces and the inner and outer radius are configurable using a variable.
I want the final thing to be a simple version of this: Helo Wars Radial Menu
I have something parially working but it looks very rough. This is the best I have so far. Below I attached my code and a screenshot of the result. I want every piece to be equal in size that all surround the inner circle
Also as a note, I have seen other posts that make use of increasing the width of an arc I would rather not use that because I was running into issues with a mouse over listener, where there "hit zone" was a little off.
package com.example.javafx21;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.stage.Stage;
public class HelloApplication extends Application {
@Override
public void start(Stage primaryStage) {
Pane root = new Pane();
root.setPrefSize(300, 300);
double centerX = 150;
double centerY = 150;
double innerRadius = 40;
double outerRadius = 100;
int numPieces = 8;
for (int i = 0; i < numPieces; i++) {
double angle = 360.0 / numPieces * i;
Arc arc = new Arc();
arc.setCenterX(centerX);
arc.setCenterY(centerY);
arc.setRadiusX(outerRadius);
arc.setRadiusY(outerRadius);
arc.setStartAngle(angle);
arc.setLength((double) 360 / numPieces);
arc.setType(ArcType.OPEN);
arc.setStroke(Color.color(Math.random(), Math.random(), Math.random()));
arc.setStrokeWidth(outerRadius - innerRadius);
arc.setFill(null);
root.getChildren().add(arc);
}
Scene scene = new Scene(root);
primaryStage.setTitle("Adjustable Radius Semi-Rings");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If it helps here is a full open source implementation you can learn and extend from:
https://github.com/Birdasaur/LitFX/blob/master/litfx-controls/src/main/java/lit/litfx/controls/menus/LitRadialMenu.java
The arc drawing calls are lower down in the Menu Item classes. This implementation is itself a significantly upgraded version of the JFXtras radial component which was originally made by Mr.Lonee.