From 8c28fc683910e3a409cb9fe93a9254944a8f2d49 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 1 Jan 2019 15:49:13 -0800 Subject: [PATCH] add imgui_wrapper --- .gitmodules | 2 +- platform/imgui/{ => imgui_wrapper}/cimgui | 0 platform/imgui/imgui_wrapper/imgui_wrapper.go | 44 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) rename platform/imgui/{ => imgui_wrapper}/cimgui (100%) create mode 100644 platform/imgui/imgui_wrapper/imgui_wrapper.go diff --git a/.gitmodules b/.gitmodules index b8fa7af..26256ca 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,5 +2,5 @@ path = formats/mpq/stormlib url = https://github.com/ladislav-zezula/StormLib.git [submodule "platform/imgui/cimgui"] - path = platform/imgui/cimgui + path = platform/imgui/imgui_wrapper/cimgui url = https://github.com/cimgui/cimgui.git diff --git a/platform/imgui/cimgui b/platform/imgui/imgui_wrapper/cimgui similarity index 100% rename from platform/imgui/cimgui rename to platform/imgui/imgui_wrapper/cimgui diff --git a/platform/imgui/imgui_wrapper/imgui_wrapper.go b/platform/imgui/imgui_wrapper/imgui_wrapper.go new file mode 100644 index 0000000..19a728c --- /dev/null +++ b/platform/imgui/imgui_wrapper/imgui_wrapper.go @@ -0,0 +1,44 @@ +package imgui + +// #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS +// #include "cimgui/cimgui.h" +// #cgo linux LDFLAGS: -L./cimgui -l:cimgui.a -lstdc++ -lm +import "C" +import "unsafe" + +type Context = C.ImGuiContext +type DrawData = C.ImDrawData +type FontAtlas = C.ImFontAtlas +type Io = C.ImGuiIO + +func CreateContext(fontAtlas *FontAtlas) *Context { + c := C.igCreateContext(fontAtlas) + return c +} + +func (c *Context) Destroy() { + C.igDestroyContext(c) +} + +func NewFrame() { + C.igNewFrame() +} + +func Render() { + C.igRender() +} + +func GetDrawData() *DrawData { + return C.igGetDrawData() +} + +func GetIo() *Io { + return C.igGetIO() +} + +func (fa *FontAtlas) GetTexDataAsRGBA32() (pixels unsafe.Pointer, width, height int32) { + var data *C.uint8_t + var w, h C.int + C.ImFontAtlas_GetTexDataAsRGBA32(fa, &data, &w, &h, nil) + return unsafe.Pointer(data), int32(w), int32(h) +}