Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

202 lignes
6.1 KiB

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