Skip to content

Commit

Permalink
Fixed image loading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Brov3r committed Aug 11, 2024
1 parent a8bed37 commit 07fc2e2
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 174 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added notification system
- Added the ability to block the loading of lua files (useful for replacing Lua with Java)
- Fixed image loading logic
- Fixed visibility area of fields, classes and methods in Widgets
- Fixed bugs when scrolling widgets
- Fixed a bug with absolute positioning of widgets
Expand Down
61 changes: 22 additions & 39 deletions docs/javadoc/com/avrix/ui/NanoImage.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,26 @@ <h2>Method Summary</h2>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Checks if the given file extension is a supported image type.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static void</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadCacheImages(com.avrix.ui.NanoContext)" class="member-name-link">loadCacheImages</a><wbr>(<a href="NanoContext.html" title="class in com.avrix.ui">NanoContext</a>&nbsp;context)</code></div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.lang.String)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;urlString)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Loads images from the cache directory into the NVG context.</div>
<div class="block">Loads an image from a URL string and returns its ID.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.lang.String)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;urlString)</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.lang.String,java.lang.String)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;jarFilePath,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;internalFilePath)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Loads an image from a URL.</div>
<div class="block">Loads an image from a JAR file.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.lang.String,java.lang.String)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;jarFilePath,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;internalFilePath)</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.net.URL)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/URL.html" title="class or interface in java.net" class="external-link">URL</a>&nbsp;url)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Loads an image from a JAR file.</div>
<div class="block">Loads an image from a URL and returns its ID.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.net.URL)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/URL.html" title="class or interface in java.net" class="external-link">URL</a>&nbsp;url)</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.nio.file.Path)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Path.html" title="class or interface in java.nio.file" class="external-link">Path</a>&nbsp;path)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Loads an image from a URL.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#loadImage(java.nio.file.Path)" class="member-name-link">loadImage</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Path.html" title="class or interface in java.nio.file" class="external-link">Path</a>&nbsp;path)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Loads an image from a local file.</div>
<div class="block">Loads an image from a file path and returns its ID.</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -212,68 +207,56 @@ <h3>NanoImage</h3>
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="loadCacheImages(com.avrix.ui.NanoContext)">
<h3>loadCacheImages</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">loadCacheImages</span><wbr><span class="parameters">(<a href="NanoContext.html" title="class in com.avrix.ui">NanoContext</a>&nbsp;context)</span></div>
<div class="block">Loads images from the cache directory into the NVG context.
Creates the cache directory if it does not exist.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>context</code> - The NVG context used to load textures.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="loadImage(java.lang.String,java.lang.String)">
<h3>loadImage</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">loadImage</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;jarFilePath,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;internalFilePath)</span></div>
<div class="block">Loads an image from a JAR file.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>jarFilePath</code> - Path to the JAR file.</dd>
<dd><code>internalFilePath</code> - Path to the image inside the JAR.</dd>
<dd><code>jarFilePath</code> - Path to the JAR file</dd>
<dd><code>internalFilePath</code> - Path to the image inside the JAR</dd>
<dt>Returns:</dt>
<dd>The image identifier or -1 if the image could not be loaded.</dd>
<dd>the image ID, or -1 if loading failed</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="loadImage(java.nio.file.Path)">
<h3>loadImage</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">loadImage</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Path.html" title="class or interface in java.nio.file" class="external-link">Path</a>&nbsp;path)</span></div>
<div class="block">Loads an image from a local file.</div>
<div class="block">Loads an image from a file path and returns its ID. The image is cached for future use.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>path</code> - Path to the local image file.</dd>
<dd><code>path</code> - the path to the image file</dd>
<dt>Returns:</dt>
<dd>The image identifier or -1 if the image could not be loaded.</dd>
<dd>the image ID, or -1 if loading failed</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="loadImage(java.net.URL)">
<h3>loadImage</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">loadImage</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/URL.html" title="class or interface in java.net" class="external-link">URL</a>&nbsp;url)</span></div>
<div class="block">Loads an image from a URL.</div>
<div class="block">Loads an image from a URL and returns its ID. The image is cached for future use.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>url</code> - The URL string to load the image from.</dd>
<dd><code>url</code> - the URL of the image</dd>
<dt>Returns:</dt>
<dd>The image identifier or -1 if the image could not be loaded.</dd>
<dd>the image ID, or -1 if loading failed</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="loadImage(java.lang.String)">
<h3>loadImage</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">loadImage</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;urlString)</span></div>
<div class="block">Loads an image from a URL.</div>
<div class="block">Loads an image from a URL string and returns its ID. The image is cached for future use.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>urlString</code> - The URL string to load the image from.</dd>
<dd><code>urlString</code> - the URL string of the image</dd>
<dt>Returns:</dt>
<dd>The image identifier or -1 if the image could not be loaded.</dd>
<dd>the image ID, or -1 if loading failed</dd>
</dl>
</section>
</li>
Expand Down
10 changes: 3 additions & 7 deletions docs/javadoc/index-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -4290,10 +4290,6 @@ <h2 class="title" id="I:L">L</h2>
<dd>
<div class="block">The loadAgent method loads the agent into the current JVM if it is not already loaded.</div>
</dd>
<dt><a href="com/avrix/ui/NanoImage.html#loadCacheImages(com.avrix.ui.NanoContext)" class="member-name-link">loadCacheImages(NanoContext)</a> - Static method in class com.avrix.ui.<a href="com/avrix/ui/NanoImage.html" title="class in com.avrix.ui">NanoImage</a></dt>
<dd>
<div class="block">Loads images from the cache directory into the NVG context.</div>
</dd>
<dt><a href="com/avrix/plugin/Plugin.html#loadConfig(java.lang.String)" class="member-name-link">loadConfig(String)</a> - Method in class com.avrix.plugin.<a href="com/avrix/plugin/Plugin.html" title="class in com.avrix.plugin">Plugin</a></dt>
<dd>
<div class="block">Loading the configuration file.</div>
Expand All @@ -4308,19 +4304,19 @@ <h2 class="title" id="I:L">L</h2>
</dd>
<dt><a href="com/avrix/ui/NanoImage.html#loadImage(java.lang.String)" class="member-name-link">loadImage(String)</a> - Static method in class com.avrix.ui.<a href="com/avrix/ui/NanoImage.html" title="class in com.avrix.ui">NanoImage</a></dt>
<dd>
<div class="block">Loads an image from a URL.</div>
<div class="block">Loads an image from a URL string and returns its ID.</div>
</dd>
<dt><a href="com/avrix/ui/NanoImage.html#loadImage(java.lang.String,java.lang.String)" class="member-name-link">loadImage(String, String)</a> - Static method in class com.avrix.ui.<a href="com/avrix/ui/NanoImage.html" title="class in com.avrix.ui">NanoImage</a></dt>
<dd>
<div class="block">Loads an image from a JAR file.</div>
</dd>
<dt><a href="com/avrix/ui/NanoImage.html#loadImage(java.net.URL)" class="member-name-link">loadImage(URL)</a> - Static method in class com.avrix.ui.<a href="com/avrix/ui/NanoImage.html" title="class in com.avrix.ui">NanoImage</a></dt>
<dd>
<div class="block">Loads an image from a URL.</div>
<div class="block">Loads an image from a URL and returns its ID.</div>
</dd>
<dt><a href="com/avrix/ui/NanoImage.html#loadImage(java.nio.file.Path)" class="member-name-link">loadImage(Path)</a> - Static method in class com.avrix.ui.<a href="com/avrix/ui/NanoImage.html" title="class in com.avrix.ui">NanoImage</a></dt>
<dd>
<div class="block">Loads an image from a local file.</div>
<div class="block">Loads an image from a file path and returns its ID.</div>
</dd>
<dt><a href="com/avrix/lua/LuaManager.html#loadLuaFromFolder(java.lang.String,boolean)" class="member-name-link">loadLuaFromFolder(String, boolean)</a> - Static method in class com.avrix.lua.<a href="com/avrix/lua/LuaManager.html" title="class in com.avrix.lua">LuaManager</a></dt>
<dd>
Expand Down
2 changes: 1 addition & 1 deletion docs/javadoc/member-search-index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.avrix.ui.NanoColor;
import com.avrix.ui.NanoContext;
import com.avrix.ui.NanoDrawer;
import com.avrix.ui.NanoImage;
import com.avrix.utils.WindowUtils;
import zombie.GameWindow;

