Draw cursor again

This commit is contained in:
Josh Holtrop 2016-12-11 15:58:31 -05:00
parent 3d57b03af7
commit 129716e28f
3 changed files with 35 additions and 20 deletions

View File

@ -75,6 +75,10 @@ public:
{
return m_iterator < other.m_iterator;
}
bool operator==(const Cursor & other) const
{
return (m_line == other.m_line) && (m_column == other.m_column);
}
uint32_t operator*() const { return *m_iterator; }
uint8_t * address() const { return m_iterator.address(); }
bool valid() const { return m_iterator.valid(); }

View File

@ -56,25 +56,34 @@ int BufferPane::screen_rows_above_cursor(int stop_at)
void BufferPane::draw()
{
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))
if (m_cursor->valid())
{
Buffer::Cursor cursor2 = iter_cursor;
cursor2.go_end_of_line(false);
screen_row -= (1 + cursor2.column() / m_columns);
}
while (screen_row < m_rows)
{
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))
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))
{
break;
Buffer::Cursor cursor2 = iter_cursor;
cursor2.go_end_of_line(false);
screen_row -= (1 + cursor2.column() / m_columns);
}
while (screen_row < m_rows)
{
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))
{
break;
}
}
}
else
{
int x, y;
colrow_to_xy(0, 0, &x, &y);
draw_cursor(x, y, false);
}
}
@ -91,6 +100,10 @@ void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
int draw_column = iter_cursor.column() % m_columns;
int x, y;
colrow_to_xy(draw_column, draw_row, &x, &y);
if (iter_cursor == *m_cursor)
{
draw_cursor(x, y, false);
}
uint32_t c = *iter_cursor;
if ((c != '\t') && (c != ' '))
{
@ -107,10 +120,8 @@ void BufferPane::draw_buffer_character(int screen_column, int screen_row, uint32
m_gl->draw_character(win_x(x), win_y(y), character, *m_font);
}
void BufferPane::draw_cursor(int screen_column, int screen_row, bool insert_mode)
void BufferPane::draw_cursor(int x, int y, bool insert_mode)
{
int x, y;
colrow_to_xy(screen_column, screen_row, &x, &y);
int width = insert_mode ? 1 : m_font->get_advance();
int height = m_font->get_line_height();
m_gl->draw_rect(win_x(x), win_y(y), width, height, 1.0, 0.2, 1.0, 1.0);

View File

@ -27,7 +27,7 @@ protected:
void update_cursor_row();
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
void draw_buffer_character(int screen_column, int screen_row, uint32_t character);
void draw_cursor(int screen_column, int screen_row, bool insert_mode);
void draw_cursor(int x, int y, bool insert_mode);
void colrow_to_xy(int col, int row, int * x, int * y);
std::shared_ptr<Buffer> m_buffer;