WrapperConverter.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "imgui.h"
  3. #include "imguiWrapperTypes.h"
  4. extern void importValue(bool &out, IggBool const &in);
  5. extern void exportValue(IggBool &out, bool const &in);
  6. extern void importValue(float &out, IggFloat const &in);
  7. extern void exportValue(IggFloat &out, float const &in);
  8. extern void importValue(ImVec2 &out, IggVec2 const &in);
  9. extern void exportValue(IggVec2 &out, ImVec2 const &in);
  10. extern void importValue(ImVec4 &out, IggVec4 const &in);
  11. extern void exportValue(IggVec4 &out, ImVec4 const &in);
  12. template <typename ImGuiType, typename IggType> class TypeWrapper {
  13. public:
  14. TypeWrapper(IggType *iggValue) : iggValue(iggValue), imguiValue(nullptr) {
  15. if (iggValue != nullptr) {
  16. imguiValue = &imguiBuffer;
  17. importValue(*imguiValue, *iggValue);
  18. }
  19. }
  20. TypeWrapper(IggType const *constIggValue) : iggValue(nullptr), imguiValue(nullptr) {
  21. if (constIggValue != nullptr) {
  22. imguiValue = &imguiBuffer;
  23. importValue(*imguiValue, *constIggValue);
  24. }
  25. }
  26. ~TypeWrapper() {
  27. if (iggValue != nullptr) {
  28. exportValue(*iggValue, *imguiValue);
  29. }
  30. }
  31. operator ImGuiType *() { return imguiValue; }
  32. private:
  33. IggType *iggValue;
  34. ImGuiType *imguiValue;
  35. ImGuiType imguiBuffer;
  36. };
  37. typedef TypeWrapper<float, IggFloat> FloatWrapper;
  38. typedef TypeWrapper<bool, IggBool> BoolWrapper;
  39. typedef TypeWrapper<ImVec2, IggVec2> Vec2Wrapper;
  40. typedef TypeWrapper<ImVec4, IggVec4> Vec4Wrapper;