Skip to content

Commit

Permalink
Add wire thickness setting
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobTernes committed Mar 7, 2024
1 parent 28b6cf4 commit 527e8ed
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/fabulator/language/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public enum Text {
ERROR,
CLOSE,
INVALID_GEOM_FILE,
INVALID_HDL_FILE;
INVALID_HDL_FILE,

THICKNESS;

private StringProperty stringProperty;

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fabulator/ui/builder/SliderBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fabulator.ui.builder;

import javafx.beans.property.DoubleProperty;
import javafx.beans.value.ChangeListener;
import javafx.scene.control.Slider;
import javafx.util.Builder;

Expand All @@ -27,6 +28,11 @@ public SliderBuilder setMax(double maxValue) {
return this;
}

public SliderBuilder addListener(ChangeListener<Number> changeListener) {
this.slider.valueProperty().addListener(changeListener);
return this;
}

@Override
public Slider build() {
return this.slider;
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/fabulator/ui/fabric/Fabric.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package fabulator.ui.fabric;

import fabulator.geometry.*;
import fabulator.language.Text;
import fabulator.lookup.BitstreamConfiguration;
import fabulator.lookup.LineMap;
import fabulator.settings.Config;
import fabulator.ui.builder.MenuItemBuilder;
import fabulator.ui.builder.RectangleBuilder;
import fabulator.ui.builder.SliderBuilder;
import fabulator.ui.fabric.element.ElementType;
import fabulator.ui.fabric.element.FabricElement;
import fabulator.ui.fabric.port.AbstractPort;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Bounds;
import javafx.scene.Group;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Slider;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
Expand Down Expand Up @@ -46,6 +50,7 @@ public class Fabric extends Group {
private LineMap lineMap;
private Line currentlySelected;
private ContextMenu lineMenu;
private Slider thicknessController;

private Rectangle topLeft;
private Rectangle topRight;
Expand Down Expand Up @@ -78,7 +83,22 @@ private void initializeLineHandling() {
.setOnAction(colorPickedHandler)
.build();

this.lineMenu = new ContextMenu(colorItem);
ChangeListener<Number> thicknessListener = (obs, old, now) -> {
this.setWireThickness((Double) now);
};

this.thicknessController = new SliderBuilder()
.setMin(0.2)
.setMax(0.8)
.addListener(thicknessListener)
.build();

MenuItem thicknessItem = new MenuItemBuilder()
.setText(Text.THICKNESS)
.setGraphic(thicknessController)
.build();

this.lineMenu = new ContextMenu(thicknessItem, colorItem);
}

public void build() {
Expand Down Expand Up @@ -159,6 +179,7 @@ private void initLodSystem() {

public void openLineMenu(Line line, ContextMenuEvent event) {
this.currentlySelected = line;
this.thicknessController.setValue(line.getStrokeWidth());
this.lineMenu.show(line, event.getScreenX(), event.getScreenY());
}

Expand All @@ -169,6 +190,13 @@ private void colorWire(Paint color) {
for (Line wire : toBeColored) wire.setStroke(color);
}

private void setWireThickness(Double value) {
assert this.currentlySelected != null;

Set<Line> toBeColored = this.lineMap.allLinesAt(this.currentlySelected);
for (Line wire : toBeColored) wire.setStrokeWidth(value);
}

public void highlightWire(AbstractPort port) {
Config config = Config.getInstance();
Property<Color> colorProp = config.getUserDesignColor();
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/language/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ OF: of
ERROR: Error
CLOSE: Close
INVALID_GEOM_FILE: Invalid geometry file
INVALID_HDL_FILE: Invalid HDL file
INVALID_HDL_FILE: Invalid HDL file
THICKNESS: Thickness
1 change: 1 addition & 0 deletions src/main/resources/language/german.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ ERROR: Fehler
CLOSE: Schließen
INVALID_GEOM_FILE: Ungültige Geometrie-Datei
INVALID_HDL_FILE: Ungültige HDL-Datei
THICKNESS: Dicke

0 comments on commit 527e8ed

Please sign in to comment.