Prepare for screen drawing again after Cursor removal.
Add BufferPane::character_width() to handle multi-column characters.
This commit is contained in:
parent
6b27fafb26
commit
bc3309a328
@ -3,11 +3,9 @@
|
|||||||
BufferPane::BufferPane(Window * window, std::shared_ptr<Buffer> buffer)
|
BufferPane::BufferPane(Window * window, std::shared_ptr<Buffer> buffer)
|
||||||
: m_window(window), m_buffer(buffer)
|
: m_window(window), m_buffer(buffer)
|
||||||
{
|
{
|
||||||
m_cursor_row = 0;
|
m_cursor_screen_row = 0;
|
||||||
m_scroll_offset = 5;
|
m_scroll_offset = 5;
|
||||||
#if 0
|
m_iterator = buffer->add_iterator();
|
||||||
m_cursor = buffer->add_cursor();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferPane::resize(int width, int height)
|
void BufferPane::resize(int width, int height)
|
||||||
@ -58,9 +56,11 @@ int BufferPane::screen_rows_above_cursor(int stop_at)
|
|||||||
|
|
||||||
void BufferPane::draw()
|
void BufferPane::draw()
|
||||||
{
|
{
|
||||||
#if 0
|
if (m_iterator->valid())
|
||||||
if (m_cursor->valid())
|
|
||||||
{
|
{
|
||||||
|
Buffer::Iterator i = *m_iterator;
|
||||||
|
i.go_start_of_line();
|
||||||
|
#if 0
|
||||||
update_cursor_row();
|
update_cursor_row();
|
||||||
int screen_row = m_cursor_row - m_cursor->column() / m_columns;
|
int screen_row = m_cursor_row - m_cursor->column() / m_columns;
|
||||||
Buffer::Cursor iter_cursor = *m_cursor;
|
Buffer::Cursor iter_cursor = *m_cursor;
|
||||||
@ -81,12 +81,12 @@ void BufferPane::draw()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
draw_cursor(col_x(0), row_y(0), false);
|
draw_cursor(col_x(0), row_y(0), false);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -115,11 +115,38 @@ void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
|
|||||||
iter_cursor.go_right(true);
|
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)
|
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)),
|
if (character < 0x20u)
|
||||||
character, *m_window->font());
|
{
|
||||||
|
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)
|
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();
|
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);
|
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)
|
void BufferPane::handle_key(uint32_t keyval)
|
||||||
{
|
{
|
||||||
|
@ -36,9 +36,10 @@ protected:
|
|||||||
int screen_rows_above_cursor(int stop_at);
|
int screen_rows_above_cursor(int stop_at);
|
||||||
void update_cursor_row();
|
void update_cursor_row();
|
||||||
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
|
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_buffer_character(int screen_column, int screen_row, uint32_t character);
|
||||||
void draw_cursor(int x, int y, bool insert_mode);
|
void draw_cursor(int x, int y, bool insert_mode);
|
||||||
#endif
|
|
||||||
int col_x(int col)
|
int col_x(int col)
|
||||||
{
|
{
|
||||||
return col * m_window->font()->get_advance();
|
return col * m_window->font()->get_advance();
|
||||||
@ -54,10 +55,8 @@ protected:
|
|||||||
int m_rows;
|
int m_rows;
|
||||||
int m_columns;
|
int m_columns;
|
||||||
int m_scroll_offset;
|
int m_scroll_offset;
|
||||||
int m_cursor_row;
|
int m_cursor_screen_row;
|
||||||
#if 0
|
std::shared_ptr<Buffer::Iterator> m_iterator;
|
||||||
std::shared_ptr<Buffer::Cursor> m_cursor;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user