|
|
@ -49,6 +49,9 @@ UITextEdit::UITextEdit()
|
|
|
|
m_updatesEnabled = true;
|
|
|
|
m_updatesEnabled = true;
|
|
|
|
m_selectionColor = Color::white;
|
|
|
|
m_selectionColor = Color::white;
|
|
|
|
m_selectionBackgroundColor = Color::black;
|
|
|
|
m_selectionBackgroundColor = Color::black;
|
|
|
|
|
|
|
|
m_glyphsTextCoordsBuffer.enableHardwareCaching();
|
|
|
|
|
|
|
|
m_glyphsSelectCoordsBuffer.enableHardwareCaching();
|
|
|
|
|
|
|
|
m_glyphsMustRecache = true;
|
|
|
|
blinkCursor();
|
|
|
|
blinkCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -62,39 +65,37 @@ void UITextEdit::drawSelf(Fw::DrawPane drawPane)
|
|
|
|
drawImage(m_rect);
|
|
|
|
drawImage(m_rect);
|
|
|
|
drawIcon(m_rect);
|
|
|
|
drawIcon(m_rect);
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: text rendering could be much optimized by using vertex buffer or caching the render into a texture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int textLength = m_text.length();
|
|
|
|
int textLength = m_text.length();
|
|
|
|
const TexturePtr& texture = m_font->getTexture();
|
|
|
|
const TexturePtr& texture = m_font->getTexture();
|
|
|
|
if(!texture)
|
|
|
|
if(!texture)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if(hasSelection()) {
|
|
|
|
bool glyphsMustRecache = m_glyphsMustRecache;
|
|
|
|
|
|
|
|
if(glyphsMustRecache)
|
|
|
|
|
|
|
|
m_glyphsMustRecache = false;
|
|
|
|
|
|
|
|
|
|
|
|
if(m_color != Color::alpha) {
|
|
|
|
if(m_color != Color::alpha) {
|
|
|
|
|
|
|
|
if(glyphsMustRecache) {
|
|
|
|
|
|
|
|
m_glyphsTextCoordsBuffer.clear();
|
|
|
|
|
|
|
|
for(int i=0;i<textLength;++i)
|
|
|
|
|
|
|
|
m_glyphsTextCoordsBuffer.addRect(m_glyphsCoords[i], m_glyphsTexCoords[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
g_painter->setColor(m_color);
|
|
|
|
g_painter->setColor(m_color);
|
|
|
|
for(int i=0;i<m_selectionStart;++i)
|
|
|
|
g_painter->drawTextureCoords(m_glyphsTextCoordsBuffer, texture);
|
|
|
|
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=m_selectionStart;i<m_selectionEnd;++i) {
|
|
|
|
if(hasSelection()) {
|
|
|
|
|
|
|
|
if(glyphsMustRecache) {
|
|
|
|
|
|
|
|
m_glyphsSelectCoordsBuffer.clear();
|
|
|
|
|
|
|
|
for(int i=m_selectionStart;i<m_selectionEnd;++i)
|
|
|
|
|
|
|
|
m_glyphsSelectCoordsBuffer.addRect(m_glyphsCoords[i], m_glyphsTexCoords[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
g_painter->setColor(m_selectionBackgroundColor);
|
|
|
|
g_painter->setColor(m_selectionBackgroundColor);
|
|
|
|
g_painter->drawFilledRect(m_glyphsCoords[i]);
|
|
|
|
g_painter->drawFillCoords(m_glyphsSelectCoordsBuffer);
|
|
|
|
g_painter->setColor(m_selectionColor);
|
|
|
|
g_painter->setColor(m_selectionColor);
|
|
|
|
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
|
|
|
g_painter->drawTextureCoords(m_glyphsSelectCoordsBuffer, texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(m_color != Color::alpha) {
|
|
|
|
|
|
|
|
g_painter->setColor(m_color);
|
|
|
|
|
|
|
|
for(int i=m_selectionEnd;i<textLength;++i)
|
|
|
|
|
|
|
|
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(m_color != Color::alpha) {
|
|
|
|
|
|
|
|
g_painter->setColor(m_color);
|
|
|
|
|
|
|
|
for(int i=0;i<textLength;++i)
|
|
|
|
|
|
|
|
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// render cursor
|
|
|
|
// render cursor
|
|
|
|
if(isExplicitlyEnabled() && m_cursorVisible && m_cursorInRange && isActive() && m_cursorPos >= 0) {
|
|
|
|
if(isExplicitlyEnabled() && m_cursorVisible && m_cursorInRange && isActive() && m_cursorPos >= 0) {
|
|
|
|
assert(m_cursorPos <= textLength);
|
|
|
|
assert(m_cursorPos <= textLength);
|
|
|
@ -136,6 +137,9 @@ void UITextEdit::update(bool focusCursor)
|
|
|
|
if(m_rect.isEmpty())
|
|
|
|
if(m_rect.isEmpty())
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// recache coords buffers
|
|
|
|
|
|
|
|
recacheGlyphs();
|
|
|
|
|
|
|
|
|
|
|
|
// map glyphs positions
|
|
|
|
// map glyphs positions
|
|
|
|
Size textBoxSize;
|
|
|
|
Size textBoxSize;
|
|
|
|
const std::vector<Point>& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize);
|
|
|
|
const std::vector<Point>& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize);
|
|
|
@ -360,6 +364,7 @@ void UITextEdit::setSelection(int start, int end)
|
|
|
|
|
|
|
|
|
|
|
|
m_selectionStart = stdext::clamp<int>(start, 0, (int)m_text.length());
|
|
|
|
m_selectionStart = stdext::clamp<int>(start, 0, (int)m_text.length());
|
|
|
|
m_selectionEnd = stdext::clamp<int>(end, 0, (int)m_text.length());
|
|
|
|
m_selectionEnd = stdext::clamp<int>(end, 0, (int)m_text.length());
|
|
|
|
|
|
|
|
recacheGlyphs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UITextEdit::setTextHidden(bool hidden)
|
|
|
|
void UITextEdit::setTextHidden(bool hidden)
|
|
|
|