Expand Down Expand Up @@ -45,7 +46,7 @@ public void handleEvent(NanoContext context) {
float x = 120 + AMPLITUDE * (float) Math.cos(phase);


NanoDrawer.drawImage(WidgetManagerInitHandler.testImageID, 10, (int) y, 100, 100, 1);
NanoDrawer.drawImage(WidgetManagerInitHandler.urlImageID, (int) x, (int) y, 100, 100, 1);
NanoDrawer.drawImage(NanoImage.loadImage(WidgetManagerInitHandler.jarCoreFile.getAbsolutePath(), "media/image_test.jpg"), 10, (int) y, 100, 100, 1);
NanoDrawer.drawImage(NanoImage.loadImage("https://gas-kvas.com/uploads/posts/2023-02/1675462147_gas-kvas-com-p-fonovii-risunok-2k-2.jpg"), (int) x, (int) y, 100, 100, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.avrix.example;

import com.avrix.events.OnWidgetManagerInitEvent;
import com.avrix.ui.NanoFont;
import com.avrix.ui.NanoImage;
import com.avrix.ui.NanoContext;
import com.avrix.ui.NanoFont;

import java.io.File;

/**
* Handle widget manager init
*/
public class WidgetManagerInitHandler extends OnWidgetManagerInitEvent {
public static int testImageID = -1;
public static int urlImageID = -1;
public static File jarCoreFile;

/**
* Called Event Handling Method
Expand All @@ -23,11 +21,8 @@ public class WidgetManagerInitHandler extends OnWidgetManagerInitEvent {
public void handleEvent(NanoContext context) {
// Load custom font
try {
File coreJarFile = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
NanoFont.createFont("Endeavourforever", coreJarFile.getPath(), "media/Endeavourforever.ttf");

testImageID = NanoImage.loadImage(coreJarFile.getAbsolutePath(), "media/image_test.jpg");
urlImageID = NanoImage.loadImage("https://avatarko.ru/img/kartinka/2/zhivotnye_kot_1990.jpg");
jarCoreFile = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
NanoFont.createFont("Endeavourforever", jarCoreFile.getPath(), "media/Endeavourforever.ttf");
} catch (Exception e) {
System.out.println("[!] Failed to load resources: " + e.getMessage());
}
Expand Down
Loading

0 comments on commit 07fc2e2

Please sign in to comment.