Skip to content

Commit 28a4d40

Browse files
committed
Added RGB light
1 parent abe70d9 commit 28a4d40

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

src/main/java/com/orangomango/logicsim/MainApplication.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ public void start(Stage stage){
496496
case 9:
497497
g = new TriStateBuffer(gc, new Rectangle2D(clickPoint.getX(), clickPoint.getY(), 100, 50));
498498
break;
499+
case 10:
500+
g = new LightRGB(gc, new Rectangle2D(clickPoint.getX(), clickPoint.getY(), 50, 50));
501+
break;
499502
}
500503
if (g != null){
501504
if (loaded) this.gates.add(g);
@@ -863,6 +866,10 @@ private ContextMenu buildContextMenu(Gate found, Pin pinFound){
863866
gate.setLabel(v);
864867
});
865868
});
869+
MenuItem deleteGate = new MenuItem("Delete");
870+
deleteGate.setOnAction(ev -> {
871+
this.gatesToRemove.add(found);
872+
});
866873
if (pinFound != null){
867874
final Pin pin = pinFound;
868875
if (gate instanceof Bus){
@@ -871,7 +878,7 @@ private ContextMenu buildContextMenu(Gate found, Pin pinFound){
871878
cm.getItems().add(removePin);
872879
}
873880
}
874-
cm.getItems().add(changeLabel);
881+
cm.getItems().addAll(changeLabel, deleteGate);
875882
return cm;
876883
}
877884

@@ -906,8 +913,9 @@ private void buildSideArea(GraphicsContext gc){
906913
this.sideArea = new SideArea(gc, new Rectangle2D(WIDTH-50, 250, 50, 75), new Rectangle2D(TOOLBAR_X, 0, WIDTH*0.3, HEIGHT));
907914
this.sideArea.setButtonSize(80);
908915
this.sideArea.addButton("Switch", () -> this.selectedId = 0);
909-
this.sideArea.addButton("Wire", () -> this.selectedId = 1);
910916
this.sideArea.addButton("Light", () -> this.selectedId = 2);
917+
this.sideArea.addButton("RGB Light", () -> this.selectedId = 10);
918+
this.sideArea.addButton("Wire", () -> this.selectedId = 1);
911919
this.sideArea.addButton("NOT gate", () -> this.selectedId = 3);
912920
this.sideArea.addButton("AND gate", () -> this.selectedId = 4);
913921
this.sideArea.addButton("Chip", () -> this.selectedId = 5);
@@ -1009,7 +1017,7 @@ public static JSONObject load(File file, GraphicsContext gc, List<Gate> tempGate
10091017
if (name.equals("AND")){
10101018
gt = new AndGate(gc, rect);
10111019
} else if (name.equals("LIGHT")){
1012-
gt = new Light(gc, rect);
1020+
gt = pins.size() == 3 ? new LightRGB(gc, rect) : new Light(gc, rect);
10131021
} else if (name.equals("NOT")){
10141022
gt = new NotGate(gc, rect);
10151023
} else if (name.equals("SWITCH")){

src/main/java/com/orangomango/logicsim/core/Light.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import javafx.scene.image.Image;
66

77
public class Light extends Gate{
8-
private Image image;
8+
protected Image image;
99

1010
public Light(GraphicsContext gc, Rectangle2D rect){
1111
super(gc, "LIGHT", rect, null);
@@ -20,6 +20,6 @@ public boolean isOn(){
2020

2121
@Override
2222
protected void renderGate(GraphicsContext gc){
23-
gc.drawImage(this.image, 1+(isOn() ? 52 : 0), 1, 50, 50, this.rect.getMinX(), this.rect.getMinY(), this.rect.getWidth(), this.rect.getHeight());
23+
gc.drawImage(this.image, 1+(isOn() ? 0 : 52), 1, 50, 50, this.rect.getMinX(), this.rect.getMinY(), this.rect.getWidth(), this.rect.getHeight());
2424
}
2525
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.orangomango.logicsim.core;
2+
3+
import javafx.scene.canvas.GraphicsContext;
4+
import javafx.geometry.Rectangle2D;
5+
6+
public class LightRGB extends Light{
7+
public LightRGB(GraphicsContext gc, Rectangle2D rect){
8+
super(gc, rect);
9+
this.label = "RGB Light";
10+
this.pins.clear(); // Reset pins
11+
this.pins.add(new Pin(this, new Rectangle2D(rect.getMinX()-7, rect.getMinY()+3, 10, 10), true));
12+
this.pins.add(new Pin(this, new Rectangle2D(rect.getMinX()-7, rect.getMinY()+21, 10, 10), true));
13+
this.pins.add(new Pin(this, new Rectangle2D(rect.getMinX()-7, rect.getMinY()+39, 10, 10), true));
14+
}
15+
16+
private int getRGB(){
17+
int rgb = 0;
18+
if (this.pins.get(0).isOn()) rgb |= 4;
19+
if (this.pins.get(1).isOn()) rgb |= 2;
20+
if (this.pins.get(2).isOn()) rgb |= 1;
21+
return rgb;
22+
}
23+
24+
@Override
25+
public boolean isOn(){
26+
return getRGB() != 0;
27+
}
28+
29+
@Override
30+
protected void renderGate(GraphicsContext gc){
31+
int index = getRGB()+1;
32+
gc.drawImage(this.image, 1+(52*index), 1, 50, 50, this.rect.getMinX(), this.rect.getMinY(), this.rect.getWidth(), this.rect.getHeight());
33+
}
34+
}

src/main/resources/light.png

632 Bytes
Loading

0 commit comments

Comments
 (0)