DrawData.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package imgui
  2. // #include "DrawDataWrapper.h"
  3. import "C"
  4. import "unsafe"
  5. // DrawData contains all draw data to render an ImGui frame.
  6. type DrawData uintptr
  7. func (data DrawData) handle() C.IggDrawData {
  8. return C.IggDrawData(data)
  9. }
  10. // Valid indicates whether the structure is usable.
  11. // It is valid only after Render() is called and before the next NewFrame() is called.
  12. func (data DrawData) Valid() bool {
  13. return (data.handle() != nil) && (C.iggDrawDataValid(data.handle()) != 0)
  14. }
  15. // CommandLists is an array of DrawList to render.
  16. // The DrawList are owned by the context and only pointed to from here.
  17. func (data DrawData) CommandLists() []DrawList {
  18. var handles unsafe.Pointer
  19. var count C.int
  20. C.iggDrawDataGetCommandLists(data.handle(), &handles, &count)
  21. list := make([]DrawList, int(count))
  22. for i := 0; i < int(count); i++ {
  23. list[i] = DrawList(*((*uintptr)(handles)))
  24. handles = unsafe.Pointer(uintptr(handles) + unsafe.Sizeof(handles)) // nolint: gas
  25. }
  26. return list
  27. }
  28. // ScaleClipRects is a helper to scale the ClipRect field of each DrawCmd.
  29. // Use if your final output buffer is at a different scale than ImGui expects,
  30. // or if there is a difference between your window resolution and framebuffer resolution.
  31. func (data DrawData) ScaleClipRects(scale Vec2) {
  32. scaleArg, _ := scale.wrapped()
  33. C.iggDrawDataScaleClipRects(data.handle(), scaleArg)
  34. }