Gui.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Matrix4x4.h"
  25. #include "IdTable.h"
  26. #include "IdArray.h"
  27. #include "PoolAllocator.h"
  28. #include "Vector2.h"
  29. #include "Resource.h"
  30. #define MAX_GUI_RECTS 64
  31. #define MAX_GUI_TRIANGLES 64
  32. #define MAX_GUI_IMAGES 64
  33. namespace crown
  34. {
  35. typedef Id UniformId;
  36. typedef Id GuiRectId;
  37. typedef Id GuiTriangleId;
  38. typedef Id GuiImageId;
  39. struct Renderer;
  40. struct RenderWorld;
  41. struct Vector3;
  42. struct GuiResource;
  43. struct GuiRect;
  44. struct GuiTriangle;
  45. struct GuiImage;
  46. struct Vector3;
  47. struct Vector2;
  48. struct Color4;
  49. struct Gui
  50. {
  51. Gui(RenderWorld& render_world, GuiResource* gr, Renderer& r);
  52. ~Gui();
  53. Vector2 resolution() const;
  54. void move(const Vector3& pos);
  55. GuiRectId create_rect(const Vector3& pos, const Vector2& size, const Color4& color);
  56. void update_rect(GuiRectId id, const Vector3& pos, const Vector2& size, const Color4& color);
  57. void destroy_rect(GuiRectId id);
  58. GuiTriangleId create_triangle(const Vector2& p1, const Vector2& p2, const Vector2& p3, const Color4& color);
  59. void update_triangle(GuiTriangleId id, const Vector2& p1, const Vector2& p2, const Vector2& p3, const Color4& color);
  60. void destroy_triangle(GuiTriangleId id);
  61. GuiImageId create_image(ResourceId material, const Vector3& pos, const Vector2& size);
  62. void update_image(GuiImageId id, const Vector3& pos, const Vector2& size);
  63. void destroy_image(GuiImageId);
  64. void render();
  65. public:
  66. RenderWorld& m_render_world;
  67. const GuiResource* m_resource;
  68. Renderer& m_r;
  69. Matrix4x4 m_projection;
  70. Matrix4x4 m_pose;
  71. PoolAllocator m_rect_pool;
  72. PoolAllocator m_triangle_pool;
  73. PoolAllocator m_image_pool;
  74. IdArray<MAX_GUI_RECTS, GuiRect*> m_rects;
  75. IdArray<MAX_GUI_TRIANGLES, GuiTriangle*> m_triangles;
  76. IdArray<MAX_GUI_IMAGES, GuiImage*> m_images;
  77. };
  78. } // namespace crown