From ee37616f823c61248dc9f5d43a3b3d831b869355 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 13 Dec 2016 21:48:04 -0500 Subject: [PATCH] Give BufferPane a reference to a Window --- src/gui/BufferPane.cc | 22 ++++++++++------------ src/gui/BufferPane.h | 12 +++++------- src/gui/Window.cc | 4 +++- src/gui/Window.h | 7 +++++-- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index f2523d4..33b9f9b 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -1,9 +1,7 @@ #include "BufferPane.h" -BufferPane::BufferPane(std::shared_ptr buffer, - std::shared_ptr font, - std::shared_ptr gl) - : m_buffer(buffer), m_font(font), m_gl(gl) +BufferPane::BufferPane(Window * window, std::shared_ptr buffer) + : m_window(window), m_buffer(buffer) { m_cursor_row = 0; m_scroll_offset = 5; @@ -13,8 +11,8 @@ BufferPane::BufferPane(std::shared_ptr buffer, void BufferPane::resize(int width, int height) { Pane::resize(width, height); - m_columns = std::max(1, m_width / m_font->get_advance()); - m_rows = std::max(1, (m_height + m_font->get_line_height() - 1) / m_font->get_line_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() - 1) / m_window->font()->get_line_height()); } 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; 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); } @@ -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) { - m_gl->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)), - character, *m_font); + m_window->gl()->draw_character(win_x(col_x(screen_column)), win_y(row_y(screen_row)), + character, *m_window->font()); } void BufferPane::draw_cursor(int x, int y, bool insert_mode) { - int width = insert_mode ? 1 : m_font->get_advance(); - int height = m_font->get_line_height(); - m_gl->draw_rect(win_x(x), win_y(y), width, height, 1.0, 0.2, 1.0, 1.0); + int width = insert_mode ? 1 : m_window->font()->get_advance(); + int height = m_window->font()->get_line_height(); + 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) diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index 40395cc..cb886e1 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -6,13 +6,12 @@ #include "Font.h" #include "GL.h" #include +#include "Window.h" class BufferPane : public Pane { public: - BufferPane(std::shared_ptr buffer, - std::shared_ptr font, - std::shared_ptr gl); + BufferPane(Window * window, std::shared_ptr buffer); void resize(int width, int height) override; void draw(); std::shared_ptr cursor() { return m_cursor; } @@ -41,17 +40,16 @@ protected: void draw_cursor(int x, int y, bool insert_mode); int col_x(int col) { - return col * m_font->get_advance(); + return col * m_window->font()->get_advance(); } 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); + Window * m_window; std::shared_ptr m_buffer; - std::shared_ptr m_font; - std::shared_ptr m_gl; int m_rows; int m_columns; int m_scroll_offset; diff --git a/src/gui/Window.cc b/src/gui/Window.cc index f3b8389..2c16cd6 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -1,6 +1,8 @@ #include "gl3w.h" #include "Window.h" #include "Runtime.h" +#include "BufferPane.h" +#include "BufferStatusPane.h" #define INITIAL_WIDTH 800 #define INITIAL_HEIGHT 800 @@ -119,7 +121,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_pane = std::make_shared(this, buffer); m_buffer_status_pane = std::make_shared(m_buffer_pane, m_font, m_gl); resize(); diff --git a/src/gui/Window.h b/src/gui/Window.h index d5bb2d7..417fe82 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -7,8 +7,9 @@ #include "Font.h" #include "Buffer.h" #include "GL.h" -#include "BufferPane.h" -#include "BufferStatusPane.h" + +class BufferPane; +class BufferStatusPane; class Window { @@ -16,6 +17,8 @@ public: bool create(std::shared_ptr buffer); void run_event_loop(); void request_redraw() { m_redraw_requested = true; } + std::shared_ptr font() const { return m_font; } + std::shared_ptr gl() const { return m_gl; } protected: enum : uint32_t