diff --git a/build.gradle.kts b/build.gradle.kts index 82b8d20..14bcb30 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -98,6 +98,9 @@ dependencies { // If you don't want to log in with your real minecraft account, remove this line runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.2.1") + shadowImpl("org.joml:joml:1.10.8") + shadowImpl("org.lwjgl:lwjgl-stb:3.2.2") + shadowImpl("org.lwjgl:lwjgl-stb:3.2.2:natives-windows") } // Tasks: diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/GlobalManager.kt b/src/main/java/com/github/freedownloadhere/killauravideo/GlobalManager.kt index 7ba35b4..d02eb78 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/GlobalManager.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/GlobalManager.kt @@ -1,20 +1,22 @@ package com.github.freedownloadhere.killauravideo import com.github.freedownloadhere.killauravideo.rendering.RenderUtils -import com.github.freedownloadhere.killauravideo.ui.core.Core +import com.github.freedownloadhere.killauravideo.ui.core.UICore +import com.github.freedownloadhere.killauravideo.ui.core.render.RenderingBackend import com.github.freedownloadhere.killauravideo.utils.EntityPositions import com.github.freedownloadhere.killauravideo.utils.KeybindMap import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.client.multiplayer.WorldClient import net.minecraftforge.client.event.DrawBlockHighlightEvent +import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent object GlobalManager { var clientInstance: ClientInstance? = null private set - var core: Core? = null + var core: UICore? = null private var lastPlayer: EntityPlayerSP? = null private var lastWorld: WorldClient? = null @@ -59,4 +61,18 @@ object GlobalManager { clientInstance = ClientInstance(player, world, Minecraft.getMinecraft().gameSettings) clientInstance!!.init() } + + private var tempInit = false + @SubscribeEvent + fun renderWorldEvent(e: RenderWorldLastEvent) { + if(tempInit) return + val sw = Minecraft.getMinecraft().displayWidth.toFloat() + val sh = Minecraft.getMinecraft().displayHeight.toFloat() + RenderingBackend.init(sw, sh) + RenderingBackend.loadTexture( + "checkmark", + "/assets/killauravideo/textures/gui/check.png" + ) + tempInit = true + } } \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/Mod.kt b/src/main/java/com/github/freedownloadhere/killauravideo/Mod.kt index 0d2bd13..4cdd624 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/Mod.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/Mod.kt @@ -1,8 +1,10 @@ package com.github.freedownloadhere.killauravideo import com.github.freedownloadhere.killauravideo.commands.CommandToggle -import com.github.freedownloadhere.killauravideo.ui.core.Core +import com.github.freedownloadhere.killauravideo.ui.core.UICore +import com.github.freedownloadhere.killauravideo.ui.dsl.text import com.github.freedownloadhere.killauravideo.utils.KeybindMap +import com.github.freedownloadhere.killauravideo.utils.LibraryLoading import net.minecraft.client.Minecraft import net.minecraft.client.settings.KeyBinding import net.minecraftforge.client.ClientCommandHandler @@ -15,11 +17,15 @@ import org.lwjgl.input.Keyboard class Mod { @Mod.EventHandler fun init(e: FMLInitializationEvent) { + LibraryLoading.load() + MinecraftForge.EVENT_BUS.register(GlobalManager) ClientCommandHandler.instance.registerCommand(CommandToggle()) KeybindMap.addKey(KeyBinding("Toggle UI", Keyboard.KEY_J, "")) { - GlobalManager.core = Core() + GlobalManager.core = UICore { + text("hello") + } Minecraft.getMinecraft().displayGuiScreen(GlobalManager.core!!) } } diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UIIcon.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UIIcon.kt deleted file mode 100644 index 736872f..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UIIcon.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.basic - -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost -import com.github.freedownloadhere.killauravideo.ui.interfaces.render.IDrawable -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.util.ResourceLocation - -class UIIcon(config: UIConfig) : UI(config), IDrawable, ILayoutPost { - enum class Scale(val numeric: Double) { - SMALL(20.0), - MEDIUM(35.0), - LARGE(50.0) - } - - companion object { - var iconLocation = ResourceLocation("killauravideo", "textures/gui/check.png") - } - - var scale: Scale = Scale.MEDIUM - override var hidden: Boolean = false - - override fun renderCallback(renderer: Renderer) { - GlStateManager.pushMatrix() - GlStateManager.scale(width, height, 0.0) - renderer.drawRect(iconLocation, filled = true) - GlStateManager.popMatrix() - } - - override fun layoutPostCallback() { - width = scale.numeric - height = scale.numeric - } -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UIText.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UIText.kt deleted file mode 100644 index cbacc6c..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UIText.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.basic - -import com.github.freedownloadhere.killauravideo.GlobalManager -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost -import com.github.freedownloadhere.killauravideo.ui.interfaces.render.IDrawable -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig -import net.minecraft.client.Minecraft -import net.minecraft.client.renderer.GlStateManager - -class UIText(config: UIConfig, default: String = "Text"): UI(config), IDrawable, ILayoutPost -{ - enum class Scale(val numeric: Double) { - SMALL(1.5), - MEDIUM(2.0), - LARGE(3.5) - } - - var scale: Scale = Scale.MEDIUM - var source: () -> String = { default } - - val text: String - get() = source() - - override var hidden: Boolean = false - var baseColor: UIColorEnum = UIColorEnum.TEXT_PRIMARY - - override fun renderCallback(renderer: Renderer) { - if (text.isEmpty()) return - GlobalManager.core!!.renderer.withTextState { - val fr = Minecraft.getMinecraft().fontRendererObj - GlStateManager.pushMatrix() - GlStateManager.scale(scale.numeric, scale.numeric, 1.0) - fr.drawStringWithShadow(text, 0.0f, 0.0f, baseColor.toPackedARGB()) - GlStateManager.popMatrix() - } - } - - override fun layoutPostCallback() { - val fr = Minecraft.getMinecraft().fontRendererObj - width = scale.numeric * fr.getStringWidth(text).toDouble() - height = scale.numeric * fr.FONT_HEIGHT.toDouble() - } -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UIButton.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UIButton.kt deleted file mode 100644 index 1584c84..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UIButton.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.composite - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.basic.UIText -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.implementations.uiBoxDraw -import com.github.freedownloadhere.killauravideo.ui.implementations.uiCenterBoxLayout -import com.github.freedownloadhere.killauravideo.ui.interfaces.io.IClickable -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IUniqueParent -import com.github.freedownloadhere.killauravideo.ui.interfaces.render.IDrawable -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum -import kotlin.math.max - -class UIButton(config: UIConfig): UI(config), IUniqueParent, ILayoutPost, IClickable, IDrawable -{ - private val cooldown = config.buttonClickCooldown - private var cooldownLeft: Long = 0L - override var hidden: Boolean = false - override val child: UIText = UIText(config) - var onClick: () -> Unit = { } - val text: UIText - get() = child - private var color: UIColorEnum = UIColorEnum.BOX_SECONDARY - - override fun update(deltaTime: Long) { - cooldownLeft = max(0L, cooldownLeft - deltaTime) - if(cooldownLeft == 0L) color = UIColorEnum.BOX_SECONDARY - super.update(deltaTime) - } - - override fun clickCallback(button: Int, mouseRelX: Double, mouseRelY: Double) { - if(button == 0 && cooldownLeft == 0L) { - onClick() - cooldownLeft = cooldown - color = UIColorEnum.BOX_TERNARY - } - } - - override fun layoutPostCallback() = uiCenterBoxLayout() - - override fun renderCallback(renderer: Renderer) = uiBoxDraw(renderer, color) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UICheckbox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UICheckbox.kt deleted file mode 100644 index 08c1bfc..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UICheckbox.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.composite - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.basic.UIIcon -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.implementations.uiBoxDraw -import com.github.freedownloadhere.killauravideo.ui.implementations.uiCenterBoxLayout -import com.github.freedownloadhere.killauravideo.ui.interfaces.io.IClickable -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.IPadded -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IUniqueParent -import com.github.freedownloadhere.killauravideo.ui.interfaces.render.IDrawable -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig - -class UICheckbox(config: UIConfig) : UI(config), IUniqueParent, IDrawable, IClickable, ILayoutPost, IPadded -{ - var checked: Boolean = false - set(value) { - field = value - child.hidden = !value - } - var onCheck: () -> Unit = { } - override val child: UIIcon = UIIcon(config) - override var hidden: Boolean = false - override var padding: Double = config.padding - - override fun clickCallback(button: Int, mouseRelX: Double, mouseRelY: Double) { - checked = !checked - onCheck() - } - - override fun layoutPostCallback() = uiCenterBoxLayout() - - override fun renderCallback(renderer: Renderer) = uiBoxDraw(renderer, UIColorEnum.BOX_SECONDARY) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UISlider.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UISlider.kt deleted file mode 100644 index 36b474e..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UISlider.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.composite - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.interfaces.io.IClickHoldable -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.IPadded -import com.github.freedownloadhere.killauravideo.ui.interfaces.render.IDrawable -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum -import net.minecraft.client.renderer.Tessellator -import net.minecraft.client.renderer.vertex.DefaultVertexFormats -import org.apache.logging.log4j.LogManager -import org.lwjgl.opengl.GL11 -import kotlin.math.floor -import kotlin.math.max - -class UISlider(config: UIConfig): UI(config), IPadded, IClickHoldable, IDrawable, ILayoutPost -{ - override var padding: Double = config.padding - - var minValue: Double = 0.0 - var maxValue: Double = 1.0 - private var position: Double = 0.0 - - var selectedValue: Double - get() = minValue + (maxValue - minValue) * position - set(value) { position = (value - minValue) / (maxValue - minValue) } - - var clickAction: () -> Unit = { } - - var segmented: Boolean = true - var segmentCount: Int = 5 - - override fun clickHoldCallback(button: Int, mouseRelX: Double, mouseRelY: Double) { - LogManager.getLogger().info("$mouseRelX : $position") - position = mouseRelX / width - if(segmented) { - val segmentLength = 1.0 / segmentCount - position = floor(position / segmentLength) * segmentLength - } - clickAction() - } - - override var hidden: Boolean = false - override fun renderCallback(renderer: Renderer) { - val tess = Tessellator.getInstance() - val wr = tess.worldRenderer - val lineWidth = GL11.glGetFloat(GL11.GL_LINE_WIDTH) - val sliderCol = UIColorEnum.ACCENT - val barCol = UIColorEnum.TEXT_SECONDARY - GL11.glLineWidth(2.0f) - wr.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR) - wr.pos(0.0, 0.5 * height - 1.0, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex() - wr.pos(width, 0.5 * height - 1.0, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex() - tess.draw() - for(i in 0..segmentCount) { - wr.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR) - wr.pos((width * i) / segmentCount, height * 0.25, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex() - wr.pos((width * i) / segmentCount, height * 0.75, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex() - tess.draw() - } - GL11.glLineWidth(4.0f) - wr.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR) - wr.pos(width * position, 0.0, 0.0).color(sliderCol.r, sliderCol.g, sliderCol.b, sliderCol.a).endVertex() - wr.pos(width * position, height, 0.0).color(sliderCol.r, sliderCol.g, sliderCol.b, sliderCol.a).endVertex() - tess.draw() - GL11.glLineWidth(lineWidth) - } - - override fun layoutPostCallback() { - width = max(width, 2.0 * padding) - height = max(height, 2.0 * padding) - } -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIBox.kt deleted file mode 100644 index ae0a78f..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIBox.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.containers - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.implementations.uiBoxDraw -import com.github.freedownloadhere.killauravideo.ui.interfaces.io.IMovable -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.IPadded -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IParent -import com.github.freedownloadhere.killauravideo.ui.interfaces.render.IDrawable -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig - -abstract class UIBox(config: UIConfig): UI(config), ILayoutPost, IParent, IDrawable, IMovable, IPadded -{ - override var padding: Double = config.padding - override var canBeMoved: Boolean = false - override var hidden: Boolean = false - var baseColor: UIColorEnum = UIColorEnum.BOX_TERNARY - - override fun renderCallback(renderer: Renderer) = uiBoxDraw(renderer, baseColor) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UICenteredBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UICenteredBox.kt deleted file mode 100644 index 0ba642c..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UICenteredBox.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.containers - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.implementations.uiCenterBoxLayout -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IUniqueParent -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig - -open class UICenteredBox(config: UIConfig) : UIBox(config), IUniqueParent, ILayoutPost where T: UI -{ - override lateinit var child: T - - override fun layoutPostCallback() = uiCenterBoxLayout() -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIFreeBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIFreeBox.kt deleted file mode 100644 index e995c9e..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIFreeBox.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.containers - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IParentExtendable -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig - -class UIFreeBox(config: UIConfig) : UIBox(config), IParentExtendable -{ - private val childrenList = mutableListOf() - - override val children: Sequence - get() = childrenList.asSequence() - - override fun addChild(ui: UI) { - childrenList += ui - } - - override fun layoutPostCallback() { - - } -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/Core.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/Core.kt deleted file mode 100644 index 7f32f8e..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/Core.kt +++ /dev/null @@ -1,131 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.core - -import com.github.freedownloadhere.killauravideo.GlobalManager -import com.github.freedownloadhere.killauravideo.modules.Killaura -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.basic.UIIcon -import com.github.freedownloadhere.killauravideo.ui.basic.UIText -import com.github.freedownloadhere.killauravideo.ui.core.io.InteractionManager -import com.github.freedownloadhere.killauravideo.ui.core.io.MouseInfo -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.dsl.* -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayout -import com.github.freedownloadhere.killauravideo.ui.util.TimeUtil -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.GuiScreen - -class Core: GuiScreen() { - init { - width = Minecraft.getMinecraft().displayWidth - height = Minecraft.getMinecraft().displayHeight - } - - val config = UIConfig(screenWidth = width.toDouble(), screenHeight = height.toDouble()) - private lateinit var topLevelUI: UI - - private val mouseInfo = MouseInfo() - - private lateinit var interactionManager: InteractionManager - lateinit var renderer: Renderer - - private val timeUtil = TimeUtil() - - override fun initGui() { - UIBuilderGlobals.uiConfig = config - - topLevelUI = verticalBox { - val ka = GlobalManager.clientInstance!!.moduleMap.module("killaura") as Killaura - - + centerBox { - child = text("Killaura") - width = 200.0 - } - - + verticalBox { - padding = 0.0 - hidden = true - - + horizontalBox { - placeLeft() - + text("Toggled") - placeRight() - + checkbox { - checked = ka.toggled - child.scale = UIIcon.Scale.SMALL - onCheck = { ka.toggle() } - } - } - - + verticalBox { - spacing = 5.0 - - val minReach = 3.0 - val maxReach = 6.0 - - + horizontalBox { - padding = 0.0 - hidden = true - placeLeft() - + text("Reach") - placeRight() - + text { source = { ka.limiter.maxReach.toString() } } - } - + horizontalBox { - padding = 0.0 - hidden = true - placeLeft() - + text { - source = { minReach.toString() } - scale = UIText.Scale.SMALL - baseColor = UIColorEnum.TEXT_SECONDARY - } - placeRight() - + text { - source = { maxReach.toString() } - scale = UIText.Scale.SMALL - baseColor = UIColorEnum.TEXT_SECONDARY - } - } - + slider { - minValue = minReach - maxValue = maxReach - segmented = true - segmentCount = 6 - selectedValue = ka.limiter.maxReach - clickAction = { ka.limiter.maxReach = selectedValue } - } - } - } - } - - interactionManager = InteractionManager(mouseInfo, topLevelUI) - renderer = Renderer(config, interactionManager) - } - - override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { - val deltaTime = timeUtil.newDeltaTime() - - drawDefaultBackground() - - renderer.withUIState { - if(topLevelUI is ILayout) - (topLevelUI as ILayout).applyLayout() - topLevelUI.updateRecursive(deltaTime) - topLevelUI.renderRecursive(renderer) - } - } - - override fun handleMouseInput() { - mouseInfo.update() - interactionManager.handleMouseInput() - } - - override fun keyTyped(typedChar: Char, keyCode: Int) { - super.keyTyped(typedChar, keyCode) - interactionManager.handleKeyTyped(typedChar, keyCode) - } - - override fun doesGuiPauseGame(): Boolean = false -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/UICore.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/UICore.kt new file mode 100644 index 0000000..4b789f8 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/UICore.kt @@ -0,0 +1,69 @@ +package com.github.freedownloadhere.killauravideo.ui.core + +import com.github.freedownloadhere.killauravideo.ui.core.io.InteractionManager +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayout +import com.github.freedownloadhere.killauravideo.ui.core.render.JavaNativeRendering +import com.github.freedownloadhere.killauravideo.ui.core.render.UINewRenderer +import com.github.freedownloadhere.killauravideo.ui.dsl.UIBuilderGlobals +import com.github.freedownloadhere.killauravideo.ui.util.TimeUtil +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiScreen + +class UICore(private val uiProvider: () -> UI): GuiScreen() { + // future reminder: + // the reason why this is all mutable is because + // when the screen resizes it needs to keep track of + // the new width and height + + private lateinit var config: UIStyleConfig + + private lateinit var topLevelUI: UI + + private lateinit var interactionManager: InteractionManager + private lateinit var renderer: UINewRenderer + + private val timeUtil = TimeUtil() + + override fun initGui() { + width = Minecraft.getMinecraft().displayWidth + height = Minecraft.getMinecraft().displayHeight + + config = UIStyleConfig( + screenWidth = width.toFloat(), + screenHeight = height.toFloat() + ) + + UIBuilderGlobals.uiConfig = config + + topLevelUI = uiProvider() + + interactionManager = InteractionManager(topLevelUI, config) + renderer = UINewRenderer(config) + } + + override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { + val deltaTime = timeUtil.newDeltaTime() + + drawDefaultBackground() + + JavaNativeRendering.nUpdateScreenSize(width.toFloat(), height.toFloat()) + + interactionManager.handleMouseInput() + + if(topLevelUI is ILayout) + (topLevelUI as ILayout).applyLayout() + + topLevelUI.updateRecursive(deltaTime) + + renderer.renderEverything(topLevelUI) + } + + override fun keyTyped(typedChar: Char, keyCode: Int) { + super.keyTyped(typedChar, keyCode) + interactionManager.handleKeyTyped(typedChar, keyCode) + } + + override fun doesGuiPauseGame(): Boolean = false +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IParent.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IParent.kt new file mode 100644 index 0000000..af91272 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IParent.kt @@ -0,0 +1,7 @@ +package com.github.freedownloadhere.killauravideo.ui.core.hierarchy + +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI + +interface IParent { + val children: Sequence +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IParentExtendable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IParentExtendable.kt new file mode 100644 index 0000000..11b4bf3 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IParentExtendable.kt @@ -0,0 +1,9 @@ +package com.github.freedownloadhere.killauravideo.ui.core.hierarchy + +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI + +interface IParentExtendable: IParent { + fun addChild(ui: UI) + + operator fun UI.unaryPlus() = addChild(this) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IUniqueParent.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IUniqueParent.kt similarity index 51% rename from src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IUniqueParent.kt rename to src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IUniqueParent.kt index 83308ea..a947ab6 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IUniqueParent.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/hierarchy/IUniqueParent.kt @@ -1,6 +1,6 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.parents +package com.github.freedownloadhere.killauravideo.ui.core.hierarchy -import com.github.freedownloadhere.killauravideo.ui.basic.UI +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI interface IUniqueParent: IParent where T: UI { val child: T diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IInteractable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IInteractable.kt new file mode 100644 index 0000000..b9cb9d3 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IInteractable.kt @@ -0,0 +1,3 @@ +package com.github.freedownloadhere.killauravideo.ui.core.io + +interface IInteractable \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IKeyboardEvent.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IKeyboardEvent.kt new file mode 100644 index 0000000..e354183 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IKeyboardEvent.kt @@ -0,0 +1,5 @@ +package com.github.freedownloadhere.killauravideo.ui.core.io + +interface IKeyboardEvent : IInteractable { + fun keyTypedCallback(typedChar : Char, keyCode : Int) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IMouseEvent.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IMouseEvent.kt new file mode 100644 index 0000000..b63f85a --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/IMouseEvent.kt @@ -0,0 +1,5 @@ +package com.github.freedownloadhere.killauravideo.ui.core.io + +interface IMouseEvent: IInteractable { + fun mouseEventCallback(mouseInfo: MouseInfo) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/InteractionManager.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/InteractionManager.kt index dd2798e..2eea279 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/InteractionManager.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/InteractionManager.kt @@ -1,113 +1,25 @@ package com.github.freedownloadhere.killauravideo.ui.core.io -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.interfaces.io.* -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IParent +import com.github.freedownloadhere.killauravideo.ui.util.RecursiveIterator +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI -class InteractionManager(private val mouseInfo: MouseInfo, private val topUI: UI) { - var focused: UI? = null - private set - var hovered: UI? = null - private set - private var lastMouseOn: UI? = null - private var lastMouseUIAbsX: Double = 0.0 - private var lastMouseUIAbsY: Double = 0.0 - private var moveLock: UI? = null +class InteractionManager( + private val topUI: UI, + private val config: UIStyleConfig, +) { + private val mi: MouseInfo = MouseInfo() fun handleMouseInput() { - val findMouseResult = topUI.findMouseOn(0.0, 0.0) - if(findMouseResult != null) { - val (newLastMouseOn, absX, absY) = findMouseResult - lastMouseOn = newLastMouseOn - lastMouseUIAbsX = absX - lastMouseUIAbsY = absY - } else { - lastMouseOn = null + mi.update(topUI, config) + RecursiveIterator.basic.dfs(topUI) { + if(this is IMouseEvent) + mouseEventCallback(mi) } - onHover() - onClick() - onHold() - onScroll() - onMove() } fun handleKeyTyped(typedChar : Char, keyCode : Int) { - if(focused != null && focused is ITypable) - (focused as ITypable).keyTypedCallback(typedChar, keyCode) - } - - private fun onHover() { - if(lastMouseOn != hovered) { - if(hovered != null && hovered is IHoverable) - (hovered as IHoverable).hoverStopCallback() - if(lastMouseOn != null && lastMouseOn is IHoverable) - (lastMouseOn as IHoverable).hoverStartCallback() - hovered = lastMouseOn - } - } - - private fun onClick() { - if(!mouseInfo.isClicked) return - focused = lastMouseOn - if(focused == null) return - if(focused is IClickable) - (focused as IClickable).clickCallback( - mouseInfo.buttonmask, - mouseInfo.lastX.toDouble() - lastMouseUIAbsX, - mouseInfo.lastY.toDouble() - lastMouseUIAbsY - ) - else if(focused is IMovable && moveLock == null) - moveLock = focused - } - - private fun onHold() { - if(!mouseInfo.isHeldDown) return - if(focused != lastMouseOn) return - if(focused is IClickHoldable) - (focused as IClickHoldable).clickHoldCallback( - mouseInfo.buttonmask, - mouseInfo.lastX.toDouble() - lastMouseUIAbsX, - mouseInfo.lastY.toDouble() - lastMouseUIAbsY - ) - } - - private fun onScroll() { - if(mouseInfo.lastDwheel != 0) { - val d = mouseInfo.lastDwheel / mouseInfo.scrollSens - if(focused != null && focused is IScrollable) - (focused as IScrollable).scrollCallback(d) - } - } - - private fun onMove() { - if(!mouseInfo.isHeldDown) { - moveLock = null - return - } - if(moveLock == null) return - moveLock!!.relX += mouseInfo.dX - moveLock!!.relY += mouseInfo.dY - } - - private fun UI.findMouseOn(absX: Double, absY: Double): Triple? { - if(!active) - return null - - if(this is IParent) - for(child in children) { - val maybeClicked = child.findMouseOn(absX + relX, absY + relY) - if(maybeClicked != null) - return maybeClicked - } - - val x = mouseInfo.lastX - val y = mouseInfo.lastY - - if(absX + relX <= x && x <= absX + relX + width) - if(absY + relY <= y && y <= absY + relY + height) - if(this is IInteractable) - return Triple(this, absX + relX, absY + relY) - - return null + if(mi.lcmCurrent != null && mi.lcmCurrent?.ui is IKeyboardEvent) + (mi.lcmCurrent!!.ui as IKeyboardEvent).keyTypedCallback(typedChar, keyCode) } } \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/MouseInfo.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/MouseInfo.kt index 87e8b34..003c2c0 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/MouseInfo.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/io/MouseInfo.kt @@ -1,9 +1,13 @@ package com.github.freedownloadhere.killauravideo.ui.core.io -import com.github.freedownloadhere.killauravideo.GlobalManager +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParent +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI import org.lwjgl.input.Mouse class MouseInfo { + data class UIAbsoluteData(val ui: UI, val absX: Float, val absY: Float) + var lastX = -1 private set var lastY = -1 @@ -16,20 +20,82 @@ class MouseInfo { private set val scrollSens = 10 - val isClicked : Boolean - get() = Mouse.getEventButtonState() - val buttonmask : Int - get() = Mouse.getEventButton() - val isHeldDown: Boolean - get() = Mouse.isButtonDown(0) + var lcmHoldTime = 0 + private set + var lcmGrabbed: UIAbsoluteData? = null + private set + var lcmCurrent: UIAbsoluteData? = null + private set + var lcmInstant: UIAbsoluteData? = null + private set + var lcmHovered: UIAbsoluteData? = null + private set + + var rcmHoldTime = 0 + private set + var rcmGrabbed: UIAbsoluteData? = null + private set + var rcmCurrent: UIAbsoluteData? = null + private set + var rcmInstant: UIAbsoluteData? = null + private set + var rcmHovered: UIAbsoluteData? = null + private set - fun update() { + fun update(topUI: UI, config: UIStyleConfig) { val newX = Mouse.getEventX() - val newY = GlobalManager.core!!.config.screenHeight.toInt() - Mouse.getEventY() - 1 + val newY = config.screenHeight.toInt() - Mouse.getEventY() - 1 dX = newX - lastX dY = newY - lastY lastX = newX lastY = newY lastDwheel = Mouse.getEventDWheel() + + lcmHoldTime = if(Mouse.isButtonDown(0)) lcmHoldTime + 1 else 0 + rcmHoldTime = if(Mouse.isButtonDown(1)) rcmHoldTime + 1 else 0 + + lcmInstant = null + rcmInstant = null + + lcmCurrent = null + rcmCurrent = null + + if(lcmHoldTime == 0) lcmGrabbed = null + if(rcmHoldTime == 0) rcmGrabbed = null + + lcmHovered = null + rcmHovered = null + + val freshUIData = topUI.findMouseCurrentlyOn() ?: return + + lcmInstant = if(lcmHoldTime == 1) freshUIData else null + rcmInstant = if(rcmHoldTime == 1) freshUIData else null + + lcmCurrent = if(lcmHoldTime > 0) freshUIData else null + rcmCurrent = if(rcmHoldTime > 0) freshUIData else null + + if(lcmHoldTime > 0 && lcmGrabbed == null) lcmGrabbed = freshUIData + if(rcmHoldTime > 0 && rcmGrabbed == null) rcmGrabbed = freshUIData + + lcmHovered = freshUIData + rcmHovered = freshUIData + } + + private fun UI.findMouseCurrentlyOn(absX: Float = 0.0f, absY: Float = 0.0f): UIAbsoluteData? { + if(!active) return null + + if(this is IParent) + for(child in children) { + val maybeMouseOn = child.findMouseCurrentlyOn(absX + relX, absY + relY) + if(maybeMouseOn != null) + return maybeMouseOn + } + + if(absX + relX <= lastX && lastX <= absX + relX + width) + if(absY + relY <= lastY && lastY <= absY + relY + height) + if(this is IInteractable) + return UIAbsoluteData(this, absX + relX, absY + relY) + + return null } } \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayout.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayout.kt similarity index 68% rename from src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayout.kt rename to src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayout.kt index b2e3212..b522948 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayout.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayout.kt @@ -1,6 +1,6 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.layout +package com.github.freedownloadhere.killauravideo.ui.core.layout -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IParent +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParent interface ILayout { fun applyLayout() { diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayoutPost.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayoutPost.kt new file mode 100644 index 0000000..3d55e8a --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayoutPost.kt @@ -0,0 +1,5 @@ +package com.github.freedownloadhere.killauravideo.ui.core.layout + +interface ILayoutPost: ILayout { + fun layoutPostCallback() +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayoutPre.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayoutPre.kt new file mode 100644 index 0000000..0693047 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/ILayoutPre.kt @@ -0,0 +1,5 @@ +package com.github.freedownloadhere.killauravideo.ui.core.layout + +interface ILayoutPre : ILayout { + fun layoutPreCallback() +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/IPadded.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/IPadded.kt new file mode 100644 index 0000000..f9b663e --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/IPadded.kt @@ -0,0 +1,5 @@ +package com.github.freedownloadhere.killauravideo.ui.core.layout + +interface IPadded { + var padding: Float +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/LayoutFunctions.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/LayoutFunctions.kt new file mode 100644 index 0000000..5d2db95 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/layout/LayoutFunctions.kt @@ -0,0 +1,13 @@ +package com.github.freedownloadhere.killauravideo.ui.core.layout + +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IUniqueParent +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI +import kotlin.math.max + +fun T.uiCenterBoxLayout() where T: UI, T: IUniqueParent<*> { + val pad = if (this is IPadded) padding else 0.0f + width = max(width, child.width + pad) + height = max(height, child.height + pad) + child.relX = 0.5f * (width - child.width) + child.relY = 0.5f * (height - child.height) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/DrawFunctions.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/DrawFunctions.kt new file mode 100644 index 0000000..46fa125 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/DrawFunctions.kt @@ -0,0 +1,18 @@ +package com.github.freedownloadhere.killauravideo.ui.core.render + +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI + +fun T.uiBoxDraw(ri: IRenderInfo, baseColor: UIColorEnum) where T: UI { + RenderingBackend.drawRect( + x = ri.absX + relX, + y = ri.absY + relY, + z = ri.layer * 0.01f, + width = width, + height = height, + baseColor = baseColor, + borderColor = UIColorEnum.BOX_PRIMARY, + rounding = ri.config.rounding, + bordering = ri.config.bordering, + ) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/IRenderInfo.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/IRenderInfo.kt new file mode 100644 index 0000000..63eb298 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/IRenderInfo.kt @@ -0,0 +1,10 @@ +package com.github.freedownloadhere.killauravideo.ui.core.render + +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig + +interface IRenderInfo { + val absX: Float + val absY: Float + val layer: Int + val config: UIStyleConfig +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/JavaNativeRendering.java b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/JavaNativeRendering.java new file mode 100644 index 0000000..bda4a86 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/JavaNativeRendering.java @@ -0,0 +1,40 @@ +package com.github.freedownloadhere.killauravideo.ui.core.render; + +public class JavaNativeRendering { + public static native void nInit( + float screenWidth, float screenHeight + ); + + public static native void nUpdateScreenSize( + float screenWidth, float screenHeight + ); + + public static native void nAddRectToMesh( + float x, float y, float z, + float width, float height, + int baseColorARGB, int borderColorARGB, + float rounding, float bordering, + int textureID + ); + + public static native void nAddTextToMesh( + String text, + float x, float y, float z, + int colorARGB, + int scaleIdx + ); + + public static native void nAddLineToMesh( + float x1, float y1, float z1, + float x2, float y2, float z2, + int colorARGB, float width + ); + + public static native float nGetTextWidth( + String text, int scaleIdx + ); + + public static native int nUploadTexture( + byte[] texBytes + ); +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/RenderScissorStack.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/RenderScissorStack.kt deleted file mode 100644 index 88475cb..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/RenderScissorStack.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.core.render - -import com.github.freedownloadhere.killauravideo.GlobalManager -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import org.lwjgl.opengl.GL11 -import java.util.* -import kotlin.math.max -import kotlin.math.min - -class RenderScissorStack { - data class ScissorData( - var x1 : Int, - var y1 : Int, - var x2 : Int, - var y2 : Int - ) - - private val stk = Stack() - - fun push(gui : UI) { - val a = ScissorData(gui.relX.toInt(), gui.relY.toInt(), (gui.relX + gui.width).toInt(), (gui.relY + gui.height).toInt()) - - if(stk.empty()) { - stk.push(a) - apply() - return - } - - val b = stk.peek() - - if(a.x2 <= b.x1 || a.x1 >= b.x2 || a.y2 <= b.y1 || a.y1 >= b.y2) { - stk.push(ScissorData(0, 0, 0, 0)) - return - } - - stk.push( - ScissorData( - max(a.x1, b.x1), - max(a.y1, b.y1), - min(a.x2, b.x2), - min(a.y2, b.y2) - ) - ) - - apply() - } - - fun pop() { - stk.pop() - if(!stk.empty()) - apply() - } - - fun disable() { - GL11.glDisable(GL11.GL_SCISSOR_TEST) - } - - fun enable() { - GL11.glEnable(GL11.GL_SCISSOR_TEST) - GL11.glScissor(0, 0, GlobalManager.core!!.width, GlobalManager.core!!.height) - } - - private fun apply() { - val thickness = GlobalManager.core!!.config.borderThickness.toInt() - val top = stk.peek() - GL11.glScissor( - top.x1 - thickness, - GlobalManager.core!!.height - thickness - top.y2, - (top.x2 - top.x1) + 2 * thickness, - (top.y2 - top.y1) + 2 * thickness - ) - } -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/Renderer.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/Renderer.kt deleted file mode 100644 index 499669c..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/Renderer.kt +++ /dev/null @@ -1,134 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.core.render - -import com.github.freedownloadhere.killauravideo.mixin.AccessorFontRenderer -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.core.io.InteractionManager -import com.github.freedownloadhere.killauravideo.ui.util.RecursiveIterator -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum -import net.minecraft.client.Minecraft -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.client.renderer.Tessellator -import net.minecraft.client.renderer.vertex.DefaultVertexFormats -import net.minecraft.util.ResourceLocation -import org.lwjgl.opengl.GL11 - -class Renderer( - private val config: UIConfig, - val interactionManager: InteractionManager -) -{ - companion object { - val renderIterator = RecursiveIterator( - onBegin = { GlStateManager.translate(relX, relY, 0.0) }, - onEnd = { GlStateManager.translate(-relX, -relY, 0.0) } - ) - } - - val scissorStack = RenderScissorStack() - - fun drawBasicBG(gui: UI, color: UIColorEnum) { - drawBG(gui, color) - if(gui == interactionManager.focused) - drawHL(gui) - else - drawBorder(gui) - } - - private fun drawHL(ui: UI) { - GlStateManager.pushMatrix() - GlStateManager.translate(0.0, 0.0, 0.1) - drawUIrect(ui, UIColorEnum.ACCENT, filled = false) - GlStateManager.popMatrix() - } - private fun drawBorder(ui: UI) = drawUIrect(ui, UIColorEnum.BOX_SECONDARY, filled = false) - private fun drawBG(ui: UI, col: UIColorEnum) = drawUIrect(ui, col, filled = true) - - private fun drawUIrect(ui: UI, col: UIColorEnum, filled: Boolean) { - GlStateManager.matrixMode(GL11.GL_MODELVIEW) - GlStateManager.pushMatrix() - GlStateManager.scale(ui.width, ui.height, 1.0) - drawRect(col, filled) - GlStateManager.popMatrix() - } - - fun withUIState(block: () -> Unit) { - GlStateManager.matrixMode(GL11.GL_PROJECTION) - GlStateManager.pushMatrix() - GlStateManager.loadIdentity() - GlStateManager.ortho(0.0, config.screenWidth, config.screenHeight, 0.0, -1.0, 1.0) - - GlStateManager.matrixMode(GL11.GL_MODELVIEW) - GlStateManager.pushMatrix() - GlStateManager.loadIdentity() - - GlStateManager.disableTexture2D() - GlStateManager.disableLighting() - - val oldLineWidth = GL11.glGetFloat(GL11.GL_LINE_WIDTH) - GL11.glLineWidth(config.borderThickness) - -// scissorStack.enable() - - block() - -// scissorStack.disable() - - GL11.glLineWidth(oldLineWidth) - - GlStateManager.enableLighting() - GlStateManager.enableTexture2D() - - GlStateManager.matrixMode(GL11.GL_MODELVIEW) - GlStateManager.popMatrix() - GlStateManager.matrixMode(GL11.GL_PROJECTION) - GlStateManager.popMatrix() - } - - fun withTextState(block: () -> Unit) { - val fr = Minecraft.getMinecraft().fontRendererObj - val fontTex = (fr as AccessorFontRenderer).fontLocation_killauravideo - - GlStateManager.enableTexture2D() - GlStateManager.enableBlend() - GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) - - Minecraft.getMinecraft().textureManager.bindTexture(fontTex) - - block() - - GlStateManager.disableBlend() - GlStateManager.disableTexture2D() - } - - fun drawRect(col: UIColorEnum, filled: Boolean) { - val worldRenderer = Tessellator.getInstance().worldRenderer - val drawType = if(filled) GL11.GL_QUADS else GL11.GL_LINE_LOOP - worldRenderer.begin(drawType, DefaultVertexFormats.POSITION_COLOR) - worldRenderer.pos(0.0, 0.0, 0.0).color(col.r, col.g, col.b, col.a).endVertex() - worldRenderer.pos(0.0, 1.0, 0.0).color(col.r, col.g, col.b, col.a).endVertex() - worldRenderer.pos(1.0, 1.0, 0.0).color(col.r, col.g, col.b, col.a).endVertex() - worldRenderer.pos(1.0, 0.0, 0.0).color(col.r, col.g, col.b, col.a).endVertex() - Tessellator.getInstance().draw() - } - - fun drawRect(tex: ResourceLocation, filled: Boolean) { - val wr = Tessellator.getInstance().worldRenderer - val drawType = if(filled) GL11.GL_QUADS else GL11.GL_LINE_LOOP - - GlStateManager.enableTexture2D() - GlStateManager.enableBlend() - GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) - Minecraft.getMinecraft().textureManager.bindTexture(tex) - - wr.begin(drawType, DefaultVertexFormats.POSITION_TEX) - wr.pos(0.0, 0.0, 0.0).tex(0.0, 0.0).endVertex() - wr.pos(0.0, 1.0, 0.0).tex(0.0, 1.0).endVertex() - wr.pos(1.0, 1.0, 0.0).tex(1.0, 1.0).endVertex() - wr.pos(1.0, 0.0, 0.0).tex(1.0, 0.0).endVertex() - Tessellator.getInstance().draw() - - GlStateManager.disableTexture2D() - GlStateManager.disableBlend() - } -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/RenderingBackend.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/RenderingBackend.kt new file mode 100644 index 0000000..7b956d8 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/RenderingBackend.kt @@ -0,0 +1,59 @@ +package com.github.freedownloadhere.killauravideo.ui.core.render + +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UIText +import java.io.FileNotFoundException + +object RenderingBackend { + private val savedTextureToID = mutableMapOf() + + fun init(screenWidth: Float, screenHeight: Float) { + JavaNativeRendering.nInit(screenWidth, screenHeight) + } + + fun loadTexture(name: String, path: String) { + val inputStream = RenderingBackend::class.java.getResourceAsStream(path) + ?: throw FileNotFoundException("Failed to find resource $path") + val inputBytes = inputStream.readBytes() + savedTextureToID[name] = JavaNativeRendering.nUploadTexture(inputBytes) + inputStream.close() + } + + fun drawLine( + x1: Float, y1: Float, z1: Float, + x2: Float, y2: Float, z2: Float, + color: UIColorEnum, + width: Float, + ) = JavaNativeRendering.nAddLineToMesh( + x1, y1, z1, + x2, y2, z2, + color.toPackedARGB(), + width + ) + + fun drawRect( + x: Float, y: Float, z: Float, + width: Float, height: Float, + baseColor: UIColorEnum, borderColor: UIColorEnum, + rounding: Float, bordering: Float, + textureName: String? = null, + ) = JavaNativeRendering.nAddRectToMesh( + x, y, z, + width, height, + baseColor.toColor().rgb, borderColor.toColor().rgb, + rounding, bordering, + savedTextureToID.getOrDefault(textureName, -1) + ) + + fun drawText( + string: String, + x: Float, y: Float, z: Float, + color: UIColorEnum, + scale: UIText.Scale, + ) = JavaNativeRendering.nAddTextToMesh( + string, + x, y, z, + color.toColor().rgb, + scale.idx + ) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/UINewRenderer.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/UINewRenderer.kt new file mode 100644 index 0000000..d4cde8d --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/core/render/UINewRenderer.kt @@ -0,0 +1,38 @@ +package com.github.freedownloadhere.killauravideo.ui.core.render + +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParent +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI + +class UINewRenderer(config: UIStyleConfig) { + data class RenderInfo( + override var absX: Float, + override var absY: Float, + override var layer: Int, + override var config: UIStyleConfig, + ) : IRenderInfo + + private val renderInfo = RenderInfo( + absX = 0.0f, absY = 0.0f, layer = 0, config = config + ) + + fun renderEverything(ui: T) where T: UI { + renderInfo.absX = 0.0f + renderInfo.absY = 0.0f + renderInfo.layer = 0 + recursiveRender(ui) + } + + private fun recursiveRender(ui: T) where T: UI { + if(!ui.hidden) ui.renderCallback(renderInfo) + renderInfo.absX += ui.relX + renderInfo.absY += ui.relY + ++renderInfo.layer + if(ui is IParent) for(child in ui.children) { + recursiveRender(child) + } + --renderInfo.layer + renderInfo.absY -= ui.relY + renderInfo.absX -= ui.relX + } +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/dsl/Dsl.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/dsl/Dsl.kt index a63437a..c28ee28 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/dsl/Dsl.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/dsl/Dsl.kt @@ -1,17 +1,17 @@ package com.github.freedownloadhere.killauravideo.ui.dsl -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.basic.UIText -import com.github.freedownloadhere.killauravideo.ui.composite.UIButton -import com.github.freedownloadhere.killauravideo.ui.composite.UICheckbox -import com.github.freedownloadhere.killauravideo.ui.composite.UISlider -import com.github.freedownloadhere.killauravideo.ui.containers.UICenteredBox -import com.github.freedownloadhere.killauravideo.ui.containers.UIHorizontalBox -import com.github.freedownloadhere.killauravideo.ui.containers.UIVerticalBox -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UIText +import com.github.freedownloadhere.killauravideo.ui.widgets.composite.UIButton +import com.github.freedownloadhere.killauravideo.ui.widgets.composite.UICheckbox +import com.github.freedownloadhere.killauravideo.ui.widgets.composite.UISlider +import com.github.freedownloadhere.killauravideo.ui.widgets.containers.UICenteredBox +import com.github.freedownloadhere.killauravideo.ui.widgets.containers.UIHorizontalBox +import com.github.freedownloadhere.killauravideo.ui.widgets.containers.UIVerticalBox object UIBuilderGlobals { - lateinit var uiConfig: UIConfig + lateinit var uiConfig: UIStyleConfig } fun verticalBox(init: UIVerticalBox.() -> Unit = {}) = newUI(UIVerticalBox(config = UIBuilderGlobals.uiConfig), init) diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/implementations/DrawFunctions.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/implementations/DrawFunctions.kt deleted file mode 100644 index 5d17780..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/implementations/DrawFunctions.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.implementations - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer -import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum - -fun T.uiBoxDraw(renderer: Renderer, baseColor: UIColorEnum) where T: UI { - val color = if(renderer.interactionManager.hovered == this) - UIColorEnum.BOX_PRIMARY - else - baseColor - renderer.drawBasicBG(this, color) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/implementations/LayoutFunctions.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/implementations/LayoutFunctions.kt deleted file mode 100644 index 6849533..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/implementations/LayoutFunctions.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.implementations - -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.IPadded -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IUniqueParent -import kotlin.math.max - -fun T.uiCenterBoxLayout() where T: UI, T: IUniqueParent<*> { - val pad = if (this is IPadded) padding else 0.0 - width = max(width, child.width + pad) - height = max(height, child.height + pad) - child.relX = 0.5 * (width - child.width) - child.relY = 0.5 * (height - child.height) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IClickHoldable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IClickHoldable.kt deleted file mode 100644 index dfbc429..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IClickHoldable.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.io - -interface IClickHoldable: IInteractable { - fun clickHoldCallback(button: Int, mouseRelX: Double, mouseRelY: Double) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IClickable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IClickable.kt deleted file mode 100644 index 8627c2d..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IClickable.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.io - -interface IClickable : IInteractable { - fun clickCallback(button: Int, mouseRelX: Double, mouseRelY: Double) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IHoverable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IHoverable.kt deleted file mode 100644 index c38d3bf..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IHoverable.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.io - -interface IHoverable : IInteractable { - fun hoverStartCallback() - fun hoverStopCallback() -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IInteractable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IInteractable.kt deleted file mode 100644 index 0523220..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IInteractable.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.io - -interface IInteractable \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IMovable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IMovable.kt deleted file mode 100644 index 6cadb70..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IMovable.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.io - -interface IMovable: IInteractable { - var canBeMoved: Boolean -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IScrollable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IScrollable.kt deleted file mode 100644 index 38579b9..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/IScrollable.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.io - -interface IScrollable : IInteractable { - fun scrollCallback(d : Int) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/ITypable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/ITypable.kt deleted file mode 100644 index df28545..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/io/ITypable.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.io - -interface ITypable : IInteractable { - fun keyTypedCallback(typedChar : Char, keyCode : Int) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayoutPost.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayoutPost.kt deleted file mode 100644 index bfec53c..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayoutPost.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.layout - -interface ILayoutPost: ILayout { - fun layoutPostCallback() -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayoutPre.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayoutPre.kt deleted file mode 100644 index 17f3d45..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/ILayoutPre.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.layout - -interface ILayoutPre : ILayout { - fun layoutPreCallback() -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/IPadded.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/IPadded.kt deleted file mode 100644 index 9dfc845..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/layout/IPadded.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.layout - -interface IPadded { - var padding: Double -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IParent.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IParent.kt deleted file mode 100644 index 458e06f..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IParent.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.parents - -import com.github.freedownloadhere.killauravideo.ui.basic.UI - -interface IParent { - val children: Sequence -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IParentExtendable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IParentExtendable.kt deleted file mode 100644 index 4feefd2..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/parents/IParentExtendable.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.parents - -import com.github.freedownloadhere.killauravideo.ui.basic.UI - -interface IParentExtendable: IParent { - fun addChild(ui: UI) - - operator fun UI.unaryPlus() = addChild(this) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/render/IDrawable.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/render/IDrawable.kt deleted file mode 100644 index 763ec2e..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/interfaces/render/IDrawable.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.interfaces.render - -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer - -interface IDrawable { - var hidden: Boolean - fun renderCallback(renderer: Renderer) -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/MathStuff.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/MathStuff.kt deleted file mode 100644 index 6bf59f5..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/MathStuff.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.util - -import kotlin.math.floor -import kotlin.math.pow - -// Might overflow if big number but Eh -fun Double.round(digits: Int): Double { - val pow10 = 10.0.pow(digits) - return floor(this * pow10) / pow10 -} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/RecursiveIterator.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/RecursiveIterator.kt index 7f53ff6..9840b0e 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/RecursiveIterator.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/RecursiveIterator.kt @@ -1,7 +1,7 @@ package com.github.freedownloadhere.killauravideo.ui.util -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IParent +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParent +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI class RecursiveIterator( private val onBegin: (UI.()->Unit)? = null, diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIColorEnum.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIColorEnum.kt index e97996f..7960b45 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIColorEnum.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIColorEnum.kt @@ -1,5 +1,7 @@ package com.github.freedownloadhere.killauravideo.ui.util +import java.awt.Color + enum class UIColorEnum(val r: Int, val g: Int, val b: Int, val a: Int = 255) { BOX_PRIMARY(51, 51, 51), BOX_SECONDARY(26, 26, 26), @@ -11,5 +13,16 @@ enum class UIColorEnum(val r: Int, val g: Int, val b: Int, val a: Int = 255) { ACCENT(109, 56, 255); + val rFloat: Float + get() = r / 255.0f + val gFloat: Float + get() = g / 255.0f + val bFloat: Float + get() = b / 255.0f + val aFloat: Float + get() = a / 255.0f + fun toPackedARGB(): Int = (a shl 24) or (r shl 16) or (g shl 8) or b + + fun toColor(): Color = Color(r, g, b, a) } \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIConfig.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIConfig.kt deleted file mode 100644 index 8f6f1e2..0000000 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIConfig.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.freedownloadhere.killauravideo.ui.util - -data class UIConfig( - val borderThickness: Float = 2.0f, - val buttonClickCooldown: Long = 100L, - val padding: Double = 10.0, - val screenWidth: Double, - val screenHeight: Double, -) \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIStyleConfig.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIStyleConfig.kt new file mode 100644 index 0000000..4a12c0d --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/util/UIStyleConfig.kt @@ -0,0 +1,11 @@ +package com.github.freedownloadhere.killauravideo.ui.util + +data class UIStyleConfig( + val borderThickness: Float = 2.0f, + val buttonClickCooldown: Long = 100L, + val padding: Float = 10.0f, + val screenWidth: Float, + val screenHeight: Float, + val rounding: Float = 5.0f, + val bordering: Float = 1.0f, +) \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UI.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UI.kt similarity index 56% rename from src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UI.kt rename to src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UI.kt index a2c4012..99a83f1 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UI.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UI.kt @@ -1,35 +1,30 @@ -package com.github.freedownloadhere.killauravideo.ui.basic +package com.github.freedownloadhere.killauravideo.ui.widgets.basic -import com.github.freedownloadhere.killauravideo.ui.core.render.Renderer +import com.github.freedownloadhere.killauravideo.ui.core.render.IRenderInfo import com.github.freedownloadhere.killauravideo.ui.dsl.UIScopeMarker -import com.github.freedownloadhere.killauravideo.ui.interfaces.render.IDrawable import com.github.freedownloadhere.killauravideo.ui.util.RecursiveIterator -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +@Suppress("UNUSED_PARAMETER") @UIScopeMarker -abstract class UI(config: UIConfig) { - internal var relX = 0.0 - internal var relY = 0.0 - internal var width = 0.0 - internal var height = 0.0 +abstract class UI(config: UIStyleConfig) { + var relX: Float = 0.0f + var relY: Float = 0.0f + var width: Float = 0.0f + var height: Float = 0.0f var active = true set(value) { changeActiveState(value) } + var hidden: Boolean = false open fun update(deltaTime: Long) { } + open fun renderCallback(ri: IRenderInfo) { } + fun toggleActive() = changeActiveState(!active) fun enable() = changeActiveState(true) fun disable() = changeActiveState(false) - fun renderRecursive(renderer: Renderer) { - if(!active) return - Renderer.renderIterator.dfs(this) { - if(this is IDrawable && !hidden) - renderCallback(renderer) - } - } - fun updateRecursive(deltaTime: Long) { if(!active) return RecursiveIterator.basic.dfs(this) { diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UIIcon.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UIIcon.kt new file mode 100644 index 0000000..08fbd8d --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UIIcon.kt @@ -0,0 +1,35 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.basic + +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayoutPost +import com.github.freedownloadhere.killauravideo.ui.core.render.IRenderInfo +import com.github.freedownloadhere.killauravideo.ui.core.render.RenderingBackend +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig + +class UIIcon(config: UIStyleConfig): UI(config), ILayoutPost { + enum class Scale(val numeric: Float) { + SMALL(20.0f), + MEDIUM(35.0f), + LARGE(50.0f) + } + + var scale: Scale = Scale.MEDIUM + + override fun renderCallback(ri: IRenderInfo) { + RenderingBackend.drawRect( + ri.absX + relX, + ri.absY + relY, + ri.layer * 0.01f, + width, height, + UIColorEnum.BOX_SECONDARY, UIColorEnum.BOX_TERNARY, + ri.config.rounding, + ri.config.bordering, + "checkmark" + ) + } + + override fun layoutPostCallback() { + width = scale.numeric + height = scale.numeric + } +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UIText.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UIText.kt new file mode 100644 index 0000000..b29638c --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/basic/UIText.kt @@ -0,0 +1,45 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.basic + +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayoutPost +import com.github.freedownloadhere.killauravideo.ui.core.render.IRenderInfo +import com.github.freedownloadhere.killauravideo.ui.core.render.JavaNativeRendering +import com.github.freedownloadhere.killauravideo.ui.core.render.RenderingBackend +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig + +class UIText(config: UIStyleConfig, default: String = "Text"): UI(config), ILayoutPost +{ + // duplicate data + enum class Scale(val idx: Int, val vSizePx: Float) { + VERY_SMALL(0, 15.0f), + SMALL(1, 25.0f), + MEDIUM(2, 40.0f), + LARGE(3, 55.0f), + VERY_LARGE(4, 70.0f), + } + + var scale: Scale = Scale.MEDIUM + var source: () -> String = { default } + + val text: String + get() = source() + + var color: UIColorEnum = UIColorEnum.TEXT_PRIMARY + + override fun renderCallback(ri: IRenderInfo) { + if (text.isEmpty()) return + RenderingBackend.drawText( + x = ri.absX + relX, + y = ri.absY + relY, + z = ri.layer * 0.01f, + string = text, + color = color, + scale = scale, + ) + } + + override fun layoutPostCallback() { + width = JavaNativeRendering.nGetTextWidth(text, scale.idx) + height = scale.vSizePx + } +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UIButton.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UIButton.kt new file mode 100644 index 0000000..45b2dd4 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UIButton.kt @@ -0,0 +1,43 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.composite + +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IUniqueParent +import com.github.freedownloadhere.killauravideo.ui.core.io.IMouseEvent +import com.github.freedownloadhere.killauravideo.ui.core.io.MouseInfo +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayoutPost +import com.github.freedownloadhere.killauravideo.ui.core.layout.uiCenterBoxLayout +import com.github.freedownloadhere.killauravideo.ui.core.render.IRenderInfo +import com.github.freedownloadhere.killauravideo.ui.core.render.uiBoxDraw +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UIText +import kotlin.math.max + +class UIButton(config: UIStyleConfig): UI(config), IUniqueParent, ILayoutPost, IMouseEvent +{ + private val cooldown: Long = config.buttonClickCooldown + private var cooldownLeft: Long = 0L + + override val child: UIText = UIText(config) + + var onClick: () -> Unit = { } + private var color: UIColorEnum = UIColorEnum.BOX_SECONDARY + + override fun update(deltaTime: Long) { + cooldownLeft = max(0L, cooldownLeft - deltaTime) + if(cooldownLeft == 0L) color = UIColorEnum.BOX_SECONDARY + super.update(deltaTime) + } + + override fun mouseEventCallback(mouseInfo: MouseInfo) { + if(mouseInfo.lcmInstant?.ui == this && cooldownLeft == 0L) { + onClick() + cooldownLeft = cooldown + color = UIColorEnum.BOX_TERNARY + } + } + + override fun layoutPostCallback() = uiCenterBoxLayout() + + override fun renderCallback(ri: IRenderInfo) = uiBoxDraw(ri, color) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UICheckbox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UICheckbox.kt new file mode 100644 index 0000000..0ffecdb --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UICheckbox.kt @@ -0,0 +1,38 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.composite + +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IUniqueParent +import com.github.freedownloadhere.killauravideo.ui.core.io.IMouseEvent +import com.github.freedownloadhere.killauravideo.ui.core.io.MouseInfo +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayoutPost +import com.github.freedownloadhere.killauravideo.ui.core.layout.IPadded +import com.github.freedownloadhere.killauravideo.ui.core.layout.uiCenterBoxLayout +import com.github.freedownloadhere.killauravideo.ui.core.render.IRenderInfo +import com.github.freedownloadhere.killauravideo.ui.core.render.uiBoxDraw +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UIIcon + +class UICheckbox(config: UIStyleConfig): UI(config), IUniqueParent, IMouseEvent, ILayoutPost, IPadded +{ + var checked: Boolean = false + set(value) { + field = value + child.hidden = !value + } + var onCheck: () -> Unit = { } + override val child: UIIcon = UIIcon(config) + + override var padding: Float = config.padding + + override fun mouseEventCallback(mouseInfo: MouseInfo) { + if(mouseInfo.lcmInstant?.ui == this) { + checked = !checked + onCheck() + } + } + + override fun layoutPostCallback() = uiCenterBoxLayout() + + override fun renderCallback(ri: IRenderInfo) = uiBoxDraw(ri, UIColorEnum.BOX_SECONDARY) +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UISlider.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UISlider.kt new file mode 100644 index 0000000..06d0c6c --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/composite/UISlider.kt @@ -0,0 +1,85 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.composite + +import com.github.freedownloadhere.killauravideo.ui.core.io.IMouseEvent +import com.github.freedownloadhere.killauravideo.ui.core.io.MouseInfo +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayoutPost +import com.github.freedownloadhere.killauravideo.ui.core.layout.IPadded +import com.github.freedownloadhere.killauravideo.ui.core.render.IRenderInfo +import com.github.freedownloadhere.killauravideo.ui.core.render.RenderingBackend +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI +import kotlin.math.floor +import kotlin.math.max + +class UISlider(config: UIStyleConfig): UI(config), IPadded, ILayoutPost, IMouseEvent +{ + override var padding: Float = config.padding + + var minValue: Float = 0.0f + var maxValue: Float = 1.0f + private var position: Float = 0.0f + + var selectedValue: Float + get() = minValue + (maxValue - minValue) * position + set(value) { position = (value - minValue) / (maxValue - minValue) } + + var clickAction: () -> Unit = { } + + var segmented: Boolean = true + var segmentCount: Int = 5 + + override fun mouseEventCallback(mouseInfo: MouseInfo) { + if(mouseInfo.lcmGrabbed?.ui != this) + return + val relX = mouseInfo.lastX - mouseInfo.lcmGrabbed!!.absX + position = (relX / width).coerceIn(0.0f, 1.0f) + if(segmented) { + val segmentLength = 1.0f / segmentCount + position = floor(position / segmentLength) * segmentLength + } + clickAction() + } + + override fun renderCallback(ri: IRenderInfo) { + RenderingBackend.drawLine( + ri.absX + relX + 0.0f, + ri.absY + relY + 0.5f * height - 1.0f, + ri.layer * 0.01f, + ri.absX + relX + width, + ri.absY + relY + 0.5f * height - 1.0f, + ri.layer * 0.01f, + UIColorEnum.TEXT_SECONDARY, + 2.0f + ) + + for(i in 0..segmentCount) { + RenderingBackend.drawLine( + ri.absX + relX + (width * i) / segmentCount, + ri.absY + relY + height * 0.25f, + ri.layer * 0.01f, + ri.absX + relX + (width * i) / segmentCount, + ri.absY + relY + height * 0.75f, + ri.layer * 0.01f, + UIColorEnum.TEXT_SECONDARY, + 2.0f + ) + } + + RenderingBackend.drawLine( + ri.absX + relX + width * position, + ri.absY + relY + 0.0f, + ri.layer * 0.01f, + ri.absX + relX + width * position, + ri.absY + relY + height, + ri.layer * 0.01f, + UIColorEnum.ACCENT, + 4.0f + ) + } + + override fun layoutPostCallback() { + width = max(width, 2.0f * padding) + height = max(height, 2.0f * padding) + } +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIBox.kt new file mode 100644 index 0000000..f7512d8 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIBox.kt @@ -0,0 +1,28 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.containers + +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParent +import com.github.freedownloadhere.killauravideo.ui.core.io.IMouseEvent +import com.github.freedownloadhere.killauravideo.ui.core.io.MouseInfo +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayoutPost +import com.github.freedownloadhere.killauravideo.ui.core.layout.IPadded +import com.github.freedownloadhere.killauravideo.ui.core.render.IRenderInfo +import com.github.freedownloadhere.killauravideo.ui.core.render.uiBoxDraw +import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI + +abstract class UIBox(config: UIStyleConfig): UI(config), ILayoutPost, IParent, IPadded, IMouseEvent +{ + override var padding: Float = config.padding + var baseColor: UIColorEnum = UIColorEnum.BOX_TERNARY + var canBeMoved: Boolean = false + + override fun renderCallback(ri: IRenderInfo) = uiBoxDraw(ri, baseColor) + + override fun mouseEventCallback(mouseInfo: MouseInfo) { + if(canBeMoved && mouseInfo.lcmGrabbed?.ui == this) { + relX += mouseInfo.dX + relY += mouseInfo.dY + } + } +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UICenteredBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UICenteredBox.kt new file mode 100644 index 0000000..a212750 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UICenteredBox.kt @@ -0,0 +1,14 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.containers + +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IUniqueParent +import com.github.freedownloadhere.killauravideo.ui.core.layout.ILayoutPost +import com.github.freedownloadhere.killauravideo.ui.core.layout.uiCenterBoxLayout +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI + +open class UICenteredBox(config: UIStyleConfig) : UIBox(config), IUniqueParent, ILayoutPost where T: UI +{ + override lateinit var child: T + + override fun layoutPostCallback() = uiCenterBoxLayout() +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIFreeBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIFreeBox.kt new file mode 100644 index 0000000..58433d9 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIFreeBox.kt @@ -0,0 +1,21 @@ +package com.github.freedownloadhere.killauravideo.ui.widgets.containers + +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParentExtendable +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI + +class UIFreeBox(config: UIStyleConfig) : UIBox(config), IParentExtendable +{ + private val childrenList = mutableListOf() + + override val children: Sequence + get() = childrenList.asSequence() + + override fun addChild(ui: UI) { + childrenList += ui + } + + override fun layoutPostCallback() { + + } +} \ No newline at end of file diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIHorizontalBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIHorizontalBox.kt similarity index 67% rename from src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIHorizontalBox.kt rename to src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIHorizontalBox.kt index 1e759b2..a4dc382 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIHorizontalBox.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIHorizontalBox.kt @@ -1,11 +1,11 @@ -package com.github.freedownloadhere.killauravideo.ui.containers +package com.github.freedownloadhere.killauravideo.ui.widgets.containers -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IParentExtendable -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParentExtendable +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI import kotlin.math.max -class UIHorizontalBox(config: UIConfig) : UIBox(config), IParentExtendable +class UIHorizontalBox(config: UIStyleConfig) : UIBox(config), IParentExtendable { enum class Placement { LEFT, RIGHT } private var placementState = Placement.LEFT @@ -40,24 +40,24 @@ class UIHorizontalBox(config: UIConfig) : UIBox(config), IParentExtendable for(child in left) { child.relX = leftX leftX += child.width - child.relY = 0.5 * (height - child.height) + child.relY = 0.5f * (height - child.height) } for(child in right) { rightX -= child.width child.relX = rightX - child.relY = 0.5 * (height - child.height) + child.relY = 0.5f * (height - child.height) } } private fun stretchSelf() { - var minWidth = 0.0 - var minHeight = 0.0 + var minWidth = 0.0f + var minHeight = 0.0f for(child in children) { minWidth += child.width minHeight = max(minHeight, child.height) } - minWidth += 2.0 * padding - minHeight += 2.0 * padding + minWidth += 2.0f * padding + minHeight += 2.0f * padding width = max(width, minWidth) height = max(height, minHeight) } diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIVerticalBox.kt b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIVerticalBox.kt similarity index 59% rename from src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIVerticalBox.kt rename to src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIVerticalBox.kt index 6392460..23dfe81 100644 --- a/src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIVerticalBox.kt +++ b/src/main/java/com/github/freedownloadhere/killauravideo/ui/widgets/containers/UIVerticalBox.kt @@ -1,11 +1,11 @@ -package com.github.freedownloadhere.killauravideo.ui.containers +package com.github.freedownloadhere.killauravideo.ui.widgets.containers -import com.github.freedownloadhere.killauravideo.ui.basic.UI -import com.github.freedownloadhere.killauravideo.ui.interfaces.parents.IParentExtendable -import com.github.freedownloadhere.killauravideo.ui.util.UIConfig +import com.github.freedownloadhere.killauravideo.ui.core.hierarchy.IParentExtendable +import com.github.freedownloadhere.killauravideo.ui.util.UIStyleConfig +import com.github.freedownloadhere.killauravideo.ui.widgets.basic.UI import kotlin.math.max -class UIVerticalBox(config: UIConfig) : UIBox(config), IParentExtendable +class UIVerticalBox(config: UIStyleConfig) : UIBox(config), IParentExtendable { enum class Placement { TOP, BOTTOM } private var placementState = Placement.TOP @@ -13,9 +13,9 @@ class UIVerticalBox(config: UIConfig) : UIBox(config), IParentExtendable private val top = mutableListOf() private val bottom = mutableListOf() - var stretchChildren = true + var stretchChildren: Boolean = true - var spacing: Double = 0.0 + var spacing: Float = 0.0f override val children: Sequence get() = top.asSequence() + bottom.asSequence() @@ -32,29 +32,29 @@ class UIVerticalBox(config: UIConfig) : UIBox(config), IParentExtendable var topY = padding var bottomY = height - padding if(stretchChildren) for(child in children) { - child.width = width - 2.0 * padding + child.width = width - 2.0f * padding } for(child in top) { child.relY = topY topY += (child.height + spacing) - child.relX = 0.5 * (width - child.width) + child.relX = 0.5f * (width - child.width) } for(child in bottom) { bottomY -= (child.height + spacing) child.relY = bottomY - child.relX = 0.5 * (width - child.width) + child.relX = 0.5f * (width - child.width) } } private fun stretchSelf() { - var minWidth = 0.0 - var minHeight = 0.0 + var minWidth = 0.0f + var minHeight = 0.0f for(child in children) { minHeight += child.height minWidth = max(minWidth, child.width) } - minHeight += 2.0 * padding + (top.size + bottom.size - 1) * spacing - minWidth += 2.0 * padding + minHeight += 2.0f * padding + (top.size + bottom.size - 1) * spacing + minWidth += 2.0f * padding height = max(height, minHeight) width = max(width, minWidth) } diff --git a/src/main/java/com/github/freedownloadhere/killauravideo/utils/LibraryLoading.kt b/src/main/java/com/github/freedownloadhere/killauravideo/utils/LibraryLoading.kt new file mode 100644 index 0000000..aef8fc0 --- /dev/null +++ b/src/main/java/com/github/freedownloadhere/killauravideo/utils/LibraryLoading.kt @@ -0,0 +1,29 @@ +package com.github.freedownloadhere.killauravideo.utils + +import java.io.File +import java.io.FileNotFoundException + +object LibraryLoading { + private var loaded: Boolean = false + + private const val LIB_NAME = "JavaNativeRendering.dll" + private const val LIB_PATH = "/assets/killauravideo/natives/$LIB_NAME" + + fun load() { + assert(!loaded) { "The native libraries are already loaded!" } + + val libraryInputStream = LibraryLoading::class.java.getResourceAsStream(LIB_PATH) + ?: throw FileNotFoundException("Failed to find $LIB_PATH") + + val libraryBytes = libraryInputStream.readBytes() + libraryInputStream.close() + + val tempFile = File.createTempFile("killauravideo-", LIB_NAME) + tempFile.writeBytes(libraryBytes) + + System.load(tempFile.absolutePath) + + tempFile.delete() + loaded = true + } +} \ No newline at end of file diff --git a/src/main/resources/assets/killauravideo/fonts/arial.ttf b/src/main/resources/assets/killauravideo/fonts/arial.ttf new file mode 100644 index 0000000..8682d94 Binary files /dev/null and b/src/main/resources/assets/killauravideo/fonts/arial.ttf differ diff --git a/src/main/resources/assets/killauravideo/natives/JavaNativeRendering.dll b/src/main/resources/assets/killauravideo/natives/JavaNativeRendering.dll new file mode 100644 index 0000000..472add2 Binary files /dev/null and b/src/main/resources/assets/killauravideo/natives/JavaNativeRendering.dll differ diff --git a/src/main/resources/assets/killauravideo/shaders/uiRect.frag b/src/main/resources/assets/killauravideo/shaders/uiRect.frag new file mode 100644 index 0000000..f8fb78c --- /dev/null +++ b/src/main/resources/assets/killauravideo/shaders/uiRect.frag @@ -0,0 +1,52 @@ +#version 330 core + +in vec2 fragCoord; + +out vec4 FragColor; + +uniform vec2 uTopLeft; +uniform vec2 uBottomRight; + +uniform float uRounding = 10.0; +uniform float uBordering = 2.0; + +uniform vec4 uBaseColor; +uniform vec4 uBorderColor; + +void main() { + vec2 corners[4] = vec2[]( + uTopLeft, + vec2(uTopLeft.x, uBottomRight.y), + vec2(uBottomRight.x, uTopLeft.y), + uBottomRight + ); + + vec2 innerCorners[4] = vec2[]( + uTopLeft + vec2(uRounding), + vec2(uTopLeft.x, uBottomRight.y) + vec2(uRounding, -uRounding), + vec2(uBottomRight.x, uTopLeft.y) + vec2(-uRounding, uRounding), + uBottomRight - vec2(uRounding) + ); + + bool isBorder = false; + + for(int i = 0; i < 4; ++i) { + if(abs(fragCoord.x - corners[i].x) <= uRounding && abs(fragCoord.y - corners[i].y) <= uRounding) { + float dist = distance(innerCorners[i], fragCoord); + if(dist > uRounding) { + discard; + } + else if(dist > uRounding - uBordering) { + isBorder = true; + break; + } + } else if(abs(fragCoord.x - corners[i].x) <= uBordering || abs(fragCoord.y - corners[i].y) <= uBordering) { + isBorder = true; + } + } + + if(isBorder) + FragColor = uBorderColor; + else + FragColor = uBaseColor; +} \ No newline at end of file diff --git a/src/main/resources/assets/killauravideo/shaders/uiRect.vert b/src/main/resources/assets/killauravideo/shaders/uiRect.vert new file mode 100644 index 0000000..519d183 --- /dev/null +++ b/src/main/resources/assets/killauravideo/shaders/uiRect.vert @@ -0,0 +1,13 @@ +#version 330 core + +layout (location = 0) in vec3 aPos; + +uniform mat4 uProj; +uniform mat4 uModel; + +out vec2 fragCoord; + +void main() { + fragCoord = (uModel * vec4(aPos, 1.0)).xy; + gl_Position = uProj * vec4(fragCoord, 0.0, 1.0); +} \ No newline at end of file