imgui-bindings 0.1.10-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,454 @@
1
+ require 'ffi'
2
+ require 'raylib'
3
+
4
+ require_relative 'imgui'
5
+
6
+ module ImGui
7
+
8
+ @@g_BackendPlatformName = FFI::MemoryPointer.from_string("imgui_impl_raylib")
9
+
10
+ # ImGui::GetCurrentContext().address => ImGui_ImplRaylib_Data
11
+ @@g_BackendData = Hash.new
12
+
13
+ # [INTERNAL]
14
+ class ImGui_ImplRaylib_Data
15
+ attr_accessor :time
16
+
17
+ def initialize
18
+ @time = 0.0
19
+ end
20
+ end
21
+
22
+ # [INTERNAL]
23
+ def self.ImGui_ImplRaylib_GetBackendData()
24
+ if ImGui::GetCurrentContext() != nil
25
+ @@g_BackendData[ImGui::GetCurrentContext().address]
26
+ else
27
+ nil
28
+ end
29
+ end
30
+
31
+ # [TODO] Support ClipboardText
32
+ # g_ClipboardTextData
33
+ # ImplRaylib_GetClipboardText
34
+ # ImplRaylib_SetClipboardText
35
+
36
+ KEY_IDS = [
37
+ # Alphanumeric keys
38
+ Raylib::KEY_APOSTROPHE, # Key: '
39
+ Raylib::KEY_COMMA, # Key: ,
40
+ Raylib::KEY_MINUS, # Key: -
41
+ Raylib::KEY_PERIOD, # Key: .
42
+ Raylib::KEY_SLASH, # Key: /
43
+ Raylib::KEY_ZERO, # Key: 0
44
+ Raylib::KEY_ONE, # Key: 1
45
+ Raylib::KEY_TWO, # Key: 2
46
+ Raylib::KEY_THREE, # Key: 3
47
+ Raylib::KEY_FOUR, # Key: 4
48
+ Raylib::KEY_FIVE, # Key: 5
49
+ Raylib::KEY_SIX, # Key: 6
50
+ Raylib::KEY_SEVEN, # Key: 7
51
+ Raylib::KEY_EIGHT, # Key: 8
52
+ Raylib::KEY_NINE, # Key: 9
53
+ Raylib::KEY_SEMICOLON, # Key: ;
54
+ Raylib::KEY_EQUAL, # Key: =
55
+ Raylib::KEY_A, # Key: A | a
56
+ Raylib::KEY_B, # Key: B | b
57
+ Raylib::KEY_C, # Key: C | c
58
+ Raylib::KEY_D, # Key: D | d
59
+ Raylib::KEY_E, # Key: E | e
60
+ Raylib::KEY_F, # Key: F | f
61
+ Raylib::KEY_G, # Key: G | g
62
+ Raylib::KEY_H, # Key: H | h
63
+ Raylib::KEY_I, # Key: I | i
64
+ Raylib::KEY_J, # Key: J | j
65
+ Raylib::KEY_K, # Key: K | k
66
+ Raylib::KEY_L, # Key: L | l
67
+ Raylib::KEY_M, # Key: M | m
68
+ Raylib::KEY_N, # Key: N | n
69
+ Raylib::KEY_O, # Key: O | o
70
+ Raylib::KEY_P, # Key: P | p
71
+ Raylib::KEY_Q, # Key: Q | q
72
+ Raylib::KEY_R, # Key: R | r
73
+ Raylib::KEY_S, # Key: S | s
74
+ Raylib::KEY_T, # Key: T | t
75
+ Raylib::KEY_U, # Key: U | u
76
+ Raylib::KEY_V, # Key: V | v
77
+ Raylib::KEY_W, # Key: W | w
78
+ Raylib::KEY_X, # Key: X | x
79
+ Raylib::KEY_Y, # Key: Y | y
80
+ Raylib::KEY_Z, # Key: Z | z
81
+ Raylib::KEY_LEFT_BRACKET, # Key: [
82
+ Raylib::KEY_BACKSLASH, # Key: '\'
83
+ Raylib::KEY_RIGHT_BRACKET, # Key: ]
84
+ Raylib::KEY_GRAVE, # Key: `
85
+ # Function keys
86
+ Raylib::KEY_SPACE, # Key: Space
87
+ Raylib::KEY_ESCAPE, # Key: Esc
88
+ Raylib::KEY_ENTER, # Key: Enter
89
+ Raylib::KEY_TAB, # Key: Tab
90
+ Raylib::KEY_BACKSPACE, # Key: Backspace
91
+ Raylib::KEY_INSERT, # Key: Ins
92
+ Raylib::KEY_DELETE, # Key: Del
93
+ Raylib::KEY_RIGHT, # Key: Cursor right
94
+ Raylib::KEY_LEFT, # Key: Cursor left
95
+ Raylib::KEY_DOWN, # Key: Cursor down
96
+ Raylib::KEY_UP, # Key: Cursor up
97
+ Raylib::KEY_PAGE_UP, # Key: Page up
98
+ Raylib::KEY_PAGE_DOWN, # Key: Page down
99
+ Raylib::KEY_HOME, # Key: Home
100
+ Raylib::KEY_END, # Key: End
101
+ Raylib::KEY_CAPS_LOCK, # Key: Caps lock
102
+ Raylib::KEY_SCROLL_LOCK, # Key: Scroll down
103
+ Raylib::KEY_NUM_LOCK, # Key: Num lock
104
+ Raylib::KEY_PRINT_SCREEN, # Key: Print screen
105
+ Raylib::KEY_PAUSE, # Key: Pause
106
+ Raylib::KEY_F1, # Key: F1
107
+ Raylib::KEY_F2, # Key: F2
108
+ Raylib::KEY_F3, # Key: F3
109
+ Raylib::KEY_F4, # Key: F4
110
+ Raylib::KEY_F5, # Key: F5
111
+ Raylib::KEY_F6, # Key: F6
112
+ Raylib::KEY_F7, # Key: F7
113
+ Raylib::KEY_F8, # Key: F8
114
+ Raylib::KEY_F9, # Key: F9
115
+ Raylib::KEY_F10, # Key: F10
116
+ Raylib::KEY_F11, # Key: F11
117
+ Raylib::KEY_F12, # Key: F12
118
+ Raylib::KEY_LEFT_SHIFT, # Key: Shift left
119
+ Raylib::KEY_LEFT_CONTROL, # Key: Control left
120
+ Raylib::KEY_LEFT_ALT, # Key: Alt left
121
+ Raylib::KEY_LEFT_SUPER, # Key: Super left
122
+ Raylib::KEY_RIGHT_SHIFT, # Key: Shift right
123
+ Raylib::KEY_RIGHT_CONTROL, # Key: Control right
124
+ Raylib::KEY_RIGHT_ALT, # Key: Alt right
125
+ Raylib::KEY_RIGHT_SUPER, # Key: Super right
126
+ Raylib::KEY_KB_MENU, # Key: KB menu
127
+ # Keypad keys
128
+ Raylib::KEY_KP_0, # Key: Keypad 0
129
+ Raylib::KEY_KP_1, # Key: Keypad 1
130
+ Raylib::KEY_KP_2, # Key: Keypad 2
131
+ Raylib::KEY_KP_3, # Key: Keypad 3
132
+ Raylib::KEY_KP_4, # Key: Keypad 4
133
+ Raylib::KEY_KP_5, # Key: Keypad 5
134
+ Raylib::KEY_KP_6, # Key: Keypad 6
135
+ Raylib::KEY_KP_7, # Key: Keypad 7
136
+ Raylib::KEY_KP_8, # Key: Keypad 8
137
+ Raylib::KEY_KP_9, # Key: Keypad 9
138
+ Raylib::KEY_KP_DECIMAL, # Key: Keypad .
139
+ Raylib::KEY_KP_DIVIDE, # Key: Keypad /
140
+ Raylib::KEY_KP_MULTIPLY, # Key: Keypad *
141
+ Raylib::KEY_KP_SUBTRACT, # Key: Keypad -
142
+ Raylib::KEY_KP_ADD, # Key: Keypad +
143
+ Raylib::KEY_KP_ENTER, # Key: Keypad Enter
144
+ Raylib::KEY_KP_EQUAL, # Key: Keypad =
145
+ ]
146
+
147
+ # [INTERNAL]
148
+ def self.ImGui_ImplRaylib_KeyToImGuiKey(key)
149
+ case key
150
+ when Raylib::KEY_TAB then ImGuiKey_Tab
151
+ when Raylib::KEY_LEFT then ImGuiKey_LeftArrow
152
+ when Raylib::KEY_RIGHT then ImGuiKey_RightArrow
153
+ when Raylib::KEY_UP then ImGuiKey_UpArrow
154
+ when Raylib::KEY_DOWN then ImGuiKey_DownArrow
155
+ when Raylib::KEY_PAGE_UP then ImGuiKey_PageUp
156
+ when Raylib::KEY_PAGE_DOWN then ImGuiKey_PageDown
157
+ when Raylib::KEY_HOME then ImGuiKey_Home
158
+ when Raylib::KEY_END then ImGuiKey_End
159
+ when Raylib::KEY_INSERT then ImGuiKey_Insert
160
+ when Raylib::KEY_DELETE then ImGuiKey_Delete
161
+ when Raylib::KEY_BACKSPACE then ImGuiKey_Backspace
162
+ when Raylib::KEY_SPACE then ImGuiKey_Space
163
+ when Raylib::KEY_ENTER then ImGuiKey_Enter
164
+ when Raylib::KEY_ESCAPE then ImGuiKey_Escape
165
+ when Raylib::KEY_APOSTROPHE then ImGuiKey_Apostrophe
166
+ when Raylib::KEY_COMMA then ImGuiKey_Comma
167
+ when Raylib::KEY_MINUS then ImGuiKey_Minus
168
+ when Raylib::KEY_PERIOD then ImGuiKey_Period
169
+ when Raylib::KEY_SLASH then ImGuiKey_Slash
170
+ when Raylib::KEY_SEMICOLON then ImGuiKey_Semicolon
171
+ when Raylib::KEY_EQUAL then ImGuiKey_Equal
172
+ when Raylib::KEY_LEFT_BRACKET then ImGuiKey_LeftBracket
173
+ when Raylib::KEY_BACKSLASH then ImGuiKey_Backslash
174
+ when Raylib::KEY_RIGHT_BRACKET then ImGuiKey_RightBracket
175
+ when Raylib::KEY_GRAVE then ImGuiKey_GraveAccent
176
+ when Raylib::KEY_CAPS_LOCK then ImGuiKey_CapsLock
177
+ when Raylib::KEY_SCROLL_LOCK then ImGuiKey_ScrollLock
178
+ when Raylib::KEY_NUM_LOCK then ImGuiKey_NumLock
179
+ when Raylib::KEY_PRINT_SCREEN then ImGuiKey_PrintScreen
180
+ when Raylib::KEY_PAUSE then ImGuiKey_Pause
181
+ when Raylib::KEY_KP_0 then ImGuiKey_Keypad0
182
+ when Raylib::KEY_KP_1 then ImGuiKey_Keypad1
183
+ when Raylib::KEY_KP_2 then ImGuiKey_Keypad2
184
+ when Raylib::KEY_KP_3 then ImGuiKey_Keypad3
185
+ when Raylib::KEY_KP_4 then ImGuiKey_Keypad4
186
+ when Raylib::KEY_KP_5 then ImGuiKey_Keypad5
187
+ when Raylib::KEY_KP_6 then ImGuiKey_Keypad6
188
+ when Raylib::KEY_KP_7 then ImGuiKey_Keypad7
189
+ when Raylib::KEY_KP_8 then ImGuiKey_Keypad8
190
+ when Raylib::KEY_KP_9 then ImGuiKey_Keypad9
191
+ when Raylib::KEY_KP_DECIMAL then ImGuiKey_KeypadDecimal
192
+ when Raylib::KEY_KP_DIVIDE then ImGuiKey_KeypadDivide
193
+ when Raylib::KEY_KP_MULTIPLY then ImGuiKey_KeypadMultiply
194
+ when Raylib::KEY_KP_SUBTRACT then ImGuiKey_KeypadSubtract
195
+ when Raylib::KEY_KP_ADD then ImGuiKey_KeypadAdd
196
+ when Raylib::KEY_KP_ENTER then ImGuiKey_KeypadEnter
197
+ when Raylib::KEY_KP_EQUAL then ImGuiKey_KeypadEqual
198
+ when Raylib::KEY_LEFT_CONTROL then ImGuiKey_LeftCtrl
199
+ when Raylib::KEY_LEFT_SHIFT then ImGuiKey_LeftShift
200
+ when Raylib::KEY_LEFT_ALT then ImGuiKey_LeftAlt
201
+ when Raylib::KEY_LEFT_SUPER then ImGuiKey_LeftSuper
202
+ when Raylib::KEY_RIGHT_CONTROL then ImGuiKey_RightCtrl
203
+ when Raylib::KEY_RIGHT_SHIFT then ImGuiKey_RightShift
204
+ when Raylib::KEY_RIGHT_ALT then ImGuiKey_RightAlt
205
+ when Raylib::KEY_RIGHT_SUPER then ImGuiKey_RightSuper
206
+ when Raylib::KEY_MENU then ImGuiKey_Menu
207
+ when Raylib::KEY_ZERO then ImGuiKey_0
208
+ when Raylib::KEY_ONE then ImGuiKey_1
209
+ when Raylib::KEY_TWO then ImGuiKey_2
210
+ when Raylib::KEY_THREE then ImGuiKey_3
211
+ when Raylib::KEY_FOUR then ImGuiKey_4
212
+ when Raylib::KEY_FIVE then ImGuiKey_5
213
+ when Raylib::KEY_SIX then ImGuiKey_6
214
+ when Raylib::KEY_SEVEN then ImGuiKey_7
215
+ when Raylib::KEY_EIGHT then ImGuiKey_8
216
+ when Raylib::KEY_NINE then ImGuiKey_9
217
+ when Raylib::KEY_A then ImGuiKey_A
218
+ when Raylib::KEY_B then ImGuiKey_B
219
+ when Raylib::KEY_C then ImGuiKey_C
220
+ when Raylib::KEY_D then ImGuiKey_D
221
+ when Raylib::KEY_E then ImGuiKey_E
222
+ when Raylib::KEY_F then ImGuiKey_F
223
+ when Raylib::KEY_G then ImGuiKey_G
224
+ when Raylib::KEY_H then ImGuiKey_H
225
+ when Raylib::KEY_I then ImGuiKey_I
226
+ when Raylib::KEY_J then ImGuiKey_J
227
+ when Raylib::KEY_K then ImGuiKey_K
228
+ when Raylib::KEY_L then ImGuiKey_L
229
+ when Raylib::KEY_M then ImGuiKey_M
230
+ when Raylib::KEY_N then ImGuiKey_N
231
+ when Raylib::KEY_O then ImGuiKey_O
232
+ when Raylib::KEY_P then ImGuiKey_P
233
+ when Raylib::KEY_Q then ImGuiKey_Q
234
+ when Raylib::KEY_R then ImGuiKey_R
235
+ when Raylib::KEY_S then ImGuiKey_S
236
+ when Raylib::KEY_T then ImGuiKey_T
237
+ when Raylib::KEY_U then ImGuiKey_U
238
+ when Raylib::KEY_V then ImGuiKey_V
239
+ when Raylib::KEY_W then ImGuiKey_W
240
+ when Raylib::KEY_X then ImGuiKey_X
241
+ when Raylib::KEY_Y then ImGuiKey_Y
242
+ when Raylib::KEY_Z then ImGuiKey_Z
243
+ when Raylib::KEY_F1 then ImGuiKey_F1
244
+ when Raylib::KEY_F2 then ImGuiKey_F2
245
+ when Raylib::KEY_F3 then ImGuiKey_F3
246
+ when Raylib::KEY_F4 then ImGuiKey_F4
247
+ when Raylib::KEY_F5 then ImGuiKey_F5
248
+ when Raylib::KEY_F6 then ImGuiKey_F6
249
+ when Raylib::KEY_F7 then ImGuiKey_F7
250
+ when Raylib::KEY_F8 then ImGuiKey_F8
251
+ when Raylib::KEY_F9 then ImGuiKey_F9
252
+ when Raylib::KEY_F10 then ImGuiKey_F10
253
+ when Raylib::KEY_F11 then ImGuiKey_F11
254
+ when Raylib::KEY_F12 then ImGuiKey_F12
255
+ else ImGuiKey_None
256
+ end
257
+ end
258
+
259
+ # [INTERNAL]
260
+ def self.ImGui_ImplRaylib_UpdateKeyModifiers()
261
+ io = ImGuiIO.new(ImGui::GetIO())
262
+ io.AddKeyEvent(ImGuiMod_Ctrl, Raylib.IsKeyDown(Raylib::KEY_RIGHT_CONTROL) || Raylib.IsKeyDown(Raylib::KEY_LEFT_CONTROL))
263
+ io.AddKeyEvent(ImGuiMod_Shift, Raylib.IsKeyDown(Raylib::KEY_RIGHT_SHIFT) || Raylib.IsKeyDown(Raylib::KEY_LEFT_SHIFT))
264
+ io.AddKeyEvent(ImGuiMod_Alt, Raylib.IsKeyDown(Raylib::KEY_RIGHT_ALT) || Raylib.IsKeyDown(Raylib::KEY_LEFT_ALT))
265
+ io.AddKeyEvent(ImGuiMod_Super, Raylib.IsKeyDown(Raylib::KEY_RIGHT_SUPER) || Raylib.IsKeyDown(Raylib::KEY_LEFT_SUPER))
266
+ end
267
+
268
+ def self.ImplRaylib_ProcessKeyboard()
269
+ io = ImGuiIO.new(ImGui::GetIO())
270
+
271
+ ImGui_ImplRaylib_UpdateKeyModifiers()
272
+
273
+ KEY_IDS.each do |raylib_key|
274
+ if Raylib.IsKeyPressed(raylib_key)
275
+ key = ImGui_ImplRaylib_KeyToImGuiKey(raylib_key)
276
+ io.AddKeyEvent(key, true)
277
+ elsif Raylib.IsKeyReleased(raylib_key)
278
+ key = ImGui_ImplRaylib_KeyToImGuiKey(raylib_key)
279
+ io.AddKeyEvent(key, false)
280
+ end
281
+ end
282
+
283
+ while (charPressed = Raylib.GetCharPressed()) != 0
284
+ io.AddInputCharacter(charPressed)
285
+ end
286
+
287
+ return true
288
+ end
289
+
290
+ # [INTERNAL]
291
+ def self.ImplRaylib_UpdateMouseData()
292
+ bd = ImGui_ImplRaylib_GetBackendData()
293
+ io = ImGuiIO.new(ImGui::GetIO())
294
+
295
+ # Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
296
+ if io[:WantSetMousePos]
297
+ Raylib.SetMousePosition(io[:MousePos][:x].to_i, io[:MousePos][:y].to_i)
298
+ end
299
+
300
+ wheel_move = Raylib.GetMouseWheelMove()
301
+ wheel_y = if wheel_move > 0
302
+ 1.0
303
+ elsif wheel_move < 0
304
+ -1.0
305
+ else
306
+ 0.0
307
+ end
308
+ io.AddMouseWheelEvent(0, wheel_y) # [TODO] Get wheel tilt from Raylib
309
+
310
+ [Raylib::MOUSE_BUTTON_LEFT, Raylib::MOUSE_BUTTON_RIGHT, Raylib::MOUSE_BUTTON_MIDDLE].each_with_index do |button, mouse_button|
311
+ pressed = Raylib.IsMouseButtonPressed(button)
312
+ released = Raylib.IsMouseButtonReleased(button)
313
+ if pressed || released
314
+ io.AddMouseButtonEvent(mouse_button, pressed)
315
+ end
316
+ end
317
+
318
+ mouse_pos = Raylib.GetMousePosition()
319
+ io.AddMousePosEvent(mouse_pos[:x].to_f, mouse_pos[:y].to_f)
320
+ end
321
+
322
+ # [INTERNAL]
323
+ def self.ImplRaylib_UpdateMouseCursor()
324
+ io = ImGuiIO.new(ImGui::GetIO())
325
+ return if (io[:ConfigFlags] & ImGuiConfigFlags_NoMouseCursorChange)
326
+
327
+ if io[:MouseDrawCursor] || ImGui::GetMouseCursor() == ImGuiMouseCursor_None
328
+ Raylib.HideCursor() # Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
329
+ else
330
+ Raylib.ShowCursor() # Show OS mouse cursor
331
+ end
332
+ end
333
+
334
+ #
335
+ # [TODO] Support ImplRaylib_UpdateGamepads
336
+ #
337
+
338
+ def self.ImplRaylib_Init()
339
+ # Setup backend capabilities flags
340
+ bd = ImGui_ImplRaylib_Data.new
341
+ @@g_BackendData[ImGui::GetCurrentContext().address] = bd
342
+
343
+ io = ImGuiIO.new(ImGui::GetIO())
344
+
345
+ io[:BackendPlatformUserData] = nil
346
+ io[:BackendPlatformName] = @@g_BackendPlatformName
347
+ io[:BackendFlags] |= ImGuiBackendFlags_HasMouseCursors # We can honor GetMouseCursor() values (optional)
348
+ io[:BackendFlags] |= ImGuiBackendFlags_HasSetMousePos # We can honor io.WantSetMousePos requests (optional, rarely used)
349
+
350
+ bd.time = 0.0
351
+
352
+ return true
353
+ end
354
+
355
+ def self.ImplRaylib_Shutdown()
356
+ io = ImGuiIO.new(ImGui::GetIO())
357
+ io[:BackendPlatformName] = nil
358
+ io[:BackendPlatformUserData] = nil
359
+ @@g_BackendData[ImGui::GetCurrentContext()] = nil
360
+ end
361
+
362
+ def self.ImplRaylib_NewFrame()
363
+ bd = ImGui_ImplRaylib_GetBackendData()
364
+ io = ImGuiIO.new(ImGui::GetIO())
365
+
366
+ # Setup display size (every frame to accommodate for window resizing)
367
+ io[:DisplaySize][:x] = Raylib.GetScreenWidth()
368
+ io[:DisplaySize][:y] = Raylib.GetScreenHeight()
369
+
370
+ # Setup time step
371
+ current_time = Raylib.GetTime()
372
+
373
+ io[:DeltaTime] = bd.time > 0 ? (current_time - bd.time).to_f : 1.0 / 60.0
374
+ bd.time = current_time
375
+
376
+ ImplRaylib_ProcessKeyboard()
377
+ ImplRaylib_UpdateMouseData()
378
+ ImplRaylib_UpdateMouseCursor()
379
+
380
+ # [TODO] update gamepads
381
+ end
382
+
383
+ # [INTERNAL]
384
+ def self.set_vertex(xy, uv, color)
385
+ Raylib.rlColor4ub(color[0], color[1], color[2], color[3])
386
+ Raylib.rlTexCoord2f(uv[0], uv[1])
387
+ Raylib.rlVertex2f(xy[0], xy[1])
388
+ end
389
+
390
+ def self.ImplRaylib_RenderDrawData(draw_data_raw)
391
+ draw_data = ImDrawData.new(draw_data_raw)
392
+ Raylib.rlDisableBackfaceCulling()
393
+
394
+ clip_offset = draw_data[:DisplayPos]
395
+ draw_data[:CmdListsCount].times do |n|
396
+ cmd_list = ImDrawList.new((draw_data[:CmdLists][:Data] + FFI.type_size(:pointer) * n).read_pointer)
397
+ vtx_buffer = cmd_list[:VtxBuffer][:Data] # const ImDrawVert*
398
+ idx_buffer = cmd_list[:IdxBuffer][:Data] # const ImDrawIdx*
399
+
400
+ cmd_list[:CmdBuffer][:Size].times do |cmd_i|
401
+ pcmd = ImDrawCmd.new(cmd_list[:CmdBuffer][:Data] + ImDrawCmd.size * cmd_i) # const ImDrawCmd*
402
+ if pcmd[:UserCallback] != nil
403
+ # [TODO] Handle user callback (Ref.: https://github.com/ffi/ffi/wiki/Callbacks )
404
+ else
405
+ rect_min_x = (pcmd[:ClipRect][:x] - clip_offset[:x])
406
+ rect_min_y = (pcmd[:ClipRect][:y] - clip_offset[:y])
407
+ rect_max_x = (pcmd[:ClipRect][:z] - clip_offset[:x])
408
+ rect_max_y = (pcmd[:ClipRect][:w] - clip_offset[:y])
409
+
410
+ rect_w = rect_max_x - rect_min_x
411
+ rect_h = rect_max_y - rect_min_y
412
+
413
+ Raylib.BeginScissorMode(rect_min_x, rect_min_y, rect_w, rect_h)
414
+
415
+ # Render triangles
416
+ indices = idx_buffer + FFI.type_size(:ImDrawIdx) * pcmd[:IdxOffset]
417
+ vertices = vtx_buffer + ImDrawVert.size * pcmd[:VtxOffset]
418
+ 0.step(pcmd[:ElemCount] - 3, 3) do |i|
419
+ Raylib.rlPushMatrix()
420
+ Raylib.rlBegin(Raylib::RL_TRIANGLES)
421
+ Raylib.rlSetTexture(pcmd[:TextureId].read_uint32)
422
+
423
+ index = indices.get_array_of_uint16(i * FFI::type_size(:ImDrawIdx), 3)
424
+
425
+ base_offset = ImDrawVert.size * index[0]
426
+ xy = vertices + (base_offset + ImDrawVert.offset_of(:pos))
427
+ uv = vertices + (base_offset + ImDrawVert.offset_of(:uv))
428
+ color = vertices + (base_offset + ImDrawVert.offset_of(:col))
429
+ set_vertex(xy.read_array_of_float(2), uv.read_array_of_float(2), color.read_array_of_uint8(4))
430
+
431
+ base_offset = ImDrawVert.size * index[2]
432
+ xy = vertices + (base_offset + ImDrawVert.offset_of(:pos))
433
+ uv = vertices + (base_offset + ImDrawVert.offset_of(:uv))
434
+ color = vertices + (base_offset + ImDrawVert.offset_of(:col))
435
+ set_vertex(xy.read_array_of_float(2), uv.read_array_of_float(2), color.read_array_of_uint8(4))
436
+
437
+ base_offset = ImDrawVert.size * index[1]
438
+ xy = vertices + (base_offset + ImDrawVert.offset_of(:pos))
439
+ uv = vertices + (base_offset + ImDrawVert.offset_of(:uv))
440
+ color = vertices + (base_offset + ImDrawVert.offset_of(:col))
441
+ set_vertex(xy.read_array_of_float(2), uv.read_array_of_float(2), color.read_array_of_uint8(4))
442
+
443
+ Raylib.rlSetTexture(0)
444
+ Raylib.rlEnd()
445
+ Raylib.rlPopMatrix()
446
+ end
447
+ Raylib.EndScissorMode()
448
+ end
449
+ end
450
+ end
451
+ Raylib.rlEnableBackfaceCulling()
452
+ end
453
+
454
+ end