From 6d8c8e76a9a553735c5f64d3f0000681a002cea3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 13 Sep 2016 21:46:31 -0400 Subject: [PATCH] add colrow_to_xy() and refactor to use it --- src/gui/Window.cc | 24 ++++++++++++------------ src/gui/Window.h | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/gui/Window.cc b/src/gui/Window.cc index 42e6dbc..bc1df57 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -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(); +} diff --git a/src/gui/Window.h b/src/gui/Window.h index 677845e..036b543 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -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);