start re-implementing BufferPane::draw_buffer_line()
This commit is contained in:
parent
83d4a86e4b
commit
24fced221f
@ -51,6 +51,7 @@ int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line)
|
||||
screen_column += c_width;
|
||||
}
|
||||
}
|
||||
i.go_forward();
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
@ -106,6 +107,7 @@ int BufferPane::rows_in_line_with_iterator_offset(const Buffer::Iterator & start
|
||||
{
|
||||
*iterator_row_offset = rows;
|
||||
}
|
||||
i.go_forward();
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
@ -121,25 +123,27 @@ int BufferPane::screen_rows_below_line(const Buffer::Iterator & line)
|
||||
return rows;
|
||||
}
|
||||
|
||||
int BufferPane::screen_rows_above_line(const Buffer::Iterator & line)
|
||||
int BufferPane::screen_rows_above_line(const Buffer::Iterator & line, std::list<std::pair<int, Buffer::Iterator>> backward_lines)
|
||||
{
|
||||
Buffer::Iterator i = line;
|
||||
int rows = 0;
|
||||
while ((rows < m_rows) && i.go_previous_line())
|
||||
{
|
||||
rows += rows_in_line(i);
|
||||
int rows_in_this_line = rows_in_line(i);
|
||||
rows += rows_in_this_line;
|
||||
backward_lines.push_back(std::pair<int, Buffer::Iterator>(rows_in_this_line, i));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
int BufferPane::update_cursor_row()
|
||||
int BufferPane::update_cursor_row(std::list<std::pair<int, Buffer::Iterator>> backward_lines)
|
||||
{
|
||||
Buffer::Iterator start_of_line = *m_iterator;
|
||||
start_of_line.go_start_of_line();
|
||||
int cursor_row_offset;
|
||||
int rows_in_cursor_line = rows_in_line_with_iterator_offset(start_of_line, *m_iterator, &cursor_row_offset);
|
||||
int so = effective_scroll_offset();
|
||||
int rows_above = screen_rows_above_line(*m_iterator) + cursor_row_offset;
|
||||
int rows_above = screen_rows_above_line(*m_iterator, backward_lines) + cursor_row_offset;
|
||||
int rows_below = screen_rows_below_line(*m_iterator) + std::min(0, rows_in_cursor_line - cursor_row_offset - 1);
|
||||
int min_rows_to_leave_above = std::min(rows_above, so);
|
||||
int min_rows_to_leave_below = std::min(rows_below, so);
|
||||
@ -151,28 +155,31 @@ void BufferPane::draw()
|
||||
{
|
||||
if (m_iterator->valid())
|
||||
{
|
||||
#if 0
|
||||
update_cursor_row();
|
||||
int screen_row = m_cursor_row - m_cursor->column() / m_columns;
|
||||
Buffer::Cursor iter_cursor = *m_cursor;
|
||||
iter_cursor.go_start_of_line();
|
||||
while ((screen_row > 0) && iter_cursor.go_up(0u))
|
||||
std::list<std::pair<int, Buffer::Iterator>> backward_lines;
|
||||
int cursor_row_offset_in_current_line = update_cursor_row(backward_lines);
|
||||
int screen_row = m_cursor_screen_row - cursor_row_offset_in_current_line;
|
||||
Buffer::Iterator i = *m_iterator;
|
||||
if (screen_row <= 0)
|
||||
{
|
||||
Buffer::Cursor cursor2 = iter_cursor;
|
||||
cursor2.go_end_of_line(false);
|
||||
screen_row -= (1 + cursor2.column() / m_columns);
|
||||
i.go_start_of_line();
|
||||
}
|
||||
while (screen_row < m_rows)
|
||||
else for (auto rows_iterator_pair : backward_lines)
|
||||
{
|
||||
draw_buffer_line(screen_row, iter_cursor);
|
||||
iter_cursor.go_end_of_line(false);
|
||||
screen_row += (1 + iter_cursor.column() / m_columns);
|
||||
if (!iter_cursor.go_down(0u))
|
||||
screen_row -= rows_iterator_pair.first;
|
||||
i = rows_iterator_pair.second;
|
||||
if (screen_row <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (screen_row < m_rows)
|
||||
{
|
||||
screen_row += draw_buffer_line(screen_row, i);
|
||||
if (!i.go_next_line())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -180,33 +187,84 @@ void BufferPane::draw()
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
|
||||
int BufferPane::draw_buffer_line(int screen_row, const Buffer::Iterator & start_of_line)
|
||||
{
|
||||
Buffer::Cursor iter_cursor = cursor;
|
||||
while (!iter_cursor.is_end_of_line(true))
|
||||
int row_offset = 0;
|
||||
int screen_column = 0;
|
||||
int virtual_column = 0;
|
||||
Buffer::Iterator i = start_of_line;
|
||||
for (;;)
|
||||
{
|
||||
int draw_row = screen_row + (iter_cursor.column() / m_columns);
|
||||
if (draw_row < 0)
|
||||
continue;
|
||||
if (draw_row >= m_rows)
|
||||
uint32_t code_point = *i;
|
||||
if ((code_point == '\n') || (!i.valid()))
|
||||
{
|
||||
if (i == *m_iterator)
|
||||
{
|
||||
if (screen_column == m_columns)
|
||||
{
|
||||
int x = col_x(0);
|
||||
int y = row_y(screen_row + row_offset + 1);
|
||||
draw_cursor(x, y, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = col_x(screen_column);
|
||||
int y = row_y(screen_row + row_offset);
|
||||
draw_cursor(x, y, false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
int draw_column = iter_cursor.column() % m_columns;
|
||||
int x = col_x(draw_column);
|
||||
int y = row_y(draw_row);
|
||||
if (iter_cursor == *m_cursor)
|
||||
{
|
||||
draw_cursor(x, y, false);
|
||||
}
|
||||
uint32_t c = *iter_cursor;
|
||||
if ((c != '\t') && (c != ' '))
|
||||
else if (code_point == '\t')
|
||||
{
|
||||
m_window->gl()->draw_character(win_x(x), win_y(y), c, *m_window->font());
|
||||
uint8_t tabstop = m_buffer->tabstop();
|
||||
int col_increment = tabstop - screen_column % tabstop;
|
||||
virtual_column += col_increment;
|
||||
screen_column += col_increment;
|
||||
if (screen_column > m_columns)
|
||||
{
|
||||
screen_column -= m_columns;
|
||||
row_offset++;
|
||||
}
|
||||
}
|
||||
iter_cursor.go_right(true);
|
||||
else
|
||||
{
|
||||
int c_width = character_width(code_point);
|
||||
virtual_column += c_width;
|
||||
if (((screen_column + c_width) > m_columns) &&
|
||||
(c_width <= m_columns))
|
||||
{
|
||||
row_offset++;
|
||||
screen_column = c_width;
|
||||
}
|
||||
else
|
||||
{
|
||||
screen_column += c_width;
|
||||
}
|
||||
}
|
||||
int draw_row = screen_row + row_offset;
|
||||
if (draw_row >= m_rows)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (draw_row >= 0)
|
||||
{
|
||||
int x = col_x(screen_column);
|
||||
int y = row_y(screen_row + row_offset);
|
||||
if (i == *m_iterator)
|
||||
{
|
||||
draw_cursor(x, y, false);
|
||||
}
|
||||
uint32_t c = *i;
|
||||
if ((c != '\t') && (c != ' '))
|
||||
{
|
||||
m_window->gl()->draw_character(win_x(x), win_y(y), c, *m_window->font());
|
||||
}
|
||||
}
|
||||
i.go_forward();
|
||||
}
|
||||
return row_offset + 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int BufferPane::character_width(uint32_t character)
|
||||
{
|
||||
|
@ -31,17 +31,15 @@ protected:
|
||||
{
|
||||
return std::min(m_scroll_offset, (m_rows - 1) / 2);
|
||||
}
|
||||
#if 0
|
||||
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
|
||||
#endif
|
||||
int draw_buffer_line(int screen_row, const Buffer::Iterator & start_of_line);
|
||||
int character_width(uint32_t character);
|
||||
void draw_buffer_character(int screen_column, int screen_row, uint32_t character);
|
||||
void draw_cursor(int x, int y, bool insert_mode);
|
||||
int rows_in_line(const Buffer::Iterator & start_of_line);
|
||||
int rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset);
|
||||
int screen_rows_below_line(const Buffer::Iterator & line);
|
||||
int screen_rows_above_line(const Buffer::Iterator & line);
|
||||
int update_cursor_row();
|
||||
int screen_rows_above_line(const Buffer::Iterator & line, std::list<std::pair<int, Buffer::Iterator>> backward_lines);
|
||||
int update_cursor_row(std::list<std::pair<int, Buffer::Iterator>> backward_lines);
|
||||
int col_x(int col)
|
||||
{
|
||||
return col * m_window->font()->get_advance();
|
||||
@ -58,6 +56,7 @@ protected:
|
||||
int m_columns;
|
||||
int m_scroll_offset;
|
||||
int m_cursor_screen_row;
|
||||
int m_cursor_virtual_column;
|
||||
std::shared_ptr<Buffer::Iterator> m_iterator;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user