IOWrapper.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #include "imguiWrappedHeader.h"
  2. #include "IOWrapper.h"
  3. #include "WrapperConverter.h"
  4. #include <string>
  5. IggBool iggWantCaptureMouse(IggIO handle)
  6. {
  7. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  8. return io->WantCaptureMouse ? 1 : 0;
  9. }
  10. IggBool iggWantCaptureKeyboard(IggIO handle)
  11. {
  12. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  13. return io->WantCaptureKeyboard ? 1 : 0;
  14. }
  15. IggBool iggWantTextInput(IggIO handle)
  16. {
  17. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  18. return io->WantTextInput ? 1 : 0;
  19. }
  20. IggFontAtlas iggIoGetFonts(IggIO handle)
  21. {
  22. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  23. return reinterpret_cast<IggFontAtlas>(io->Fonts);
  24. }
  25. void iggIoSetDisplaySize(IggIO handle, IggVec2 const *value)
  26. {
  27. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  28. importValue(io->DisplaySize, *value);
  29. }
  30. void iggIoSetMousePosition(IggIO handle, IggVec2 const *value)
  31. {
  32. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  33. importValue(io->MousePos, *value);
  34. }
  35. void iggIoSetMouseButtonDown(IggIO handle, int index, IggBool value)
  36. {
  37. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  38. io->MouseDown[index] = value != 0;
  39. }
  40. void iggIoAddMouseWheelDelta(IggIO handle, float horizontal, float vertical)
  41. {
  42. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  43. io->MouseWheelH += horizontal;
  44. io->MouseWheel += vertical;
  45. }
  46. void iggIoGetMouseWheelDelta(IggIO handle, IggFloat *value)
  47. {
  48. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  49. exportValue(*value, io->MouseWheel);
  50. }
  51. void iggIoGetMouseWheelHDelta(IggIO handle, IggFloat *value)
  52. {
  53. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  54. exportValue(*value, io->MouseWheelH);
  55. }
  56. void iggIoGetMouseDelta(IggIO handle, IggVec2 *value)
  57. {
  58. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  59. exportValue(*value, io->MouseDelta);
  60. }
  61. void iggIoSetDeltaTime(IggIO handle, float value)
  62. {
  63. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  64. io->DeltaTime = value;
  65. }
  66. void iggIoSetFontGlobalScale(IggIO handle, float value)
  67. {
  68. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  69. io->FontGlobalScale = value;
  70. }
  71. IggBool iggIoGetMouseDrawCursor(IggIO handle)
  72. {
  73. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  74. return io->MouseDrawCursor ? 1 : 0;
  75. }
  76. void iggIoSetMouseDrawCursor(IggIO handle, IggBool value)
  77. {
  78. ImGuiIO *io = reinterpret_cast<ImGuiIO *>(handle);
  79. io->MouseDrawCursor = value != 0;
  80. }
  81. void iggIoKeyPress(IggIO handle, int key)
  82. {
  83. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  84. io.KeysDown[key] = true;
  85. }
  86. void iggIoKeyRelease(IggIO handle, int key)
  87. {
  88. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  89. io.KeysDown[key] = false;
  90. }
  91. void iggIoKeyMap(IggIO handle, int imguiKey, int nativeKey)
  92. {
  93. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  94. io.KeyMap[imguiKey] = nativeKey;
  95. }
  96. void iggIoKeyCtrl(IggIO handle, int leftCtrl, int rightCtrl)
  97. {
  98. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  99. io.KeyCtrl = io.KeysDown[leftCtrl] || io.KeysDown[rightCtrl];
  100. }
  101. void iggIoKeyShift(IggIO handle, int leftShift, int rightShift)
  102. {
  103. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  104. io.KeyShift = io.KeysDown[leftShift] || io.KeysDown[rightShift];
  105. }
  106. void iggIoKeyAlt(IggIO handle, int leftAlt, int rightAlt)
  107. {
  108. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  109. io.KeyAlt = io.KeysDown[leftAlt] || io.KeysDown[rightAlt];
  110. }
  111. void iggIoKeySuper(IggIO handle, int leftSuper, int rightSuper)
  112. {
  113. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  114. io.KeySuper = io.KeysDown[leftSuper] || io.KeysDown[rightSuper];
  115. }
  116. void iggIoAddInputCharactersUTF8(IggIO handle, char const *utf8Chars)
  117. {
  118. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  119. io.AddInputCharactersUTF8(utf8Chars);
  120. }
  121. void iggIoSetIniFilename(IggIO handle, char const *value)
  122. {
  123. static std::string bufferValue;
  124. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  125. bufferValue = (value != nullptr) ? value : "";
  126. io.IniFilename = bufferValue.empty() ? nullptr : bufferValue.c_str();
  127. }
  128. void iggIoSetConfigFlags(IggIO handle, int flags)
  129. {
  130. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  131. io.ConfigFlags = flags;
  132. }
  133. int iggIoGetConfigFlags(IggIO handle)
  134. {
  135. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  136. return io.ConfigFlags;
  137. }
  138. void iggIoSetBackendFlags(IggIO handle, int flags)
  139. {
  140. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  141. io.BackendFlags = flags;
  142. }
  143. extern "C" void iggIoSetClipboardText(IggIO handle, char *text);
  144. extern "C" char *iggIoGetClipboardText(IggIO handle);
  145. static void iggIoSetClipboardTextWrapper(void *userData, char const *text)
  146. {
  147. iggIoSetClipboardText(userData, const_cast<char *>(text));
  148. }
  149. static char const *iggIoGetClipboardTextWrapper(void *userData)
  150. {
  151. return iggIoGetClipboardText(userData);
  152. }
  153. void iggIoRegisterClipboardFunctions(IggIO handle)
  154. {
  155. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  156. io.ClipboardUserData = handle;
  157. io.GetClipboardTextFn = iggIoGetClipboardTextWrapper;
  158. io.SetClipboardTextFn = iggIoSetClipboardTextWrapper;
  159. }
  160. void iggIoClearClipboardFunctions(IggIO handle)
  161. {
  162. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  163. io.GetClipboardTextFn = nullptr;
  164. io.SetClipboardTextFn = nullptr;
  165. io.ClipboardUserData = nullptr;
  166. }
  167. int iggGetFrameCountSinceLastInput(IggIO handle)
  168. {
  169. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  170. return io.FrameCountSinceLastInput;
  171. }
  172. void iggSetFrameCountSinceLastInput(IggIO handle, int count)
  173. {
  174. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  175. io.FrameCountSinceLastInput = count;
  176. }
  177. void iggIoAddFocusEvent(IggIO handle, IggBool focused)
  178. {
  179. ImGuiIO &io = *reinterpret_cast<ImGuiIO *>(handle);
  180. io.AddFocusEvent(focused);
  181. }