From ec9b47d1136d7063666dc0aa548bf790f8b55a19 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 19 Jan 2017 21:48:02 -0500 Subject: [PATCH] Add cursor crosshairs --- src/gui/BufferPane.cc | 48 ++++++++++++++++++++++++++++++++++++++++++- src/gui/BufferPane.h | 1 + 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 58e3865..242c964 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -310,6 +310,33 @@ int BufferPane::draw_buffer_line(int screen_row, const Buffer::Iterator & start_ int draw_row = screen_row + row_offset; 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) { 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)) { 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() { if (insert_mode()) diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index 5f50bdf..e798b1c 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -46,6 +46,7 @@ protected: void draw_character(uint32_t character, int screen_row, int screen_column); int character_width(uint32_t character); 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_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);