Add Keyboard input and enter support for text editor.
This commit is contained in:
parent
cf9bace272
commit
9301769d58
23 changed files with 315 additions and 121 deletions
|
@ -44,13 +44,16 @@ void OpenGlTextPainter::initializeShader()
|
|||
|
||||
void OpenGlTextPainter::initializeTextures(const TextData& textData, DrawingContext* context)
|
||||
{
|
||||
for (auto c : textData.mContent)
|
||||
for (auto line : textData.mLines)
|
||||
{
|
||||
if (auto iter = mFontTextures.find(c); iter == mFontTextures.end())
|
||||
for (auto c : line)
|
||||
{
|
||||
auto glyph = context->getFontsManager()->getGlyph(textData.mFont.getFaceName(), textData.mFont.getSize(), c);
|
||||
auto new_texture = std::make_unique<OpenGlFontTexture>(glyph);
|
||||
mFontTextures[c] = std::move(new_texture);
|
||||
if (auto iter = mFontTextures.find(c); iter == mFontTextures.end())
|
||||
{
|
||||
auto glyph = context->getFontsManager()->getGlyph(textData.mFont.getFaceName(), textData.mFont.getSize(), c);
|
||||
auto new_texture = std::make_unique<OpenGlFontTexture>(glyph);
|
||||
mFontTextures[c] = std::move(new_texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,36 +107,43 @@ void OpenGlTextPainter::paint(SceneText* text, DrawingContext* context)
|
|||
|
||||
auto transform = text->getTransform();
|
||||
|
||||
float x = transform.getLocation().getX();
|
||||
const float y = height - transform.getLocation().getY();
|
||||
for (auto c : text_data.mContent)
|
||||
float line_delta = 20;
|
||||
float line_offset = 0;
|
||||
for (auto line : text_data.mLines)
|
||||
{
|
||||
auto texture = mFontTextures[c].get();
|
||||
float x = transform.getLocation().getX();
|
||||
const float y = height - line_offset - transform.getLocation().getY();
|
||||
for (auto c : line)
|
||||
{
|
||||
auto texture = mFontTextures[c].get();
|
||||
|
||||
float xpos = x + texture->getGlyph()->getBearingX();
|
||||
float ypos = y - (texture->getGlyph()->getHeight() - texture->getGlyph()->getBearingY());
|
||||
float xpos = x + texture->getGlyph()->getBearingX();
|
||||
float ypos = y - (texture->getGlyph()->getHeight() - texture->getGlyph()->getBearingY());
|
||||
|
||||
float w = texture->getGlyph()->getWidth();
|
||||
float h = texture->getGlyph()->getHeight();
|
||||
float vertices[6][4] = {
|
||||
{ xpos, ypos + h, 0.0f, 0.0f },
|
||||
{ xpos, ypos, 0.0f, 1.0f },
|
||||
{ xpos + w, ypos, 1.0f, 1.0f },
|
||||
float w = texture->getGlyph()->getWidth();
|
||||
float h = texture->getGlyph()->getHeight();
|
||||
float vertices[6][4] = {
|
||||
{ xpos, ypos + h, 0.0f, 0.0f },
|
||||
{ xpos, ypos, 0.0f, 1.0f },
|
||||
{ xpos + w, ypos, 1.0f, 1.0f },
|
||||
|
||||
{ xpos, ypos + h, 0.0f, 0.0f },
|
||||
{ xpos + w, ypos, 1.0f, 1.0f },
|
||||
{ xpos + w, ypos + h, 1.0f, 0.0f }
|
||||
};
|
||||
{ xpos, ypos + h, 0.0f, 0.0f },
|
||||
{ xpos + w, ypos, 1.0f, 1.0f },
|
||||
{ xpos + w, ypos + h, 1.0f, 0.0f }
|
||||
};
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getHandle());
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getHandle());
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
x += (texture->getGlyph()->getAdvanceX() >> 6); // bitshift by 6 to get value in pixels (2^6 = 64)
|
||||
x += (texture->getGlyph()->getAdvanceX() >> 6); // bitshift by 6 to get value in pixels (2^6 = 64)
|
||||
}
|
||||
|
||||
line_offset += line_delta;
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue