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,
|
||||
"title",sol::writeonly_property(&window::set_title),
|
||||
"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",
|
||||
|
@ -19,6 +20,7 @@ void script_system::load(sol::table &ns)
|
|||
"get",&input::get,
|
||||
"mouse_position",sol::readonly_property(&input::mouse_position),
|
||||
"mouse_button",sol::readonly_property(&input::mouse_button),
|
||||
"mouse_pressed",sol::readonly_property(&input::mouse_pressed),
|
||||
"input_string",sol::readonly_property(&input::input_string)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ do
|
|||
|
||||
if (pw.input:get().mouse_button == 1) then
|
||||
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y)
|
||||
-- w.fullscreen = not w.fullscreen
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -12,10 +12,15 @@ public:
|
|||
static input& get();
|
||||
|
||||
point mouse_position() const { return _mouse_position; }
|
||||
|
||||
bool mouse_pressed() const { return _mouse_pressed; }
|
||||
int mouse_button() const { return _mouse_button; }
|
||||
|
||||
|
||||
std::string input_string() const { return _input_string; }
|
||||
|
||||
|
||||
|
||||
~input() = default;
|
||||
|
||||
enum mouse_button_state {
|
||||
|
@ -23,6 +28,8 @@ public:
|
|||
released
|
||||
};
|
||||
|
||||
void reset();
|
||||
|
||||
protected:
|
||||
|
||||
friend class window;
|
||||
|
@ -33,6 +40,7 @@ private:
|
|||
|
||||
point _mouse_position;
|
||||
int _mouse_button;
|
||||
bool _mouse_pressed;
|
||||
|
||||
std::string _input_string;
|
||||
|
||||
|
|
|
@ -18,13 +18,17 @@ public:
|
|||
void set_title(const std::string& title);
|
||||
|
||||
void set_size(const size& s);
|
||||
size size() const;
|
||||
pw::size size() const;
|
||||
|
||||
void set_position(const point& p);
|
||||
point position() const;
|
||||
|
||||
typedef void drop_callback;
|
||||
|
||||
bool fullscreen() const;
|
||||
void set_fullscreen(bool use_fullscreen);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
struct impl;
|
||||
|
|
|
@ -12,5 +12,11 @@ input &input::get()
|
|||
return instance;
|
||||
}
|
||||
|
||||
void input::reset()
|
||||
{
|
||||
_input_string.clear();
|
||||
_mouse_button = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ struct window::impl {
|
|||
|
||||
GLFWwindow *_window = nullptr;
|
||||
|
||||
sizei _old_size;
|
||||
pointi _old_pos;
|
||||
|
||||
// window_context _context;
|
||||
|
||||
static void drop_callback(GLFWwindow* window, int count, const char** paths)
|
||||
|
@ -133,6 +136,10 @@ struct window::impl {
|
|||
if (!glfwWindowShouldClose(_window)) {
|
||||
|
||||
|
||||
// reset input
|
||||
input::get().reset();
|
||||
|
||||
// get new events
|
||||
glfwPollEvents();
|
||||
|
||||
// do other stuff
|
||||
|
@ -179,10 +186,33 @@ struct window::impl {
|
|||
glfwSetWindowPos(_window,x,y);
|
||||
}
|
||||
|
||||
void set_fullscreen()
|
||||
void set_fullscreen(bool use_fullscreen)
|
||||
{
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -225,6 +255,18 @@ point window::position() const
|
|||
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