Skip to content

Commit

Permalink
universal register method
Browse files Browse the repository at this point in the history
  • Loading branch information
grngxd committed Mar 10, 2024
1 parent 5308855 commit 885d2c4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/main/kotlin/com/neptuneclient/voidui/rendering/Renderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.neptuneclient.voidui.rendering

import com.neptuneclient.voidui.utils.Font
import org.jetbrains.annotations.NotNull
import java.awt.Color

/**
Expand Down Expand Up @@ -43,12 +44,13 @@ interface Renderer {
}

/**
* Registers a font to the renderer. The [Font] class provides the render backend with all necessary resources
* to create the font.
* Registers a font/image/etc. to the render backend.
* The [Font] class provides the render backend with all necessary resources
* to create a font.
*
* @param font The font object to register.
* @param o The object to register.
*/
fun registerFont(font: Font)
fun register(o: Any): Renderer

/**
* Renders a rectangle with the given dimensions, size, radius and color.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.neptuneclient.voidui.testmod;

import com.neptuneclient.voidui.VoidUI;
import com.neptuneclient.voidui.testmod.impl.RendererImpl;
import com.neptuneclient.voidui.testmod.impl.IRenderer;
import com.neptuneclient.voidui.utils.Font;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
Expand All @@ -19,7 +19,7 @@ public void onInitializeClient() {
LOGGER.info("VoidUI is best!");

ClientLifecycleEvents.CLIENT_STARTED.register((client) -> {
VoidUI vui = new VoidUI(new RendererImpl());
VoidUI vui = new VoidUI(new IRenderer());

// testing if nanovg will handle the font buffer
new Font(vui, "testFont", Path.of("fonts/WorkSans-Regular.ttf"), 28);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import static org.lwjgl.nanovg.NanoVG.*;

public class RendererImpl implements Renderer {
public class IRenderer implements Renderer {

private long vg = NanoVGGL3.nvgCreate(NanoVGGL3.NVG_ANTIALIAS | NanoVGGL3.NVG_STENCIL_STROKES);

Expand Down Expand Up @@ -60,8 +60,16 @@ public void roundedRectangle(float x, float y, float width, float height, float
}

@Override
public void registerFont(@NotNull Font font) {
nvgCreateFontMem(vg, font.getIdentifier(), font.getData(), 1);
public @NotNull IRenderer register(@NotNull Object o) {
switch (o.getClass().getSimpleName()) {
default:
throw new IllegalArgumentException("Unknown object type: " + o.getClass().getSimpleName());
case "Font":
Font font = (Font) o;
nvgCreateFontMem(vg, font.getIdentifier(), font.getData(), 1);
break;
}
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.neptuneclient.voidui.VoidUI;
import com.neptuneclient.voidui.testmod.impl.RendererImpl;
import com.neptuneclient.voidui.testmod.impl.IRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,7 +15,7 @@
@Mixin(InGameHud.class)
public class MixinIngameHud {

private VoidUI v = new VoidUI(new RendererImpl());
private VoidUI v = new VoidUI(new IRenderer());

@Inject(method = "render", at = @At("RETURN"))
public void renderIngameHud(DrawContext context, float tickDelta, CallbackInfo ci) {
Expand Down

0 comments on commit 885d2c4

Please sign in to comment.