text_buffer_manager.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2013 Jeremie Roy. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef __TEXT_BUFFER_MANAGER_H__
  6. #define __TEXT_BUFFER_MANAGER_H__
  7. #include "font_manager.h"
  8. BGFX_HANDLE(TextBufferHandle);
  9. /// type of vertex and index buffer to use with a TextBuffer
  10. struct BufferType
  11. {
  12. enum Enum
  13. {
  14. Static,
  15. Dynamic,
  16. Transient,
  17. };
  18. };
  19. /// special style effect (can be combined)
  20. enum TextStyleFlags
  21. {
  22. STYLE_NORMAL = 0,
  23. STYLE_OVERLINE = 1,
  24. STYLE_UNDERLINE = 1 << 1,
  25. STYLE_STRIKE_THROUGH = 1 << 2,
  26. STYLE_BACKGROUND = 1 << 3,
  27. };
  28. struct TextRectangle
  29. {
  30. float width, height;
  31. };
  32. class TextBuffer;
  33. class TextBufferManager
  34. {
  35. public:
  36. TextBufferManager(FontManager* _fontManager);
  37. ~TextBufferManager();
  38. TextBufferHandle createTextBuffer(uint32_t _type, BufferType::Enum _bufferType);
  39. void destroyTextBuffer(TextBufferHandle _handle);
  40. void submitTextBuffer(TextBufferHandle _handle, uint8_t _id, int32_t _depth = 0);
  41. void setStyle(TextBufferHandle _handle, uint32_t _flags = STYLE_NORMAL);
  42. void setTextColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  43. void setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  44. void setOverlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  45. void setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  46. void setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
  47. void setPenPosition(TextBufferHandle _handle, float _x, float _y);
  48. /// Append an ASCII/utf-8 string to the buffer using current pen position and color.
  49. void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char* _string, const char* _end = NULL);
  50. /// Append a wide char unicode string to the buffer using current pen position and color.
  51. void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t* _string, const wchar_t* _end = NULL);
  52. /// Append a whole face of the atlas cube, mostly used for debugging and visualizing atlas.
  53. void appendAtlasFace(TextBufferHandle _handle, uint16_t _faceIndex);
  54. /// Clear the text buffer and reset its state (pen/color).
  55. void clearTextBuffer(TextBufferHandle _handle);
  56. /// Return the rectangular size of the current text buffer (including all its content).
  57. TextRectangle getRectangle(TextBufferHandle _handle) const;
  58. private:
  59. struct BufferCache
  60. {
  61. uint16_t indexBufferHandle;
  62. uint16_t vertexBufferHandle;
  63. TextBuffer* textBuffer;
  64. BufferType::Enum bufferType;
  65. uint32_t fontType;
  66. };
  67. BufferCache* m_textBuffers;
  68. bx::HandleAlloc m_textBufferHandles;
  69. FontManager* m_fontManager;
  70. bgfx::VertexDecl m_vertexDecl;
  71. bgfx::UniformHandle u_texColor;
  72. bgfx::UniformHandle u_fontParam;
  73. bgfx::ProgramHandle m_basicProgram;
  74. bgfx::ProgramHandle m_distanceProgram;
  75. bgfx::ProgramHandle m_distanceSubpixelProgram;
  76. };
  77. #endif // __TEXT_BUFFER_MANAGER_H__