forked from AllenDang/cimgui-go
/
type_accessor.go
69 lines (57 loc) · 1.87 KB
/
type_accessor.go
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
package imgui
// #include "cimgui_wrapper.h"
// #include "util.h"
import "C"
import "unsafe"
func (io IO) SetMouseButtonDown(i int, down bool) {
C.wrap_ImGuiIO_SetMouseButtonDown(io.handle(), C.int(i), C.bool(down))
}
func (io IO) AddMouseWheelDelta(horizontal, vertical float32) {
v := io.MouseWheel() + vertical
h := io.MouseWheelH() + horizontal
io.SetMouseWheel(v)
io.SetMouseWheelH(h)
}
// Commands returns the list of draw commands.
// Typically 1 command = 1 GPU draw call, unless the command is a callback.
func (d DrawData) CommandLists() []DrawList {
count := d.CmdListsCount()
lists := make([]DrawList, count)
for i := 0; i < count; i++ {
lists[i] = d.getDrawListAt(i)
}
return lists
}
func (d DrawData) getDrawListAt(idx int) DrawList {
return (DrawList)(unsafe.Pointer(C.wrap_DrawData_GetDrawListAt(d.handle(), C.int(idx))))
}
func (d DrawList) GetVertexBuffer() (unsafe.Pointer, int) {
buffer := d.c().VtxBuffer.Data
bufferSize := C.sizeof_ImDrawVert * d.c().VtxBuffer.Size
return unsafe.Pointer(buffer), int(bufferSize)
}
func (d DrawList) GetIndexBuffer() (unsafe.Pointer, int) {
buffer := d.c().IdxBuffer.Data
bufferSize := C.sizeof_ImDrawIdx * d.c().IdxBuffer.Size
return unsafe.Pointer(buffer), int(bufferSize)
}
func (d DrawList) getDrawCmdAt(idx int) DrawCmd {
return (DrawCmd)(unsafe.Pointer(C.wrap_DrawList_GetDrawCmdAt(d.handle(), C.int(idx))))
}
func (d DrawList) Commands() []DrawCmd {
count := int(d.c().CmdBuffer.Size)
cmds := make([]DrawCmd, count)
for i := 0; i < count; i++ {
cmds[i] = d.getDrawCmdAt(i)
}
return cmds
}
func (d DrawCmd) HasUserCallback() bool {
return d.c().UserCallback != nil
}
func (d DrawCmd) CallUserCallback(list DrawList) {
C.wrap_DrawCmd_CallUserCallback(list.handle(), d.handle())
}
func (fa FontGlyphRangesBuilder) BuildRanges(ranges GlyphRange) {
C.ImFontGlyphRangesBuilder_BuildRanges(fa.handle(), ranges.handle())
}