Add BufferStatusPane
move status bar drawing logic from Window to BufferStatusPane
This commit is contained in:
parent
8bffc05f09
commit
8631a94a2b
16
src/gui/BufferStatusPane.cc
Normal file
16
src/gui/BufferStatusPane.cc
Normal file
@ -0,0 +1,16 @@
|
||||
#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->cursor()->line() + 1, m_buffer_pane->cursor()->column() + 1u);
|
||||
int cursor_position_length = strlen(cursor_position);
|
||||
int x = m_width - m_font->get_advance() * cursor_position_length;
|
||||
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();
|
||||
}
|
||||
}
|
25
src/gui/BufferStatusPane.h
Normal file
25
src/gui/BufferStatusPane.h
Normal file
@ -0,0 +1,25 @@
|
||||
#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
|
@ -120,6 +120,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_status_pane = std::make_shared<BufferStatusPane>(m_buffer_pane, m_font, m_gl);
|
||||
|
||||
resize();
|
||||
|
||||
@ -340,8 +341,11 @@ 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);
|
||||
m_buffer_pane->move(0, m_font->get_line_height() + 1);
|
||||
m_buffer_pane->resize(m_width, m_height - m_font->get_line_height() - 1);
|
||||
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);
|
||||
}
|
||||
|
||||
void Window::redraw()
|
||||
@ -349,26 +353,11 @@ void Window::redraw()
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
m_buffer_pane->draw();
|
||||
draw_status_bar();
|
||||
m_buffer_status_pane->draw();
|
||||
|
||||
SDL_GL_SwapWindow(m_window);
|
||||
}
|
||||
|
||||
void Window::draw_status_bar()
|
||||
{
|
||||
m_gl->draw_rect(0, m_font->get_line_height(), m_width, 1, 0.5, 0.5, 0.5, 1.0);
|
||||
m_gl->draw_rect(0, 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->cursor()->line() + 1, m_buffer_pane->cursor()->column() + 1u);
|
||||
int cursor_position_length = strlen(cursor_position);
|
||||
int x = m_width - m_font->get_advance() * cursor_position_length;
|
||||
for (int i = 0; i < cursor_position_length; i++)
|
||||
{
|
||||
m_gl->draw_character(x, 0, cursor_position[i], *m_font);
|
||||
x += m_font->get_advance();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Window::get_keyval(SDL_Keycode keysym)
|
||||
{
|
||||
uint32_t keyval = keysym;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "Buffer.h"
|
||||
#include "GL.h"
|
||||
#include "BufferPane.h"
|
||||
#include "BufferStatusPane.h"
|
||||
|
||||
class Window
|
||||
{
|
||||
@ -40,7 +41,6 @@ protected:
|
||||
void handle_keysym(uint32_t keysym);
|
||||
void handle_keyval(uint32_t keyval);
|
||||
void cursor_move(int which);
|
||||
void draw_status_bar();
|
||||
uint32_t get_keyval(SDL_Keycode keysym);
|
||||
uint32_t get_shifted(uint32_t keysym);
|
||||
|
||||
@ -55,6 +55,7 @@ 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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user