Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

252 рядки
8.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. //Imgui extension ---------------------------------------------------------------------------------
  31. typedef int ImGuiSetDock; // condition flags for Set*() // enum ImGuiSetCond_
  32. enum ImGuiSetDock_
  33. {
  34. ImGuiSetDock_Center,
  35. ImGuiSetDock_Top,
  36. ImGuiSetDock_TopRight,
  37. ImGuiSetDock_Right,
  38. ImGuiSetDock_BottomRight,
  39. ImGuiSetDock_Bottom,
  40. ImGuiSetDock_BottomLeft,
  41. ImGuiSetDock_Left,
  42. ImGuiSetDock_TopLeft,
  43. };
  44. namespace ImGui
  45. {
  46. IMGUI_API void SetNextWindowDockingAndSize(const ImVec2& size, ImGuiSetDock dock, const ImVec2& padding, ImGuiSetCond cond = 0);
  47. IMGUI_API void SetNextWindowDockingAndSize(const ImVec2& size, ImGuiSetDock dock, const ImVec4& padding = ImVec4(0, 0, 0, 0), ImGuiSetCond cond = 0);
  48. IMGUI_API void SetNextWindowDocking(ImGuiSetDock dock, const ImVec2& padding, ImGuiSetCond cond = 0);
  49. IMGUI_API void SetNextWindowDocking(ImGuiSetDock dock, const ImVec4& padding = ImVec4(0, 0, 0, 0), ImGuiSetCond cond = 0);
  50. IMGUI_API float GetMainMenuBarHeight();
  51. }
  52. //LolImGui ----------------------------------------------------------------------------------------
  53. namespace lol
  54. {
  55. class LolImGui : public Entity
  56. {
  57. typedef Entity super;
  58. //ImGuiKeyBase ------------------------------------------------------------
  59. struct LolImGuiKeyBase : public StructSafeEnum
  60. {
  61. enum Type
  62. {
  63. KEY_START,
  64. Tab = KEY_START,
  65. LeftArrow,
  66. RightArrow,
  67. UpArrow,
  68. DownArrow,
  69. Home,
  70. End,
  71. Delete,
  72. Backspace,
  73. Enter,
  74. Escape,
  75. A,
  76. C,
  77. V,
  78. X,
  79. Y,
  80. Z,
  81. LShift,
  82. RShift,
  83. LCtrl,
  84. RCtrl,
  85. KEY_END,
  86. MOUSE_KEY_START = KEY_END,
  87. LeftClick = MOUSE_KEY_START,
  88. RightClick,
  89. MiddleClick,
  90. Focus,
  91. MOUSE_KEY_END,
  92. MAX = MOUSE_KEY_END,
  93. };
  94. protected:
  95. virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
  96. {
  97. enum_map[Tab] = g_name_key_Tab;
  98. enum_map[LeftArrow] = g_name_key_Left;
  99. enum_map[RightArrow] = g_name_key_Right;
  100. enum_map[UpArrow] = g_name_key_Up;
  101. enum_map[DownArrow] = g_name_key_Down;
  102. enum_map[Home] = g_name_key_Home;
  103. enum_map[End] = g_name_key_End;
  104. enum_map[Delete] = g_name_key_Delete;
  105. enum_map[Backspace] = g_name_key_Backspace;
  106. enum_map[Enter] = g_name_key_Return;
  107. enum_map[Escape] = g_name_key_Escape;
  108. enum_map[A] = g_name_key_A;
  109. enum_map[C] = g_name_key_C;
  110. enum_map[V] = g_name_key_V;
  111. enum_map[X] = g_name_key_X;
  112. enum_map[Y] = g_name_key_Y;
  113. enum_map[Z] = g_name_key_Z;
  114. enum_map[LShift] = g_name_key_LShift;
  115. enum_map[RShift] = g_name_key_RShift;
  116. enum_map[LCtrl] = g_name_key_LCtrl;
  117. enum_map[RCtrl] = g_name_key_RCtrl;
  118. enum_map[LeftClick] = g_name_mouse_key_left;
  119. enum_map[RightClick] = g_name_mouse_key_right;
  120. enum_map[MiddleClick] = g_name_mouse_key_middle;
  121. enum_map[Focus] = g_name_mouse_key_in_screen;
  122. return true;
  123. }
  124. };
  125. typedef SafeEnum<LolImGuiKeyBase> LolImGuiKey;
  126. //ImGuiKeyBase ------------------------------------------------------------
  127. struct LolImGuiAxisBase : public StructSafeEnum
  128. {
  129. enum Type
  130. {
  131. MOUSE_AXIS_START = 0,
  132. Scroll = MOUSE_AXIS_START,
  133. MOUSE_AXIS_END,
  134. MAX = MOUSE_AXIS_END,
  135. };
  136. protected:
  137. virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
  138. {
  139. enum_map[Scroll] = g_name_mouse_axis_scroll;
  140. return true;
  141. }
  142. };
  143. typedef SafeEnum<LolImGuiAxisBase> LolImGuiAxis;
  144. public:
  145. //-------------------------------------------------------------------------
  146. LolImGui();
  147. ~LolImGui();
  148. std::string GetName() const { return "<LolImGui>"; }
  149. //-------------------------------------------------------------------------
  150. static void Init();
  151. static void Shutdown();
  152. //-------------------------------------------------------------------------
  153. static std::string GetClipboard();
  154. protected:
  155. virtual void TickGame(float seconds);
  156. virtual void TickDraw(float seconds, Scene &scene);
  157. static void SetClipboardCallback(void *data, const char* text);
  158. static const char* GetClipboardCallback(void *data);
  159. static void RenderDrawLists(ImDrawData* draw_data);
  160. void RenderDrawListsMethod(ImDrawData* draw_data);
  161. struct Uniform
  162. {
  163. Uniform() { }
  164. Uniform(ShaderVar var) { m_var = var; }
  165. std::string tostring() const { return m_var.tostring(); }
  166. operator ShaderVar() const { return m_var; }
  167. operator ShaderUniform() const { return m_uniform; }
  168. //--
  169. ShaderVar m_var;
  170. ShaderUniform m_uniform;
  171. };
  172. //-------------------------------------------------------------------------
  173. TextureImage* m_font = nullptr;
  174. ShaderBuilder m_builder = ShaderBuilder("imgui_shader", "120");
  175. Shader* m_shader = nullptr;
  176. Uniform m_ortho;
  177. Uniform m_texture;
  178. array<ShaderAttrib> m_attribs;
  179. VertexDeclaration* m_vdecl = nullptr;
  180. IndexBuffer* m_ibuff = nullptr;
  181. Controller* m_controller = nullptr;
  182. InputDevice* m_mouse = nullptr;
  183. InputDevice* m_keyboard = nullptr;
  184. InputProfile m_profile;
  185. //std::map<ImGuiKey_, LolImGuiKey> m_keys;
  186. std::string m_clipboard;
  187. };
  188. //-----------------------------------------------------------------------------
  189. class PrimitiveLolImGui : public PrimitiveRenderer
  190. {
  191. public:
  192. PrimitiveLolImGui() { }
  193. virtual void Render(Scene& scene, PrimitiveSource* primitive);
  194. };
  195. //bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks);
  196. //void ImGui_ImplGlfw_Shutdown();
  197. //void ImGui_ImplGlfw_NewFrame();
  198. //
  199. //// Use if you want to reset your rendering device without losing ImGui state.
  200. //void ImGui_ImplGlfw_InvalidateDeviceObjects();
  201. //bool ImGui_ImplGlfw_CreateDeviceObjects();
  202. //
  203. //// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
  204. //// Provided here if you want to chain callbacks.
  205. //// You can also handle inputs yourself and use those as a reference.
  206. //void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
  207. //void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
  208. //void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
  209. //void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
  210. } /* namespace lol */