Skip to content

Commit

Permalink
Merge branch 'master' into 1.79
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/codeStyles/Project.xml
#	core/src/main/kotlin/imgui/internal/api/inputText.kt
  • Loading branch information
elect86 committed Nov 25, 2020
2 parents d0b49f1 + fa3d5f9 commit c2c3d2d
Show file tree
Hide file tree
Showing 38 changed files with 3,896 additions and 1,697 deletions.
10 changes: 0 additions & 10 deletions .idea/codeStyles/Project.xml

This file was deleted.

15 changes: 15 additions & 0 deletions .idea/runConfigurations/VulkanKt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/runConfigurations/Vulkan_Vanilla_Kt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,20 @@ Dear ImGui allows you create elaborate tools as well as very short-lived ones. O

### Demo

You should be able to try the examples from `test` (tested on Windows/Mac/Linux) within minutes. If you don't, let me know!
You should be able to try the examples from `test` (tested on Windows/Mac/Linux) within minutes. If you can't, let me know!

OpenGL Kotlin:
OpenGL:
- [Kotlin](gl/src/test/kotlin/examples/opengl3.kt)
- [Java](gl/src/test/java/imgui/examples/OpenGL3.java)

- [lwjgl](imgui-gl/src/test/kotlin/imgui/examples/opengl3.kt)
- [jogl](jogl/src/test/kotlin/imgui/examples/JoglGL3.kt) (currently not-maintained)
Vulkan:
- Kotlin:

OpenGL Java:

- [lwjgl](imgui-gl/src/test/java/imgui/examples/OpenGL3.java)

Vulkan Kotlin:

- [lwjgl](imgui-vk/src/test/kotlin/imgui/vulkan.kt) (broken, to fix)
- [VK²](vk/src/test/kotlin/imguiVk/vulkan.kt)

- [LWJGL vanilla](vk/src/test/kotlin/imguiVk_/vulkan_.kt)
- Java:
- PR me!

