Skip to content

Commit 2f16133

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 80d5be8 + a0ea623 commit 2f16133

File tree

7 files changed

+296
-39
lines changed

7 files changed

+296
-39
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ ImGui supports also other languages, such as japanese, initiliazed [here](https:
6868
```kotlin
6969
IO.fonts.addFontFromFileTTF("extraFonts/ArialUni.ttf", 18f, glyphRanges = IO.fonts.glyphRangesJapanese)!!
7070
```
71+
or [here](https://github.com/kotlin-graphics/imgui/blob/master/src/test/java/imgui/Test_lwjgl.java#L50-L51)
72+
```java
73+
Font font = io.getFonts().addFontFromFileTTF("extraFonts/ArialUni.ttf", 18f, new FontConfig(), io.getFonts().getGlyphRangesJapanese());
74+
assert (font != null);
75+
```
7176

72-
![Imgur](https://i.imgur.com/ASwYzBo.png?1)
77+
![Imgur](https://i.imgur.com/vul0VbT.png?1)
7378

7479

7580
### References

src/main/kotlin/imgui/Context.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ object Context {
179179
/** Last cursor position passed to the OS Input Method Editor */
180180
var osImePosSet = Vec2(-1f)
181181

182+
var imeInProgress = false
183+
var imeLastKey = 0
184+
182185

183186
//------------------------------------------------------------------
184187
// Logging

src/main/kotlin/imgui/Ref.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object Ref {
4242
var bPtr = 0
4343
var cPtr = 0
4444

45-
val size = 100
45+
val size = 500
4646

4747
val ints = IntArray(size)
4848
val floats = FloatArray(size)

src/main/kotlin/imgui/font.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class FontAtlas {
625625
var i = 0
626626
inRange[0] = cfg.glyphRanges[i++]
627627
inRange[1] = cfg.glyphRanges[i++]
628-
while(inRange[0] != 0 && inRange[1] != 0) {
628+
while (inRange[0] != 0 && inRange[1] != 0) {
629629
fontGlyphsCount += (inRange[1] - inRange[0]) + 1
630630
inRange[0] = cfg.glyphRanges.getOrElse(i++, { 0 })
631631
inRange[1] = cfg.glyphRanges.getOrElse(i++, { 0 })
@@ -635,7 +635,7 @@ class FontAtlas {
635635
tmp.rangesCount = fontRangesCount
636636
bufRangesN += fontRangesCount
637637
i = 0
638-
while(i < fontRangesCount) {
638+
while (i < fontRangesCount) {
639639
inRange[0] = cfg.glyphRanges[i * 2]
640640
inRange[1] = cfg.glyphRanges[i * 2 + 1]
641641
val range = tmp.ranges[i++]

src/main/kotlin/imgui/imgui/internal.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package imgui.imgui
22

33
import gli_.has
44
import gli_.hasnt
5+
import glm_.c
56
import glm_.f
67
import glm_.func.common.max
78
import glm_.func.common.min
@@ -1430,8 +1431,19 @@ interface imgui_internal {
14301431
var clearActiveId = false
14311432

14321433
var selectAll = g.activeId != id && flags has Itf.AutoSelectAll
1433-
if (focusRequested || userClicked || userScrolled) {
1434-
if (g.activeId != id) {
1434+
// println(g.imeLastKey)
1435+
if (focusRequested || userClicked || userScrolled || g.imeLastKey != 0) {
1436+
if (g.activeId != id || g.imeLastKey != 0) {
1437+
// JVM, put char if no more in ime mode and last key is valid
1438+
// println("${g.imeInProgress}, ${g.imeLastKey}")
1439+
if(!g.imeInProgress && g.imeLastKey != 0) {
1440+
for(i in 0 until buf.size)
1441+
if(buf[i] == NUL) {
1442+
buf[i] = g.imeLastKey.c
1443+
break
1444+
}
1445+
g.imeLastKey = 0
1446+
}
14351447
/* Start edition
14361448
Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
14371449
From the moment we focused we are ignoring the content of 'buf' (unless we are in read-only mode) */
@@ -1531,7 +1543,8 @@ interface imgui_internal {
15311543
is Alt+Ctrl - to input certain characters. */
15321544
if (!(IO.keyCtrl && !IO.keyAlt) && isEditable)
15331545
IO.inputCharacters.filter { it != NUL }.map {
1534-
withChar { c -> // Insert character if they pass filtering
1546+
withChar { c ->
1547+
// Insert character if they pass filtering
15351548
if (inputTextFilterCharacter(c.apply { set(it) }, flags/*, callback, user_data*/))
15361549
editState.onKeyPressed(c().i)
15371550
}
@@ -1766,7 +1779,7 @@ interface imgui_internal {
17661779
}
17671780
// Copy back to user buffer
17681781
if (isEditable && !Arrays.equals(editState.tempTextBuffer, buf)) {
1769-
repeat(buf.size) { buf[it] = editState.tempTextBuffer[it] }
1782+
for(i in 0 until buf.size) buf[i] = editState.tempTextBuffer[i]
17701783
valueChanged = true
17711784
}
17721785
}
@@ -1914,7 +1927,7 @@ interface imgui_internal {
19141927
}
19151928

19161929
drawWindow.drawList.addText(g.font, g.fontSize, renderPos - renderScroll, Col.Text.u32, bufDisplay,
1917-
editState.curLenA, 0f, if (isMultiline) null else clipRect)
1930+
editState.curLenA, 0f, clipRect.takeIf { isMultiline })
19181931

19191932
// Draw blinking cursor
19201933
val cursorIsVisible = !IO.optCursorBlink || g.inputTextState.cursorAnim <= 0f || glm.mod(g.inputTextState.cursorAnim, 1.2f) <= 0.8f

src/main/kotlin/imgui/impl/LwjglGL3.kt

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import gln.vertexArray.glBindVertexArray
2020
import gln.vertexArray.glVertexAttribPointer
2121
import gln.vertexArray.withVertexArray
2222
import imgui.*
23+
import imgui.Context as g
2324
import org.lwjgl.glfw.GLFW.*
2425
import org.lwjgl.glfw.GLFWNativeWin32.glfwGetWin32Window
2526
import org.lwjgl.opengl.GL11.*
@@ -99,40 +100,11 @@ object LwjglGL3 {
99100
window.scrollCallback = scrollCallback
100101
window.keyCallback = keyCallback
101102
window.charCallback = charCallback // TODO check if used (jogl doesnt have)
102-
if (Platform.get() == Platform.WINDOWS) {
103-
val hwnd = glfwGetWin32Window(window.handle)
104-
val glfwProc = GetWindowLongPtr(hwnd, GWL_WNDPROC)
105-
windowProc = object : WindowProc() {
106-
override fun invoke(hwnd: Long, msg: Int, w: Long, l: Long) = when (msg) {
107-
0x02E0 -> { // WM_DPICHANGED
108-
with(RECT.create(l)) {
109-
SetWindowPos(hwnd, NULL, left(), top(), right() - left(), bottom() - top(), SWP_NOZORDER or SWP_NOACTIVATE)
110-
}
111-
NULL
112-
}
113-
WM_IME_STARTCOMPOSITION -> println("Ime startComposition w: $w l: $l").let { 0L }
114-
WM_IME_ENDCOMPOSITION -> println("Ime endComposition w: $w l: $l").let { 0L }
115-
WM_IME_COMPOSITION /*,WM_IME_KEYLAST*/ -> println("Ime composition/keyLast w: $w l: $l").let { 0L }
116-
WM_IME_SETCONTEXT -> println("Ime setContex w: $w l: $l").let { 0L }
117-
WM_IME_NOTIFY -> println("Ime notify w: $w l: $l").let { 0L }
118-
WM_IME_CONTROL -> println("Ime control w: $w l: $l").let { 0L }
119-
WM_IME_COMPOSITIONFULL -> println("Ime compositionFull w: $w l: $l").let { 0L }
120-
WM_IME_SELECT -> println("Ime select w: $w l: $l").let { 0L }
121-
WM_IME_CHAR -> println("Ime char w: $w l: $l").let { 0L }
122-
WM_IME_REQUEST -> println("Ime request w: $w l: $l").let { 0L }
123-
WM_IME_KEYDOWN -> println("Ime keyDown w: $w l: $l").let { 0L }
124-
WM_IME_KEYUP -> println("Ime keyUp w: $w l: $l").let { 0L }
125-
else -> nCallWindowProc(glfwProc, hwnd, msg, w, l)
126-
}
127-
}
128-
SetWindowLongPtr(hwnd, GWL_WNDPROC, windowProc!!.address())
129-
}
103+
imeListner.install(window.handle)
130104
}
131105
return true
132106
}
133107

134-
var windowProc: Callback? = null
135-
136108
var vtxSize = 1 shl 5 // 32768
137109
var idxSize = 1 shl 6 // 65536
138110
var vtxBuffer = bufferBig(vtxSize)

0 commit comments

Comments
 (0)