Wrap lines
This commit is contained in:
parent
10a0b33dbe
commit
31422709e8
@ -247,6 +247,9 @@ void Window::resize()
|
|||||||
glViewport(0, 0, m_width, m_height);
|
glViewport(0, 0, m_width, m_height);
|
||||||
m_programs.text->use();
|
m_programs.text->use();
|
||||||
m_programs.text->set_viewport_size(m_width, m_height);
|
m_programs.text->set_viewport_size(m_width, m_height);
|
||||||
|
m_chars_per_line = m_width / m_font.get_advance();
|
||||||
|
if (m_chars_per_line < 1)
|
||||||
|
m_chars_per_line = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::redraw()
|
void Window::redraw()
|
||||||
@ -258,21 +261,33 @@ void Window::redraw()
|
|||||||
|
|
||||||
int advance = m_font.get_advance();
|
int advance = m_font.get_advance();
|
||||||
int line_height = m_font.get_line_height();
|
int line_height = m_font.get_line_height();
|
||||||
|
int x = 0;
|
||||||
int y = m_height - line_height;
|
int y = m_height - line_height;
|
||||||
for (PieceTable::PieceDescriptor * pd = m_start_piece;
|
for (PieceTable::PieceDescriptor * pd = m_start_piece;
|
||||||
pd != m_buffer->piece_table->end_descriptor;
|
pd != m_buffer->piece_table->end_descriptor;
|
||||||
pd = pd->next)
|
pd = pd->next)
|
||||||
{
|
{
|
||||||
int x = 0;
|
|
||||||
for (int i = 0, len = pd->length; i < len; i++)
|
for (int i = 0, len = pd->length; i < len; i++)
|
||||||
{
|
{
|
||||||
uint8_t c = pd->start[i];
|
uint8_t c = pd->start[i];
|
||||||
auto g = m_font.get_glyph(c);
|
auto g = m_font.get_glyph(c);
|
||||||
m_programs.text->set_position(x, y);
|
m_programs.text->set_position(x, y);
|
||||||
g->render();
|
g->render();
|
||||||
x += advance;
|
if ((i + 1) % m_chars_per_line == 0)
|
||||||
|
{
|
||||||
|
y -= line_height;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x += advance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pd->eol())
|
||||||
|
{
|
||||||
|
y -= line_height;
|
||||||
|
x = 0;
|
||||||
}
|
}
|
||||||
y -= line_height;
|
|
||||||
if (y + line_height < 0)
|
if (y + line_height < 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -29,6 +29,7 @@ protected:
|
|||||||
} m_programs;
|
} m_programs;
|
||||||
|
|
||||||
Font m_font;
|
Font m_font;
|
||||||
|
int m_chars_per_line;
|
||||||
|
|
||||||
std::shared_ptr<Buffer> m_buffer;
|
std::shared_ptr<Buffer> m_buffer;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user