Skip to content

Commit

Permalink
Merge branch 'v1' into isolated-lwjgl3
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Oct 11, 2024
2 parents 40b231b + e570e36 commit 3fb93a2
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 92 deletions.
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ hypixel-modapi = "1.0"
lwjgl = "3.3.3"
universalcraft = "299"
mixin = "0.7.11-SNAPSHOT"
isolated-lwjgl3-loader = "0.1.1"

# Testing
junit-bom = "5.10.2"
Expand All @@ -33,8 +32,6 @@ junit-bom = { module = "org.junit:junit-bom", version.ref = "junit-bom" }

mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }

isolated-lwjgl3-loader = { module = "org.polyfrost:isolated-lwjgl3-loader", version.ref = "isolated-lwjgl3-loader" }

hypixel-modapi = { module = "net.hypixel:mod-api", version.ref = "hypixel-modapi" }

polyui = { module = "org.polyfrost:polyui", version.ref = "polyui" }
Expand Down
3 changes: 0 additions & 3 deletions modules/dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ allprojects {

repositories {
mavenLocal()
maven("https://repo.polyfrost.org/snapshots")
}

dependencies {
Expand All @@ -22,6 +21,4 @@ dependencies {
api(libs.hypixel.modapi)

api(libs.bundles.nightconfig)

api(libs.isolated.lwjgl3.loader)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.api.ui.v1.api;
package org.polyfrost.oneconfig.api.ui.v1;


import org.jetbrains.annotations.NotNull;
Expand All @@ -33,7 +33,7 @@
import java.nio.file.Path;

@SuppressWarnings("unused")
public interface TinyFdApi {
public interface TinyFD {
String QUESTION_ICON = "question";
String ERROR_ICON = "error";
String WARNING_ICON = "warning";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.polyfrost.oneconfig.api.event.v1.events.HudRenderEvent;
import org.polyfrost.oneconfig.api.event.v1.events.ResizeEvent;
import org.polyfrost.oneconfig.api.platform.v1.Platform;
import org.polyfrost.oneconfig.api.ui.v1.api.TinyFdApi;
import org.polyfrost.polyui.PolyUI;
import org.polyfrost.polyui.component.Component;
import org.polyfrost.polyui.Settings;
Expand Down Expand Up @@ -61,7 +60,7 @@ public interface UIManager {
* Return the TinyFD implementation instance. This interface specifies operations for opening native
* file dialogs, and showing notifications.
*/
TinyFdApi getTinyFD();
TinyFD getTinyFD();

/**
* Create a new window that is backed by this Minecraft instance. Returns accurate sizing and has cursor support on MC 1.13+.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import org.polyfrost.oneconfig.api.ui.v1.api.NanoVgApi
import org.polyfrost.oneconfig.api.ui.v1.api.StbApi
import org.polyfrost.universal.UGraphics
import org.polyfrost.polyui.PolyUI
import org.polyfrost.polyui.color.PolyColor
import org.polyfrost.polyui.renderer.Renderer
import org.polyfrost.polyui.data.Font
import org.polyfrost.polyui.data.PolyImage
Expand Down Expand Up @@ -105,15 +104,23 @@ class RendererImpl(

private val queue = ArrayList<() -> Unit>()

// ByteBuffer.of("px\u0000")
private val PIXELS: ByteBuffer = MemoryUtil.memAlloc(3).put(112).put(120).put(0).flip() as ByteBuffer
private val errorHandler: (Throwable) -> Unit = { LOGGER.error("failed to load resource!", it) }
var gl3 = false

override fun init() {
nanoVg.maybeSetup()
if (vg == 0L) {
vg = if(gl3) NanoVGGL3.nvgCreate(NVG_ANTIALIAS) else NanoVGGL2.nvgCreate(NVG_ANTIALIAS)
}
if (raster == 0L) raster = nsvgCreateRasterizer()
require(vg != 0L) { "Could not initialize NanoVG" }
require(raster != 0L) { "Could not initialize NanoSVG" }

if (defaultFont == null) {
val font = PolyUI.defaultFonts.regular
val fdata = font.load().toDirectByteBuffer()
val fit = NvgFont(nanoVg.createFont(font.name, fdata), fdata)
val fit = NVGFont(nvgCreateFontMem(vg, font.name, fdata, false), fdata)
this.defaultFont = fit
fonts[font] = fit
}
Expand All @@ -130,8 +137,7 @@ class RendererImpl(
}

override fun beginFrame(width: Float, height: Float, pixelRatio: Float) {
if (isDrawing) throw IllegalStateException("Already drawing")

if (drawing) throw IllegalStateException("Already drawing")
queue.fastRemoveIfReversed { it(); true }
UGraphics.disableAlpha()
// if(!isGl3) {
Expand All @@ -153,29 +159,29 @@ class RendererImpl(
isDrawing = false
}

override fun globalAlpha(alpha: Float) = nanoVg.globalAlpha(alpha)
override fun globalAlpha(alpha: Float) = nvgGlobalAlpha(vg, alpha)

override fun translate(x: Float, y: Float) = nanoVg.translate(x, y)
override fun translate(x: Float, y: Float) = nvgTranslate(vg, x, y)

override fun scale(sx: Float, sy: Float, px: Float, py: Float) = nanoVg.scale(sx, sy)
override fun scale(sx: Float, sy: Float, px: Float, py: Float) = nvgScale(vg, sx, sy)

override fun rotate(angleRadians: Double, px: Float, py: Float) = nanoVg.rotate(angleRadians.toFloat())
override fun rotate(angleRadians: Double, px: Float, py: Float) = nvgRotate(vg, angleRadians.toFloat())

override fun skewX(angleRadians: Double, px: Float, py: Float) = nanoVg.skewX(angleRadians.toFloat())
override fun skewX(angleRadians: Double, px: Float, py: Float) = nvgSkewX(vg, angleRadians.toFloat())

override fun skewY(angleRadians: Double, px: Float, py: Float) = nanoVg.skewY(angleRadians.toFloat())
override fun skewY(angleRadians: Double, px: Float, py: Float) = nvgSkewY(vg, angleRadians.toFloat())

override fun transformsWithPoint() = false

override fun push() = nanoVg.save()
override fun push() = nvgSave(vg)

override fun pop() = nanoVg.restore()
override fun pop() = nvgRestore(vg)

override fun pushScissor(x: Float, y: Float, width: Float, height: Float) = nanoVg.scissor(x, y, width, height)
override fun pushScissor(x: Float, y: Float, width: Float, height: Float) = nvgScissor(vg, x, y, width, height)

override fun pushScissorIntersecting(x: Float, y: Float, width: Float, height: Float) = nanoVg.intersectScissor(x, y, width, height)
override fun pushScissorIntersecting(x: Float, y: Float, width: Float, height: Float) = nvgIntersectScissor(vg, x, y, width, height)

override fun popScissor() = nanoVg.resetScissor()
override fun popScissor() = nvgResetScissor(vg)

override fun text(
font: Font,
Expand Down Expand Up @@ -210,7 +216,7 @@ class RendererImpl(
) {
nanoVg.imagePattern(x, y, width, height, 0f, getOrPopulateImage(image, width, height), 1f, paintAddress)
if (colorMask != 0) {
populateNvgColor(colorMask, nanoVg.getPaintColor(paintAddress))
nvgARGB(colorMask, nvgPaint.innerColor())
}

nanoVg.beginPath()
Expand All @@ -226,15 +232,15 @@ class RendererImpl(
override fun delete(image: PolyImage?) {
images.remove(image).also {
if (it != null) {
nanoVg.deleteImage(it)
nvgDeleteImage(vg, it)
return
}
}
svgs.remove(image).also {
if (it != null) {
nanoVg.deleteSvg(it.first)
nsvgDelete(it.first)
it.second.forEach { _, handle ->
nanoVg.deleteImage(handle)
nvgDeleteImage(vg, handle)
}
}
}
Expand All @@ -258,8 +264,9 @@ class RendererImpl(
) {
if (color.transparent) return
// note: nvg checks params and draws classic rect if 0, so we don't need to
nanoVg.beginPath()
nanoVg.roundedRectVarying(
nvgBeginPath(vg)
nvgRoundedRectVarying(
vg,
x,
y,
width,
Expand All @@ -269,8 +276,12 @@ class RendererImpl(
bottomRightRadius,
bottomLeftRadius,
)
populateFillOrColor(color, x, y, width, height)
nanoVg.fill()
if (color(color, x, y, width, height)) {
nvgFillPaint(vg, nvgPaint)
} else {
nvgFillColor(vg, nvgColor)
}
nvgFill(vg)
}

override fun hollowRect(
Expand All @@ -286,8 +297,9 @@ class RendererImpl(
bottomRightRadius: Float,
) {
if (color.transparent) return
nanoVg.beginPath()
nanoVg.roundedRectVarying(
nvgBeginPath(vg)
nvgRoundedRectVarying(
vg,
x,
y,
width,
Expand All @@ -297,19 +309,27 @@ class RendererImpl(
bottomRightRadius,
bottomLeftRadius,
)
nanoVg.strokeWidth(lineWidth)
populateStrokeColor(color, x, y, width, height)
nanoVg.stroke()
nvgStrokeWidth(vg, lineWidth)
if (color(color, x, y, width, height)) {
nvgStrokePaint(vg, nvgPaint)
} else {
nvgStrokeColor(vg, nvgColor)
}
nvgStroke(vg)
}

override fun line(x1: Float, y1: Float, x2: Float, y2: Float, color: Color, width: Float) {
if (color.transparent) return
nanoVg.beginPath()
nanoVg.moveTo(x1, y1)
nanoVg.lineTo(x2, y2)
nanoVg.strokeWidth(width)
populateStrokeColor(color, x1, y1, x2, y2)
nanoVg.stroke()
nvgBeginPath(vg)
nvgMoveTo(vg, x1, y1)
nvgLineTo(vg, x2, y2)
nvgStrokeWidth(vg, width)
if (color(color, x1, y1, x2, y2)) {
nvgStrokePaint(vg, nvgPaint)
} else {
nvgStrokeColor(vg, nvgColor)
}
nvgStroke(vg)
}

override fun dropShadow(
Expand All @@ -321,13 +341,13 @@ class RendererImpl(
spread: Float,
radius: Float,
) {
nanoVg.boxGradient(paintAddress, x - spread, y - spread, width + spread * 2f, height + spread * 2f, radius + spread, blur, color1Address, color2Address)
nanoVg.beginPath()
nanoVg.roundedRect(x - spread, y - spread - blur, width + spread * 2f + blur * 2f, height + spread * 2f + blur * 2f, radius + spread)
nanoVg.roundedRect(x, y, width, height, radius)
nanoVg.pathWinding(nanoVg.constants().NVG_HOLE())
nanoVg.fillPaint(paintAddress)
nanoVg.fill()
nvgBoxGradient(vg, x - spread, y - spread, width + spread * 2f, height + spread * 2f, radius + spread, blur, nvgColor, nvgColor2, nvgPaint)
nvgBeginPath(vg)
nvgRoundedRect(vg, x - spread, y - spread - blur, width + spread * 2f + blur * 2f, height + spread * 2f + blur * 2f, radius + spread)
nvgRoundedRect(vg, x, y, width, height, radius)
nvgPathWinding(vg, NVG_HOLE)
nvgFillPaint(vg, nvgPaint)
nvgFill(vg)
}

@Suppress("NAME_SHADOWING")
Expand Down Expand Up @@ -619,4 +639,6 @@ class RendererImpl(

// asm: renderer is persistent
override fun cleanup() {}

private data class NVGFont(val id: Int, val data: ByteBuffer)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ package org.polyfrost.oneconfig.api.ui.v1.internal
import org.lwjgl.PointerBuffer
import org.lwjgl.system.MemoryStack
import org.lwjgl.util.tinyfd.TinyFileDialogs.*
import org.polyfrost.oneconfig.api.ui.v1.api.TinyFdApi
import org.polyfrost.oneconfig.api.ui.v1.TinyFD
import org.polyfrost.polyui.utils.mapToArray
import java.nio.file.Path
import java.nio.file.Paths

class TinyFdImpl : TinyFdApi {
class TinyFDImpl : TinyFD {
override fun openSaveSelector(title: String?, defaultFilePath: String?, filterPatterns: Array<String>?, filterDescription: String?) =
tinyfd_saveFileDialog(title ?: "Save", defaultFilePath, malloc(filterPatterns), filterDescription)?.toPath()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2024 Polyfrost.
* <https://polyfrost.org> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.api.ui.v1.internal;

import net.minecraft.client.Minecraft;
import org.jetbrains.annotations.NotNull;
import org.polyfrost.oneconfig.api.ui.v1.TinyFD;
import org.polyfrost.oneconfig.api.ui.v1.UIManager;
import org.polyfrost.oneconfig.api.ui.v1.internal.wrappers.MCWindow;
import org.polyfrost.oneconfig.api.ui.v1.internal.wrappers.PolyUIScreen;
import org.polyfrost.polyui.PolyUI;
import org.polyfrost.polyui.renderer.Renderer;
import org.polyfrost.polyui.renderer.Window;

import java.util.function.Consumer;

public class UIManagerImpl implements UIManager {
private static final TinyFD impl = new TinyFDImpl();
//#if MC>=11700
//$$ static {
//$$ RendererImpl.INSTANCE.setGl3(true);
//$$ }
//#endif
private PolyUI ui;

@Override
public Renderer getRenderer() {
return RendererImpl.INSTANCE;
}

@Override
public TinyFD getTinyFD() {
return impl;
}

@Override
public Object createPolyUIScreen(@NotNull PolyUI polyUI, float desiredScreenWidth, float desiredScreenHeight, boolean pauses, boolean blurs, Consumer<PolyUI> onClose) {
return new PolyUIScreen(polyUI, desiredScreenWidth, desiredScreenHeight, pauses, blurs, onClose);
}

@Override
public Window createWindow() {
return new MCWindow(Minecraft.getInstance());
}

@Override
public @NotNull PolyUI getDefaultInstance() {
return ui == null ? ui = createDefault() : ui;
}
}
Loading

0 comments on commit 3fb93a2

Please sign in to comment.