absorb BufferStatusPane logic into BufferPane

This commit is contained in:
Josh Holtrop 2016-12-27 20:54:05 -05:00
parent e6501ec4fc
commit 301fbf09f1
6 changed files with 34 additions and 66 deletions

View File

@ -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<void(int, int, int, int, const Buffer::Iterator &)> 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();
}
}

View File

@ -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> 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<Buffer> m_buffer;

View File

@ -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();
}
}

View File

@ -1,25 +0,0 @@
#ifndef BUFFERSTATUSPANE
#define BUFFERSTATUSPANE
#include <memory>
#include "BufferPane.h"
class BufferStatusPane : public Pane
{
public:
BufferStatusPane(std::shared_ptr<BufferPane> buffer_pane,
std::shared_ptr<Font> font,
std::shared_ptr<GL> gl)
: m_buffer_pane(buffer_pane), m_font(font), m_gl(gl)
{
}
void draw();
protected:
std::shared_ptr<BufferPane> m_buffer_pane;
std::shared_ptr<Font> m_font;
std::shared_ptr<GL> m_gl;
};
#endif

View File

@ -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> buffer)
glClearColor (0.0, 0.0, 0.0, 0.0);
m_buffer_pane = std::make_shared<BufferPane>(this, buffer);
m_buffer_status_pane = std::make_shared<BufferStatusPane>(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);
}

View File

@ -50,7 +50,6 @@ protected:
std::shared_ptr<GL> m_gl;
std::shared_ptr<BufferPane> m_buffer_pane;
std::shared_ptr<BufferStatusPane> m_buffer_status_pane;
Uint16 m_keymod;
};