Give BufferPane a reference to a Window
This commit is contained in:
parent
659a64b367
commit
ee37616f82
@ -1,9 +1,7 @@
|
||||
#include "BufferPane.h"
|
||||
|
||||
BufferPane::BufferPane(std::shared_ptr<Buffer> buffer,
|
||||
std::shared_ptr<Font> font,
|
||||
std::shared_ptr<GL> gl)
|
||||
: m_buffer(buffer), m_font(font), m_gl(gl)
|
||||
BufferPane::BufferPane(Window * window, std::shared_ptr<Buffer> 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> 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)
|
||||
|
@ -6,13 +6,12 @@
|
||||
#include "Font.h"
|
||||
#include "GL.h"
|
||||
#include <memory>
|
||||
#include "Window.h"
|
||||
|
||||
class BufferPane : public Pane
|
||||
{
|
||||
public:
|
||||
BufferPane(std::shared_ptr<Buffer> buffer,
|
||||
std::shared_ptr<Font> font,
|
||||
std::shared_ptr<GL> gl);
|
||||
BufferPane(Window * window, std::shared_ptr<Buffer> buffer);
|
||||
void resize(int width, int height) override;
|
||||
void draw();
|
||||
std::shared_ptr<Buffer::Cursor> 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<Buffer> m_buffer;
|
||||
std::shared_ptr<Font> m_font;
|
||||
std::shared_ptr<GL> m_gl;
|
||||
int m_rows;
|
||||
int m_columns;
|
||||
int m_scroll_offset;
|
||||
|
@ -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> buffer)
|
||||
|
||||
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);
|
||||
|
||||
resize();
|
||||
|
@ -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> buffer);
|
||||
void run_event_loop();
|
||||
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:
|
||||
enum : uint32_t
|
||||
|
Loading…
x
Reference in New Issue
Block a user