Skip to content

Commit b065d00

Browse files
committed
[API] Simplify flags API
1 parent 9e81399 commit b065d00

File tree

7 files changed

+130
-11
lines changed

7 files changed

+130
-11
lines changed

imgui-binding/src/main/java/imgui/ImDrawList.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ public ImDrawList(final long ptr) {
4141
IM_DRAW_LIST->Flags = imDrawListFlags;
4242
*/
4343

44+
/**
45+
* Flags, you may poke into these to adjust anti-aliasing settings per-primitive.
46+
*/
47+
public void addImDrawListFlags(final int flags) {
48+
setImDrawListFlags(getImDrawListFlags() | flags);
49+
}
50+
51+
/**
52+
* Flags, you may poke into these to adjust anti-aliasing settings per-primitive.
53+
*/
54+
public void removeImDrawListFlags(final int flags) {
55+
setImDrawListFlags(getImDrawListFlags() & ~(flags));
56+
}
57+
58+
/**
59+
* Flags, you may poke into these to adjust anti-aliasing settings per-primitive.
60+
*/
61+
public boolean hasImDrawListFlags(final int flags) {
62+
return (getImDrawListFlags() & flags) != 0;
63+
}
64+
4465
/**
4566
* Render-level scissoring.
4667
* This is passed down to your render function but not used for CPU-side coarse clipping.

imgui-binding/src/main/java/imgui/ImFontAtlas.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,40 @@ public int addCustomRectFontGlyph(final ImFont imFont, final short id, final int
506506
*/
507507

508508
/**
509-
* Build flags (see ImFontAtlasFlags_)
509+
* Build flags (see {@link imgui.flag.ImFontAtlasFlags})
510510
*/
511511
public native int getFlags(); /*
512512
return IM_FONT_ATLAS->Flags;
513513
*/
514514

515515
/**
516-
* Build flags (see ImFontAtlasFlags_)
516+
* Build flags (see {@link imgui.flag.ImFontAtlasFlags})
517517
*/
518518
public native void setFlags(int imFontAtlasFlags); /*
519519
IM_FONT_ATLAS->Flags = imFontAtlasFlags;
520520
*/
521521

522+
/**
523+
* Build flags (see {@link imgui.flag.ImFontAtlasFlags})
524+
*/
525+
public void addFlags(final int flags) {
526+
setFlags(getFlags() | flags);
527+
}
528+
529+
/**
530+
* Build flags (see {@link imgui.flag.ImFontAtlasFlags})
531+
*/
532+
public void removeFlags(final int flags) {
533+
setFlags(getFlags() & ~(flags));
534+
}
535+
536+
/**
537+
* Build flags (see {@link imgui.flag.ImFontAtlasFlags})
538+
*/
539+
public boolean hasFlags(final int flags) {
540+
return (getFlags() & flags) != 0;
541+
}
542+
522543
/**
523544
* User data to refer to the texture once it has been uploaded to user's graphic systems.
524545
* It is passed back to you during rendering via the ImDrawCmd structure.

imgui-binding/src/main/java/imgui/ImGuiIO.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public void removeConfigFlags(final int configFlags) {
5252
setConfigFlags(getConfigFlags() & ~(configFlags));
5353
}
5454

55+
/**
56+
* See ImGuiConfigFlags enum. Set by user/application. Gamepad/keyboard navigation options, etc.
57+
*/
58+
public boolean hasConfigFlags(final int flags) {
59+
return (getConfigFlags() & flags) != 0;
60+
}
61+
5562
/**
5663
* See ImGuiBackendFlags enum. Set by back-end to communicate features supported by the back-end.
5764
*/
@@ -80,6 +87,13 @@ public void removeBackendFlags(final int backendFlags) {
8087
setBackendFlags(getBackendFlags() & ~(backendFlags));
8188
}
8289

90+
/**
91+
* See ImGuiBackendFlags enum. Set by back-end to communicate features supported by the back-end.
92+
*/
93+
public boolean hasBackendFlags(final int flags) {
94+
return (getBackendFlags() & flags) != 0;
95+
}
96+
8397
/**
8498
* Minimum time between saving positions/sizes to .ini file, in seconds.
8599
*/

imgui-binding/src/main/java/imgui/ImGuiViewport.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ public ImGuiViewport(final long ptr) {
5151
IMGUI_VIEWPORT->Flags = flags;
5252
*/
5353

54+
/**
55+
* See {@link imgui.flag.ImGuiViewportFlags}.
56+
*/
57+
public void addFlags(final int flags) {
58+
setFlags(getFlags() | flags);
59+
}
60+
61+
/**
62+
* See {@link imgui.flag.ImGuiViewportFlags}.
63+
*/
64+
public void removeFlags(final int flags) {
65+
setFlags(getFlags() & ~(flags));
66+
}
67+
68+
/**
69+
* See {@link imgui.flag.ImGuiViewportFlags}.
70+
*/
71+
public boolean hasFlags(final int flags) {
72+
return (getFlags() & flags) != 0;
73+
}
74+
5475
/**
5576
* Main Area: Position of the viewport (the imgui coordinates are the same as OS desktop/native coordinates).
5677
*/

imgui-binding/src/main/java/imgui/ImGuiWindowClass.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ protected long create() {
112112
IMGUI_WINDOW_CLASS->DockNodeFlagsOverrideSet = dockNodeFlagsOverrideSet;
113113
*/
114114

115+
/**
116+
* [EXPERIMENTAL] Dock node flags to set when a window of this class is hosted by a dock node (it doesn't have to be selected!)
117+
*/
118+
public void addDockNodeFlagsOverrideSet(final int flags) {
119+
setDockNodeFlagsOverrideSet(getDockNodeFlagsOverrideSet() | flags);
120+
}
121+
122+
/**
123+
* [EXPERIMENTAL] Dock node flags to set when a window of this class is hosted by a dock node (it doesn't have to be selected!)
124+
*/
125+
public void removeDockNodeFlagsOverrideSet(final int flags) {
126+
setDockNodeFlagsOverrideSet(getDockNodeFlagsOverrideSet() & ~(flags));
127+
}
128+
129+
/**
130+
* [EXPERIMENTAL] Dock node flags to set when a window of this class is hosted by a dock node (it doesn't have to be selected!)
131+
*/
132+
public boolean hasDockNodeFlagsOverrideSet(final int flags) {
133+
return (getDockNodeFlagsOverrideSet() & flags) != 0;
134+
}
135+
115136
/**
116137
* [EXPERIMENTAL]
117138
*/
@@ -126,6 +147,27 @@ protected long create() {
126147
IMGUI_WINDOW_CLASS->DockNodeFlagsOverrideClear = dockNodeFlagsOverrideClear;
127148
*/
128149

150+
/**
151+
* [EXPERIMENTAL]
152+
*/
153+
public void addDockNodeFlagsOverrideClear(final int flags) {
154+
setDockNodeFlagsOverrideClear(getDockNodeFlagsOverrideClear() | flags);
155+
}
156+
157+
/**
158+
* [EXPERIMENTAL]
159+
*/
160+
public void removeDockNodeFlagsOverrideClear(final int flags) {
161+
setDockNodeFlagsOverrideClear(getDockNodeFlagsOverrideClear() & ~(flags));
162+
}
163+
164+
/**
165+
* [EXPERIMENTAL]
166+
*/
167+
public boolean hasDockNodeFlagsOverrideClear(final int flags) {
168+
return (getDockNodeFlagsOverrideClear() & flags) != 0;
169+
}
170+
129171
/**
130172
* Set to true to enforce single floating windows of this class always having their own docking node
131173
* (equivalent of setting the global io.ConfigDockingAlwaysTabBar)

imgui-lwjgl3/src/main/java/imgui/gl3/ImGuiImplGl3.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void init(final String glslVersion) {
122122

123123
createDeviceObjects();
124124

125-
if ((ImGui.getIO().getConfigFlags() & ImGuiConfigFlags.ViewportsEnable) != 0) {
125+
if (ImGui.getIO().hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) {
126126
initPlatformInterface();
127127
}
128128
}
@@ -422,7 +422,7 @@ private void initPlatformInterface() {
422422
ImGui.getPlatformIO().setRendererRenderWindow(new ImPlatformFuncViewport() {
423423
@Override
424424
public void accept(final ImGuiViewport vp) {
425-
if ((vp.getFlags() & ImGuiViewportFlags.NoRendererClear) == 0) {
425+
if (!vp.hasFlags(ImGuiViewportFlags.NoRendererClear)) {
426426
glClearColor(0, 0, 0, 0);
427427
glClear(GL_COLOR_BUFFER_BIT);
428428
}

imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void accept(final String str) {
246246
mainViewport.setPlatformHandleRaw(GLFWNativeWin32.glfwGetWin32Window(windowId));
247247
}
248248

249-
if ((io.getConfigFlags() & ImGuiConfigFlags.ViewportsEnable) != 0) {
249+
if (io.hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) {
250250
initPlatformInterface();
251251
}
252252

@@ -332,7 +332,7 @@ private void updateMousePosAndButtons() {
332332
} else {
333333
glfwGetCursorPos(windowPtr, mouseX, mouseY);
334334

335-
if ((io.getConfigFlags() & ImGuiConfigFlags.ViewportsEnable) != 0) {
335+
if (io.hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) {
336336
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
337337
glfwGetWindowPos(windowPtr, windowX, windowY);
338338
io.setMousePos((float) mouseX[0] + windowX[0], (float) mouseY[0] + windowY[0]);
@@ -352,7 +352,7 @@ private void updateMousePosAndButtons() {
352352
private void updateMouseCursor() {
353353
final ImGuiIO io = ImGui.getIO();
354354

355-
final boolean noCursorChange = (io.getConfigFlags() & ImGuiConfigFlags.NoMouseCursorChange) == ImGuiConfigFlags.NoMouseCursorChange;
355+
final boolean noCursorChange = io.hasConfigFlags(ImGuiConfigFlags.NoMouseCursorChange);
356356
final boolean cursorDisabled = glfwGetInputMode(windowPtr, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
357357

358358
if (noCursorChange || cursorDisabled) {
@@ -380,7 +380,7 @@ private void updateMouseCursor() {
380380
private void updateGamepads() {
381381
final ImGuiIO io = ImGui.getIO();
382382

383-
if ((io.getConfigFlags() & ImGuiConfigFlags.NavEnableGamepad) == 0) {
383+
if (!io.hasConfigFlags(ImGuiConfigFlags.NavEnableGamepad)) {
384384
return;
385385
}
386386

@@ -527,8 +527,8 @@ public void accept(final ImGuiViewport vp) {
527527
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
528528
glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
529529
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
530-
glfwWindowHint(GLFW_DECORATED, (vp.getFlags() & ImGuiViewportFlags.NoDecoration) != 0 ? GLFW_FALSE : GLFW_TRUE);
531-
glfwWindowHint(GLFW_FLOATING, (vp.getFlags() & ImGuiViewportFlags.TopMost) != 0 ? GLFW_TRUE : GLFW_FALSE);
530+
glfwWindowHint(GLFW_DECORATED, vp.hasFlags(ImGuiViewportFlags.NoDecoration) ? GLFW_FALSE : GLFW_TRUE);
531+
glfwWindowHint(GLFW_FLOATING, vp.hasFlags(ImGuiViewportFlags.TopMost) ? GLFW_TRUE : GLFW_FALSE);
532532

533533
data.window = glfwCreateWindow((int) vp.getSizeX(), (int) vp.getSizeY(), "No Title Yet", NULL, windowPtr);
534534
data.windowOwned = true;
@@ -574,7 +574,7 @@ private static final class ShowWindowFunction extends ImPlatformFuncViewport {
574574
public void accept(final ImGuiViewport vp) {
575575
final ImGuiViewportDataGlfw data = (ImGuiViewportDataGlfw) vp.getPlatformUserData();
576576

577-
if (IS_WINDOWS && (vp.getFlags() & ImGuiViewportFlags.NoTaskBarIcon) != 0) {
577+
if (IS_WINDOWS && vp.hasFlags(ImGuiViewportFlags.NoTaskBarIcon)) {
578578
ImGuiImplGlfwNative.win32hideFromTaskBar(vp.getPlatformHandleRaw());
579579
}
580580

0 commit comments

Comments
 (0)