add colrow_to_xy() and refactor to use it
This commit is contained in:
parent
980ec3a295
commit
6d8c8e76a9
@ -414,11 +414,9 @@ void Window::draw_text()
|
|||||||
|
|
||||||
void Window::draw_character(int screen_column, int screen_row, uint32_t character)
|
void Window::draw_character(int screen_column, int screen_row, uint32_t character)
|
||||||
{
|
{
|
||||||
|
int x, y;
|
||||||
m_shaders.text->use();
|
m_shaders.text->use();
|
||||||
int advance = m_font.get_advance();
|
colrow_to_xy(screen_column, screen_row, &x, &y);
|
||||||
int line_height = m_font.get_line_height();
|
|
||||||
int x = screen_column * advance;
|
|
||||||
int y = m_height - (screen_row + 1) * line_height;
|
|
||||||
auto g = m_font.get_glyph(character);
|
auto g = m_font.get_glyph(character);
|
||||||
m_shaders.text->set_position(x, y + m_font.get_baseline_offset());
|
m_shaders.text->set_position(x, y + m_font.get_baseline_offset());
|
||||||
g->render();
|
g->render();
|
||||||
@ -451,10 +449,8 @@ void Window::redraw()
|
|||||||
|
|
||||||
void Window::draw_cursor(int screen_column, int screen_row)
|
void Window::draw_cursor(int screen_column, int screen_row)
|
||||||
{
|
{
|
||||||
int advance = m_font.get_advance();
|
int x, y;
|
||||||
int line_height = m_font.get_line_height();
|
colrow_to_xy(screen_column, screen_row, &x, &y);
|
||||||
int x = screen_column * advance;
|
|
||||||
int y = m_height - (screen_row + 1) * line_height;
|
|
||||||
m_cursor_array->bind();
|
m_cursor_array->bind();
|
||||||
m_shaders.flat->use();
|
m_shaders.flat->use();
|
||||||
m_shaders.flat->set_color(1.0, 0.2, 1.0, 1.0);
|
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)
|
void Window::draw_crosshair(int screen_column, int screen_row)
|
||||||
{
|
{
|
||||||
int advance = m_font.get_advance();
|
int x, y;
|
||||||
int line_height = m_font.get_line_height();
|
colrow_to_xy(screen_column, screen_row, &x, &y);
|
||||||
int x = screen_column * advance;
|
|
||||||
int y = m_height - (screen_row + 1) * line_height;
|
|
||||||
m_cursor_array->bind();
|
m_cursor_array->bind();
|
||||||
m_shaders.flat->use();
|
m_shaders.flat->use();
|
||||||
m_shaders.flat->set_color(0.1, 0.1, 0.1, 1.0);
|
m_shaders.flat->set_color(0.1, 0.1, 0.1, 1.0);
|
||||||
m_shaders.flat->set_position(x, y);
|
m_shaders.flat->set_position(x, y);
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
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();
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ protected:
|
|||||||
void redraw();
|
void redraw();
|
||||||
void draw_cursor(int screen_column, int screen_row);
|
void draw_cursor(int screen_column, int screen_row);
|
||||||
void draw_crosshair(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_event(SDL_Event & event);
|
||||||
void handle_key(uint32_t scancode, uint32_t mod);
|
void handle_key(uint32_t scancode, uint32_t mod);
|
||||||
void cursor_move(int which);
|
void cursor_move(int which);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user