-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚗️ testing jank dearimgui lib port setup
- Loading branch information
Showing
4 changed files
with
101 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 86 additions & 62 deletions
148
src/main/kotlin/gay/asoji/innerpastels/client/imgui/InnerPastelsImGuiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,134 @@ | ||
package gay.asoji.innerpastels.client.imgui | ||
|
||
import gln.cap.Caps | ||
import imgui.ImFontAtlas | ||
import imgui.ImFontConfig | ||
import imgui.ImGui | ||
import imgui.MINECRAFT_BEHAVIORS | ||
import imgui.MouseButton | ||
import imgui.classes.Context | ||
import imgui.impl.gl.ImplGL3 | ||
import imgui.impl.glfw.ImplGlfw | ||
import imgui.impl.glfw.ImplGlfw.Companion.imguiKey | ||
import imgui.flag.ImGuiConfigFlags | ||
import imgui.gl3.ImGuiImplGl3 | ||
import imgui.glfw.ImGuiImplGlfw | ||
import net.fabricmc.api.EnvType | ||
import net.fabricmc.api.Environment | ||
import net.minecraft.client.Minecraft | ||
import org.lwjgl.glfw.GLFW | ||
import uno.gl.GlWindow | ||
import uno.glfw.GlfwWindow | ||
import org.lwjgl.glfw.GLFW.glfwGetCurrentContext | ||
import org.lwjgl.glfw.GLFW.glfwMakeContextCurrent | ||
|
||
|
||
@Environment(EnvType.CLIENT) | ||
object InnerPastelsImGuiImpl { | ||
val imgui = ImGui | ||
var implGl3: ImplGL3 | ||
var implGlfw: ImplGlfw | ||
var implGl3: ImGuiImplGl3 = ImGuiImplGl3() | ||
var implGlfw: ImGuiImplGlfw = ImGuiImplGlfw() | ||
var imGui: ImGui = ImGui() | ||
var imGuiIO = ImGui.getIO() | ||
var windowHandle: Long = Minecraft.getInstance().window.window | ||
|
||
// GLFW Initialization for imgui. | ||
fun glfwInit(handle: Long) { | ||
implGlfw.init(handle, false) | ||
implGl3.init() | ||
ImGui.createContext() | ||
|
||
windowHandle = handle | ||
} | ||
|
||
fun imGuiInit() { | ||
imGuiIO.iniFilename = null | ||
imGuiIO.addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard) | ||
imGuiIO.addConfigFlags(ImGuiConfigFlags.DockingEnable) | ||
imGuiIO.addConfigFlags(ImGuiConfigFlags.ViewportsEnable) | ||
|
||
val fontAtlas: ImFontAtlas = imGuiIO.getFonts() | ||
val fontConfig = ImFontConfig() | ||
|
||
fontConfig.glyphRanges = fontAtlas.glyphRangesCyrillic | ||
|
||
fontAtlas.addFontDefault() | ||
|
||
fontConfig.mergeMode = true | ||
fontConfig.pixelSnapH = true | ||
|
||
// Initialization for imgui. | ||
init { | ||
MINECRAFT_BEHAVIORS = true | ||
fontConfig.destroy() | ||
|
||
val glfwWindow = GlfwWindow(Minecraft.getInstance().window.window) | ||
val window = GlWindow(glfwWindow, Caps.Profile.CORE, true) | ||
} | ||
|
||
window.makeCurrent(true) | ||
Context().setCurrent() | ||
fun endFrame(windowPtr: Long) { | ||
implGl3.renderDrawData(ImGui.getDrawData()) | ||
|
||
implGlfw = ImplGlfw(window, false, null) | ||
implGl3 = ImplGL3() | ||
if (ImGui.getIO().hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) { | ||
val backupWindowPtr = glfwGetCurrentContext() | ||
ImGui.updatePlatformWindows() | ||
ImGui.renderPlatformWindowsDefault() | ||
glfwMakeContextCurrent(backupWindowPtr) | ||
} | ||
} | ||
|
||
fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean { | ||
if (imgui.io.wantCaptureMouse) { | ||
imgui.io.addMouseButtonEvent(MouseButton.of(button), false) | ||
if (imGuiIO.getMouseDown(button)) { | ||
imGuiIO.setMouseDown(booleanArrayOf(true)) | ||
} | ||
|
||
return imgui.io.wantCaptureMouse | ||
return imGuiIO.wantCaptureMouse | ||
} | ||
|
||
fun mouseScrolled(mouseX: Double, mouseY: Double, scrollX: Double, scrollY: Double): Boolean { | ||
if (imgui.io.wantCaptureMouse) { | ||
imgui.io.mouseWheelH = scrollX.toFloat() | ||
imgui.io.mouseWheel = scrollY.toFloat() | ||
if (imGuiIO.wantCaptureMouse) { | ||
imGuiIO.mouseWheelH = scrollX.toFloat() | ||
imGuiIO.mouseWheel = scrollY.toFloat() | ||
} | ||
|
||
return imgui.io.wantCaptureMouse | ||
return imGuiIO.wantCaptureMouse | ||
} | ||
|
||
fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean { | ||
if (imgui.io.wantCaptureMouse) { | ||
imgui.io.addMouseButtonEvent(MouseButton.of(button), true) | ||
if (imGuiIO.wantCaptureMouse) { | ||
if (imGuiIO.getMouseDown(button)) { | ||
imGuiIO.setMouseDown(booleanArrayOf(false)) | ||
} | ||
} | ||
|
||
return imgui.io.wantCaptureMouse | ||
return imGuiIO.wantCaptureMouse | ||
} | ||
|
||
fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { | ||
if (imgui.io.wantCaptureKeyboard) { | ||
val key = uno.glfw.Key.of(keyCode).imguiKey | ||
|
||
imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0 | ||
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0 | ||
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0 | ||
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0 | ||
|
||
imgui.io.addKeyEvent(key, true) | ||
imgui.io.keysData[key.index].down = true | ||
imgui.io.setKeyEventNativeData(key, key.i, scanCode) | ||
if (imGuiIO.wantCaptureKeyboard) { | ||
imGuiIO.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0 | ||
imGuiIO.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0 | ||
imGuiIO.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0 | ||
imGuiIO.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0 | ||
|
||
if (imGuiIO.getKeysDown(keyCode)) { | ||
imGuiIO.setKeysDown(booleanArrayOf(false)) | ||
} | ||
} | ||
|
||
return imgui.io.wantCaptureKeyboard | ||
return imGuiIO.wantCaptureKeyboard | ||
} | ||
|
||
fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { | ||
if (imgui.io.wantCaptureKeyboard) { | ||
val key = uno.glfw.Key.of(keyCode).imguiKey | ||
|
||
imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0 | ||
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0 | ||
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0 | ||
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0 | ||
|
||
imgui.io.addKeyEvent(key, false) | ||
imgui.io.keysData[key.index].down = false | ||
imgui.io.setKeyEventNativeData(key, key.i, scanCode) | ||
if (imGuiIO.wantCaptureKeyboard) { | ||
imGuiIO.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0 | ||
imGuiIO.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0 | ||
imGuiIO.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0 | ||
imGuiIO.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0 | ||
|
||
if (imGuiIO.getKeysDown(keyCode)) { | ||
imGuiIO.setKeysDown(booleanArrayOf(false)) | ||
} | ||
} | ||
|
||
return imgui.io.wantCaptureKeyboard | ||
return imGuiIO.wantCaptureKeyboard | ||
} | ||
|
||
fun charTyped(codePoint: Char, modifiers: Int): Boolean { | ||
if (imgui.io.wantCaptureKeyboard) { | ||
imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0 | ||
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0 | ||
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0 | ||
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0 | ||
if (imGuiIO.wantCaptureKeyboard) { | ||
imGuiIO.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0 | ||
imGuiIO.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0 | ||
imGuiIO.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0 | ||
imGuiIO.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0 | ||
|
||
imgui.io.addInputCharacter(codePoint) | ||
imGuiIO.addInputCharacter(codePoint.code) | ||
} | ||
|
||
return imgui.io.wantCaptureKeyboard | ||
return imGuiIO.wantCaptureKeyboard | ||
} | ||
} |