2013-05-15 09:07:04 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Jeremie Roy. All rights reserved.
|
2013-04-22 16:42:11 -04:00
|
|
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
2013-05-15 09:07:04 -04:00
|
|
|
*/
|
|
|
|
|
2013-11-14 22:10:10 -05:00
|
|
|
#ifndef TEXT_BUFFER_MANAGER_H_HEADER_GUARD
|
|
|
|
#define TEXT_BUFFER_MANAGER_H_HEADER_GUARD
|
2013-05-15 09:01:38 -04:00
|
|
|
|
2013-04-22 16:42:11 -04:00
|
|
|
#include "font_manager.h"
|
|
|
|
|
|
|
|
BGFX_HANDLE(TextBufferHandle);
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-09-21 01:13:58 -04:00
|
|
|
#define MAX_TEXT_BUFFER_COUNT 64
|
|
|
|
|
2013-04-22 16:42:11 -04:00
|
|
|
/// type of vertex and index buffer to use with a TextBuffer
|
2013-06-04 02:16:02 -04:00
|
|
|
struct BufferType
|
2013-04-22 16:42:11 -04:00
|
|
|
{
|
2013-06-04 02:16:02 -04:00
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Static,
|
|
|
|
Dynamic,
|
|
|
|
Transient,
|
|
|
|
};
|
2013-04-22 16:42:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/// special style effect (can be combined)
|
|
|
|
enum TextStyleFlags
|
|
|
|
{
|
2013-05-15 09:21:23 -04:00
|
|
|
STYLE_NORMAL = 0,
|
|
|
|
STYLE_OVERLINE = 1,
|
|
|
|
STYLE_UNDERLINE = 1 << 1,
|
2013-05-15 22:42:39 -04:00
|
|
|
STYLE_STRIKE_THROUGH = 1 << 2,
|
|
|
|
STYLE_BACKGROUND = 1 << 3,
|
2013-04-22 16:42:11 -04:00
|
|
|
};
|
|
|
|
|
2013-05-08 17:55:54 -04:00
|
|
|
struct TextRectangle
|
2013-05-15 09:21:23 -04:00
|
|
|
{
|
2013-05-08 17:55:54 -04:00
|
|
|
float width, height;
|
|
|
|
};
|
|
|
|
|
2013-04-22 16:42:11 -04:00
|
|
|
class TextBuffer;
|
|
|
|
class TextBufferManager
|
|
|
|
{
|
|
|
|
public:
|
2013-05-15 22:42:39 -04:00
|
|
|
TextBufferManager(FontManager* _fontManager);
|
|
|
|
~TextBufferManager();
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-06-04 02:16:02 -04:00
|
|
|
TextBufferHandle createTextBuffer(uint32_t _type, BufferType::Enum _bufferType);
|
2013-05-15 22:42:39 -04:00
|
|
|
void destroyTextBuffer(TextBufferHandle _handle);
|
|
|
|
void submitTextBuffer(TextBufferHandle _handle, uint8_t _id, int32_t _depth = 0);
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-05-15 22:42:39 -04:00
|
|
|
void setStyle(TextBufferHandle _handle, uint32_t _flags = STYLE_NORMAL);
|
|
|
|
void setTextColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
|
|
|
|
void setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-05-15 22:42:39 -04:00
|
|
|
void setOverlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
|
|
|
|
void setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
|
|
|
|
void setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-05-15 22:42:39 -04:00
|
|
|
void setPenPosition(TextBufferHandle _handle, float _x, float _y);
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-05-23 00:34:21 -04:00
|
|
|
/// Append an ASCII/utf-8 string to the buffer using current pen position and color.
|
2013-05-22 11:15:58 -04:00
|
|
|
void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char* _string, const char* _end = NULL);
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-05-23 00:34:21 -04:00
|
|
|
/// Append a wide char unicode string to the buffer using current pen position and color.
|
2013-05-22 11:15:58 -04:00
|
|
|
void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t* _string, const wchar_t* _end = NULL);
|
|
|
|
|
2013-05-23 00:34:21 -04:00
|
|
|
/// Append a whole face of the atlas cube, mostly used for debugging and visualizing atlas.
|
2013-05-17 17:42:59 -04:00
|
|
|
void appendAtlasFace(TextBufferHandle _handle, uint16_t _faceIndex);
|
2013-05-15 09:21:23 -04:00
|
|
|
|
2013-05-23 00:34:21 -04:00
|
|
|
/// Clear the text buffer and reset its state (pen/color).
|
2013-05-15 22:42:39 -04:00
|
|
|
void clearTextBuffer(TextBufferHandle _handle);
|
2013-05-21 08:45:14 -04:00
|
|
|
|
2013-05-23 00:34:21 -04:00
|
|
|
/// Return the rectangular size of the current text buffer (including all its content).
|
2013-05-22 11:15:58 -04:00
|
|
|
TextRectangle getRectangle(TextBufferHandle _handle) const;
|
|
|
|
|
2013-04-22 16:42:11 -04:00
|
|
|
private:
|
2013-05-15 22:42:39 -04:00
|
|
|
struct BufferCache
|
|
|
|
{
|
2013-09-30 00:33:50 -04:00
|
|
|
uint16_t indexBufferHandleIdx;
|
|
|
|
uint16_t vertexBufferHandleIdx;
|
2013-05-15 22:42:39 -04:00
|
|
|
TextBuffer* textBuffer;
|
2013-06-04 02:16:02 -04:00
|
|
|
BufferType::Enum bufferType;
|
2013-05-17 01:03:57 -04:00
|
|
|
uint32_t fontType;
|
2013-05-15 22:42:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
BufferCache* m_textBuffers;
|
2013-09-21 01:13:58 -04:00
|
|
|
bx::HandleAllocT<MAX_TEXT_BUFFER_COUNT> m_textBufferHandles;
|
2013-05-15 22:42:39 -04:00
|
|
|
FontManager* m_fontManager;
|
|
|
|
bgfx::VertexDecl m_vertexDecl;
|
|
|
|
bgfx::UniformHandle u_texColor;
|
|
|
|
bgfx::ProgramHandle m_basicProgram;
|
|
|
|
bgfx::ProgramHandle m_distanceProgram;
|
|
|
|
bgfx::ProgramHandle m_distanceSubpixelProgram;
|
2013-04-22 16:42:11 -04:00
|
|
|
};
|
2013-05-15 09:01:38 -04:00
|
|
|
|
2013-11-14 22:10:10 -05:00
|
|
|
#endif // TEXT_BUFFER_MANAGER_H_HEADER_GUARD
|