Prepare for screen drawing again after Cursor removal.

Add BufferPane::character_width() to handle multi-column characters.
This commit is contained in:
Josh Holtrop 2016-12-20 20:22:19 -05:00
parent 6b27fafb26
commit bc3309a328
2 changed files with 40 additions and 15 deletions

View File

@ -3,11 +3,9 @@
BufferPane::BufferPane(Window * window, std::shared_ptr<Buffer> buffer)
: m_window(window), m_buffer(buffer)
{
m_cursor_row = 0;
m_cursor_screen_row = 0;
m_scroll_offset = 5;
#if 0
m_cursor = buffer->add_cursor();
#endif
m_iterator = buffer->add_iterator();
}
void BufferPane::resize(int width, int height)
@ -58,9 +56,11 @@ int BufferPane::screen_rows_above_cursor(int stop_at)
void BufferPane::draw()
{
#if 0
if (m_cursor->valid())
if (m_iterator->valid())
{
Buffer::Iterator i = *m_iterator;
i.go_start_of_line();
#if 0
update_cursor_row();
int screen_row = m_cursor_row - m_cursor->column() / m_columns;
Buffer::Cursor iter_cursor = *m_cursor;
@ -81,12 +81,12 @@ void BufferPane::draw()
break;
}
}
#endif
}
else
{
draw_cursor(col_x(0), row_y(0), false);
}
#endif
}
#if 0
@ -115,11 +115,38 @@ void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
iter_cursor.go_right(true);
}
}
#endif
int BufferPane::character_width(uint32_t character)
{
if (character < 0x20u)
{
return 2;
}
else if (character < 0x80u)
{
return 1u;
}
else
{
return std::max(1, m_window->font()->get_glyph(character)->get_advance() / m_window->font()->get_advance());
}
}
void BufferPane::draw_buffer_character(int screen_column, int screen_row, uint32_t character)
{
m_window->gl()->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)),
character, *m_window->font());
if (character < 0x20u)
{
m_window->gl()->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)),
'^', *m_window->font());
m_window->gl()->draw_character(win_x(col_x(screen_column + 1)), win_y(row_y(screen_row)),
(character - 0x20u + 'A'), *m_window->font());
}
else
{
m_window->gl()->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)),
character, *m_window->font());
}
}
void BufferPane::draw_cursor(int x, int y, bool insert_mode)
@ -128,7 +155,6 @@ void BufferPane::draw_cursor(int x, int y, bool insert_mode)
int height = m_window->font()->get_line_height();
m_window->gl()->draw_rect(win_x(x), win_y(y), width, height, 1.0, 0.2, 1.0, 1.0);
}
#endif
void BufferPane::handle_key(uint32_t keyval)
{

View File

@ -36,9 +36,10 @@ protected:
int screen_rows_above_cursor(int stop_at);
void update_cursor_row();
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
#endif
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);
#endif
int col_x(int col)
{
return col * m_window->font()->get_advance();
@ -54,10 +55,8 @@ protected:
int m_rows;
int m_columns;
int m_scroll_offset;
int m_cursor_row;
#if 0
std::shared_ptr<Buffer::Cursor> m_cursor;
#endif
int m_cursor_screen_row;
std::shared_ptr<Buffer::Iterator> m_iterator;
};
#endif