diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 5454e06..4aaf5df 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -14,7 +14,7 @@ void BufferPane::resize(int width, int height) { Pane::resize(width, height); m_columns = std::max(1, m_width / m_window->font()->get_advance()); - m_rows = std::max(1, m_height / m_window->font()->get_line_height()); + m_rows = std::max(1, (m_height - m_window->font()->get_line_height() - 1) / m_window->font()->get_line_height()); } void BufferPane::walk_line(const Buffer::Iterator & start_of_line, std::function callback) @@ -208,6 +208,7 @@ void BufferPane::draw() { draw_cursor(col_x(0), row_y(0), m_buffer->insert_mode()); } + draw_status_bar(); } int BufferPane::draw_buffer_line(int screen_row, const Buffer::Iterator & start_of_line) @@ -466,3 +467,30 @@ void BufferPane::forward_to_column(int column, bool allow_eol) } }); } + +void BufferPane::draw_status_bar() +{ + m_window->gl()->draw_rect(win_x(0), win_y(m_window->font()->get_line_height()), m_width, 1, 0.5, 0.5, 0.5, 1.0); + m_window->gl()->draw_rect(win_x(0), win_y(0), m_width, m_window->font()->get_line_height(), 0.0, 0.0, 0.0, 1.0); + char cursor_position[20]; + sprintf(cursor_position, "%zu, %zu", display_line(), display_column()); + int cursor_position_length = strlen(cursor_position); + int x = m_width - m_window->font()->get_advance() * cursor_position_length; + m_window->gl()->draw_rect(win_x(x - 2), win_y(0), 1, m_window->font()->get_line_height(), 0.5, 0.5, 0.5, 1.0); + std::string filename = m_buffer->filename(); + if (filename == "") + { + filename = "[No Name]"; + } + int filename_x = std::min(0, x - 3 - (int)filename.size() * m_window->font()->get_advance()); + for (int i = 0; i < cursor_position_length; i++) + { + m_window->gl()->draw_character(win_x(x), win_y(0), cursor_position[i], *m_window->font()); + x += m_window->font()->get_advance(); + } + for (size_t i = 0; i < filename.size(); i++) + { + m_window->gl()->draw_character(win_x(filename_x), win_y(0), filename[i], *m_window->font()); + filename_x += m_window->font()->get_advance(); + } +} diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index de7ae95..ea189af 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -15,9 +15,6 @@ public: void resize(int width, int height) override; void draw(); void handle_key(uint32_t keyval); - size_t display_line() const { return m_iterator->line() + 1u; } - size_t display_column() const; - std::shared_ptr buffer() const { return m_buffer; } protected: enum class CursorMovement : uint8_t @@ -55,6 +52,9 @@ protected: } void cursor_move(CursorMovement which); void forward_to_column(int column, bool allow_eol); + size_t display_line() const { return m_iterator->line() + 1u; } + size_t display_column() const; + void draw_status_bar(); Window * m_window; std::shared_ptr m_buffer; diff --git a/src/gui/BufferStatusPane.cc b/src/gui/BufferStatusPane.cc deleted file mode 100644 index 1270a7d..0000000 --- a/src/gui/BufferStatusPane.cc +++ /dev/null @@ -1,28 +0,0 @@ -#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->display_line(), m_buffer_pane->display_column()); - int cursor_position_length = strlen(cursor_position); - int x = m_width - m_font->get_advance() * cursor_position_length; - m_gl->draw_rect(win_x(x - 2), win_y(0), 1, m_height, 0.5, 0.5, 0.5, 1.0); - std::string filename = m_buffer_pane->buffer()->filename(); - if (filename == "") - { - filename = "[No Name]"; - } - int filename_x = std::min(0, x - 3 - (int)filename.size() * m_font->get_advance()); - 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(); - } - for (size_t i = 0; i < filename.size(); i++) - { - m_gl->draw_character(win_x(filename_x), win_y(0), filename[i], *m_font); - filename_x += m_font->get_advance(); - } -} diff --git a/src/gui/BufferStatusPane.h b/src/gui/BufferStatusPane.h deleted file mode 100644 index 2424e45..0000000 --- a/src/gui/BufferStatusPane.h +++ /dev/null @@ -1,25 +0,0 @@ -#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 2c16cd6..962eaba 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -2,7 +2,6 @@ #include "Window.h" #include "Runtime.h" #include "BufferPane.h" -#include "BufferStatusPane.h" #define INITIAL_WIDTH 800 #define INITIAL_HEIGHT 800 @@ -122,7 +121,6 @@ bool Window::create(std::shared_ptr buffer) glClearColor (0.0, 0.0, 0.0, 0.0); m_buffer_pane = std::make_shared(this, buffer); - m_buffer_status_pane = std::make_shared(m_buffer_pane, m_font, m_gl); resize(); @@ -243,11 +241,8 @@ 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); - 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); + m_buffer_pane->move(0, 0); + m_buffer_pane->resize(m_width, m_height); } void Window::redraw() @@ -255,7 +250,6 @@ void Window::redraw() glClear(GL_COLOR_BUFFER_BIT); m_buffer_pane->draw(); - m_buffer_status_pane->draw(); SDL_GL_SwapWindow(m_window); } diff --git a/src/gui/Window.h b/src/gui/Window.h index 28a637f..c0b30d2 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -50,7 +50,6 @@ protected: std::shared_ptr m_gl; std::shared_ptr m_buffer_pane; - std::shared_ptr m_buffer_status_pane; Uint16 m_keymod; };