25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

227 lines
7.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  5. // © 2017—2018 Sam Hocevar <sam@hocevar.net>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #pragma once
  14. #include <string>
  15. #include <map>
  16. //
  17. // The Imgui integration
  18. //
  19. #define IM_VEC2_CLASS_EXTRA ImVec2(const lol::vec2 &v) { x = v.x; y = v.y; } \
  20. ImVec2(const lol::ivec2 &v) : ImVec2(lol::vec2(v)) { } \
  21. operator lol::vec2() const { return lol::vec2(x, y); } \
  22. operator lol::ivec2() const { return lol::ivec2(lol::vec2(x, y)); }
  23. #define IM_VEC4_CLASS_EXTRA ImVec4(const lol::vec4 &v) { x = v.x; y = v.y; z = v.z; w = v.w; } \
  24. ImVec4(const lol::ivec4 &v) : ImVec4(lol::vec4(v)) { } \
  25. operator lol::vec4() const { return lol::vec4(x, y, z, w); } \
  26. operator lol::ivec4() const { return lol::ivec4(lol::vec4(x, y, z, w)); }
  27. #include "imgui.h"
  28. #undef IM_VEC2_CLASS_EXTRA
  29. #undef IM_VEC4_CLASS_EXTRA
  30. //LolImGui ----------------------------------------------------------------------------------------
  31. namespace lol
  32. {
  33. class LolImGui : public Entity
  34. {
  35. typedef Entity super;
  36. //ImGuiKeyBase ------------------------------------------------------------
  37. struct LolImGuiKeyBase : public StructSafeEnum
  38. {
  39. enum Type
  40. {
  41. KEY_START,
  42. Tab = KEY_START,
  43. LeftArrow,
  44. RightArrow,
  45. UpArrow,
  46. DownArrow,
  47. Home,
  48. End,
  49. Delete,
  50. Backspace,
  51. Enter,
  52. Escape,
  53. A,
  54. C,
  55. V,
  56. X,
  57. Y,
  58. Z,
  59. LShift,
  60. RShift,
  61. LCtrl,
  62. RCtrl,
  63. KEY_END,
  64. MOUSE_KEY_START = KEY_END,
  65. LeftClick = MOUSE_KEY_START,
  66. RightClick,
  67. MiddleClick,
  68. Focus,
  69. MOUSE_KEY_END,
  70. MAX = MOUSE_KEY_END,
  71. };
  72. protected:
  73. virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
  74. {
  75. enum_map[Tab] = g_name_key_Tab;
  76. enum_map[LeftArrow] = g_name_key_Left;
  77. enum_map[RightArrow] = g_name_key_Right;
  78. enum_map[UpArrow] = g_name_key_Up;
  79. enum_map[DownArrow] = g_name_key_Down;
  80. enum_map[Home] = g_name_key_Home;
  81. enum_map[End] = g_name_key_End;
  82. enum_map[Delete] = g_name_key_Delete;
  83. enum_map[Backspace] = g_name_key_Backspace;
  84. enum_map[Enter] = g_name_key_Return;
  85. enum_map[Escape] = g_name_key_Escape;
  86. enum_map[A] = g_name_key_A;
  87. enum_map[C] = g_name_key_C;
  88. enum_map[V] = g_name_key_V;
  89. enum_map[X] = g_name_key_X;
  90. enum_map[Y] = g_name_key_Y;
  91. enum_map[Z] = g_name_key_Z;
  92. enum_map[LShift] = g_name_key_LShift;
  93. enum_map[RShift] = g_name_key_RShift;
  94. enum_map[LCtrl] = g_name_key_LCtrl;
  95. enum_map[RCtrl] = g_name_key_RCtrl;
  96. enum_map[LeftClick] = g_name_mouse_key_left;
  97. enum_map[RightClick] = g_name_mouse_key_right;
  98. enum_map[MiddleClick] = g_name_mouse_key_middle;
  99. enum_map[Focus] = g_name_mouse_key_in_screen;
  100. return true;
  101. }
  102. };
  103. typedef SafeEnum<LolImGuiKeyBase> LolImGuiKey;
  104. //ImGuiKeyBase ------------------------------------------------------------
  105. struct LolImGuiAxisBase : public StructSafeEnum
  106. {
  107. enum Type
  108. {
  109. MOUSE_AXIS_START = 0,
  110. Scroll = MOUSE_AXIS_START,
  111. MOUSE_AXIS_END,
  112. MAX = MOUSE_AXIS_END,
  113. };
  114. protected:
  115. virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
  116. {
  117. enum_map[Scroll] = g_name_mouse_axis_scroll;
  118. return true;
  119. }
  120. };
  121. typedef SafeEnum<LolImGuiAxisBase> LolImGuiAxis;
  122. public:
  123. //-------------------------------------------------------------------------
  124. LolImGui();
  125. ~LolImGui();
  126. std::string GetName() const { return "<LolImGui>"; }
  127. //-------------------------------------------------------------------------
  128. static void Init();
  129. static void Shutdown();
  130. //-------------------------------------------------------------------------
  131. static std::string GetClipboard();
  132. protected:
  133. virtual void tick_game(float seconds);
  134. virtual void tick_draw(float seconds, Scene &scene);
  135. static void SetClipboardCallback(void *data, const char* text);
  136. static const char* GetClipboardCallback(void *data);
  137. static void RenderDrawLists(ImDrawData* draw_data);
  138. void RenderDrawListsMethod(ImDrawData* draw_data);
  139. struct Uniform
  140. {
  141. Uniform() { }
  142. Uniform(ShaderVar var) { m_var = var; }
  143. std::string tostring() const { return m_var.tostring(); }
  144. operator ShaderVar() const { return m_var; }
  145. operator ShaderUniform() const { return m_uniform; }
  146. //--
  147. ShaderVar m_var;
  148. ShaderUniform m_uniform;
  149. };
  150. //-------------------------------------------------------------------------
  151. TextureImage* m_font = nullptr;
  152. ShaderBuilder m_builder = ShaderBuilder("imgui_shader", "120");
  153. Shader* m_shader = nullptr;
  154. Uniform m_ortho;
  155. Uniform m_texture;
  156. array<ShaderAttrib> m_attribs;
  157. VertexDeclaration* m_vdecl = nullptr;
  158. IndexBuffer* m_ibuff = nullptr;
  159. Controller* m_controller = nullptr;
  160. InputDevice* m_mouse = nullptr;
  161. InputDevice* m_keyboard = nullptr;
  162. InputProfile m_profile;
  163. //std::map<ImGuiKey_, LolImGuiKey> m_keys;
  164. std::string m_clipboard;
  165. };
  166. //-----------------------------------------------------------------------------
  167. class PrimitiveLolImGui : public PrimitiveRenderer
  168. {
  169. public:
  170. PrimitiveLolImGui() { }
  171. virtual void Render(Scene& scene, PrimitiveSource* primitive);
  172. };
  173. //bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks);
  174. //void ImGui_ImplGlfw_Shutdown();
  175. //void ImGui_ImplGlfw_NewFrame();
  176. //
  177. //// Use if you want to reset your rendering device without losing ImGui state.
  178. //void ImGui_ImplGlfw_InvalidateDeviceObjects();
  179. //bool ImGui_ImplGlfw_CreateDeviceObjects();
  180. //
  181. //// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
  182. //// Provided here if you want to chain callbacks.
  183. //// You can also handle inputs yourself and use those as a reference.
  184. //void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
  185. //void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
  186. //void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
  187. //void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
  188. } /* namespace lol */