Skip to content

Commit 1dfc53b

Browse files
committed
fixing bug in circle out of ring tool
make exported file background transparent
1 parent 32e2be3 commit 1dfc53b

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ hs_err_pid*
2727
/.classpath
2828
/.project
2929
/build/
30+
/bin/
3031
/.settings/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ir.hosseinmp76.shayancircles;
2+
3+
import java.awt.image.RenderedImage;
4+
import java.io.File;
5+
import java.io.IOException;
6+
7+
import javax.imageio.ImageIO;
8+
9+
import ir.hosseinmp76.shayancircles.ui.fx.MyCanvas;
10+
import javafx.embed.swing.SwingFXUtils;
11+
import javafx.scene.SnapshotParameters;
12+
import javafx.scene.image.WritableImage;
13+
import javafx.scene.paint.Color;
14+
15+
public class Utills {
16+
public static void savePNG(int width, int height, MyCanvas canvas, File file) {
17+
try {
18+
final WritableImage writableImage = new WritableImage(width,
19+
height);
20+
SnapshotParameters sp = new SnapshotParameters();
21+
sp.setFill(Color.TRANSPARENT);
22+
23+
canvas.snapshot(sp, writableImage);
24+
final RenderedImage renderedImage = SwingFXUtils
25+
.fromFXImage(writableImage, null);
26+
ImageIO.write(renderedImage, "png", file);
27+
} catch (final IOException ex) {
28+
}
29+
}
30+
}

src/main/java/ir/hosseinmp76/shayancircles/tools/ClasicCircleOutOfRingTool.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public static Vector2D staticGetPoint(
1212
final var r = tool.getInnerCirleRadios();
1313
final var R = tool.getOuterCirleBigRadios();
1414
final double outerAngle = tool.toolState.getTraveledRadius()
15-
% (2 * Math.PI * tool.getOuterCirleSmallRadios())
16-
/ tool.getOuterCirleSmallRadios();
15+
% (2 * Math.PI * R) / R;
1716
final double innerAngle = tool.toolState.getTraveledRadius()
1817
% (2 * Math.PI * r) / r;
1918

@@ -35,6 +34,12 @@ public ClasicCircleOutOfRingTool(final double outerCirleRadios,
3534
penHoleDistanceToInnerCirleCenter, color);
3635
// TODO Auto-generated constructor stub
3736
}
37+
38+
39+
@Override
40+
public Vector2D getPoint() {
41+
return ClasicCircleOutOfRingTool.staticGetPoint(this);
42+
}
3843

3944
@Override
4045
public boolean isFinished() {

src/main/java/ir/hosseinmp76/shayancircles/ui/fx/FXApplication.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import javax.imageio.ImageIO;
88

9-
9+
import ir.hosseinmp76.shayancircles.Utills;
1010
import ir.hosseinmp76.shayancircles.tools.AbstractTool;
1111
import ir.hosseinmp76.shayancircles.tools.ClasicCircleOutOfRingTool;
1212
import ir.hosseinmp76.shayancircles.tools.ClasicRingCircleTool;
@@ -20,6 +20,7 @@
2020
import javafx.event.EventHandler;
2121
import javafx.geometry.Orientation;
2222
import javafx.scene.Scene;
23+
import javafx.scene.SnapshotParameters;
2324
import javafx.scene.control.Button;
2425
import javafx.scene.control.ColorPicker;
2526
import javafx.scene.control.ComboBox;
@@ -126,7 +127,7 @@ public void handle(final long now) {
126127
FXApplication.this.tool.changeColor(colorPicker.getValue());
127128
});
128129
final var myCanvasParentPane = new Pane();
129-
130+
myCanvasParentPane.setBackground(null);
130131
ComboBox<ToolType> comboBox = new ComboBox();
131132
comboBox.getItems().add(ToolType.ClasicCircleOutOfRingTool);
132133
comboBox.getItems().add(ToolType.ClasicRingCircleTool);
@@ -199,15 +200,8 @@ public void handle(final long now) {
199200
final File file = fileChooser.showSaveDialog(stage);
200201

201202
if (file != null) {
202-
try {
203-
final WritableImage writableImage = new WritableImage(
204-
FXApplication.width, FXApplication.height);
205-
FXApplication.this.myCanvas.snapshot(null, writableImage);
206-
final RenderedImage renderedImage = SwingFXUtils
207-
.fromFXImage(writableImage, null);
208-
ImageIO.write(renderedImage, "png", file);
209-
} catch (final IOException ex) {
210-
}
203+
Utills.savePNG(FXApplication.this.width, FXApplication.this.height,
204+
myCanvas, file);
211205
}
212206
});
213207

@@ -245,4 +239,5 @@ public void handle(final long now) {
245239

246240
}
247241

242+
248243
}

src/main/java/ir/hosseinmp76/shayancircles/ui/fx/MyCanvas.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ public class MyCanvas extends Canvas {
3030
this.tool = tool;
3131
this.perSecond = perSecond;
3232
this.centerOfCanvas = new Vector2D(widght / 2, height / 2);
33-
var gc = this.getGraphicsContext2D();
34-
gc.fillOval(0, 0, widght, height);
33+
34+
// var gc = this.getGraphicsContext2D();
35+
// gc.setFill(Color.TRANSPARENT);
36+
// gc.fillRect(0, 0, widght, height);
37+
// gc.setFill(Color.BLACK);
38+
// gc.fillOval(0, 0, widght, height);
3539

3640
}
3741

0 commit comments

Comments
 (0)