imgui-bindings 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +298 -268
- data/LICENSE.txt +0 -0
- data/README.md +111 -91
- data/lib/imgui.dll +0 -0
- data/lib/imgui.dylib +0 -0
- data/lib/imgui.rb +5598 -5414
- data/lib/imgui_impl_glfw.rb +511 -240
- data/lib/imgui_impl_opengl2.rb +212 -212
- data/lib/imgui_impl_opengl3.rb +3 -3
- data/lib/imgui_impl_raylib.rb +460 -334
- data/lib/imgui_impl_sdl2.rb +409 -296
- data/lib/imgui_impl_sdlrenderer.rb +200 -201
- data/lib/imgui_internal.rb +49 -0
- data/lib/imnodes.dll +0 -0
- data/lib/imnodes.dylib +0 -0
- data/lib/imnodes.rb +161 -0
- metadata +7 -5
- data/lib/imgui_debug.dll +0 -0
- data/lib/imgui_debug.dylib +0 -0
@@ -1,201 +1,200 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
require 'sdl2'
|
3
|
-
require_relative 'imgui'
|
4
|
-
|
5
|
-
module ImGui
|
6
|
-
|
7
|
-
class ImGui_ImplSDLRenderer_Data < FFI::Struct
|
8
|
-
layout(
|
9
|
-
:SDLRenderer, :pointer,
|
10
|
-
:FontTexture, :pointer
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.ImGui_ImplSDLRenderer_GetBackendData()
|
15
|
-
if ImGui::GetCurrentContext() != nil
|
16
|
-
io = ImGuiIO.new(ImGui::GetIO())
|
17
|
-
instance = ImGui_ImplSDLRenderer_Data.new(io[:BackendRendererUserData])
|
18
|
-
return instance
|
19
|
-
else
|
20
|
-
return nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
@@g_BackendRendererName = FFI::MemoryPointer.from_string("imgui_impl_sdlrenderer")
|
25
|
-
@@g_BackendRendererUserData = nil
|
26
|
-
|
27
|
-
def self.ImplSDLRenderer_Init(renderer)
|
28
|
-
io = ImGuiIO.new(ImGui::GetIO())
|
29
|
-
|
30
|
-
# Setup backend capabilities flags
|
31
|
-
|
32
|
-
io[:BackendRendererName] = @@g_BackendRendererName
|
33
|
-
|
34
|
-
@@g_BackendRendererUserData = ImGui_ImplSDLRenderer_Data.new
|
35
|
-
@@g_BackendRendererUserData[:SDLRenderer] = renderer
|
36
|
-
@@g_BackendRendererUserData[:FontTexture] = nil
|
37
|
-
io[:BackendRendererUserData] = @@g_BackendRendererUserData
|
38
|
-
|
39
|
-
io[:BackendFlags] |= ImGuiBackendFlags_RendererHasVtxOffset # We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
40
|
-
|
41
|
-
return true
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.ImplSDLRenderer_Shutdown()
|
45
|
-
ImplSDLRenderer_DestroyDeviceObjects()
|
46
|
-
io = ImGuiIO.new(ImGui::GetIO())
|
47
|
-
io[:BackendRendererName] = nil
|
48
|
-
io[:BackendRendererUserData] = nil
|
49
|
-
@@g_BackendRendererUserData = nil
|
50
|
-
end
|
51
|
-
|
52
|
-
# [Internal]
|
53
|
-
def self.ImplSDLRenderer_SetupRenderState()
|
54
|
-
bd = ImGui_ImplSDLRenderer_GetBackendData()
|
55
|
-
|
56
|
-
# Clear out any viewports and cliprect set by the user
|
57
|
-
# FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process.
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.ImplSDLRenderer_NewFrame()
|
63
|
-
|
64
|
-
bd
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# If
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
render_scale =
|
79
|
-
render_scale[:
|
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
|
-
pcmd
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
#
|
113
|
-
#
|
114
|
-
|
115
|
-
|
116
|
-
#
|
117
|
-
#
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
clip_min[:
|
124
|
-
|
125
|
-
clip_max[:
|
126
|
-
clip_max[:
|
127
|
-
|
128
|
-
|
129
|
-
r =
|
130
|
-
r[:
|
131
|
-
r[:
|
132
|
-
r[:
|
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
|
-
height
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
bd[:FontTexture]
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
bd
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
end
|
1
|
+
require 'ffi'
|
2
|
+
require 'sdl2'
|
3
|
+
require_relative 'imgui'
|
4
|
+
|
5
|
+
module ImGui
|
6
|
+
|
7
|
+
class ImGui_ImplSDLRenderer_Data < FFI::Struct
|
8
|
+
layout(
|
9
|
+
:SDLRenderer, :pointer,
|
10
|
+
:FontTexture, :pointer
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.ImGui_ImplSDLRenderer_GetBackendData()
|
15
|
+
if ImGui::GetCurrentContext() != nil
|
16
|
+
io = ImGuiIO.new(ImGui::GetIO())
|
17
|
+
instance = ImGui_ImplSDLRenderer_Data.new(io[:BackendRendererUserData])
|
18
|
+
return instance
|
19
|
+
else
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@@g_BackendRendererName = FFI::MemoryPointer.from_string("imgui_impl_sdlrenderer")
|
25
|
+
@@g_BackendRendererUserData = nil
|
26
|
+
|
27
|
+
def self.ImplSDLRenderer_Init(renderer)
|
28
|
+
io = ImGuiIO.new(ImGui::GetIO())
|
29
|
+
|
30
|
+
# Setup backend capabilities flags
|
31
|
+
|
32
|
+
io[:BackendRendererName] = @@g_BackendRendererName
|
33
|
+
|
34
|
+
@@g_BackendRendererUserData = ImGui_ImplSDLRenderer_Data.new
|
35
|
+
@@g_BackendRendererUserData[:SDLRenderer] = renderer
|
36
|
+
@@g_BackendRendererUserData[:FontTexture] = nil
|
37
|
+
io[:BackendRendererUserData] = @@g_BackendRendererUserData
|
38
|
+
|
39
|
+
io[:BackendFlags] |= ImGuiBackendFlags_RendererHasVtxOffset # We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
40
|
+
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.ImplSDLRenderer_Shutdown()
|
45
|
+
ImplSDLRenderer_DestroyDeviceObjects()
|
46
|
+
io = ImGuiIO.new(ImGui::GetIO())
|
47
|
+
io[:BackendRendererName] = nil
|
48
|
+
io[:BackendRendererUserData] = nil
|
49
|
+
@@g_BackendRendererUserData = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
# [Internal]
|
53
|
+
def self.ImplSDLRenderer_SetupRenderState()
|
54
|
+
bd = ImGui_ImplSDLRenderer_GetBackendData()
|
55
|
+
|
56
|
+
# Clear out any viewports and cliprect set by the user
|
57
|
+
# FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process.
|
58
|
+
SDL.RenderSetViewport(bd[:SDLRenderer], nil)
|
59
|
+
SDL.RenderSetClipRect(bd[:SDLRenderer], nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.ImplSDLRenderer_NewFrame()
|
63
|
+
bd = ImGui_ImplSDLRenderer_GetBackendData()
|
64
|
+
ImGui::ImplSDLRenderer_CreateDeviceObjects() if bd[:FontTexture] == nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.ImplSDLRenderer_RenderDrawData(draw_data_raw)
|
68
|
+
draw_data = ImDrawData.new(draw_data_raw)
|
69
|
+
bd = ImGui_ImplSDLRenderer_GetBackendData()
|
70
|
+
|
71
|
+
# If there's a scale factor set by the user, use that instead
|
72
|
+
# If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass
|
73
|
+
# to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here.
|
74
|
+
rsx = FFI::MemoryPointer.new :float
|
75
|
+
rsy = FFI::MemoryPointer.new :float
|
76
|
+
SDL.RenderGetScale(bd[:SDLRenderer], rsx, rsy)
|
77
|
+
render_scale = ImVec2.create(0, 0)
|
78
|
+
render_scale[:x] = (rsx.read_float() == 1.0) ? draw_data[:FramebufferScale][:x] : 1.0
|
79
|
+
render_scale[:y] = (rsy.read_float() == 1.0) ? draw_data[:FramebufferScale][:y] : 1.0
|
80
|
+
|
81
|
+
# Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
82
|
+
fb_width = (draw_data[:DisplaySize][:x] * render_scale[:x]).to_i
|
83
|
+
fb_height = (draw_data[:DisplaySize][:y] * render_scale[:y]).to_i
|
84
|
+
return if fb_width == 0 || fb_height == 0
|
85
|
+
|
86
|
+
# Backup SDL_Renderer state that will be modified to restore it afterwards
|
87
|
+
oldViewport = SDL::Rect.new
|
88
|
+
oldClipEnabled = FFI::MemoryPointer.new :bool
|
89
|
+
oldClipRect = SDL::Rect.new
|
90
|
+
|
91
|
+
oldClipEnabled = (SDL.RenderIsClipEnabled(bd[:SDLRenderer]) == SDL::TRUE)
|
92
|
+
SDL.RenderGetViewport(bd[:SDLRenderer], oldViewport)
|
93
|
+
SDL.RenderGetClipRect(bd[:SDLRenderer], oldClipRect)
|
94
|
+
|
95
|
+
# Will project scissor/clipping rectangles into framebuffer space
|
96
|
+
clip_off = draw_data[:DisplayPos] # (0,0) unless using multi-viewports
|
97
|
+
clip_scale = render_scale
|
98
|
+
|
99
|
+
# Render command lists
|
100
|
+
ImplSDLRenderer_SetupRenderState()
|
101
|
+
draw_data[:CmdListsCount].times do |n|
|
102
|
+
cmd_list = ImDrawList.new((draw_data[:CmdLists].pointer + FFI.type_size(:pointer) * n).read_pointer)
|
103
|
+
vtx_buffer = cmd_list[:VtxBuffer][:Data] # const ImDrawVert*
|
104
|
+
idx_buffer = cmd_list[:IdxBuffer][:Data] # const ImDrawIdx*
|
105
|
+
|
106
|
+
cmd_list[:CmdBuffer][:Size].times do |cmd_i|
|
107
|
+
pcmd = ImDrawCmd.new(cmd_list[:CmdBuffer][:Data] + ImDrawCmd.size * cmd_i) # const ImDrawCmd*
|
108
|
+
if pcmd[:UserCallback] != nil
|
109
|
+
# [TODO] Handle user callback (Ref.: https://github.com/ffi/ffi/wiki/Callbacks )
|
110
|
+
|
111
|
+
# User callback, registered via ImDrawList::AddCallback()
|
112
|
+
# (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
113
|
+
# if pcmd[:UserCallback] == :ImDrawCallback_ResetRenderState
|
114
|
+
ImGui_ImplSDLRenderer_SetupRenderState()
|
115
|
+
# else
|
116
|
+
# pcmd[:UserCallback](cmd_list, pcmd)
|
117
|
+
# end
|
118
|
+
else
|
119
|
+
clip_min = ImVec2.create((pcmd[:ClipRect][:x] - clip_off[:x]) * clip_scale[:x], (pcmd[:ClipRect][:y] - clip_off[:y]) * clip_scale[:y])
|
120
|
+
clip_max = ImVec2.create((pcmd[:ClipRect][:z] - clip_off[:x]) * clip_scale[:x], (pcmd[:ClipRect][:w] - clip_off[:y]) * clip_scale[:y])
|
121
|
+
|
122
|
+
clip_min[:x] = 0.0 if clip_min[:x] < 0.0
|
123
|
+
clip_min[:y] = 0.0 if clip_min[:y] < 0.0
|
124
|
+
clip_max[:x] = fb_width.to_f if clip_max[:x] > fb_width
|
125
|
+
clip_max[:y] = fb_height.to_f if clip_max[:y] > fb_height
|
126
|
+
next if (clip_max[:x] <= clip_min[:x] || clip_max[:y] <= clip_min[:y])
|
127
|
+
|
128
|
+
r = SDL::Rect.new
|
129
|
+
r[:x] = clip_min[:x].to_i
|
130
|
+
r[:y] = clip_min[:y].to_i
|
131
|
+
r[:w] = (clip_max[:x] - clip_min[:x]).to_i
|
132
|
+
r[:h] = (clip_max[:y] - clip_min[:y]).to_i
|
133
|
+
|
134
|
+
SDL.RenderSetClipRect(bd[:SDLRenderer], r.to_ptr)
|
135
|
+
|
136
|
+
xy = vtx_buffer + (pcmd[:VtxOffset] + ImDrawVert.offset_of(:pos))
|
137
|
+
uv = vtx_buffer + (pcmd[:VtxOffset] + ImDrawVert.offset_of(:uv))
|
138
|
+
color = vtx_buffer + (pcmd[:VtxOffset] + ImDrawVert.offset_of(:col))
|
139
|
+
|
140
|
+
SDL.RenderGeometryRaw(bd[:SDLRenderer], pcmd[:TextureId],
|
141
|
+
xy, ImDrawVert.size,
|
142
|
+
color, ImDrawVert.size,
|
143
|
+
uv, ImDrawVert.size,
|
144
|
+
cmd_list[:VtxBuffer][:Size] - pcmd[:VtxOffset],
|
145
|
+
idx_buffer + FFI.type_size(:ImDrawIdx) * pcmd[:IdxOffset], pcmd[:ElemCount], FFI.type_size(:ImDrawIdx)) # FFI.type_size(:ImDrawIdx) == FFI::Type::UINT16.size
|
146
|
+
|
147
|
+
# Restore modified SDL_Renderer state
|
148
|
+
SDL.RenderSetViewport(bd[:SDLRenderer], oldViewport)
|
149
|
+
SDL.RenderSetClipRect(bd[:SDLRenderer], oldClipEnabled ? oldClipRect : nil)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Called by Init/NewFrame/Shutdown
|
156
|
+
def self.ImplSDLRenderer_CreateFontsTexture()
|
157
|
+
io = ImGuiIO.new(ImGui::GetIO())
|
158
|
+
bd = ImGui_ImplSDLRenderer_GetBackendData()
|
159
|
+
|
160
|
+
# Build texture atlas
|
161
|
+
pixels = FFI::MemoryPointer.new :pointer
|
162
|
+
width = FFI::MemoryPointer.new :int
|
163
|
+
height = FFI::MemoryPointer.new :int
|
164
|
+
io[:Fonts].GetTexDataAsRGBA32(pixels, width, height, nil) # Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
165
|
+
|
166
|
+
# Upload texture to graphics system
|
167
|
+
bd[:FontTexture] = SDL.CreateTexture(bd[:SDLRenderer], SDL::PIXELFORMAT_ABGR8888, SDL::TEXTUREACCESS_STATIC, width.read_int, height.read_int)
|
168
|
+
if bd[:FontTexture] == nil
|
169
|
+
SDL.Log("error creating texture")
|
170
|
+
return false
|
171
|
+
end
|
172
|
+
|
173
|
+
SDL.UpdateTexture(bd[:FontTexture], nil, pixels.read_pointer, 4 * width.read_int)
|
174
|
+
SDL.SetTextureBlendMode(bd[:FontTexture], SDL::BLENDMODE_BLEND)
|
175
|
+
|
176
|
+
# Store our identifier
|
177
|
+
io[:Fonts].SetTexID(bd[:FontTexture])
|
178
|
+
|
179
|
+
return true
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.ImplSDLRenderer_DestroyFontsTexture()
|
183
|
+
io = ImGuiIO.new(ImGui::GetIO())
|
184
|
+
bd = ImGui_ImplSDLRenderer_GetBackendData()
|
185
|
+
if bd[:FontTexture] != nil
|
186
|
+
io[:Fonts].SetTexID(nil)
|
187
|
+
SDL.DestroyTexture(bd[:FontTexture])
|
188
|
+
bd[:FontTexture] = nil
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.ImplSDLRenderer_CreateDeviceObjects()
|
193
|
+
return ImGui::ImplSDLRenderer_CreateFontsTexture()
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.ImplSDLRenderer_DestroyDeviceObjects()
|
197
|
+
ImGui::ImplSDLRenderer_DestroyFontsTexture()
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# imgui-bindings : Yet another ImGui wrapper for Ruby
|
2
|
+
#
|
3
|
+
# * https://github.com/vaiorabbit/ruby-imgui
|
4
|
+
|
5
|
+
require 'ffi'
|
6
|
+
|
7
|
+
module ImGui
|
8
|
+
|
9
|
+
extend FFI::Library
|
10
|
+
|
11
|
+
@@imgui_import_internal_done = false
|
12
|
+
|
13
|
+
def self.import_internal_symbols(output_error = false)
|
14
|
+
|
15
|
+
symbols = [
|
16
|
+
:igFocusWindow,
|
17
|
+
:igGetCurrentWindow,
|
18
|
+
]
|
19
|
+
|
20
|
+
args = {
|
21
|
+
:igFocusWindow => [:pointer],
|
22
|
+
:igGetCurrentWindow => [],
|
23
|
+
}
|
24
|
+
|
25
|
+
retvals = {
|
26
|
+
:igFocusWindow => :void,
|
27
|
+
:igGetCurrentWindow => :pointer,
|
28
|
+
}
|
29
|
+
|
30
|
+
symbols.each do |sym|
|
31
|
+
begin
|
32
|
+
attach_function sym, args[sym], retvals[sym]
|
33
|
+
rescue FFI::NotFoundError
|
34
|
+
$stderr.puts("[Warning] Failed to import #{sym}.\n") if output_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@@imgui_import_internal_done = true
|
39
|
+
end # self.import_internal_symbols
|
40
|
+
|
41
|
+
def self.GetCurrentWindow()
|
42
|
+
igGetCurrentWindow()
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.FocusWindow(window)
|
46
|
+
igFocusWindow(window)
|
47
|
+
end
|
48
|
+
|
49
|
+
end # module ImGui
|
data/lib/imnodes.dll
ADDED
Binary file
|
data/lib/imnodes.dylib
ADDED
Binary file
|
data/lib/imnodes.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# imgui-bindings : Yet another ImGui wrapper for Ruby
|
2
|
+
#
|
3
|
+
# * https://github.com/vaiorabbit/ruby-imgui
|
4
|
+
|
5
|
+
require 'ffi'
|
6
|
+
|
7
|
+
# ImNodes::StyleColor
|
8
|
+
ImNodesStyleColor_ColCanvasLines = 0
|
9
|
+
ImNodesStyleColor_ColNodeBg = 1
|
10
|
+
ImNodesStyleColor_ColNodeActiveBg = 2
|
11
|
+
ImNodesStyleColor_ColNodeBorder = 3
|
12
|
+
ImNodesStyleColor_ColConnection = 4
|
13
|
+
ImNodesStyleColor_ColConnectionActive = 5
|
14
|
+
ImNodesStyleColor_ColSelectBg = 6
|
15
|
+
ImNodesStyleColor_ColSelectBorder = 7
|
16
|
+
ImNodesStyleColor_ColMax = 8
|
17
|
+
|
18
|
+
# ImNodesStyleVar
|
19
|
+
ImNodesStyleVar_GridSpacing = 0 # float
|
20
|
+
ImNodesStyleVar_CurveThickness = 1 # float
|
21
|
+
ImNodesStyleVar_CurveStrength = 2 # float
|
22
|
+
ImNodesStyleVar_SlotRadius = 3 # float
|
23
|
+
ImNodesStyleVar_NodeRounding = 4 # float
|
24
|
+
ImNodesStyleVar_NodeSpacing = 5 # ImVec2
|
25
|
+
ImNodesStyleVar_ItemSpacing = 6 # ImVec2
|
26
|
+
ImNodesStyleVar_COUNT = 7
|
27
|
+
|
28
|
+
# ImNodesStyleCol
|
29
|
+
ImNodesStyleCol_GridLines = 0
|
30
|
+
ImNodesStyleCol_NodeBodyBg = 1
|
31
|
+
ImNodesStyleCol_NodeBodyBgHovered = 2
|
32
|
+
ImNodesStyleCol_NodeBodyBgActive = 3
|
33
|
+
ImNodesStyleCol_NodeBorder = 4
|
34
|
+
ImNodesStyleCol_Connection = 5
|
35
|
+
ImNodesStyleCol_ConnectionActive = 6
|
36
|
+
ImNodesStyleCol_SelectBg = 7
|
37
|
+
ImNodesStyleCol_SelectBorder = 8
|
38
|
+
ImNodesStyleCol_NodeTitleBarBg = 9
|
39
|
+
ImNodesStyleCol_NodeTitleBarBgHovered = 10
|
40
|
+
ImNodesStyleCol_NodeTitleBarBgActive = 11
|
41
|
+
ImNodesStyleCol_COUNT = 12
|
42
|
+
|
43
|
+
module ImNodes
|
44
|
+
|
45
|
+
extend FFI::Library
|
46
|
+
|
47
|
+
@@imnodes_import_done = false
|
48
|
+
|
49
|
+
class CanvasStyle < FFI::Struct
|
50
|
+
layout(
|
51
|
+
# Thickness of curves that connect slots together.
|
52
|
+
:CurveThickness, :float,
|
53
|
+
# Indent connection into slot widget a little. Useful when slot content covers connection end with some kind
|
54
|
+
# of icon (like a circle) and then no seam between icon and connection end is visible.
|
55
|
+
:ConnectionIndent, :float,
|
56
|
+
:GridSpacing, :float,
|
57
|
+
:CurveStrength, :float,
|
58
|
+
:NodeRounding, :float,
|
59
|
+
:NodeSpacing, ImVec2.by_value
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
class CanvasState < FFI::Struct
|
64
|
+
layout(
|
65
|
+
# Current zoom of canvas.
|
66
|
+
:Zoom, :float,
|
67
|
+
# Current scroll offset of canvas.
|
68
|
+
:Offset, ImVec2.by_value,
|
69
|
+
# Colors used to style elements of this canvas.
|
70
|
+
:Colors, [ImColor.by_value, ImNodesStyleColor_ColMax],
|
71
|
+
# Style parameters
|
72
|
+
:Style, CanvasStyle.by_value,
|
73
|
+
# Implementation detail.
|
74
|
+
:_Impl, :pointer
|
75
|
+
)
|
76
|
+
|
77
|
+
def self.create()
|
78
|
+
return CanvasState.new(ImNodesCanvasStateCtor())
|
79
|
+
end
|
80
|
+
|
81
|
+
def destroy()
|
82
|
+
ImNodesCanvasStateDtor(self)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class SlotInfo < FFI::Struct
|
87
|
+
layout(
|
88
|
+
:title, :pointer,
|
89
|
+
:kind, :int
|
90
|
+
)
|
91
|
+
|
92
|
+
def self.create(title, kind)
|
93
|
+
instance = SlotInfo.new
|
94
|
+
instance[:title] = FFI::MemoryPointer.from_string(title)
|
95
|
+
instance[:kind] = kind
|
96
|
+
return instance
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.load_lib(libpath = './imnodes.dylib', output_error = false)
|
101
|
+
ffi_lib_flags :now, :global
|
102
|
+
ffi_lib libpath
|
103
|
+
import_symbols(output_error) unless @@imnodes_import_done
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.import_symbols(output_error = false)
|
107
|
+
|
108
|
+
symbols = [
|
109
|
+
# name, func, args, returns
|
110
|
+
[:CanvasStateCtor, :ImNodesCanvasStateCtor, [], :pointer],
|
111
|
+
[:CanvasStateDtor, :ImNodesCanvasStateDtor, [:pointer], :void],
|
112
|
+
[:BeginCanvas, :ImNodesBeginCanvas, [:pointer], :void],
|
113
|
+
[:EndCanvas, :ImNodesEndCanvas, [], :void],
|
114
|
+
[:BeginNode, :ImNodesBeginNode, [:pointer, :pointer, :pointer], :bool],
|
115
|
+
[:EndNode, :ImNodesEndNode, [], :void],
|
116
|
+
[:IsNodeHovered, :ImNodesIsNodeHovered, [], :bool],
|
117
|
+
[:AutoPositionNode, :ImNodesAutoPositionNode, [:pointer], :void],
|
118
|
+
[:GetNewConnection, :ImNodesGetNewConnection, [:pointer, :pointer, :pointer, :pointer], :bool],
|
119
|
+
[:GetPendingConnection, :ImNodesGetPendingConnection, [:pointer, :pointer, :pointer], :bool],
|
120
|
+
[:Connection, :ImNodesConnection, [:pointer, :pointer, :pointer, :pointer], :bool],
|
121
|
+
[:GetCurrentCanvas, :ImNodesGetCurrentCanvas, [], :pointer],
|
122
|
+
[:InputSlotKind, :ImNodesInputSlotKind, [:int], :int],
|
123
|
+
[:OutputSlotKind, :ImNodesOutputSlotKind, [:int], :int],
|
124
|
+
[:IsInputSlotKind, :ImNodesIsInputSlotKind, [:int], :bool],
|
125
|
+
[:IsOutputSlotKind, :ImNodesIsOutputSlotKind, [:int], :bool],
|
126
|
+
[:BeginSlot, :ImNodesBeginSlot, [:pointer, :int], :bool],
|
127
|
+
[:BeginInputSlot, :ImNodesBeginInputSlot, [:pointer, :int], :bool],
|
128
|
+
[:BeginOutputSlot, :ImNodesBeginOutputSlot, [:pointer, :int], :bool],
|
129
|
+
[:EndSlot, :ImNodesEndSlot, [], :void],
|
130
|
+
[:IsSlotCurveHovered, :ImNodesIsSlotCurveHovered, [], :bool],
|
131
|
+
[:IsConnectingCompatibleSlot, :ImNodesIsConnectingCompatibleSlot, [], :bool],
|
132
|
+
[:EzCreateContext, :ImNodesEzCreateContext, [], :pointer],
|
133
|
+
[:EzFreeContext, :ImNodesEzFreeContext, [:pointer], :void],
|
134
|
+
[:EzSetContext, :ImNodesEzSetContext, [:pointer], :void],
|
135
|
+
[:EzGetState, :ImNodesEzGetState, [], :pointer],
|
136
|
+
[:EzBeginCanvas, :ImNodesEzBeginCanvas, [], :void],
|
137
|
+
[:EzEndCanvas, :ImNodesEzEndCanvas, [], :void],
|
138
|
+
[:EzBeginNode, :ImNodesEzBeginNode, [:pointer, :pointer, :pointer, :pointer], :bool],
|
139
|
+
[:EzEndNode, :ImNodesEzEndNode, [], :void],
|
140
|
+
[:EzInputSlots, :ImNodesEzInputSlots, [:pointer, :int], :void],
|
141
|
+
[:EzOutputSlots, :ImNodesEzOutputSlots, [:pointer, :int], :void],
|
142
|
+
[:EzConnection, :ImNodesEzConnection, [:pointer, :pointer, :pointer, :pointer], :bool],
|
143
|
+
[:EzPushStyleVarFloat, :ImNodesEzPushStyleVarFloat, [:int, :float], :void],
|
144
|
+
[:EzPushStyleVarVec2, :ImNodesEzPushStyleVarVec2, [:int, :pointer], :void],
|
145
|
+
[:EzPopStyleVar, :ImNodesEzPopStyleVar, [:int], :void],
|
146
|
+
[:EzPushStyleColorU32, :ImNodesEzPushStyleColorU32, [:int, :uint], :void],
|
147
|
+
[:EzPushStyleColorVec4, :ImNodesEzPushStyleColorVec4, [:int, :pointer], :void],
|
148
|
+
[:EzPopStyleColor, :ImNodesEzPopStyleColor, [:int], :void],
|
149
|
+
]
|
150
|
+
|
151
|
+
symbols.each do |sym|
|
152
|
+
begin
|
153
|
+
attach_function *sym
|
154
|
+
rescue FFI::NotFoundError
|
155
|
+
$stderr.puts("[Warning] Failed to import #{sym}.\n") if output_error
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end # self.import_symbols
|
160
|
+
|
161
|
+
end # module ImNodes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgui-bindings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaiorabbit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -53,14 +53,16 @@ files:
|
|
53
53
|
- lib/imgui.dll
|
54
54
|
- lib/imgui.dylib
|
55
55
|
- lib/imgui.rb
|
56
|
-
- lib/imgui_debug.dll
|
57
|
-
- lib/imgui_debug.dylib
|
58
56
|
- lib/imgui_impl_glfw.rb
|
59
57
|
- lib/imgui_impl_opengl2.rb
|
60
58
|
- lib/imgui_impl_opengl3.rb
|
61
59
|
- lib/imgui_impl_raylib.rb
|
62
60
|
- lib/imgui_impl_sdl2.rb
|
63
61
|
- lib/imgui_impl_sdlrenderer.rb
|
62
|
+
- lib/imgui_internal.rb
|
63
|
+
- lib/imnodes.dll
|
64
|
+
- lib/imnodes.dylib
|
65
|
+
- lib/imnodes.rb
|
64
66
|
homepage: https://github.com/vaiorabbit/ruby-imgui
|
65
67
|
licenses:
|
66
68
|
- Zlib
|
@@ -73,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
75
|
requirements:
|
74
76
|
- - ">="
|
75
77
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
78
|
+
version: 3.0.0
|
77
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
80
|
requirements:
|
79
81
|
- - ">="
|