handle window resizes
This commit is contained in:
parent
de31e97556
commit
5999d62660
@ -121,7 +121,7 @@ bool Window::create(std::shared_ptr<Buffer> buffer)
|
|||||||
m_command_buffer_pane->set_command_mode();
|
m_command_buffer_pane->set_command_mode();
|
||||||
m_command_buffer_screen_rows = 1;
|
m_command_buffer_screen_rows = 1;
|
||||||
|
|
||||||
resize();
|
resize(INITIAL_WIDTH, INITIAL_HEIGHT);
|
||||||
|
|
||||||
m_redraw_requested = true;
|
m_redraw_requested = true;
|
||||||
|
|
||||||
@ -177,6 +177,11 @@ void Window::handle_event(Jtk_Event & event)
|
|||||||
m_redraw_requested = true;
|
m_redraw_requested = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case JTK_EVENT_WINDOW_RESIZE:
|
||||||
|
resize(event.resize.width, event.resize.height);
|
||||||
|
m_redraw_requested = true;
|
||||||
|
break;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
switch (event.window.event)
|
switch (event.window.event)
|
||||||
@ -355,13 +360,10 @@ void Window::handle_keypress(uint32_t keyval)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::resize()
|
void Window::resize(size_t width, size_t height)
|
||||||
{
|
{
|
||||||
m_width = 800;
|
m_width = width;
|
||||||
m_height = 800;
|
m_height = height;
|
||||||
#if 0
|
|
||||||
SDL_GetWindowSize(m_window, &m_width, &m_height);
|
|
||||||
#endif
|
|
||||||
glViewport(0, 0, m_width, m_height);
|
glViewport(0, 0, m_width, m_height);
|
||||||
m_gl->resize(m_width, m_height);
|
m_gl->resize(m_width, m_height);
|
||||||
int command_buffer_height = m_command_buffer_screen_rows * m_font->get_line_height();
|
int command_buffer_height = m_command_buffer_screen_rows * m_font->get_line_height();
|
||||||
@ -378,7 +380,7 @@ void Window::redraw()
|
|||||||
m_command_buffer_screen_rows = 1;
|
m_command_buffer_screen_rows = 1;
|
||||||
if (m_command_buffer_screen_rows != last_command_buffer_screen_rows)
|
if (m_command_buffer_screen_rows != last_command_buffer_screen_rows)
|
||||||
{
|
{
|
||||||
resize();
|
resize(m_width, m_height);
|
||||||
}
|
}
|
||||||
last_command_buffer_screen_rows = m_command_buffer_screen_rows;
|
last_command_buffer_screen_rows = m_command_buffer_screen_rows;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void resize();
|
void resize(size_t width, size_t height);
|
||||||
void redraw();
|
void redraw();
|
||||||
void handle_event(Jtk_Event & event);
|
void handle_event(Jtk_Event & event);
|
||||||
void handle_keypress(uint32_t keyval);
|
void handle_keypress(uint32_t keyval);
|
||||||
|
@ -260,6 +260,22 @@ static bool ProcessXKeyReleaseEvent(XEvent * x_event, Jtk_Event * event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process an X configure event.
|
||||||
|
*
|
||||||
|
* @param x_event
|
||||||
|
* Pointer to the X event.
|
||||||
|
* @param event
|
||||||
|
* Pointer to the Jtk event.
|
||||||
|
*/
|
||||||
|
static bool ProcessConfigureEvent(XEvent * x_event, Jtk_Event * event)
|
||||||
|
{
|
||||||
|
event->type = JTK_EVENT_WINDOW_RESIZE;
|
||||||
|
event->resize.width = x_event->xconfigure.width;
|
||||||
|
event->resize.height = x_event->xconfigure.height;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process an X event.
|
* Process an X event.
|
||||||
*
|
*
|
||||||
@ -292,6 +308,9 @@ static bool ProcessXEvent(XEvent * x_event, Jtk_Event * event)
|
|||||||
case Expose:
|
case Expose:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ConfigureNotify:
|
||||||
|
return ProcessConfigureEvent(x_event, event);
|
||||||
|
|
||||||
case MappingNotify:
|
case MappingNotify:
|
||||||
XRefreshKeyboardMapping(&x_event->xmapping);
|
XRefreshKeyboardMapping(&x_event->xmapping);
|
||||||
return false;
|
return false;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#define JTK_EVENT_BUTTON_PRESS 5u
|
#define JTK_EVENT_BUTTON_PRESS 5u
|
||||||
#define JTK_EVENT_BUTTON_RELEASE 6u
|
#define JTK_EVENT_BUTTON_RELEASE 6u
|
||||||
#define JTK_EVENT_TIMER 7u
|
#define JTK_EVENT_TIMER 7u
|
||||||
|
#define JTK_EVENT_WINDOW_RESIZE 8u
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -33,6 +34,12 @@ typedef struct
|
|||||||
void * user2;
|
void * user2;
|
||||||
} Jtk_TimerEvent;
|
} Jtk_TimerEvent;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
size_t width;
|
||||||
|
size_t height;
|
||||||
|
} Jtk_WindowResizeEvent;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
@ -41,6 +48,7 @@ typedef struct
|
|||||||
Jtk_KeyEvent key;
|
Jtk_KeyEvent key;
|
||||||
Jtk_ButtonEvent button;
|
Jtk_ButtonEvent button;
|
||||||
Jtk_TimerEvent timer;
|
Jtk_TimerEvent timer;
|
||||||
|
Jtk_WindowResizeEvent resize;
|
||||||
};
|
};
|
||||||
} Jtk_Event;
|
} Jtk_Event;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user