You should refer to those also to learn how to use the imgui library.

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/imgui/api/demoDebugInformations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ interface demoDebugInformations {

text("Dear ImGui $version ($IMGUI_VERSION_NUM)")
separator()
text("sizeof(size_t): ${Int.BYTES}, sizeof(DrawIdx): ${DrawIdx.BYTES}, sizeof(DrawVert): ${DrawVert.size}")
text("sizeof(size_t): ${Int.BYTES}, sizeof(DrawIdx): ${DrawIdx.BYTES}, sizeof(DrawVert): ${DrawVert.SIZE}")
text("IMGUI_USE_BGRA_PACKED_COLOR: $USE_BGRA_PACKED_COLOR")
separator()
text("io.backendPlatformName: ${io.backendPlatformName}")
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/kotlin/imgui/api/widgetsColorEditorPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ interface widgetsColorEditorPicker {
* With typical options: Left-click on colored square to open color picker. Right-click to open option menu.
* CTRL-Click over input fields to edit them and TAB to go to next item. */
fun colorEdit4(label: String, col: Vec4, flags: ColorEditFlags = 0): Boolean =
colorEdit4(label, col to _fa, flags)
.also { col put _fa }
colorEdit4(label, col to _fa, flags).also { col put _fa }

fun colorEdit4(label: String, col: FloatArray, flags_: ColorEditFlags = 0): Boolean {

Expand Down Expand Up @@ -171,7 +170,7 @@ interface widgetsColorEditorPicker {
val hidePrefix = wItemOne <= calcTextSize(if (flags has Cef.Float) "M:0.000" else "M:000").x
val fmtIdx = if (hidePrefix) 0 else if (flags has Cef.DisplayHSV) 2 else 1

for (n in 0 until components) {
repeat (components) { n ->
if (n > 0)
sameLine(0f, style.itemInnerSpacing.x)
setNextItemWidth(if (n + 1 < components) wItemOne else wItemLast)
Expand Down
37 changes: 22 additions & 15 deletions core/src/main/kotlin/imgui/classes/DrawList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kool.*
import org.lwjgl.system.MemoryUtil
import uno.kotlin.plusAssign
import java.nio.ByteBuffer
import java.nio.IntBuffer
import java.util.Stack
import kotlin.math.sqrt

Expand Down Expand Up @@ -1468,7 +1469,7 @@ class DrawList(sharedData: DrawListSharedData?) {
val colDeltaG = ((col1 ushr COL32_G_SHIFT) and 0xFF) - col0G
val colDeltaB = ((col1 ushr COL32_B_SHIFT) and 0xFF) - col0B
for (i in vertStart until vertEnd) {
var offset = i * DrawVert.size
var offset = i * DrawVert.SIZE
val pos = Vec2(vtxBuffer.data, offset)
val d = pos - gradientP0 dot gradientExtent
val t = glm.clamp(d * gradientInvLength2, 0f, 1f)
Expand All @@ -1493,15 +1494,15 @@ class DrawList(sharedData: DrawListSharedData?) {
val min = uvA min uvB
val max = uvA max uvB
for (i in vertStart until vertEnd) {
val vertexPos = Vec2(vtxBuffer.data, i * DrawVert.size)
val vertexPos = Vec2(vtxBuffer.data, i * DrawVert.SIZE)
val vertexUV = glm.clamp(uvA + (vertexPos - a) * scale, min, max)
vertexUV.to(vtxBuffer.data, i * DrawVert.size + Vec2.size)
vertexUV.to(vtxBuffer.data, i * DrawVert.SIZE + Vec2.size)
}
} else
for (i in vertStart until vertEnd) {
val vertexPos = Vec2(vtxBuffer.data, i * DrawVert.size)
val vertexPos = Vec2(vtxBuffer.data, i * DrawVert.SIZE)
val vertexUV = uvA + (vertexPos - a) * scale
vertexUV.to(vtxBuffer.data, i * DrawVert.size + Vec2.size)
vertexUV.to(vtxBuffer.data, i * DrawVert.SIZE + Vec2.size)
}
}

Expand All @@ -1519,9 +1520,9 @@ private fun DrawVert_Buffer(size: Int = 0) = DrawVert_Buffer(ByteBuffer(size))
inline class DrawVert_Buffer(val data: ByteBuffer) {

operator fun get(index: Int) = DrawVert(
Vec2(data, index * DrawVert.size),
Vec2(data, index * DrawVert.size + DrawVert.ofsUv),
data.getInt(index * DrawVert.size + DrawVert.ofsCol))
Vec2(data, index * DrawVert.SIZE),
Vec2(data, index * DrawVert.SIZE + DrawVert.OFS_UV),
data.getInt(index * DrawVert.SIZE + DrawVert.OFS_COL))

operator fun plusAssign(v: Vec2) {
data.putFloat(v.x)
Expand All @@ -1537,26 +1538,32 @@ inline class DrawVert_Buffer(val data: ByteBuffer) {
}

inline val cap: Int
get() = data.cap / DrawVert.size
get() = data.cap / DrawVert.SIZE

inline var lim: Int
get() = data.lim / DrawVert.size
get() = data.lim / DrawVert.SIZE
set(value) {
data.lim = value * DrawVert.size
data.lim = value * DrawVert.SIZE
}

inline var pos: Int
get() = data.pos / DrawVert.size
get() = data.pos / DrawVert.SIZE
set(value) {
data.pos = value * DrawVert.size
data.pos = value * DrawVert.SIZE
}

inline val rem: Int
get() = data.rem / DrawVert.size
get() = data.rem / DrawVert.SIZE

inline val size: Int
get() = rem

inline val sizeByte: Int
get() = data.rem

inline val adr: Ptr
get() = data.adr

fun hasRemaining(): Boolean = rem > 0

infix fun resize(newSize: Int): DrawVert_Buffer = when {
Expand All @@ -1578,7 +1585,7 @@ inline class DrawVert_Buffer(val data: ByteBuffer) {
infix fun reserve(newCapacity: Int): DrawVert_Buffer {
if (newCapacity <= cap)
return this
val newData = ByteBuffer(newCapacity * DrawVert.size)
val newData = ByteBuffer(newCapacity * DrawVert.SIZE)
if (lim > 0)
MemoryUtil.memCopy(data.adr, newData.adr, data.lim.L)
data.free()
Expand Down
1 change: 0 additions & 1 deletion core/src/main/kotlin/imgui/helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.lwjgl.system.MemoryUtil
import uno.kotlin.NUL
import java.nio.IntBuffer
import java.util.logging.FileHandler
import java.util.logging.Level
import java.util.logging.Logger
import java.util.logging.SimpleFormatter
import kotlin.reflect.KMutableProperty0
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/kotlin/imgui/internal/api/inputText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -965,12 +965,12 @@ internal interface inputText {
else -> Itf.CharsDecimal
}
var valueChanged = false
if (tempInputText(bb, id, label, dataBuf.toByteArray(), flags)) {
if (tempInputText(bb, id, label, buf, flags)) {
// Backup old value
val dataBackup = pData()

// Apply new value (or operations) then clamp
dataTypeApplyOpFromText(dataBuf, g.inputTextState.initialTextA, dataType, pData)
dataTypeApplyOpFromText(buf.cStr, g.inputTextState.initialTextA, dataType, pData)
if (clampMin != null && clampMax != null) {
if (clampMin > clampMax) {
val t = clampMin
Expand All @@ -981,7 +981,7 @@ internal interface inputText {
}

// Only mark as edited if new value is different
valueChanged = dataBackup != pData
valueChanged = dataBackup != pData()

if (valueChanged)
markItemEdited(id)
Expand Down
41 changes: 27 additions & 14 deletions core/src/main/kotlin/imgui/internal/api/templateFunctions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import imgui.ImGui.clearActiveID
import imgui.ImGui.getNavInputAmount2d
import imgui.ImGui.io
import imgui.ImGui.isMousePosValid
import imgui.ImGui.parseFormatFindEnd
import imgui.ImGui.parseFormatFindStart2
import imgui.ImGui.parseFormatPrecision
import imgui.ImGui.style
Expand Down Expand Up @@ -2292,9 +2293,11 @@ internal interface templateFunctions {
val fmtStart = parseFormatFindStart2(fmt)
if (fmt.getOrNul(fmtStart + 0) != '%' || fmt.getOrNul(fmtStart + 1) == '%') // Don't apply if the value is not visible in the format string
return v
val vStr = fmt.substring(fmtStart).format(v)
val fmtEnd = parseFormatFindEnd(fmt, fmtStart)
var vStr = fmt.substring(fmtStart, fmtEnd).format(v)
vStr = vStr.trimStart()
return when (dataType) {
DataType.Float, DataType.Double -> vStr.d.i
DataType.Float, DataType.Double -> vStr.replace(',', '.').d.i
else -> vStr.i
}
}
Expand All @@ -2304,9 +2307,11 @@ internal interface templateFunctions {
val fmtStart = parseFormatFindStart2(fmt)
if (fmt.getOrNul(fmtStart + 0) != '%' || fmt.getOrNul(fmtStart + 1) == '%') // Don't apply if the value is not visible in the format string
return v
val vStr = fmt.substring(fmtStart).format(v.v)
val fmtEnd = parseFormatFindEnd(fmt, fmtStart)
val vStr = fmt.substring(fmtStart, fmtEnd).format(v.v)
vStr.trimStart()
return when (dataType) {
DataType.Float, DataType.Double -> vStr.d.ui
DataType.Float, DataType.Double -> vStr.replace(',', '.').d.ui
else -> vStr.ui
}
}
Expand All @@ -2316,9 +2321,11 @@ internal interface templateFunctions {
val fmtStart = parseFormatFindStart2(fmt)
if (fmt.getOrNul(fmtStart + 0) != '%' || fmt.getOrNul(fmtStart + 1) == '%') // Don't apply if the value is not visible in the format string
return v
val vStr = fmt.substring(fmtStart).format(v)
val fmtEnd = parseFormatFindEnd(fmt, fmtStart)
val vStr = fmt.substring(fmtStart, fmtEnd).format(v)
vStr.trimStart()
return when (dataType) {
DataType.Float, DataType.Double -> vStr.d.L
DataType.Float, DataType.Double -> vStr.replace(',', '.').d.L
else -> vStr.L
}
}
Expand All @@ -2328,9 +2335,11 @@ internal interface templateFunctions {
val fmtStart = parseFormatFindStart2(fmt)
if (fmt.getOrNul(fmtStart + 0) != '%' || fmt.getOrNul(fmtStart + 1) == '%') // Don't apply if the value is not visible in the format string
return v
val vStr = fmt.substring(fmtStart).format(v.v)
val fmtEnd = parseFormatFindEnd(fmt, fmtStart)
val vStr = fmt.substring(fmtStart, fmtEnd).format(v.v)
vStr.trimStart()
return when (dataType) {
DataType.Float, DataType.Double -> vStr.d.ul
DataType.Float, DataType.Double -> vStr.replace(',', '.').d.ul
else -> vStr.ul
}
}
Expand All @@ -2340,10 +2349,12 @@ internal interface templateFunctions {
val fmtStart = parseFormatFindStart2(fmt)
if (fmt.getOrNul(fmtStart + 0) != '%' || fmt.getOrNul(fmtStart + 1) == '%') // Don't apply if the value is not visible in the format string
return v
val vStr = fmt.substring(fmtStart).format(v)
val fmtEnd = parseFormatFindEnd(fmt, fmtStart)
val vStr = fmt.substring(fmtStart, fmtEnd).format(v)
vStr.trimStart()
return when (dataType) {
DataType.Float, DataType.Double -> vStr.d.f
else -> vStr.f
DataType.Float, DataType.Double -> vStr.replace(',', '.').d.f
else -> vStr.replace(',', '.').f
}
}

Expand All @@ -2352,10 +2363,12 @@ internal interface templateFunctions {
val fmtStart = parseFormatFindStart2(fmt)
if (fmt.getOrNul(fmtStart + 0) != '%' || fmt.getOrNul(fmtStart + 1) == '%') // Don't apply if the value is not visible in the format string
return v
val vStr = fmt.substring(fmtStart).format(v)
val fmtEnd = parseFormatFindEnd(fmt, fmtStart)
val vStr = fmt.substring(fmtStart, fmtEnd).format(v)
vStr.trimStart()
return when (dataType) {
DataType.Float, DataType.Double -> vStr.d
else -> vStr.d
DataType.Float, DataType.Double -> vStr.replace(',', '.').d
else -> vStr.replace(',', '.').d
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/kotlin/imgui/internal/draw.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class DrawVert(
) {

companion object {
val size = 2 * Vec2.size + Int.BYTES
val ofsPos = 0f
val ofsUv = Vec2.size
val ofsCol = Vec2.size * 2
val SIZE = 2 * Vec2.size + Int.BYTES
val OFS_POS = 0
val OFS_UV = OFS_POS + Vec2.size
val OFS_COL = OFS_UV + Vec2.size
}

override fun toString() = "pos: $pos, uv: $uv, col: $col"
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/kotlin/imgui/internal/sections/Macros.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package imgui.internal.sections

import imgui.DEBUG
import imgui.api.g


fun IMGUI_DEBUG_LOG(fmt: String, vararg args: Any) = println("[%05d] ".format(g.frameCount) + fmt.format(args))
fun IMGUI_DEBUG_LOG(fmt: String, vararg args: Any) = println("[%05d] ".format(g.frameCount) + fmt.format(*args))

// Debug Logging for selected systems. Remove the '((void)0) //' to enable.
fun IMGUI_DEBUG_LOG_POPUP(fmt: String, vararg args: Any) = IMGUI_DEBUG_LOG(fmt, *args) // Enable log
fun IMGUI_DEBUG_LOG_POPUP(fmt: String, vararg args: Any) {
if (DEBUG) IMGUI_DEBUG_LOG(fmt, *args)
}
//fun IMGUI_DEBUG_LOG_POPUP(fmt: String, vararg args: String) = Unit // Disable log
//fun IMGUI_DEBUG_LOG_NAV(fmt: String, vararg args: Any) = IMGUI_DEBUG_LOG(fmt, *args) // Enable log
fun IMGUI_DEBUG_LOG_NAV(fmt: String, vararg args: Any) = Unit // Disable log
Expand Down
6 changes: 3 additions & 3 deletions gl/src/main/kotlin/imgui/impl/gl/ImplGL2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ class ImplGL2 : GLInterface {
for (cmdList in drawData.cmdLists) {

// Upload vertex/index buffers
GL11.glVertexPointer(Vec2.length, GL_FLOAT, DrawVert.size, cmdList.vtxBuffer.data.adr + 0)
GL11.glTexCoordPointer(Vec2.length, GL_FLOAT, DrawVert.size, cmdList.vtxBuffer.data.adr + Vec2.size)
GL11.glColorPointer(Vec4b.length, GL_UNSIGNED_BYTE, DrawVert.size, cmdList.vtxBuffer.data.adr + Vec2.size * 2)
GL11.glVertexPointer(Vec2.length, GL_FLOAT, DrawVert.SIZE, cmdList.vtxBuffer.data.adr + 0)
GL11.glTexCoordPointer(Vec2.length, GL_FLOAT, DrawVert.SIZE, cmdList.vtxBuffer.data.adr + Vec2.size)
GL11.glColorPointer(Vec4b.length, GL_UNSIGNED_BYTE, DrawVert.SIZE, cmdList.vtxBuffer.data.adr + Vec2.size * 2)

var idxBufferOffset = cmdList.idxBuffer.adr

Expand Down
6 changes: 3 additions & 3 deletions gl/src/main/kotlin/imgui/impl/gl/ImplGL2_mac.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class ImplGL2_mac : GLInterface {
for (cmdList in drawData.cmdLists) {

// Upload vertex/index buffers
GL11.glVertexPointer(Vec2.length, GL_FLOAT, DrawVert.size, cmdList.vtxBuffer.data.adr + 0)
GL11.glTexCoordPointer(Vec2.length, GL_FLOAT, DrawVert.size, cmdList.vtxBuffer.data.adr + Vec2.size)
GL11.glColorPointer(Vec4b.length, GL_UNSIGNED_BYTE, DrawVert.size, cmdList.vtxBuffer.data.adr + Vec2.size * 2)
GL11.glVertexPointer(Vec2.length, GL_FLOAT, DrawVert.SIZE, cmdList.vtxBuffer.data.adr + 0)
GL11.glTexCoordPointer(Vec2.length, GL_FLOAT, DrawVert.SIZE, cmdList.vtxBuffer.data.adr + Vec2.size)
GL11.glColorPointer(Vec4b.length, GL_UNSIGNED_BYTE, DrawVert.SIZE, cmdList.vtxBuffer.data.adr + Vec2.size * 2)

var idxBufferOffset = cmdList.idxBuffer.adr

Expand Down
Loading

0 comments on commit c2c3d2d

Please sign in to comment.