@@ -17,13 +17,13 @@ public final class ImGui {
17
17
private static final String LIB_TMP_DIR_PREFIX = "imgui-java-bin_" + System .getProperty ("user.name" , "user" );
18
18
19
19
private static final ImGuiIO IMGUI_IO ;
20
+ private static final ImDrawList WINDOW_DRAW_LIST ;
21
+ private static final ImDrawList BACKGROUND_DRAW_LIST ;
22
+ private static final ImDrawList FOREGROUND_DRAW_LIST ;
20
23
21
24
private static ImDrawData drawData ;
22
25
private static ImFont font ;
23
26
private static ImGuiStyle style ;
24
- private static ImDrawList windowDrawList ;
25
- private static ImDrawList backgroundDrawList ;
26
- private static ImDrawList foregroundDrawList ;
27
27
28
28
static {
29
29
final String libPath = System .getProperty (LIB_PATH_PROP );
@@ -41,6 +41,9 @@ public final class ImGui {
41
41
}
42
42
43
43
IMGUI_IO = new ImGuiIO ();
44
+ WINDOW_DRAW_LIST = new ImDrawList (0 );
45
+ BACKGROUND_DRAW_LIST = new ImDrawList (0 );
46
+ FOREGROUND_DRAW_LIST = new ImDrawList (0 );
44
47
45
48
nInitJni ();
46
49
ImDrawList .nInit ();
@@ -467,12 +470,22 @@ public static boolean begin(String title, ImBool pOpen, int imGuiWindowFlags) {
467
470
468
471
/**
469
472
* Get draw list associated to the current window, to append your own drawing primitives
473
+ * <p>
474
+ * BINDING NOTICE: to minimize overhead, method ALWAYS returns the same object, but changes its underlying pointer.
475
+ * If you need to get an object with constant pointer (which will point to the same window all the time) use {@link #getWindowDrawListNew()}.
470
476
*/
471
477
public static ImDrawList getWindowDrawList () {
472
- if (windowDrawList == null ) {
473
- windowDrawList = new ImDrawList (nGetWindowDrawList ());
474
- }
475
- return windowDrawList ;
478
+ WINDOW_DRAW_LIST .ptr = nGetWindowDrawList ();
479
+ return WINDOW_DRAW_LIST ;
480
+ }
481
+
482
+ /**
483
+ * Get draw list associated to the current window, to append your own drawing primitives
484
+ * <p>
485
+ * BINDING NOTICE: returns {@link ImDrawList} for current window with constant pointer to it. Prefer to use {@link #getWindowDrawList()}.
486
+ */
487
+ public static ImDrawList getWindowDrawListNew () {
488
+ return new ImDrawList (nGetWindowDrawList ());
476
489
}
477
490
478
491
private static native long nGetWindowDrawList (); /*
@@ -4514,12 +4527,23 @@ public static byte[] acceptDragDropPayload(String type, int imGuiDragDropFlags)
4514
4527
/**
4515
4528
* Get background draw list for the viewport associated to the current window.
4516
4529
* This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
4530
+ * <p>
4531
+ * BINDING NOTICE: to minimize overhead, method ALWAYS returns the same object, but changes its underlying pointer.
4532
+ * If you need to get an object with constant pointer (which will point to the same background all the time) use {@link #getBackgroundDrawListNew()}.
4517
4533
*/
4518
4534
public static ImDrawList getBackgroundDrawList () {
4519
- if (backgroundDrawList == null ) {
4520
- backgroundDrawList = new ImDrawList (nGetBackgroundDrawList ());
4521
- }
4522
- return backgroundDrawList ;
4535
+ BACKGROUND_DRAW_LIST .ptr = nGetBackgroundDrawList ();
4536
+ return BACKGROUND_DRAW_LIST ;
4537
+ }
4538
+
4539
+ /**
4540
+ * Get background draw list for the viewport associated to the current window.
4541
+ * This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
4542
+ * <p>
4543
+ * BINDING NOTICE: returns {@link ImDrawList} for current background with constant pointer to it. Prefer to use {@link #getBackgroundDrawList()}.
4544
+ */
4545
+ public static ImDrawList getBackgroundDrawListNew () {
4546
+ return new ImDrawList (nGetBackgroundDrawList ());
4523
4547
}
4524
4548
4525
4549
private static native long nGetBackgroundDrawList (); /*
@@ -4529,12 +4553,23 @@ public static ImDrawList getBackgroundDrawList() {
4529
4553
/**
4530
4554
* Get foreground draw list for the viewport associated to the current window.
4531
4555
* This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
4556
+ * <p>
4557
+ * BINDING NOTICE: to minimize overhead, method ALWAYS returns the same object, but changes its underlying pointer.
4558
+ * If you need to get an object with constant pointer (which will point to the same foreground all the time) use {@link #getForegroundDrawListNew()}.
4532
4559
*/
4533
4560
public static ImDrawList getForegroundDrawList () {
4534
- if (foregroundDrawList == null ) {
4535
- foregroundDrawList = new ImDrawList (nGetForegroundDrawList ());
4536
- }
4537
- return foregroundDrawList ;
4561
+ FOREGROUND_DRAW_LIST .ptr = nGetForegroundDrawList ();
4562
+ return FOREGROUND_DRAW_LIST ;
4563
+ }
4564
+
4565
+ /**
4566
+ * Get foreground draw list for the viewport associated to the current window.
4567
+ * This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
4568
+ * <p>
4569
+ * BINDING NOTICE: returns {@link ImDrawList} for current foreground with constant pointer to it. Prefer to use {@link #getForegroundDrawList()}.
4570
+ */
4571
+ public static ImDrawList getForegroundDrawListNew () {
4572
+ return new ImDrawList (nGetForegroundDrawList ());
4538
4573
}
4539
4574
4540
4575
private static native long nGetForegroundDrawList (); /*
0 commit comments