gui.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "math_types.h"
  25. #include "color4.h"
  26. #include "render_world_types.h"
  27. #include "material.h"
  28. #include <bgfx.h>
  29. namespace crown
  30. {
  31. class RenderWorld;
  32. /// Manages the rendering of GUI objects.
  33. ///
  34. /// @ingroup Graphics
  35. struct Gui
  36. {
  37. Gui(uint16_t width, uint16_t height, const char* material);
  38. const GuiId id() const;
  39. void set_id(const GuiId id);
  40. Vector2 resolution() const;
  41. void move(const Vector2& pos);
  42. Vector2 screen_to_gui(const Vector2& pos);
  43. /// Draws a rectangle of size @a size at @a pos.
  44. /// @note Higher values of pos.z make the object appear in front of other objects.
  45. void draw_rectangle(const Vector3& pos, const Vector2& size, const Color4& color = Color4::WHITE);
  46. /// Draws an image with the given @a material.
  47. /// @note Higher values of pos.z make the object appear in front of other objects.
  48. void draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color = Color4::WHITE);
  49. /// Draws an image with the given @a material and @a uv0 and @a uv1 coordinates.
  50. /// @note Higher values of pos.z make the object appear in front of other objects.
  51. void draw_image_uv(const char* material, const Vector3& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, const Color4& color = Color4::WHITE);
  52. /// Draws the text @a str with the given @a font and @a font_size.
  53. /// @note Higher values of pos.z make the object appear in front of other objects.
  54. void draw_text(const char* str, const char* font, uint32_t font_size, const Vector3& pos, const Color4& color = Color4::WHITE);
  55. public:
  56. GuiId m_id;
  57. uint16_t m_width;
  58. uint16_t m_height;
  59. typedef Id MaterialId;
  60. MaterialId m_material;
  61. Matrix4x4 m_projection;
  62. Matrix4x4 m_pose;
  63. static void init();
  64. private:
  65. static bgfx::VertexDecl s_pos_col;
  66. static bgfx::VertexDecl s_pos_col_tex;
  67. };
  68. } // namespace crown