Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.piitex.engine</groupId>
<artifactId>ren-engine</artifactId>
<version>1.0.5-SNAPSHOT</version>
<version>1.0.6-SNAPSHOT</version>
<name>RenEngine</name>

<properties>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/piitex/engine/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Renderer extends Element {
private Color borderColor;
private double borderWidth = 1;
private final List<String> styles = new ArrayList<>();
private Window window;

// Handlers for events
private IRendererKey iRendererKey;
Expand Down Expand Up @@ -146,6 +147,15 @@ public void addStyle(String style) {
styles.add(style);
}

public Window getWindow() {
return window;
}

public void setWindow(Window window) {
this.window = window;
}


public TreeMap<Integer, Element> getElements() {
return elements;
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/me/piitex/engine/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import me.piitex.engine.layouts.Layout;
import me.piitex.engine.loaders.ImageLoader;
import me.piitex.engine.overlays.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedList;
import java.util.Map;
Expand Down Expand Up @@ -86,11 +88,14 @@

private final boolean scale;
private final boolean focused;
private boolean antialiasing;

Check warning on line 91 in src/main/java/me/piitex/engine/Window.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `antialiasing` may be 'final'

private TreeMap<Integer, Container> containers = new TreeMap<>();
private Container currentPopup = null;
private IWindowResize windowResize;

private static final Logger logger = LoggerFactory.getLogger(Window.class);

/**
* Constructs a Window instance using properties defined in a {@link WindowBuilder}.
* This allows for a flexible and readable way to configure window properties.
Expand Down Expand Up @@ -125,6 +130,7 @@
this.maximized = builder.isMaximized();
this.focused = builder.isFocused();
this.scale = builder.isScale();
this.antialiasing = builder.isAntialiasing();
buildStage();

// Display stage.
Expand Down Expand Up @@ -157,6 +163,11 @@
Scale scale = new Scale(getWidthScale(), getHeightScale(), 0, 0);
root.getTransforms().setAll(scale);
}
if (!antialiasing) {
logger.warn("Forced disabled anti-aliasing.");
System.setProperty("prism.lcdtext", "false");
System.setProperty("prism.subpixeltext", "false");
}

handleWindowScaling(stage);

Expand Down Expand Up @@ -301,6 +312,7 @@
addContainer(current, i);
}
containers.put(index, container);
container.setWindow(this); // Store window reference.

Node assemble = container.assemble();

Expand Down Expand Up @@ -460,8 +472,12 @@
* Closes the JavaFX Stage associated with this window.
* A garbage collection hint is provided to the JVM.
*/
public void close() {
public void close(boolean handleEvent) {
if (stage != null) {
if (!handleEvent) {
stage.setOnHidden(null);
stage.setOnCloseRequest(null);
}
stage.close();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/me/piitex/engine/WindowBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class WindowBuilder {
private boolean maximized = false;
private boolean focused = true;
private boolean scale = true;
private boolean antialiasing = true;

/**
* Starts the building process for a new Window with a required title.
Expand Down Expand Up @@ -130,6 +131,11 @@ public WindowBuilder setScale(boolean scale) {
return this;
}

public WindowBuilder setAntiAliasing(boolean aliasing) {
this.antialiasing = aliasing;
return this;
}

/**
* Constructs and returns a new {@link Window} object based on the builder's configurations.
* @return A new Window instance.
Expand Down Expand Up @@ -182,4 +188,7 @@ public boolean isScale() {
return scale;
}

public boolean isAntialiasing() {
return antialiasing;
}
}
2 changes: 1 addition & 1 deletion src/main/java/me/piitex/engine/loaders/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;
import me.piitex.engine.LimitedHashMap;
import me.piitex.engine.maps.LimitedHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.piitex.engine;
package me.piitex.engine.maps;

import java.util.Collection;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.piitex.engine;
package me.piitex.engine.maps;

import java.util.TreeMap;

Expand Down
15 changes: 14 additions & 1 deletion src/main/java/me/piitex/engine/overlays/FileChooserOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class FileChooserOverlay extends Overlay {
private String text;
private ButtonOverlay button;
private FontLoader fontLoader;
private String[] fileExtensions;

public FileChooserOverlay(Window window, String text) {
this.window = window;
Expand All @@ -31,6 +32,10 @@ public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public ButtonOverlay getButton() {
return button;
}
Expand All @@ -51,6 +56,14 @@ public void onFileSelect(IDirectorySelect iDirectorySelect) {
this.directorySelect = iDirectorySelect;
}

/**
* Set a specific file extension to be use used. You can set both a prefix and a subfix; *.png, filename.*, *.*
* @param fileExtensions The array of all valid file extensions.
*/
public void setFileExtensions(String[] fileExtensions) {
this.fileExtensions = fileExtensions;
}

@Override
public Node render() {
Button jfxButton;
Expand All @@ -64,7 +77,7 @@ public Node render() {

jfxButton.setOnMouseClicked(event -> {
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Select character card", "*.png"));
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(text, fileExtensions));
File directory = chooser.showOpenDialog(window.getStage());

if (getFileSelect() != null) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/me/piitex/engine/overlays/TextFlowOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.FontSmoothingType;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import me.piitex.engine.loaders.FontLoader;
Expand All @@ -16,6 +17,7 @@ public class TextFlowOverlay extends Overlay implements Region {
private String text;
private Color textFillColor;
private FontLoader font;
private FontSmoothingType fontSmoothingType = FontSmoothingType.GRAY;
private double width, height, prefWidth, prefHeight, maxWidth, maxHeight;
private double scaleWidth, scaleHeight;

Expand Down Expand Up @@ -88,6 +90,14 @@ public void setFont(FontLoader font) {
}
}

public FontSmoothingType getFontSmoothingType() {
return fontSmoothingType;
}

public void setFontSmoothingType(FontSmoothingType fontSmoothingType) {
this.fontSmoothingType = fontSmoothingType;
}

public void add(Overlay overlay) {
texts.add(overlay);
textFlow.getChildren().add(overlay.assemble());
Expand Down Expand Up @@ -135,6 +145,9 @@ public Node render() {
if (textFillColor != null) {
text1.setTextFill(textFillColor);
}
if (fontSmoothingType != null) {
text1.setFontSmoothingType(fontSmoothingType);
}
}
case HyperLinkOverlay hyperlink -> {
if (font != null) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/me/piitex/engine/overlays/TextOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.text.FontSmoothingType;
import javafx.scene.text.Text;
import me.piitex.engine.loaders.FontLoader;
import org.kordamp.ikonli.javafx.FontIcon;
Expand All @@ -11,6 +12,7 @@ public class TextOverlay extends Overlay {
private String string;
private Color textFillColor;
private FontLoader fontLoader;
private FontSmoothingType fontSmoothingType;
private boolean strikeout, underline;


Expand Down Expand Up @@ -66,6 +68,14 @@ public TextOverlay(String text, Color textFillColor, FontLoader fontLoader, int
setY(y);
}

public FontSmoothingType getFontSmoothingType() {
return fontSmoothingType;
}

public void setFontSmoothingType(FontSmoothingType fontSmoothingType) {
this.fontSmoothingType = fontSmoothingType;
}

@Override
public Node render() {
if (node instanceof FontIcon icon) {
Expand All @@ -75,6 +85,7 @@ public Node render() {
} else if (node instanceof Text text) {
// If text is set, render a Text node.
text.setText(string);
text.setFontSmoothingType(fontSmoothingType);
if (textFillColor != null) {
text.setFill(textFillColor);
}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/me/piitex/os/FileDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.*;

Expand All @@ -20,6 +23,8 @@ public class FileDownloader {
private final ConcurrentMap<String, URLConnection> activeConnections = new ConcurrentHashMap<>();
private final Set<DownloadListener> listeners = Collections.newSetFromMap(new ConcurrentHashMap<>());

private final Map<String, String> requestProperties = new HashMap<>();

/**
* Initializes the FileDownloader and its thread pool.
*/
Expand Down Expand Up @@ -47,9 +52,11 @@ public void startDownload(String fileUrl, File outputFile) {
private void performDownload(String fileUrl, File outputFile) {
DownloadInfo info = null;
try {
URL url = new URL(fileUrl);
URL url = new URI(fileUrl).toURL();
URLConnection connection = url.openConnection();
connection.setConnectTimeout(5000);
requestProperties.forEach(connection::setRequestProperty);

activeConnections.put(fileUrl, connection); // Store the connection

long fileSize = connection.getContentLengthLong();
Expand Down Expand Up @@ -152,6 +159,10 @@ public long getRemoteFileSize(String fileUrl) throws IOException {
return connection.getContentLengthLong();
}

public void addRequestProperty(String key, String value) {
requestProperties.put(key, value);
}

public void addDownloadListener(DownloadListener listener) {
this.listeners.add(listener);
logger.debug("DownloadListener added: {}", listener.getClass().getSimpleName());
Expand Down
Loading