Give BufferPane a reference to a Window

This commit is contained in:
Josh Holtrop 2016-12-13 21:48:04 -05:00
parent 659a64b367
commit ee37616f82
4 changed files with 23 additions and 22 deletions

View File

@ -1,9 +1,7 @@
#include "BufferPane.h" #include "BufferPane.h"
BufferPane::BufferPane(std::shared_ptr<Buffer> buffer, BufferPane::BufferPane(Window * window, std::shared_ptr<Buffer> buffer)
std::shared_ptr<Font> font, : m_window(window), m_buffer(buffer)
std::shared_ptr<GL> gl)
: m_buffer(buffer), m_font(font), m_gl(gl)
{ {
m_cursor_row = 0; m_cursor_row = 0;
m_scroll_offset = 5; m_scroll_offset = 5;
@ -13,8 +11,8 @@ BufferPane::BufferPane(std::shared_ptr<Buffer> buffer,
void BufferPane::resize(int width, int height) void BufferPane::resize(int width, int height)
{ {
Pane::resize(width, height); Pane::resize(width, height);
m_columns = std::max(1, m_width / m_font->get_advance()); m_columns = std::max(1, m_width / m_window->font()->get_advance());
m_rows = std::max(1, (m_height + m_font->get_line_height() - 1) / m_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::update_cursor_row() void BufferPane::update_cursor_row()
@ -105,7 +103,7 @@ void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
uint32_t c = *iter_cursor; uint32_t c = *iter_cursor;
if ((c != '\t') && (c != ' ')) if ((c != '\t') && (c != ' '))
{ {
m_gl->draw_character(win_x(x), win_y(y), c, *m_font); m_window->gl()->draw_character(win_x(x), win_y(y), c, *m_window->font());
} }
iter_cursor.go_right(true); iter_cursor.go_right(true);
} }
@ -113,15 +111,15 @@ void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
void BufferPane::draw_buffer_character(int screen_column, int screen_row, uint32_t character) void BufferPane::draw_buffer_character(int screen_column, int screen_row, uint32_t character)
{ {
m_gl->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)), m_window->gl()->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)),
character, *m_font); character, *m_window->font());
} }
void BufferPane::draw_cursor(int x, int y, bool insert_mode) void BufferPane::draw_cursor(int x, int y, bool insert_mode)
{ {
int width = insert_mode ? 1 : m_font->get_advance(); int width = insert_mode ? 1 : m_window->font()->get_advance();
int height = m_font->get_line_height(); int height = m_window->font()->get_line_height();
m_gl->draw_rect(win_x(x), win_y(y), width, height, 1.0, 0.2, 1.0, 1.0); m_window->gl()->draw_rect(win_x(x), win_y(y), width, height, 1.0, 0.2, 1.0, 1.0);
} }
void BufferPane::handle_key(uint32_t keyval) void BufferPane::handle_key(uint32_t keyval)

View File

@ -6,13 +6,12 @@
#include "Font.h" #include "Font.h"
#include "GL.h" #include "GL.h"
#include <memory> #include <memory>
#include "Window.h"
class BufferPane : public Pane class BufferPane : public Pane
{ {
public: public:
BufferPane(std::shared_ptr<Buffer> buffer, BufferPane(Window * window, std::shared_ptr<Buffer> buffer);
std::shared_ptr<Font> font,
std::shared_ptr<GL> gl);
void resize(int width, int height) override; void resize(int width, int height) override;
void draw(); void draw();
std::shared_ptr<Buffer::Cursor> cursor() { return m_cursor; } std::shared_ptr<Buffer::Cursor> cursor() { return m_cursor; }
@ -41,17 +40,16 @@ protected:
void draw_cursor(int x, int y, bool insert_mode); void draw_cursor(int x, int y, bool insert_mode);
int col_x(int col) int col_x(int col)
{ {
return col * m_font->get_advance(); return col * m_window->font()->get_advance();
} }
int row_y(int row) int row_y(int row)
{ {
return m_height - (row + 1) * m_font->get_line_height(); return m_height - (row + 1) * m_window->font()->get_line_height();
} }
void cursor_move(CursorMovement which); void cursor_move(CursorMovement which);
Window * m_window;
std::shared_ptr<Buffer> m_buffer; std::shared_ptr<Buffer> m_buffer;
std::shared_ptr<Font> m_font;
std::shared_ptr<GL> m_gl;
int m_rows; int m_rows;
int m_columns; int m_columns;
int m_scroll_offset; int m_scroll_offset;

View File

@ -1,6 +1,8 @@
#include "gl3w.h" #include "gl3w.h"
#include "Window.h" #include "Window.h"
#include "Runtime.h" #include "Runtime.h"
#include "BufferPane.h"
#include "BufferStatusPane.h"
#define INITIAL_WIDTH 800 #define INITIAL_WIDTH 800
#define INITIAL_HEIGHT 800 #define INITIAL_HEIGHT 800
@ -119,7 +121,7 @@ bool Window::create(std::shared_ptr<Buffer> buffer)
glClearColor (0.0, 0.0, 0.0, 0.0); glClearColor (0.0, 0.0, 0.0, 0.0);
m_buffer_pane = std::make_shared<BufferPane>(buffer, m_font, m_gl); m_buffer_pane = std::make_shared<BufferPane>(this, buffer);
m_buffer_status_pane = std::make_shared<BufferStatusPane>(m_buffer_pane, m_font, m_gl); m_buffer_status_pane = std::make_shared<BufferStatusPane>(m_buffer_pane, m_font, m_gl);
resize(); resize();

View File

@ -7,8 +7,9 @@
#include "Font.h" #include "Font.h"
#include "Buffer.h" #include "Buffer.h"
#include "GL.h" #include "GL.h"
#include "BufferPane.h"
#include "BufferStatusPane.h" class BufferPane;
class BufferStatusPane;
class Window class Window
{ {
@ -16,6 +17,8 @@ public:
bool create(std::shared_ptr<Buffer> buffer); bool create(std::shared_ptr<Buffer> buffer);
void run_event_loop(); void run_event_loop();
void request_redraw() { m_redraw_requested = true; } void request_redraw() { m_redraw_requested = true; }
std::shared_ptr<Font> font() const { return m_font; }
std::shared_ptr<GL> gl() const { return m_gl; }
protected: protected:
enum : uint32_t enum : uint32_t