add some utility functions in preparation for drawing screen with multi-column characters
This commit is contained in:
parent
bc3309a328
commit
cf4723854e
@ -54,12 +54,72 @@ int BufferPane::screen_rows_above_cursor(int stop_at)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line)
|
||||||
|
{
|
||||||
|
int rows = 1;
|
||||||
|
int screen_column = 0;
|
||||||
|
Buffer::Iterator i = start_of_line;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
uint32_t code_point = *i;
|
||||||
|
if ((code_point == '\n') || (!i.valid()))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int c_width = character_width(code_point);
|
||||||
|
if (((screen_column + c_width) > m_columns) &&
|
||||||
|
(c_width <= m_columns))
|
||||||
|
{
|
||||||
|
rows++;
|
||||||
|
screen_column = c_width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
screen_column += c_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BufferPane::rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset)
|
||||||
|
{
|
||||||
|
int rows = 1;
|
||||||
|
int screen_column = 0;
|
||||||
|
Buffer::Iterator i = start_of_line;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
uint32_t code_point = *i;
|
||||||
|
if ((code_point == '\n') || (!i.valid()))
|
||||||
|
{
|
||||||
|
if (screen_column == m_columns)
|
||||||
|
{
|
||||||
|
*iterator_row_offset = rows;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*iterator_row_offset = rows - 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int c_width = character_width(code_point);
|
||||||
|
if (((screen_column + c_width) > m_columns) &&
|
||||||
|
(c_width <= m_columns))
|
||||||
|
{
|
||||||
|
rows++;
|
||||||
|
screen_column = c_width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
screen_column += c_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
void BufferPane::draw()
|
void BufferPane::draw()
|
||||||
{
|
{
|
||||||
if (m_iterator->valid())
|
if (m_iterator->valid())
|
||||||
{
|
{
|
||||||
Buffer::Iterator i = *m_iterator;
|
|
||||||
i.go_start_of_line();
|
|
||||||
#if 0
|
#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;
|
||||||
|
@ -40,6 +40,8 @@ protected:
|
|||||||
int character_width(uint32_t character);
|
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);
|
||||||
|
int rows_in_line(const Buffer::Iterator & start_of_line);
|
||||||
|
int rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset);
|
||||||
int col_x(int col)
|
int col_x(int col)
|
||||||
{
|
{
|
||||||
return col * m_window->font()->get_advance();
|
return col * m_window->font()->get_advance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user