add colrow_to_xy() and refactor to use it

This commit is contained in:
Josh Holtrop 2016-09-13 21:46:31 -04:00
parent 980ec3a295
commit 6d8c8e76a9
2 changed files with 13 additions and 12 deletions

View File

@ -414,11 +414,9 @@ void Window::draw_text()
void Window::draw_character(int screen_column, int screen_row, uint32_t character)
{
int x, y;
m_shaders.text->use();
int advance = m_font.get_advance();
int line_height = m_font.get_line_height();
int x = screen_column * advance;
int y = m_height - (screen_row + 1) * line_height;
colrow_to_xy(screen_column, screen_row, &x, &y);
auto g = m_font.get_glyph(character);
m_shaders.text->set_position(x, y + m_font.get_baseline_offset());
g->render();
@ -451,10 +449,8 @@ void Window::redraw()
void Window::draw_cursor(int screen_column, int screen_row)
{
int advance = m_font.get_advance();
int line_height = m_font.get_line_height();
int x = screen_column * advance;
int y = m_height - (screen_row + 1) * line_height;
int x, y;
colrow_to_xy(screen_column, screen_row, &x, &y);
m_cursor_array->bind();
m_shaders.flat->use();
m_shaders.flat->set_color(1.0, 0.2, 1.0, 1.0);
@ -464,13 +460,17 @@ void Window::draw_cursor(int screen_column, int screen_row)
void Window::draw_crosshair(int screen_column, int screen_row)
{
int advance = m_font.get_advance();
int line_height = m_font.get_line_height();
int x = screen_column * advance;
int y = m_height - (screen_row + 1) * line_height;
int x, y;
colrow_to_xy(screen_column, screen_row, &x, &y);
m_cursor_array->bind();
m_shaders.flat->use();
m_shaders.flat->set_color(0.1, 0.1, 0.1, 1.0);
m_shaders.flat->set_position(x, y);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
void Window::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

@ -30,6 +30,7 @@ protected:
void redraw();
void draw_cursor(int screen_column, int screen_row);
void draw_crosshair(int screen_column, int screen_row);
void colrow_to_xy(int col, int row, int * x, int * y);
void handle_event(SDL_Event & event);
void handle_key(uint32_t scancode, uint32_t mod);
void cursor_move(int which);