add fullscreen mode
This commit is contained in:
parent
b2b12b64ab
commit
5160ec4b0b
6 changed files with 183 additions and 120 deletions
|
@ -11,7 +11,8 @@ void script_system::load(sol::table &ns)
|
||||||
"update",&window::update,
|
"update",&window::update,
|
||||||
"title",sol::writeonly_property(&window::set_title),
|
"title",sol::writeonly_property(&window::set_title),
|
||||||
"size",sol::property(&window::size,&window::set_size),
|
"size",sol::property(&window::size,&window::set_size),
|
||||||
"position",sol::property(&window::position,&window::set_position)
|
"position",sol::property(&window::position,&window::set_position),
|
||||||
|
"fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen)
|
||||||
);
|
);
|
||||||
|
|
||||||
ns.new_usertype<input>("input",
|
ns.new_usertype<input>("input",
|
||||||
|
@ -19,6 +20,7 @@ void script_system::load(sol::table &ns)
|
||||||
"get",&input::get,
|
"get",&input::get,
|
||||||
"mouse_position",sol::readonly_property(&input::mouse_position),
|
"mouse_position",sol::readonly_property(&input::mouse_position),
|
||||||
"mouse_button",sol::readonly_property(&input::mouse_button),
|
"mouse_button",sol::readonly_property(&input::mouse_button),
|
||||||
|
"mouse_pressed",sol::readonly_property(&input::mouse_pressed),
|
||||||
"input_string",sol::readonly_property(&input::input_string)
|
"input_string",sol::readonly_property(&input::input_string)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ do
|
||||||
|
|
||||||
if (pw.input:get().mouse_button == 1) then
|
if (pw.input:get().mouse_button == 1) then
|
||||||
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y)
|
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y)
|
||||||
|
-- w.fullscreen = not w.fullscreen
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,13 @@ public:
|
||||||
static input& get();
|
static input& get();
|
||||||
|
|
||||||
point mouse_position() const { return _mouse_position; }
|
point mouse_position() const { return _mouse_position; }
|
||||||
int mouse_button() const { return _mouse_button; }
|
|
||||||
std::string input_string() const { return _input_string; }
|
bool mouse_pressed() const { return _mouse_pressed; }
|
||||||
|
int mouse_button() const { return _mouse_button; }
|
||||||
|
|
||||||
|
|
||||||
|
std::string input_string() const { return _input_string; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
~input() = default;
|
~input() = default;
|
||||||
|
@ -23,6 +28,8 @@ public:
|
||||||
released
|
released
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
friend class window;
|
friend class window;
|
||||||
|
@ -33,6 +40,7 @@ private:
|
||||||
|
|
||||||
point _mouse_position;
|
point _mouse_position;
|
||||||
int _mouse_button;
|
int _mouse_button;
|
||||||
|
bool _mouse_pressed;
|
||||||
|
|
||||||
std::string _input_string;
|
std::string _input_string;
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,17 @@ public:
|
||||||
void set_title(const std::string& title);
|
void set_title(const std::string& title);
|
||||||
|
|
||||||
void set_size(const size& s);
|
void set_size(const size& s);
|
||||||
size size() const;
|
pw::size size() const;
|
||||||
|
|
||||||
void set_position(const point& p);
|
void set_position(const point& p);
|
||||||
point position() const;
|
point position() const;
|
||||||
|
|
||||||
typedef void drop_callback;
|
typedef void drop_callback;
|
||||||
|
|
||||||
|
bool fullscreen() const;
|
||||||
|
void set_fullscreen(bool use_fullscreen);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct impl;
|
struct impl;
|
||||||
|
|
|
@ -12,5 +12,11 @@ input &input::get()
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void input::reset()
|
||||||
|
{
|
||||||
|
_input_string.clear();
|
||||||
|
_mouse_button = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@ namespace pw {
|
||||||
|
|
||||||
struct window_context : context
|
struct window_context : context
|
||||||
{
|
{
|
||||||
virtual bool make_current() override;
|
virtual bool make_current() override;
|
||||||
virtual void resize() override;
|
virtual void resize() override;
|
||||||
// virtual context::size size() override;
|
// virtual context::size size() override;
|
||||||
virtual void flush() override;
|
virtual void flush() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool window_context::make_current()
|
bool window_context::make_current()
|
||||||
|
@ -36,158 +36,188 @@ void window_context::flush()
|
||||||
|
|
||||||
struct window::impl {
|
struct window::impl {
|
||||||
|
|
||||||
GLFWwindow *_window = nullptr;
|
GLFWwindow *_window = nullptr;
|
||||||
|
|
||||||
// window_context _context;
|
sizei _old_size;
|
||||||
|
pointi _old_pos;
|
||||||
|
|
||||||
static void drop_callback(GLFWwindow* window, int count, const char** paths)
|
// window_context _context;
|
||||||
{
|
|
||||||
// std::cout << __FUNCTION__ << std::endl;
|
|
||||||
// for (int i = 0; i < count; i++)
|
|
||||||
// std::cout << "\t" << paths[i] << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
static void drop_callback(GLFWwindow* window, int count, const char** paths)
|
||||||
{
|
{
|
||||||
std::cout << __FUNCTION__ << std::endl;
|
// std::cout << __FUNCTION__ << std::endl;
|
||||||
}
|
// for (int i = 0; i < count; i++)
|
||||||
|
// std::cout << "\t" << paths[i] << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
input::get()._mouse_button = button;
|
std::cout << __FUNCTION__ << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << __FUNCTION__ << " " << button << " " << action << " " << mods << std::endl;
|
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
||||||
// input::get()._mouse_position
|
{
|
||||||
}
|
input::get()._mouse_button = button;
|
||||||
|
|
||||||
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
|
std::cout << __FUNCTION__ << " " << button << " " << action << " " << mods << std::endl;
|
||||||
{
|
// input::get()._mouse_position
|
||||||
input::get()._mouse_position = point(xpos,ypos);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
|
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
{
|
{
|
||||||
std::cout << __FUNCTION__ << std::endl;
|
input::get()._mouse_position = point(xpos,ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static void character_callback(GLFWwindow* window, unsigned int codepoint)
|
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
|
||||||
// {
|
{
|
||||||
// std::cout << __FUNCTION__ << std::endl;
|
std::cout << __FUNCTION__ << std::endl;
|
||||||
// }
|
}
|
||||||
|
|
||||||
static void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods)
|
// static void character_callback(GLFWwindow* window, unsigned int codepoint)
|
||||||
{
|
// {
|
||||||
// build the string from a Unicode code point
|
// std::cout << __FUNCTION__ << std::endl;
|
||||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
|
// }
|
||||||
std::string u8str = converter.to_bytes(codepoint);
|
|
||||||
|
|
||||||
input::get()._input_string = u8str;
|
static void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods)
|
||||||
}
|
{
|
||||||
|
// build the string from a Unicode code point
|
||||||
|
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
|
||||||
|
std::string u8str = converter.to_bytes(codepoint);
|
||||||
|
|
||||||
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
input::get()._input_string = u8str;
|
||||||
{
|
}
|
||||||
window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window));
|
|
||||||
// impl->on_resize(width,height);
|
|
||||||
|
|
||||||
// std::cout << "framebuffer " << width << "x" << height << std::endl;
|
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||||
// glViewport(0, 0, width, height);
|
{
|
||||||
}
|
window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window));
|
||||||
|
// impl->on_resize(width,height);
|
||||||
|
|
||||||
impl()
|
// std::cout << "framebuffer " << width << "x" << height << std::endl;
|
||||||
{
|
// glViewport(0, 0, width, height);
|
||||||
glfwInit();
|
}
|
||||||
|
|
||||||
_window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr);
|
impl()
|
||||||
|
{
|
||||||
|
glfwInit();
|
||||||
|
|
||||||
glfwSetWindowUserPointer(_window,this);
|
_window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr);
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
|
glfwSetWindowUserPointer(_window,this);
|
||||||
glfwSetKeyCallback(_window, window::impl::key_callback);
|
|
||||||
// glfwSetCharCallback(_window, character_callback);
|
|
||||||
glfwSetCharModsCallback(_window, charmods_callback);
|
|
||||||
glfwSetScrollCallback(_window, scroll_callback);
|
|
||||||
|
|
||||||
glfwSetDropCallback(_window, drop_callback);
|
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
|
||||||
|
glfwSetKeyCallback(_window, window::impl::key_callback);
|
||||||
|
// glfwSetCharCallback(_window, character_callback);
|
||||||
|
glfwSetCharModsCallback(_window, charmods_callback);
|
||||||
|
glfwSetScrollCallback(_window, scroll_callback);
|
||||||
|
|
||||||
glfwSetCursorPosCallback(_window, cursor_pos_callback);
|
glfwSetDropCallback(_window, drop_callback);
|
||||||
glfwSetMouseButtonCallback(_window, mouse_button_callback);
|
|
||||||
glfwSetScrollCallback(_window, scroll_callback);
|
glfwSetCursorPosCallback(_window, cursor_pos_callback);
|
||||||
|
glfwSetMouseButtonCallback(_window, mouse_button_callback);
|
||||||
|
glfwSetScrollCallback(_window, scroll_callback);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
glfwMakeContextCurrent(_window);
|
glfwMakeContextCurrent(_window);
|
||||||
|
|
||||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~impl()
|
~impl()
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(_window);
|
glfwDestroyWindow(_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update()
|
bool update()
|
||||||
{
|
{
|
||||||
if (!glfwWindowShouldClose(_window)) {
|
if (!glfwWindowShouldClose(_window)) {
|
||||||
|
|
||||||
|
|
||||||
glfwPollEvents();
|
// reset input
|
||||||
|
input::get().reset();
|
||||||
|
|
||||||
// do other stuff
|
// get new events
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
|
// do other stuff
|
||||||
#if 0
|
#if 0
|
||||||
glClearColor(1,0,0,1);
|
glClearColor(1,0,0,1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glfwSwapBuffers(_window);
|
glfwSwapBuffers(_window);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_title(const std::string& title)
|
void set_title(const std::string& title)
|
||||||
{
|
{
|
||||||
glfwSetWindowTitle(_window,title.c_str());
|
glfwSetWindowTitle(_window,title.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_size(int w,int h)
|
void set_size(int w,int h)
|
||||||
{
|
{
|
||||||
glfwSetWindowSize(_window,w,h);
|
glfwSetWindowSize(_window,w,h);
|
||||||
}
|
}
|
||||||
|
|
||||||
::pw::size size() const
|
::pw::size size() const
|
||||||
{
|
{
|
||||||
int w,h;
|
int w,h;
|
||||||
glfwGetWindowSize(_window,&w,&h);
|
glfwGetWindowSize(_window,&w,&h);
|
||||||
return ::pw::size(w,h);
|
return ::pw::size(w,h);
|
||||||
}
|
}
|
||||||
|
|
||||||
::pw::point position() const
|
::pw::point position() const
|
||||||
{
|
{
|
||||||
int x,y;
|
int x,y;
|
||||||
glfwGetWindowPos(_window,&x,&y);
|
glfwGetWindowPos(_window,&x,&y);
|
||||||
return ::pw::point(x,y);
|
return ::pw::point(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_position(int x,int y)
|
void set_position(int x,int y)
|
||||||
{
|
{
|
||||||
glfwSetWindowPos(_window,x,y);
|
glfwSetWindowPos(_window,x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_fullscreen()
|
void set_fullscreen(bool use_fullscreen)
|
||||||
{
|
{
|
||||||
// glfwSetWindow
|
if (fullscreen() == use_fullscreen)
|
||||||
}
|
return;
|
||||||
|
|
||||||
|
if (use_fullscreen)
|
||||||
|
{
|
||||||
|
glfwGetWindowPos( _window, &_old_pos.x, &_old_pos.y );
|
||||||
|
glfwGetWindowSize( _window, &_old_size.width, &_old_size.height );
|
||||||
|
|
||||||
|
GLFWmonitor * monitor = glfwGetPrimaryMonitor();
|
||||||
|
const GLFWvidmode * mode = glfwGetVideoMode(monitor);
|
||||||
|
|
||||||
|
glfwSetWindowMonitor( _window, monitor, 0, 0, mode->width, mode->height, 0 );
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
|
||||||
|
glfwSetWindowMonitor( _window, nullptr, _old_pos.x,_old_pos.y, _old_size.width,_old_size.height,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// glfwSetWindow
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fullscreen() const {
|
||||||
|
return glfwGetWindowMonitor(_window) != nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
window::window()
|
window::window()
|
||||||
: _impl(std::make_unique<window::impl>())
|
: _impl(std::make_unique<window::impl>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,34 +227,46 @@ window::~window()
|
||||||
|
|
||||||
bool window::update()
|
bool window::update()
|
||||||
{
|
{
|
||||||
return _impl->update();
|
return _impl->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void window::set_title(const std::string& title)
|
void window::set_title(const std::string& title)
|
||||||
{
|
{
|
||||||
_impl->set_title(title);
|
_impl->set_title(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window::set_size(const ::pw::size& s)
|
void window::set_size(const ::pw::size& s)
|
||||||
{
|
{
|
||||||
_impl->set_size(static_cast<int>(std::round(s.width)),static_cast<int>(std::round(s.height)));
|
_impl->set_size(static_cast<int>(std::round(s.width)),static_cast<int>(std::round(s.height)));
|
||||||
}
|
}
|
||||||
|
|
||||||
size window::size() const
|
size window::size() const
|
||||||
{
|
{
|
||||||
return _impl->size();
|
return _impl->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void window::set_position(const point &p)
|
void window::set_position(const point &p)
|
||||||
{
|
{
|
||||||
_impl->set_position(p.x,p.y);
|
_impl->set_position(p.x,p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
point window::position() const
|
point window::position() const
|
||||||
{
|
{
|
||||||
return _impl->position();
|
return _impl->position();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool window::fullscreen() const
|
||||||
|
{
|
||||||
|
return _impl->fullscreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void window::set_fullscreen(bool use_fullscreen)
|
||||||
|
{
|
||||||
|
_impl->set_fullscreen(use_fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue