diff --git a/src/gui/BufferStatusPane.cc b/src/gui/BufferStatusPane.cc new file mode 100644 index 0000000..7940a94 --- /dev/null +++ b/src/gui/BufferStatusPane.cc @@ -0,0 +1,16 @@ +#include "BufferStatusPane.h" + +void BufferStatusPane::draw() +{ + m_gl->draw_rect(win_x(0), win_y(m_font->get_line_height()), m_width, 1, 0.5, 0.5, 0.5, 1.0); + m_gl->draw_rect(win_x(0), win_y(0), m_width, m_font->get_line_height(), 0.0, 0.0, 0.0, 1.0); + char cursor_position[20]; + sprintf(cursor_position, "%zu, %zu", m_buffer_pane->cursor()->line() + 1, m_buffer_pane->cursor()->column() + 1u); + int cursor_position_length = strlen(cursor_position); + int x = m_width - m_font->get_advance() * cursor_position_length; + for (int i = 0; i < cursor_position_length; i++) + { + m_gl->draw_character(win_x(x), win_y(0), cursor_position[i], *m_font); + x += m_font->get_advance(); + } +} diff --git a/src/gui/BufferStatusPane.h b/src/gui/BufferStatusPane.h new file mode 100644 index 0000000..2424e45 --- /dev/null +++ b/src/gui/BufferStatusPane.h @@ -0,0 +1,25 @@ +#ifndef BUFFERSTATUSPANE +#define BUFFERSTATUSPANE + +#include +#include "BufferPane.h" + +class BufferStatusPane : public Pane +{ +public: + BufferStatusPane(std::shared_ptr buffer_pane, + std::shared_ptr font, + std::shared_ptr gl) + : m_buffer_pane(buffer_pane), m_font(font), m_gl(gl) + { + } + + void draw(); + +protected: + std::shared_ptr m_buffer_pane; + std::shared_ptr m_font; + std::shared_ptr m_gl; +}; + +#endif diff --git a/src/gui/Window.cc b/src/gui/Window.cc index 028c0ce..874dd85 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -120,6 +120,7 @@ bool Window::create(std::shared_ptr buffer) glClearColor (0.0, 0.0, 0.0, 0.0); m_buffer_pane = std::make_shared(buffer, m_font, m_gl); + m_buffer_status_pane = std::make_shared(m_buffer_pane, m_font, m_gl); resize(); @@ -340,8 +341,11 @@ void Window::resize() SDL_GetWindowSize(m_window, &m_width, &m_height); glViewport(0, 0, m_width, m_height); m_gl->resize(m_width, m_height); - m_buffer_pane->move(0, m_font->get_line_height() + 1); - m_buffer_pane->resize(m_width, m_height - m_font->get_line_height() - 1); + int buffer_status_pane_height = m_font->get_line_height() + 1; + m_buffer_pane->move(0, buffer_status_pane_height); + m_buffer_pane->resize(m_width, m_height - buffer_status_pane_height); + m_buffer_status_pane->move(0, 0); + m_buffer_status_pane->resize(m_width, buffer_status_pane_height); } void Window::redraw() @@ -349,26 +353,11 @@ void Window::redraw() glClear(GL_COLOR_BUFFER_BIT); m_buffer_pane->draw(); - draw_status_bar(); + m_buffer_status_pane->draw(); SDL_GL_SwapWindow(m_window); } -void Window::draw_status_bar() -{ - m_gl->draw_rect(0, m_font->get_line_height(), m_width, 1, 0.5, 0.5, 0.5, 1.0); - m_gl->draw_rect(0, 0, m_width, m_font->get_line_height(), 0.0, 0.0, 0.0, 1.0); - char cursor_position[20]; - sprintf(cursor_position, "%zu, %zu", m_buffer_pane->cursor()->line() + 1, m_buffer_pane->cursor()->column() + 1u); - int cursor_position_length = strlen(cursor_position); - int x = m_width - m_font->get_advance() * cursor_position_length; - for (int i = 0; i < cursor_position_length; i++) - { - m_gl->draw_character(x, 0, cursor_position[i], *m_font); - x += m_font->get_advance(); - } -} - uint32_t Window::get_keyval(SDL_Keycode keysym) { uint32_t keyval = keysym; diff --git a/src/gui/Window.h b/src/gui/Window.h index 37317b6..182da2f 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -8,6 +8,7 @@ #include "Buffer.h" #include "GL.h" #include "BufferPane.h" +#include "BufferStatusPane.h" class Window { @@ -40,7 +41,6 @@ protected: void handle_keysym(uint32_t keysym); void handle_keyval(uint32_t keyval); void cursor_move(int which); - void draw_status_bar(); uint32_t get_keyval(SDL_Keycode keysym); uint32_t get_shifted(uint32_t keysym); @@ -55,6 +55,7 @@ protected: std::shared_ptr m_gl; std::shared_ptr m_buffer_pane; + std::shared_ptr m_buffer_status_pane; Uint16 m_keymod; };