Skip to content

Commit 1209caa

Browse files
committed
Initial Multi-Viewport implementation
1 parent a392a42 commit 1209caa

File tree

5 files changed

+396
-12
lines changed

5 files changed

+396
-12
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* BINDING NOTICE: Since it's impossible to do a 1:1 mapping with JNI, current class provides "getCmdList*()" methods.
1212
* Those are used to get the data needed to do a rendering.
1313
*/
14-
public final class ImDrawData implements ImGuiDestroyableStruct {
14+
public final class ImDrawData {
1515
public static final int SIZEOF_IM_DRAW_IDX = 2;
1616
public static final int SIZEOF_IM_DRAW_VERT = (4 + 1) * 4;
1717

@@ -26,11 +26,6 @@ public final class ImDrawData implements ImGuiDestroyableStruct {
2626
this.ptr = ptr;
2727
}
2828

29-
@Override
30-
public void destroy() {
31-
nDestroy(ptr);
32-
}
33-
3429
/*JNI
3530
#include <stdint.h>
3631
#include <imgui.h>
@@ -46,10 +41,6 @@ public void destroy() {
4641
imDrawDataPtrID = env->GetFieldID(jImDrawDataClass, "ptr", "J");
4742
*/
4843

49-
private native void nDestroy(long ptr); /*
50-
delete (ImDrawData*)ptr;
51-
*/
52-
5344
///////// Start of Render Methods | Binding
5445

5546
/**

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public final class ImGui {
6565
ImGuiStyle.nInit();
6666
ImGuiWindowClass.nInit();
6767
ImGuiStorage.nInit();
68+
ImGuiViewport.nInit();
6869
nInitInputTextData();
6970
}
7071

@@ -4373,7 +4374,25 @@ public static void dockSpace(int imGuiID, float sizeX, float sizeY, int imGuiDoc
43734374
ImGui::DockSpace(imGuiID, ImVec2(sizeX, sizeY), imGuiDockNodeFlags, windowClassPtr != 0 ? (ImGuiWindowClass*)windowClassPtr : NULL);
43744375
*/
43754376

4376-
// TODO: DockSpaceOverViewport
4377+
public static int dockSpaceOverViewport() {
4378+
return nDockSpaceOverViewport(0, 0, 0);
4379+
}
4380+
4381+
public static int dockSpaceOverViewport(ImGuiViewport viewport) {
4382+
return nDockSpaceOverViewport(viewport.ptr, 0, 0);
4383+
}
4384+
4385+
public static int dockSpaceOverViewport(ImGuiViewport viewport, int imGuiDockNodeFlags) {
4386+
return nDockSpaceOverViewport(viewport.ptr, imGuiDockNodeFlags, 0);
4387+
}
4388+
4389+
public static int dockSpaceOverViewport(ImGuiViewport viewport, int imGuiDockNodeFlags, ImGuiWindowClass windowClass) {
4390+
return nDockSpaceOverViewport(viewport.ptr, imGuiDockNodeFlags, windowClass.ptr);
4391+
}
4392+
4393+
private static native int nDockSpaceOverViewport(long viewportPtr, int imGuiDockNodeFlags, long windowClassPtr); /*
4394+
return ImGui::DockSpaceOverViewport(viewportPtr != 0 ? (ImGuiViewport*)viewportPtr : NULL, imGuiDockNodeFlags, windowClassPtr != 0 ? (ImGuiWindowClass*)windowClassPtr : NULL);
4395+
*/
43774396

43784397
/**
43794398
* Set next window dock id
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
package imgui;
2+
3+
/**
4+
* The viewports created and managed by Dear ImGui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport.
5+
* - Main Area = entire viewport.
6+
* - Work Area = entire viewport minus sections optionally used by menu bars, status bars. Some positioning code will prefer to use this. Window are also trying to stay within this area.
7+
*/
8+
public final class ImGuiViewport {
9+
final long ptr;
10+
11+
ImGuiViewport(final long ptr) {
12+
this.ptr = ptr;
13+
}
14+
15+
/*JNI
16+
#include <stdint.h>
17+
#include <imgui.h>
18+
#include "jni_common.h"
19+
20+
jfieldID imGuiViewportPtrID;
21+
22+
#define IMGUI_VIEWPORT ((ImGuiViewport*)env->GetLongField(object, imGuiViewportPtrID))
23+
*/
24+
25+
static native void nInit(); /*
26+
jclass jImGuiViewportClass = env->FindClass("imgui/ImGuiViewport");
27+
imGuiViewportPtrID = env->GetFieldID(jImGuiViewportClass, "ptr", "J");
28+
*/
29+
30+
/**
31+
* Unique identifier for the viewport.
32+
*/
33+
public native int getImGuiId(); /*
34+
return IMGUI_VIEWPORT->ID;
35+
*/
36+
37+
/**
38+
* Unique identifier for the viewport.
39+
*/
40+
public native void setImGuiId(int imGuiID); /*
41+
IMGUI_VIEWPORT->ID = imGuiID;
42+
*/
43+
44+
/**
45+
* See ImGuiViewportFlags_.
46+
*/
47+
public native int getFlags(); /*
48+
return IMGUI_VIEWPORT->Flags;
49+
*/
50+
51+
/**
52+
* See ImGuiViewportFlags_.
53+
*/
54+
public native void setFlags(int flags); /*
55+
IMGUI_VIEWPORT->Flags = flags;
56+
*/
57+
58+
/**
59+
* Main Area: Position of the viewport (the imgui coordinates are the same as OS desktop/native coordinates).
60+
*/
61+
public native void getPos(ImVec2 dstImVec2); /*
62+
Jni::ImVec2Cpy(env, &IMGUI_VIEWPORT->Pos, dstImVec2);
63+
*/
64+
65+
/**
66+
* Main Area: Position of the viewport (the imgui coordinates are the same as OS desktop/native coordinates).
67+
*/
68+
public native float getPosX(); /*
69+
return IMGUI_VIEWPORT->Pos.x;
70+
*/
71+
72+
/**
73+
* Main Area: Position of the viewport (the imgui coordinates are the same as OS desktop/native coordinates).
74+
*/
75+
public native float getPosY(); /*
76+
return IMGUI_VIEWPORT->Pos.y;
77+
*/
78+
79+
/**
80+
* Main Area: Position of the viewport (the imgui coordinates are the same as OS desktop/native coordinates).
81+
*/
82+
public native void setPos(float x, float y); /*
83+
IMGUI_VIEWPORT->Pos = ImVec2(x, y);
84+
*/
85+
86+
/**
87+
* Main Area: Size of the viewport.
88+
*/
89+
public native void getSize(ImVec2 dstImVec2); /*
90+
Jni::ImVec2Cpy(env, &IMGUI_VIEWPORT->Size, dstImVec2);
91+
*/
92+
93+
/**
94+
* Main Area: Size of the viewport.
95+
*/
96+
public native float getSizeX(); /*
97+
return IMGUI_VIEWPORT->Size.x;
98+
*/
99+
100+
/**
101+
* Main Area: Size of the viewport.
102+
*/
103+
public native float getSizeY(); /*
104+
return IMGUI_VIEWPORT->Size.y;
105+
*/
106+
107+
/**
108+
* Main Area: Size of the viewport.
109+
*/
110+
public native void seSize(float x, float y); /*
111+
IMGUI_VIEWPORT->Size = ImVec2(x, y);
112+
*/
113+
114+
/**
115+
* Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height).
116+
* Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!)
117+
*/
118+
public native void getWorkOffsetMin(ImVec2 dstImVec2); /*
119+
Jni::ImVec2Cpy(env, &IMGUI_VIEWPORT->WorkOffsetMin, dstImVec2);
120+
*/
121+
122+
/**
123+
* Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height).
124+
* Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!)
125+
*/
126+
public native float getWorkOffsetMinX(); /*
127+
return IMGUI_VIEWPORT->WorkOffsetMin.x;
128+
*/
129+
130+
/**
131+
* Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height).
132+
* Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!)
133+
*/
134+
public native float getWorkOffsetMinY(); /*
135+
return IMGUI_VIEWPORT->WorkOffsetMin.y;
136+
*/
137+
138+
/**
139+
* Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height).
140+
* Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!)
141+
*/
142+
public native void seWorkOffsetMin(float x, float y); /*
143+
IMGUI_VIEWPORT->WorkOffsetMin = ImVec2(x, y);
144+
*/
145+
146+
/**
147+
* Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height).
148+
*/
149+
public native void getWorkOffsetMax(ImVec2 dstImVec2); /*
150+
Jni::ImVec2Cpy(env, &IMGUI_VIEWPORT->WorkOffsetMax, dstImVec2);
151+
*/
152+
153+
/**
154+
* Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height).
155+
*/
156+
public native float getWorkOffsetMaxX(); /*
157+
return IMGUI_VIEWPORT->WorkOffsetMax.x;
158+
*/
159+
160+
/**
161+
* Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height).
162+
*/
163+
public native float getWorkOffsetMaxY(); /*
164+
return IMGUI_VIEWPORT->WorkOffsetMax.y;
165+
*/
166+
167+
/**
168+
* Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height).
169+
*/
170+
public native void seWorkOffsetMax(float x, float y); /*
171+
IMGUI_VIEWPORT->WorkOffsetMax = ImVec2(x, y);
172+
*/
173+
174+
/**
175+
* 1.0f = 96 DPI = No extra scale.
176+
*/
177+
public native float getDpiScale(); /*
178+
return IMGUI_VIEWPORT->DpiScale;
179+
*/
180+
181+
/**
182+
* 1.0f = 96 DPI = No extra scale.
183+
*/
184+
public native void setDpiScale(float dpiScale); /*
185+
IMGUI_VIEWPORT->DpiScale = dpiScale;
186+
*/
187+
188+
// TODO: DrawData
189+
190+
/**
191+
* (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows.
192+
*/
193+
public native int getParentViewportId(); /*
194+
return IMGUI_VIEWPORT->ParentViewportId;
195+
*/
196+
197+
/**
198+
* (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows.
199+
*/
200+
public native void setParentViewportId(int parentViewportId); /*
201+
IMGUI_VIEWPORT->ParentViewportId = parentViewportId;
202+
*/
203+
204+
// Our design separate the Renderer and Platform back-ends to facilitate combining default back-ends with each others.
205+
// When our create your own back-end for a custom engine, it is possible that both Renderer and Platform will be handled
206+
// by the same system and you may not need to use all the UserData/Handle fields.
207+
// The library never uses those fields, they are merely storage to facilitate back-end implementation.
208+
209+
// TODO: PlatformUserData, PlatformHandle, PlatformHandleRaw
210+
211+
/**
212+
* Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position).
213+
*/
214+
public native boolean getPlatformRequestMove(); /*
215+
return IMGUI_VIEWPORT->PlatformRequestMove;
216+
*/
217+
218+
/**
219+
* Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position).
220+
*/
221+
public native void setPlatformRequestMove(boolean platformRequestMove); /*
222+
IMGUI_VIEWPORT->PlatformRequestMove = platformRequestMove;
223+
*/
224+
225+
/**
226+
* Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size).
227+
*/
228+
public native boolean getPlatformRequestResize(); /*
229+
return IMGUI_VIEWPORT->PlatformRequestResize;
230+
*/
231+
232+
/**
233+
* Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size).
234+
*/
235+
public native void setPlatformRequestResize(boolean platformRequestResize); /*
236+
IMGUI_VIEWPORT->PlatformRequestResize = platformRequestResize;
237+
*/
238+
239+
/**
240+
* Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4).
241+
*/
242+
public native boolean getPlatformRequestClose(); /*
243+
return IMGUI_VIEWPORT->PlatformRequestClose;
244+
*/
245+
246+
/**
247+
* Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4).
248+
*/
249+
public native void setPlatformRequestClose(boolean platformRequestClose); /*
250+
IMGUI_VIEWPORT->PlatformRequestClose = platformRequestClose;
251+
*/
252+
253+
// Access work-area rectangle with GetWorkXXX functions (see comments above)
254+
255+
public native void getCenter(ImVec2 dstImVec2); /*
256+
Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->GetCenter(), dstImVec2);
257+
*/
258+
259+
public native float getCenterX(); /*
260+
return IMGUI_VIEWPORT->GetCenter().x;
261+
*/
262+
263+
public native float getCenterY(); /*
264+
return IMGUI_VIEWPORT->GetCenter().y;
265+
*/
266+
267+
public native void getWorkPos(ImVec2 dstImVec2); /*
268+
Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->GetWorkPos(), dstImVec2);
269+
*/
270+
271+
public native float getWorkPosX(); /*
272+
return IMGUI_VIEWPORT->GetWorkPos().x;
273+
*/
274+
275+
public native float getWorkPosY(); /*
276+
return IMGUI_VIEWPORT->GetWorkPos().y;
277+
*/
278+
279+
public native void getWorkSize(ImVec2 dstImVec2); /*
280+
Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->GetWorkSize(), dstImVec2);
281+
*/
282+
283+
public native float getWorkSizeX(); /*
284+
return IMGUI_VIEWPORT->GetWorkSize().x;
285+
*/
286+
287+
public native float getWorkSizeY(); /*
288+
return IMGUI_VIEWPORT->GetWorkSize().y;
289+
*/
290+
}

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,37 @@ public void destroy() {
8383
IMGUI_WINDOW_CLASS->ParentViewportId = parentViewportId;
8484
*/
8585

86-
// TODO: ViewportFlagsOverrideSet, ViewportFlagsOverrideClear
86+
/**
87+
* Viewport flags to set when a window of this class owns a viewport.
88+
* This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis.
89+
*/
90+
public native int getViewportFlagsOverrideSet(); /*
91+
return IMGUI_WINDOW_CLASS->ViewportFlagsOverrideSet;
92+
*/
93+
94+
/**
95+
* Viewport flags to set when a window of this class owns a viewport.
96+
* This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis.
97+
*/
98+
public native void setViewportFlagsOverrideSet(int viewportFlagsOverrideSet); /*
99+
IMGUI_WINDOW_CLASS->ViewportFlagsOverrideSet = viewportFlagsOverrideSet;
100+
*/
101+
102+
/**
103+
* Viewport flags to clear when a window of this class owns a viewport.
104+
* This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis.
105+
*/
106+
public native int getViewportFlagsOverrideClear(); /*
107+
return IMGUI_WINDOW_CLASS->ViewportFlagsOverrideClear;
108+
*/
109+
110+
/**
111+
* Viewport flags to clear when a window of this class owns a viewport.
112+
* This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis.
113+
*/
114+
public native void setViewportFlagsOverrideClear(int viewportFlagsOverrideClear); /*
115+
IMGUI_WINDOW_CLASS->ViewportFlagsOverrideClear = viewportFlagsOverrideClear;
116+
*/
87117

88118
/**
89119
* [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!)

0 commit comments

Comments
 (0)