imgui-bindings 0.1.15-x86_64-linux → 0.1.17-x86_64-linux
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 +389 -381
- data/LICENSE.txt +1 -1
- data/README.md +121 -121
- data/lib/imgui.rb +6476 -6188
- data/lib/imgui.x86_64.so +0 -0
- data/lib/imgui_impl_glfw.rb +511 -511
- data/lib/imgui_impl_opengl2.rb +212 -212
- data/lib/imgui_impl_opengl3.rb +1 -1
- data/lib/imgui_impl_raylib.rb +2 -1
- data/lib/imgui_impl_sdl2.rb +409 -409
- data/lib/imgui_impl_sdlrenderer.rb +200 -200
- data/lib/imgui_internal.rb +49 -49
- data/lib/imnodes.rb +161 -161
- data/lib/imnodes.x86_64.so +0 -0
- metadata +3 -6
@@ -1,200 +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
|
-
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][:Data] + 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
|
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][:Data] + 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
|
data/lib/imgui_internal.rb
CHANGED
@@ -1,49 +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
|
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
|