Skip to content

Commit

Permalink
🩹 smoother dearimgui
Browse files Browse the repository at this point in the history
  • Loading branch information
asoji committed Aug 25, 2024
1 parent c055b54 commit c877dc7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 30 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ repositories {
mavenCentral()
maven("https://maven.parchmentmc.org")
maven("https://mvn.devos.one/snapshots")
maven { url = uri("https://api.modrinth.com/maven") }

}

//All dependencies and their versions are in ./gradle/libs.versions.toml
Expand All @@ -115,6 +117,7 @@ dependencies {
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
modImplementation(libs.fabric.language.kotlin) // how did i not have this
modImplementation(libs.sodium)
include(implementation("com.moulberry:mixinconstraints:1.0.1")!!)

listOf(
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true

# Mod Properties
mod_version=1.3.3
mod_version=1.3.4
maven_group=gay.asoji
archives_base_name=innerpastels

Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ minecraft = "1.21"
fabric-loader = "0.15.11"
fabric-api = "0.102.0+1.21"
fabric-language-kotlin = "1.11.0+kotlin.2.0.0"
imgui-java = "1.86.12"
dokka = "1.9.10"
sodium_version = "mc1.21-0.6.0-beta.1-fabric"


[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
fabric_loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" }
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" }
fabric_language_kotlin = { module = "net.fabricmc:fabric-language-kotlin", version.ref = "fabric-language-kotlin" }
sodium = { module = "maven.modrinth:sodium", version.ref = "sodium_version" }

[plugins]
grgit = { id = "org.ajoberstar.grgit", version = "5.2.1"}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/gay/asoji/innerpastels/mixins/RenderSystemMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gay.asoji.innerpastels.mixins;

import com.mojang.blaze3d.systems.RenderSystem;
import gay.asoji.innerpastels.client.ImGuiClient;
import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl;
import imgui.type.ImBoolean;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(RenderSystem.class)
public class RenderSystemMixin {
@Inject(method = "flipFrame", at = @At("HEAD"), remap = false)
private static void imgui$renderImGui(long handle, CallbackInfo ci) {
InnerPastelsImGuiImpl.INSTANCE.initialize(handle);
InnerPastelsImGuiImpl.INSTANCE.startFrame();

if (ImGuiClient.INSTANCE.isImGuiRenderEnabled()) {
ImGuiClient.INSTANCE.getPanels().forEach((it) -> {
it.theme();
it.render(new ImBoolean());
}
);
}

InnerPastelsImGuiImpl.INSTANCE.endFrame();
}
}
45 changes: 18 additions & 27 deletions src/main/kotlin/gay/asoji/innerpastels/client/ImGuiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl
import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl.endFrame
import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl.initialize
import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl.startFrame
import gay.asoji.innerpastels.client.imgui.TestDockSpace
import gay.asoji.innerpastels.client.imgui.TestPanel
import gay.asoji.innerpastels.events.InputAction
import gay.asoji.innerpastels.events.KeyInputEvent
import gay.asoji.innerpastels.events.MouseInputEvent
import gay.asoji.innerpastels.events.MouseScrollInputEvent
import imgui.ImGui
import imgui.type.ImBoolean
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper
Expand All @@ -19,7 +22,8 @@ import net.minecraft.client.Minecraft
import org.lwjgl.glfw.GLFW

object ImGuiClient {
private var isImGuiRenderEnabled: Boolean = false
var isImGuiRenderEnabled: Boolean = false
private set

val DEVELOPER_UI_BINDING = KeyMapping(
"key.innerpastels.developerui",
Expand All @@ -43,35 +47,22 @@ object ImGuiClient {
}

fun init() {
// panels.addAll( // testing stuff
// listOf(
// object : ImGuiPanel {
// override fun theme() {
//
// }
//
// override fun render(open_: ImBoolean) {
// ImGui.showDemoWindow()
// }
// },
// TestDockSpace, TestPanel
// )
// )
panels.addAll( // testing stuff
listOf(
object : ImGuiPanel {
override fun theme() {

initializeDevKeybinds()
HudRenderCallback.EVENT.register { gui, tickDelta ->
initialize(Minecraft.getInstance().window.window)
startFrame()
}

if (isImGuiRenderEnabled) {
panels.forEach {
it.theme()
it.render(ImBoolean())
}
}
override fun render(open_: ImBoolean) {
ImGui.showDemoWindow()
}
},
TestDockSpace, TestPanel
)
)

endFrame()
}
initializeDevKeybinds()

KeyInputEvent.EVENT.register { key, action, mods, scanCode ->
when (action ?: return@register) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/innerpastels.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"GLFWInitMixin",
"KeyboardHandlerMixin",
"MinecraftMixin",
"MouseHandlerMixin"
"MouseHandlerMixin",
"RenderSystemMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit c877dc7

Please sign in to comment.