@@ -12,42 +12,35 @@ import org.lwjgl.glfw.*
12
12
import org.lwjgl.glfw.GLFW.*
13
13
import org.lwjgl.system.MemoryStack
14
14
import org.lwjgl.system.MemoryUtil
15
- import org.lwjgl.system.MemoryUtil.*
15
+ import org.lwjgl.system.MemoryUtil.memGetAddress
16
+ import org.lwjgl.system.MemoryUtil.memUTF8
16
17
import org.lwjgl.system.Pointer
17
18
import uno.kotlin.*
18
19
import java.util.*
19
20
import java.util.function.BooleanSupplier
20
21
import java.util.function.Consumer
21
-
22
- class Wut (dummy : Int ) {
23
-
24
- constructor () : this (0 )
25
- init {
26
- println (" init" )
27
- }
28
- }
29
22
open class GlfwWindow (var handle : Long ) {
30
23
31
24
@Throws(RuntimeException ::class )
32
25
constructor (windowSize: Vec2i ,
33
26
title: String = " Glfw Window" ,
34
27
monitor: GlfwMonitor = GlfwMonitor .NULL ,
35
- share: GlfwWindow = NULL ,
28
+ share: GlfwWindow ? = null ,
36
29
position: Vec2i ? = null ) : this (windowSize.x, windowSize.y, title, monitor, share, position)
37
30
38
31
@Throws(RuntimeException ::class )
39
32
constructor (x: Int ,
40
33
title: String = " Glfw Window" ,
41
34
monitor: GlfwMonitor = GlfwMonitor .NULL ,
42
- share: GlfwWindow = NULL ,
35
+ share: GlfwWindow ? = null ,
43
36
position: Vec2i ? = null ) : this (x, x, title, monitor, share, position)
44
37
45
38
@Throws(RuntimeException ::class )
46
39
constructor (width: Int , height: Int ,
47
40
title: String = " Glfw Window" ,
48
41
monitor: GlfwMonitor = GlfwMonitor .NULL ,
49
- share: GlfwWindow = NULL ,
50
- position: Vec2i ? = null ) : this (glfwCreateWindow(width, height, title, monitor.handle, share.handle)) {
42
+ share: GlfwWindow ? = null ,
43
+ position: Vec2i ? = null ) : this (glfwCreateWindow(width, height, title, monitor.handle, share? .handle ? : MemoryUtil . NULL )) {
51
44
52
45
this .title = title
53
46
@@ -57,11 +50,10 @@ open class GlfwWindow(var handle: Long) {
57
50
// --- [ glfwCreateWindow ] ---
58
51
59
52
init {
60
- println (" init" )
61
- // if (handle == MemoryUtil.NULL) {
62
- // glfw.terminate()
63
- // throw RuntimeException("Failed to create the GLFW window")
64
- // }
53
+ if (handle == MemoryUtil .NULL ) {
54
+ glfw.terminate()
55
+ throw RuntimeException (" Failed to create the GLFW window" )
56
+ }
65
57
}
66
58
67
59
// --- [ glfwDestroyWindow ] ---
@@ -361,7 +353,8 @@ open class GlfwWindow(var handle: Long) {
361
353
enum class CursorMode (val i : Int ) {
362
354
Normal (GLFW_CURSOR_NORMAL ),
363
355
Hidden (GLFW_CURSOR_HIDDEN ),
364
- Disabled (GLFW_CURSOR_DISABLED ), ;
356
+ Disabled (GLFW_CURSOR_DISABLED ),
357
+ Captured (GLFW_CURSOR_CAPTURED );
365
358
366
359
companion object {
367
360
infix fun of (i : Int ) = values().first { it.i == i }
@@ -420,7 +413,7 @@ open class GlfwWindow(var handle: Long) {
420
413
var keyCB: KeyCB ?
421
414
@Deprecated(message = " Write only property" , level = DeprecationLevel .HIDDEN ) get() = error(" " )
422
415
set(value) {
423
- val cb = value?.let { GLFWKeyCallbackI { wnd, key, scanCode, action, mods -> it(GlfwWindow (wnd), key, scanCode, action, mods) } }
416
+ val cb = value?.let { GLFWKeyCallbackI { wnd, key, scanCode, action, mods -> it(GlfwWindow (wnd), Key of key, scanCode, InputAction of action, mods) } }
424
417
glfwSetKeyCallback(handle, cb)?.free()
425
418
}
426
419
@@ -453,7 +446,7 @@ open class GlfwWindow(var handle: Long) {
453
446
var cursorPosCB: CursorPosCB ?
454
447
@Deprecated(message = " Write only property" , level = DeprecationLevel .HIDDEN ) get() = error(" " )
455
448
set(value) {
456
- val cb = value?.let { GLFWCursorPosCallbackI { wnd, xPos, yPos -> it(GlfwWindow (wnd), Vec2 (xPos, yPos)) } }
449
+ val cb = value?.let { GLFWCursorPosCallbackI { wnd, xPos, yPos -> it(GlfwWindow (wnd), Vec2d (xPos, yPos)) } }
457
450
glfwSetCursorPosCallback(handle, cb)?.free()
458
451
}
459
452
@@ -487,17 +480,19 @@ open class GlfwWindow(var handle: Long) {
487
480
glfwSetDropCallback(handle, cb)?.free()
488
481
}
489
482
490
-
491
483
// --- [ glfwGetClipboardString ] ---
492
484
// --- [ glfwSetClipboardString ] ---
485
+ // Parameters
486
+ // [in] window Deprecated. Any valid window or NULL.
487
+ // -> glfw object
493
488
var clipboardString: String?
494
489
get() = glfwGetClipboardString(handle)
495
490
set(value) {
496
491
value?.let { glfwSetClipboardString(handle, it) }
497
492
}
498
493
499
494
// --- [ glfwMakeContextCurrent ] ---
500
- fun makeContextCurrent (current : Boolean = true) = glfwMakeContextCurrent(if (current) handle else MemoryUtil .NULL )
495
+ fun makeCurrent (current : Boolean = true) = glfwMakeContextCurrent(if (current) handle else MemoryUtil .NULL )
501
496
502
497
// --- [ glfwSwapBuffers ] ---
503
498
@@ -507,16 +502,16 @@ open class GlfwWindow(var handle: Long) {
507
502
fun present () = swapBuffers()
508
503
509
504
inline fun inContext (block : () -> Unit ) {
510
- makeContextCurrent ()
505
+ makeCurrent ()
511
506
block()
512
- makeContextCurrent (false )
507
+ makeCurrent (false )
513
508
}
514
509
515
510
/* * for Java */
516
511
open fun inContext (runnable : Runnable ) {
517
- makeContextCurrent ()
512
+ makeCurrent ()
518
513
runnable.run ()
519
- makeContextCurrent (false )
514
+ makeCurrent (false )
520
515
}
521
516
522
517
var autoSwap = true
@@ -573,7 +568,5 @@ open class GlfwWindow(var handle: Long) {
573
568
574
569
@JvmStatic
575
570
infix fun from (handle : Long ): GlfwWindow = GlfwWindow (handle)
576
-
577
- val NULL = GlfwWindow (MemoryUtil .NULL )
578
571
}
579
572
}
0 commit comments