103 line
3.0 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2017—2019 Sam Hocevar <sam@hocevar.net>
  5. // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  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. #include <memory>
  17. //
  18. // The Imgui integration
  19. //
  20. #define IM_VEC2_CLASS_EXTRA \
  21. ImVec2(const lol::vec2 &v) { x = v.x; y = v.y; } \
  22. ImVec2(const lol::ivec2 &v) : ImVec2(lol::vec2(v)) { } \
  23. operator lol::vec2() const { return lol::vec2(x, y); } \
  24. operator lol::ivec2() const { return lol::ivec2(lol::vec2(x, y)); }
  25. #define IM_VEC4_CLASS_EXTRA \
  26. ImVec4(const lol::vec4 &v) { x = v.x; y = v.y; z = v.z; w = v.w; } \
  27. ImVec4(const lol::ivec4 &v) : ImVec4(lol::vec4(v)) { } \
  28. operator lol::vec4() const { return lol::vec4(x, y, z, w); } \
  29. operator lol::ivec4() const { return lol::ivec4(lol::vec4(x, y, z, w)); }
  30. #include "imgui.h"
  31. #undef IM_VEC2_CLASS_EXTRA
  32. #undef IM_VEC4_CLASS_EXTRA
  33. namespace lol
  34. {
  35. class gui : public entity
  36. {
  37. public:
  38. gui(ImFontAtlas *shared_font_atlas);
  39. ~gui();
  40. std::string GetName() const override { return "<gui>"; }
  41. static void init(ImFontAtlas *shared_font_atlas = nullptr);
  42. static void shutdown();
  43. static std::string clipboard();
  44. static void refresh_fonts();
  45. private:
  46. typedef entity super;
  47. protected:
  48. virtual bool init_game() override;
  49. virtual bool init_draw() override;
  50. virtual void tick_game(float seconds) override;
  51. virtual void tick_draw(float seconds, Scene &scene) override;
  52. virtual bool release_game() override;
  53. virtual bool release_draw() override;
  54. static void static_set_clipboard(void *data, const char* text);
  55. static const char* static_get_clipboard(void *data);
  56. static void static_render_draw_lists(ImDrawData* draw_data);
  57. void render_draw_lists(ImDrawData* draw_data);
  58. struct Uniform
  59. {
  60. Uniform() { }
  61. Uniform(ShaderVar var) { m_var = var; }
  62. std::string tostring() const { return m_var.tostring(); }
  63. operator ShaderVar() const { return m_var; }
  64. operator ShaderUniform() const { return m_uniform; }
  65. //--
  66. ShaderVar m_var;
  67. ShaderUniform m_uniform;
  68. };
  69. //-------------------------------------------------------------------------
  70. TextureImage* m_font = nullptr;
  71. ShaderBuilder m_builder = ShaderBuilder("imgui_shader", "120");
  72. std::shared_ptr<Shader> m_shader = nullptr;
  73. Uniform m_ortho;
  74. Uniform m_texture;
  75. array<ShaderAttrib> m_attribs;
  76. std::shared_ptr<VertexDeclaration> m_vdecl;
  77. std::string m_clipboard;
  78. class primitive : public PrimitiveRenderer
  79. {
  80. public:
  81. primitive() { }
  82. virtual void Render(Scene& scene, std::shared_ptr<PrimitiveSource> primitive);
  83. };
  84. };
  85. } /* namespace lol */