Add cursor crosshairs

This commit is contained in:
Josh Holtrop 2017-01-19 21:48:02 -05:00
parent be201ab73d
commit ec9b47d113
2 changed files with 48 additions and 1 deletions

View File

@ -310,6 +310,33 @@ int BufferPane::draw_buffer_line(int screen_row, const Buffer::Iterator & start_
int draw_row = screen_row + row_offset; int draw_row = screen_row + row_offset;
if ((draw_row >= 0) && (draw_row <= m_rows)) if ((draw_row >= 0) && (draw_row <= m_rows))
{ {
if (i.line() == m_iterator->line())
{
int row = draw_row;
int col = screen_column;
for (int i = 0; i < character_width; i++)
{
draw_crosshair(col_x(col), row_y(row));
col++;
if (col >= m_columns)
{
row++;
col = 0;
}
}
}
else if ((m_cursor_virtual_column >= virtual_column) &&
(m_cursor_virtual_column < (virtual_column + std::max(character_width, 1))))
{
int col = screen_column + (m_cursor_virtual_column - virtual_column);
int row = draw_row;
while (screen_column >= m_columns)
{
screen_column -= m_columns;
row++;
}
draw_crosshair(col_x(col), row_y(row));
}
if (i == *m_iterator) if (i == *m_iterator)
{ {
bool wrap = (code_point == '\t'); bool wrap = (code_point == '\t');
@ -327,7 +354,19 @@ int BufferPane::draw_buffer_line(int screen_row, const Buffer::Iterator & start_
} }
} }
} }
draw_character(code_point, draw_row, screen_column); if ((code_point == '\n') || (code_point == Buffer::Iterator::INVALID_CODE_POINT))
{
if ((m_cursor_virtual_column > virtual_column) &&
(m_cursor_virtual_column < (virtual_column + (m_columns - screen_column))))
{
draw_crosshair(col_x(screen_column + (m_cursor_virtual_column - virtual_column)),
row_y(draw_row));
}
}
else
{
draw_character(code_point, draw_row, screen_column);
}
if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT)) if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT))
{ {
saved_row_offset = row_offset; saved_row_offset = row_offset;
@ -413,6 +452,13 @@ void BufferPane::draw_cursor(int x, int y, int i, int columns)
} }
} }
void BufferPane::draw_crosshair(int x, int y)
{
int width = m_window->font()->get_advance();
int height = m_window->font()->get_line_height();
m_window->gl()->draw_rect(win_x(x), win_y(y), width, height, 0.1, 0.1, 0.1, 1.0);
}
void BufferPane::exit_insert_mode() void BufferPane::exit_insert_mode()
{ {
if (insert_mode()) if (insert_mode())

View File

@ -46,6 +46,7 @@ protected:
void draw_character(uint32_t character, int screen_row, int screen_column); void draw_character(uint32_t character, int screen_row, int screen_column);
int character_width(uint32_t character); int character_width(uint32_t character);
void draw_cursor(int x, int y, int i, int columns); void draw_cursor(int x, int y, int i, int columns);
void draw_crosshair(int x, int y);
int calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line); int calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line);
int calculate_rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset); int calculate_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_below_line(const Buffer::Iterator & line);