add resizable window flag and resize window events

This commit is contained in:
2019-10-22 02:19:43 +07:00
parent 0ac38ec3e5
commit 536bdd7a9c
6 changed files with 56 additions and 11 deletions

View File

@@ -132,6 +132,11 @@ namespace e2d
return *this;
}
engine::window_parameters& engine::window_parameters::resizable(bool value) noexcept {
resizable_ = value;
return *this;
}
engine::window_parameters& engine::window_parameters::fullscreen(bool value) noexcept {
fullscreen_ = value;
return *this;
@@ -149,6 +154,10 @@ namespace e2d
return vsync_;
}
bool engine::window_parameters::resizable() const noexcept {
return resizable_;
}
bool engine::window_parameters::fullscreen() const noexcept {
return fullscreen_;
}
@@ -435,6 +444,7 @@ namespace e2d
params.window_params().size(),
params.window_params().caption(),
params.window_params().vsync(),
params.window_params().resizable(),
params.window_params().fullscreen());
the<window>().register_event_listener<window_input_source>(the<input>());

View File

@@ -34,6 +34,14 @@ namespace e2d
E2D_UNUSED(key, scancode, act);
}
void window::event_listener::on_window_size(const v2u& size) noexcept {
E2D_UNUSED(size);
}
void window::event_listener::on_framebuffer_size(const v2u& size) noexcept {
E2D_UNUSED(size);
}
void window::event_listener::on_window_close() noexcept {
}
@@ -77,6 +85,14 @@ namespace e2d
keyboard_key_action_to_cstr(act));
}
void window_trace_event_listener::on_window_size(const v2u& size) noexcept {
debug_.trace("WINDOW: on_window_size(size: %0)", size);
}
void window_trace_event_listener::on_framebuffer_size(const v2u& size) noexcept {
debug_.trace("WINDOW: on_framebuffer_size(size: %0)", size);
}
void window_trace_event_listener::on_window_close() noexcept {
debug_.trace("WINDOW: on_window_close()");
}

View File

@@ -260,10 +260,11 @@ namespace e2d
v2u framebuffer_size;
str title;
bool vsync = false;
bool resizable = false;
bool fullscreen = false;
bool cursor_hidden = false;
public:
state(const v2u& size, str_view ntitle, bool nvsync, bool nfullscreen)
state(const v2u& size, str_view ntitle, bool nvsync, bool nresizable, bool nfullscreen)
: shared_state(glfw_state::get_shared_state())
, window(nullptr, glfwDestroyWindow)
, real_size(size)
@@ -271,12 +272,14 @@ namespace e2d
, framebuffer_size(size)
, title(ntitle)
, vsync(nvsync)
, resizable(nresizable)
, fullscreen(nfullscreen)
{
window = open_window_(
size,
make_utf8(ntitle),
vsync,
resizable,
fullscreen);
if ( !window ) {
@@ -295,7 +298,7 @@ namespace e2d
glfwSetKeyCallback(window.get(), keyboard_key_callback_);
glfwSetWindowSizeCallback(window.get(), window_size_callback_);
glfwSetFramebufferSizeCallback(window.get(), window_framebuffer_callback_);
glfwSetFramebufferSizeCallback(window.get(), framebuffer_size_callback_);
glfwSetWindowCloseCallback(window.get(), window_close_callback_);
glfwSetWindowFocusCallback(window.get(), window_focus_callback_);
@@ -345,6 +348,7 @@ namespace e2d
const v2u& virtual_size,
const str& title,
bool vsync,
bool resizable,
bool fullscreen) noexcept
{
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
@@ -355,11 +359,11 @@ namespace e2d
if ( !video_mode ) {
return {nullptr, glfwDestroyWindow};
}
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_RESIZABLE, resizable ? GLFW_TRUE : GLFW_FALSE);
#if defined(E2D_BUILD_MODE) && E2D_BUILD_MODE == E2D_BUILD_MODE_DEBUG
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
#endif
v2i real_size = fullscreen
? make_vec2(video_mode->width, video_mode->height)
@@ -432,14 +436,20 @@ namespace e2d
state* self = static_cast<state*>(glfwGetWindowUserPointer(window));
if ( self ) {
self->update_window_size();
self->for_all_listeners(
&event_listener::on_window_size,
make_vec2(w,h).cast_to<u32>());
}
}
static void window_framebuffer_callback_(GLFWwindow* window, int w, int h) noexcept {
static void framebuffer_size_callback_(GLFWwindow* window, int w, int h) noexcept {
E2D_UNUSED(w, h);
state* self = static_cast<state*>(glfwGetWindowUserPointer(window));
if ( self ) {
self->update_framebuffer_size();
self->for_all_listeners(
&event_listener::on_framebuffer_size,
make_vec2(w,h).cast_to<u32>());
}
}
@@ -474,8 +484,8 @@ namespace e2d
// class window
//
window::window(const v2u& size, str_view title, bool vsync, bool fullscreen)
: state_(new state(size, title, vsync, fullscreen)) {}
window::window(const v2u& size, str_view title, bool vsync, bool resizable, bool fullscreen)
: state_(new state(size, title, vsync, resizable, fullscreen)) {}
window::~window() noexcept = default;
void window::hide() noexcept {

View File

@@ -19,6 +19,7 @@ namespace e2d
v2u virtual_size;
str title;
bool vsync = false;
bool resizable = false;
bool fullscreen = false;
bool cursor_hidden = false;
bool should_close = false;
@@ -27,10 +28,11 @@ namespace e2d
bool focused = true;
bool minimized = false;
public:
state(const v2u& size, str_view title, bool vsync, bool fullscreen)
state(const v2u& size, str_view title, bool vsync, bool resizable, bool fullscreen)
: virtual_size(size)
, title(make_utf8(title))
, vsync(vsync)
, resizable(resizable)
, fullscreen(fullscreen) {}
~state() noexcept = default;
@@ -45,8 +47,8 @@ namespace e2d
}
};
window::window(const v2u& size, str_view title, bool vsync, bool fullscreen)
: state_(new state(size, title, vsync, fullscreen)) {}
window::window(const v2u& size, str_view title, bool vsync, bool resizable, bool fullscreen)
: state_(new state(size, title, vsync, resizable, fullscreen)) {}
window::~window() noexcept = default;
void window::hide() noexcept {