BufferPane: replace colrow_to_xy() with col_x() and row_y()

This commit is contained in:
Josh Holtrop 2016-12-11 19:58:16 -05:00
parent 129716e28f
commit 3422df51d6
2 changed files with 13 additions and 15 deletions

View File

@ -81,9 +81,7 @@ void BufferPane::draw()
} }
else else
{ {
int x, y; draw_cursor(col_x(0), row_y(0), false);
colrow_to_xy(0, 0, &x, &y);
draw_cursor(x, y, false);
} }
} }
@ -98,8 +96,8 @@ void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
if (draw_row >= m_rows) if (draw_row >= m_rows)
break; break;
int draw_column = iter_cursor.column() % m_columns; int draw_column = iter_cursor.column() % m_columns;
int x, y; int x = col_x(draw_column);
colrow_to_xy(draw_column, draw_row, &x, &y); int y = row_y(draw_row);
if (iter_cursor == *m_cursor) if (iter_cursor == *m_cursor)
{ {
draw_cursor(x, y, false); draw_cursor(x, y, false);
@ -115,9 +113,8 @@ void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
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)
{ {
int x, y; m_gl->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)),
colrow_to_xy(screen_column, screen_row, &x, &y); character, *m_font);
m_gl->draw_character(win_x(x), win_y(y), character, *m_font);
} }
void BufferPane::draw_cursor(int x, int y, bool insert_mode) void BufferPane::draw_cursor(int x, int y, bool insert_mode)
@ -126,9 +123,3 @@ void BufferPane::draw_cursor(int x, int y, bool insert_mode)
int height = m_font->get_line_height(); int height = m_font->get_line_height();
m_gl->draw_rect(win_x(x), win_y(y), width, height, 1.0, 0.2, 1.0, 1.0); m_gl->draw_rect(win_x(x), win_y(y), width, height, 1.0, 0.2, 1.0, 1.0);
} }
void BufferPane::colrow_to_xy(int col, int row, int * x, int * y)
{
*x = col * m_font->get_advance();
*y = m_height - (row + 1) * m_font->get_line_height();
}

View File

@ -28,7 +28,14 @@ protected:
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor); void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
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);
void colrow_to_xy(int col, int row, int * x, int * y); int col_x(int col)
{
return col * m_font->get_advance();
}
int row_y(int row)
{
return m_height - (row + 1) * m_font->get_line_height();
}
std::shared_ptr<Buffer> m_buffer; std::shared_ptr<Buffer> m_buffer;
std::shared_ptr<Font> m_font; std::shared_ptr<Font> m_font;