forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIO.go
More file actions
467 lines (417 loc) · 17.7 KB
/
Copy pathIO.go
File metadata and controls
467 lines (417 loc) · 17.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
package imgui
// #include "wrapper/IO.h"
import "C"
// IO is where your app communicate with ImGui. Access via CurrentIO().
// Read 'Programmer guide' section in imgui.cpp file for general usage.
type IO struct {
handle C.IggIO
}
// CurrentIO returns access to the ImGui communication struct for the currently active context.
func CurrentIO() IO {
return IO{handle: C.iggGetCurrentIO()}
}
// WantCaptureMouse returns true if imgui will use the mouse inputs.
// Do not dispatch them to your main game/application in this case.
// In either case, always pass on mouse inputs to imgui.
//
// e.g. unclicked mouse is hovering over an imgui window, widget is active,
// mouse was clicked over an imgui window, etc.
func (io IO) WantCaptureMouse() bool {
return C.iggWantCaptureMouse(io.handle) != 0
}
// WantCaptureMouseUnlessPopupClose returns true if imgui will use the mouse inputs.
// Alternative to WantCaptureMouse: (WantCaptureMouse == true &&
// WantCaptureMouseUnlessPopupClose == false) when a click over void is
// expected to close a popup.
func (io IO) WantCaptureMouseUnlessPopupClose() bool {
return C.iggWantCaptureMouseUnlessPopupClose(io.handle) != 0
}
// WantCaptureKeyboard returns true if imgui will use the keyboard inputs.
// Do not dispatch them to your main game/application (in both cases, always pass keyboard inputs to imgui).
//
// e.g. InputText active, or an imgui window is focused and navigation is enabled, etc.
func (io IO) WantCaptureKeyboard() bool {
return C.iggWantCaptureKeyboard(io.handle) != 0
}
// WantTextInput is true, you may display an on-screen keyboard.
// This is set by ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active).
func (io IO) WantTextInput() bool {
return C.iggWantTextInput(io.handle) != 0
}
// Framerate application estimation, in frame per second. Solely for convenience.
// Rolling average estimation based on IO.DeltaTime over 120 frames.
func (io IO) Framerate() float32 {
return float32(C.iggFramerate(io.handle))
}
// MetricsRenderVertices returns vertices output during last call to Render().
func (io IO) MetricsRenderVertices() int {
return int(C.iggMetricsRenderVertices(io.handle))
}
// MetricsRenderIndices returns indices output during last call to Render() = number of triangles * 3.
func (io IO) MetricsRenderIndices() int {
return int(C.iggMetricsRenderIndices(io.handle))
}
// MetricsRenderWindows returns number of visible windows.
func (io IO) MetricsRenderWindows() int {
return int(C.iggMetricsRenderWindows(io.handle))
}
// MetricsActiveWindows returns number of active windows.
func (io IO) MetricsActiveWindows() int {
return int(C.iggMetricsActiveWindows(io.handle))
}
// MousePosition returns the mouse position.
func (io IO) MousePosition() Vec2 {
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggIoGetMousePosition(io.handle, valueArg)
valueFin()
return value
}
// MouseDelta returns the mouse delta movement. Note that this is zero if either current or previous position
// are invalid (-math.MaxFloat32,-math.MaxFloat32), so a disappearing/reappearing mouse won't have a huge delta.
func (io IO) MouseDelta() Vec2 {
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggMouseDelta(io.handle, valueArg)
valueFin()
return value
}
// MouseWheel returns the mouse wheel movement.
func (io IO) MouseWheel() (float32, float32) {
var mouseWheelH, mouseWheel C.float
C.iggMouseWheel(io.handle, &mouseWheelH, &mouseWheel)
return float32(mouseWheelH), float32(mouseWheel)
}
// DisplayFrameBufferScale returns scale factor for HDPI displays.
// It is for retina display or other situations where window coordinates are different from framebuffer coordinates.
func (io IO) DisplayFrameBufferScale() Vec2 {
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggDisplayFrameBufferScale(io.handle, valueArg)
valueFin()
return value
}
// SetDisplaySize sets the size in pixels.
func (io IO) SetDisplaySize(value Vec2) {
out, _ := value.wrapped()
C.iggIoSetDisplaySize(io.handle, out)
}
// SetDisplayFrameBufferScale sets the frame buffer scale factor.
func (io IO) SetDisplayFrameBufferScale(value Vec2) {
out, _ := value.wrapped()
C.iggIoSetDisplayFrameBufferScale(io.handle, out)
}
// Fonts returns the font atlas to load and assemble one or more fonts into a single tightly packed texture.
func (io IO) Fonts() FontAtlas {
return FontAtlas(C.iggIoGetFonts(io.handle))
}
// SetMousePosition sets the mouse position, in pixels.
// Set to Vec2(-math.MaxFloat32,-mathMaxFloat32) if mouse is unavailable (on another screen, etc.).
func (io IO) SetMousePosition(value Vec2) {
posArg, _ := value.wrapped()
C.iggIoSetMousePosition(io.handle, posArg)
}
// SetMouseButtonDown sets whether a specific mouse button is currently pressed.
// Mouse buttons: left, right, middle + extras.
// ImGui itself mostly only uses left button (BeginPopupContext** are using right button).
// Other buttons allows us to track if the mouse is being used by your application +
// available to user as a convenience via IsMouse** API.
func (io IO) SetMouseButtonDown(index int, down bool) {
var downArg C.IggBool
if down {
downArg = 1
}
C.iggIoSetMouseButtonDown(io.handle, C.int(index), downArg)
}
// AddMouseWheelDelta adds the given offsets to the current mouse wheel values.
// 1 vertical unit scrolls about 5 lines text.
// Most users don't have a mouse with an horizontal wheel, may not be provided by all back-ends.
func (io IO) AddMouseWheelDelta(horizontal, vertical float32) {
C.iggIoAddMouseWheelDelta(io.handle, C.float(horizontal), C.float(vertical))
}
// SetDeltaTime sets the time elapsed since last frame, in seconds.
func (io IO) SetDeltaTime(value float32) {
C.iggIoSetDeltaTime(io.handle, C.float(value))
}
// SetFontGlobalScale sets the global scaling factor for all fonts.
func (io IO) SetFontGlobalScale(value float32) {
C.iggIoSetFontGlobalScale(io.handle, C.float(value))
}
// AddKeyEvents adds the key event (up or down) to the event queue.
func (io IO) AddKeyEvent(key ImguiKey, down bool) {
var downArg C.IggBool
if down {
downArg = 1
}
C.iggIoAddKeyEvent(io.handle, C.int(int(key)), downArg)
}
// KeyCtrlPressed get the keyboard modifier control pressed.
func (io IO) KeyCtrlPressed() bool {
return C.iggIoKeyCtrlPressed(io.handle) != 0
}
// KeyShiftPressed get the keyboard modifier shif pressed.
func (io IO) KeyShiftPressed() bool {
return C.iggIoKeyShiftPressed(io.handle) != 0
}
// KeyAltPressed get the keyboard modifier alt pressed.
func (io IO) KeyAltPressed() bool {
return C.iggIoKeyAltPressed(io.handle) != 0
}
// KeySuperPressed get the keyboard modifier super pressed.
func (io IO) KeySuperPressed() bool {
return C.iggIoKeySuperPressed(io.handle) != 0
}
// AddInputCharacters adds a new character into InputCharacters[].
func (io IO) AddInputCharacters(chars string) {
textArg, textFin := wrapString(chars)
defer textFin()
C.iggIoAddInputCharactersUTF8(io.handle, textArg)
}
// SetIniFilename changes the filename for the settings. Default: "imgui.ini".
// Use an empty string to disable the ini from being used.
func (io IO) SetIniFilename(value string) {
valueArg, valueFin := wrapString(value)
defer valueFin()
C.iggIoSetIniFilename(io.handle, valueArg)
}
// ConfigFlags for IO.SetConfigFlags.
type ConfigFlags int
const (
ConfigFlagsNone ConfigFlags = 0
ConfigFlagsNavEnableKeyboard ConfigFlags = 1 << 0 // Master keyboard navigation enable flag. Enable full Tabbing + directional arrows + space/enter to activate.
ConfigFlagsNavEnableGamepad ConfigFlags = 1 << 1 // Master gamepad navigation enable flag. Backend also needs to set ImGuiBackendFlags_HasGamepad.
ConfigFlagsNoMouse ConfigFlags = 1 << 4 // Instruct dear imgui to disable mouse inputs and interactions.
ConfigFlagsNoMouseCursorChange ConfigFlags = 1 << 5 // Instruct backend to not alter mouse cursor shape and visibility. Use if the backend cursor changes are interfering with yours and you don't want to use SetMouseCursor() to change mouse cursor. You may want to honor requests from imgui by reading GetMouseCursor() yourself instead.
ConfigFlagsNoKeyboard ConfigFlags = 1 << 6 // Instruct dear imgui to disable keyboard inputs and interactions. This is done by ignoring keyboard events and clearing existing states.
// [BETA] Docking
ConfigFlagsDockingEnable ConfigFlags = 1 << 7 // Docking enable flags.
// [BETA] Viewports
// When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable.
ConfigFlagsViewportsEnable ConfigFlags = 1 << 10 // Viewport enable flags (require both ImGuiBackendFlags_PlatformHasViewports + ImGuiBackendFlags_RendererHasViewports set by the respective backends)
ConfigFlagsDpiEnableScaleViewports ConfigFlags = 1 << 14 // [BETA: Don't use] FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application.
ConfigFlagsDpiEnableScaleFonts ConfigFlags = 1 << 15 // [BETA: Don't use] FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress.
// User storage (to allow your backend/engine to communicate to code that may be shared between multiple projects. Those flags are NOT used by core Dear ImGui)
ConfigFlagsIsSRGB ConfigFlags = 1 << 20 // Application is SRGB-aware.
ConfigFlagsIsTouchScreen ConfigFlags = 1 << 21 // Application is using a touch screen instead of a mouse.
)
// SetConfigFlags sets the gamepad/keyboard navigation options, etc.
func (io IO) SetConfigFlags(flags ConfigFlags) {
C.iggIoSetConfigFlags(io.handle, C.int(flags))
}
// BackendFlags for IO.SetBackendFlags.
type BackendFlags int
const (
BackendFlagsNone BackendFlags = 0
BackendFlagsHasGamepad BackendFlags = 1 << 0 // Backend Platform supports gamepad and currently has one connected.
BackendFlagsHasMouseCursors BackendFlags = 1 << 1 // Backend Platform supports honoring GetMouseCursor() value to change the OS cursor shape.
BackendFlagsHasSetMousePos BackendFlags = 1 << 2 // Backend Platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if io.ConfigNavMoveSetMousePos is set).
BackendFlagsRendererHasVtxOffset BackendFlags = 1 << 3 // Backend Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices.
)
// SetBackendFlags sets back-end capabilities.
func (io IO) SetBackendFlags(flags BackendFlags) {
C.iggIoSetBackendFlags(io.handle, C.int(flags))
}
// GetBackendFlags gets the current backend flags.
func (io IO) GetBackendFlags() BackendFlags {
return BackendFlags(C.iggIoGetBackendFlags(io.handle))
}
// SetMouseDrawCursor request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor).
func (io IO) SetMouseDrawCursor(show bool) {
C.iggIoSetMouseDrawCursor(io.handle, castBool(show))
}
// SetHighlightIdConflicts enables on-screen debugging indication when two or more widgets with the same
// ID are being drawn. Enabled by default.
func (io IO) SetHighlightIdConflicts(highlight bool) {
C.iggIoSetHighlightIdConflicts(io.handle, castBool(highlight))
}
// BackendFlags for IO.AddKeyEvent.
type ImguiKey int
// A key identifier (ImguiKey_XXX or ImGuiMod_XXX value): can represent Keyboard, Mouse and Gamepad values.
// All our named keys are >= 512. Keys value 0 to 511 are left unused and were legacy native/opaque key values (< 1.87).
// Support for legacy keys was completely removed in 1.91.5.
// Read details about the 1.87+ transition : https://github.com/ocornut/imgui/issues/4921
// Note that "Keys" related to physical keys and are not the same concept as input "Characters", the later are submitted via io.AddInputCharacter().
// The keyboard key enum values are named after the keys on a standard US keyboard, and on other keyboard types the keys reported may not match the keycaps.
const (
KeyNone ImguiKey = 0
KeyNamedKey_BEGIN ImguiKey = 512 // First valid key value (other than 0)
)
const (
KeyTab ImguiKey = iota + KeyNamedKey_BEGIN // == ImguiKeyNamedKey_BEGIN
KeyLeftArrow
KeyRightArrow
KeyUpArrow
KeyDownArrow
KeyPageUp
KeyPageDown
KeyHome
KeyEnd
KeyInsert
KeyDelete
KeyBackspace
KeySpace
KeyEnter
KeyEscape
KeyLeftCtrl
KeyLeftShift
KeyLeftAlt
KeyLeftSuper
KeyRightCtrl
KeyRightShift
KeyRightAlt
KeyRightSuper
KeyMenu
Key0
Key1
Key2
Key3
Key4
Key5
Key6
Key7
Key8
Key9
KeyA
KeyB
KeyC
KeyD
KeyE
KeyF
KeyG
KeyH
KeyI
KeyJ
KeyK
KeyL
KeyM
KeyN
KeyO
KeyP
KeyQ
KeyR
KeyS
KeyT
KeyU
KeyV
KeyW
KeyX
KeyY
KeyZ
KeyF1
KeyF2
KeyF3
KeyF4
KeyF5
KeyF6
KeyF7
KeyF8
KeyF9
KeyF10
KeyF11
KeyF12
KeyF13
KeyF14
KeyF15
KeyF16
KeyF17
KeyF18
KeyF19
KeyF20
KeyF21
KeyF22
KeyF23
KeyF24
KeyApostrophe // '
KeyComma //
KeyMinus // -
KeyPeriod // .
KeySlash // /
KeySemicolon // ;
KeyEqual // =
KeyLeftBracket // [
KeyBackslash // \ (this text inhibit multiline comment caused by backslash)
KeyRightBracket // ]
KeyGraveAccent // `
KeyCapsLock
KeyScrollLock
KeyNumLock
KeyPrintScreen
KeyPause
KeyKeypad0
KeyKeypad1
KeyKeypad2
KeyKeypad3
KeyKeypad4
KeyKeypad5
KeyKeypad6
KeyKeypad7
KeyKeypad8
KeyKeypad9
KeyKeypadDecimal
KeyKeypadDivide
KeyKeypadMultiply
KeyKeypadSubtract
KeyKeypadAdd
KeyKeypadEnter
KeyKeypadEqual
KeyAppBack // Available on some keyboard/mouses. Often referred as "Browser Back"
KeyAppForward
KeyOem102 // Non-US backslash.
// Gamepad (some of those are analog values, 0.0f to 1.0f) // NAVIGATION ACTION
// (download controller mapping PNG/PSD at http://dearimgui.com/controls_sheets)
KeyGamepadStart // Menu (Xbox) + (Switch) Start/Options (PS)
KeyGamepadBack // View (Xbox) - (Switch) Share (PS)
KeyGamepadFaceLeft // X (Xbox) Y (Switch) Square (PS) // Tap: Toggle Menu. Hold: Windowing mode (Focus/Move/Resize windows)
KeyGamepadFaceRight // B (Xbox) A (Switch) Circle (PS) // Cancel / Close / Exit
KeyGamepadFaceUp // Y (Xbox) X (Switch) Triangle (PS) // Text Input / On-screen Keyboard
KeyGamepadFaceDown // A (Xbox) B (Switch) Cross (PS) // Activate / Open / Toggle / Tweak
KeyGamepadDpadLeft // D-pad Left // Move / Tweak / Resize Window (in Windowing mode)
KeyGamepadDpadRight // D-pad Right // Move / Tweak / Resize Window (in Windowing mode)
KeyGamepadDpadUp // D-pad Up // Move / Tweak / Resize Window (in Windowing mode)
KeyGamepadDpadDown // D-pad Down // Move / Tweak / Resize Window (in Windowing mode)
KeyGamepadL1 // L Bumper (Xbox) L (Switch) L1 (PS) // Tweak Slower / Focus Previous (in Windowing mode)
KeyGamepadR1 // R Bumper (Xbox) R (Switch) R1 (PS) // Tweak Faster / Focus Next (in Windowing mode)
KeyGamepadL2 // L Trig. (Xbox) ZL (Switch) L2 (PS) [Analog]
KeyGamepadR2 // R Trig. (Xbox) ZR (Switch) R2 (PS) [Analog]
KeyGamepadL3 // L Stick (Xbox) L3 (Switch) L3 (PS)
KeyGamepadR3 // R Stick (Xbox) R3 (Switch) R3 (PS)
KeyGamepadLStickLeft // [Analog] // Move Window (in Windowing mode)
KeyGamepadLStickRight // [Analog] // Move Window (in Windowing mode)
KeyGamepadLStickUp // [Analog] // Move Window (in Windowing mode)
KeyGamepadLStickDown // [Analog] // Move Window (in Windowing mode)
KeyGamepadRStickLeft // [Analog]
KeyGamepadRStickRight // [Analog]
KeyGamepadRStickUp // [Analog]
KeyGamepadRStickDown // [Analog]
// Aliases: Mouse Buttons (auto-submitted from AddMouseButtonEvent() calls)
// - This is mirroring the data also written to io.MouseDown[], io.MouseWheel, in a format allowing them to be accessed via standard key API.
KeyMouseLeft
KeyMouseRight
KeyMouseMiddle
KeyMouseX1
KeyMouseX2
KeyMouseWheelX
KeyMouseWheelY
// [Internal] Reserved for mod storage
KeyReservedForModCtrl
KeyReservedForModShift
KeyReservedForModAlt
KeyReservedForModSuper
KeyNamedKey_END
)
const (
// Keyboard Modifiers (explicitly submitted by backend via AddKeyEvent() calls)
// - This is mirroring the data also written to io.KeyCtrl, io.KeyShift, io.KeyAlt, io.KeySuper, in a format allowing
// them to be accessed via standard key API, allowing calls such as IsKeyPressed(), IsKeyReleased(), querying duration etc.
// - Code polling every key (e.g. an interface to detect a key press for input mapping) might want to ignore those
// and prefer using the real keys (e.g. KeyLeftCtrl, ImguiKeyRightCtrl instead of ImGuiMod_Ctrl).
// - In theory the value of keyboard modifiers should be roughly equivalent to a logical or of the equivalent left/right keys.
// In practice: it's complicated; mods are often provided from different sources. Keyboard layout, IME, sticky keys and
// backends tend to interfere and break that equivalence. The safer decision is to relay that ambiguity down to the end-user...
// - On macOS, we swap Cmd(Super) and Ctrl keys at the time of the io.AddKeyEvent() call.
KeyModNone ImguiKey = 0
KeyModCtrl ImguiKey = 1 << 12 // Ctrl (non-macOS), Cmd (macOS)
KeyModShift ImguiKey = 1 << 13 // Shift
KeyModAlt ImguiKey = 1 << 14 // Option/Menu
KeyModSuper ImguiKey = 1 << 15 // Windows/Super (non-macOS), Ctrl (macOS)
)