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

@ -55,6 +55,8 @@ int BufferPane::screen_rows_above_cursor(int stop_at)
}
void BufferPane::draw()
{
if (m_cursor->valid())
{
update_cursor_row();
int screen_row = m_cursor_row - m_cursor->column() / m_columns;
@ -77,6 +79,13 @@ void BufferPane::draw()
}
}
}
else
{
int x, y;
colrow_to_xy(0, 0, &x, &y);
draw_cursor(x, y, false);
}
}
void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
{
@ -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;