2013-05-15 17:07:04 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Jeremie Roy. All rights reserved.
|
2013-04-23 00:42:11 +04:00
|
|
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
2013-05-15 17:07:04 +04:00
|
|
|
*/
|
|
|
|
|
2013-05-15 17:01:38 +04:00
|
|
|
#ifndef __TEXT_BUFFER_MANAGER_H__
|
|
|
|
#define __TEXT_BUFFER_MANAGER_H__
|
|
|
|
|
2013-04-23 00:42:11 +04:00
|
|
|
#include "font_manager.h"
|
|
|
|
|
|
|
|
BGFX_HANDLE(TextBufferHandle);
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-04-23 00:42:11 +04:00
|
|
|
/// type of vertex and index buffer to use with a TextBuffer
|
|
|
|
enum BufferType
|
|
|
|
{
|
|
|
|
STATIC,
|
2013-05-15 17:21:23 +04:00
|
|
|
DYNAMIC,
|
2013-04-23 00:42:11 +04:00
|
|
|
TRANSIENT
|
|
|
|
};
|
|
|
|
|
|
|
|
/// special style effect (can be combined)
|
|
|
|
enum TextStyleFlags
|
|
|
|
{
|
2013-05-15 17:21:23 +04:00
|
|
|
STYLE_NORMAL = 0,
|
|
|
|
STYLE_OVERLINE = 1,
|
|
|
|
STYLE_UNDERLINE = 1 << 1,
|
2013-05-16 06:42:39 +04:00
|
|
|
STYLE_STRIKE_THROUGH = 1 << 2,
|
|
|
|
STYLE_BACKGROUND = 1 << 3,
|
2013-04-23 00:42:11 +04:00
|
|
|
};
|
|
|
|
|
2013-05-09 01:55:54 +04:00
|
|
|
struct TextRectangle
|
2013-05-15 17:21:23 +04:00
|
|
|
{
|
2013-05-09 01:55:54 +04:00
|
|
|
float width, height;
|
|
|
|
};
|
|
|
|
|
2013-04-23 00:42:11 +04:00
|
|
|
class TextBuffer;
|
|
|
|
class TextBufferManager
|
|
|
|
{
|
|
|
|
public:
|
2013-05-16 06:42:39 +04:00
|
|
|
TextBufferManager(FontManager* _fontManager);
|
|
|
|
~TextBufferManager();
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
TextBufferHandle createTextBuffer(FontType _type, BufferType _bufferType);
|
|
|
|
void destroyTextBuffer(TextBufferHandle _handle);
|
|
|
|
void submitTextBuffer(TextBufferHandle _handle, uint8_t _id, int32_t _depth = 0);
|
|
|
|
void submitTextBufferMask(TextBufferHandle _handle, uint32_t _viewMask, int32_t _depth = 0);
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06: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 17:21:23 +04:00
|
|
|
|
2013-05-16 06: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 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
void setPenPosition(TextBufferHandle _handle, float _x, float _y);
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
/// append an ASCII/utf-8 string to the buffer using current pen position and color
|
|
|
|
void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char* _string);
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
/// append a wide char unicode string to the buffer using current pen position and color
|
|
|
|
void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t* _string);
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
/// Clear the text buffer and reset its state (pen/color)
|
|
|
|
void clearTextBuffer(TextBufferHandle _handle);
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
TextRectangle getRectangle(TextBufferHandle _handle) const;
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
/// return the size of the text
|
|
|
|
//Rectangle measureText(FontHandle fontHandle, const char * _string);
|
|
|
|
//Rectangle measureText(FontHandle fontHandle, const wchar_t * _string);
|
2013-04-23 00:42:11 +04:00
|
|
|
|
|
|
|
private:
|
2013-05-15 17:21:23 +04:00
|
|
|
|
2013-05-16 06:42:39 +04:00
|
|
|
struct BufferCache
|
|
|
|
{
|
|
|
|
uint16_t indexBufferHandle;
|
|
|
|
uint16_t vertexBufferHandle;
|
|
|
|
TextBuffer* textBuffer;
|
|
|
|
BufferType bufferType;
|
|
|
|
FontType fontType;
|
|
|
|
};
|
|
|
|
|
|
|
|
BufferCache* m_textBuffers;
|
|
|
|
bx::HandleAlloc m_textBufferHandles;
|
|
|
|
FontManager* m_fontManager;
|
|
|
|
bgfx::VertexDecl m_vertexDecl;
|
|
|
|
bgfx::UniformHandle u_texColor;
|
|
|
|
bgfx::UniformHandle u_inverse_gamma;
|
|
|
|
//shaders program
|
|
|
|
bgfx::ProgramHandle m_basicProgram;
|
|
|
|
bgfx::ProgramHandle m_distanceProgram;
|
|
|
|
bgfx::ProgramHandle m_distanceSubpixelProgram;
|
|
|
|
|
|
|
|
float m_height;
|
|
|
|
float m_width;
|
2013-04-23 00:42:11 +04:00
|
|
|
};
|
2013-05-15 17:01:38 +04:00
|
|
|
|
|
|
|
#endif // __TEXT_BUFFER_MANAGER_H__
|