WiP
This commit is contained in:
parent
fdf7714d11
commit
b2b12b64ab
4 changed files with 73 additions and 51 deletions
|
@ -18,7 +18,8 @@ void script_system::load(sol::table &ns)
|
||||||
"new", sol::no_constructor,
|
"new", sol::no_constructor,
|
||||||
"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),
|
||||||
|
"input_string",sol::readonly_property(&input::input_string)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ w.size = pw.size.new(1200,800)
|
||||||
while w:update()
|
while w:update()
|
||||||
do
|
do
|
||||||
|
|
||||||
if (pw.input:get().mouse_button > 0) 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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,16 @@ public:
|
||||||
|
|
||||||
point mouse_position() const { return _mouse_position; }
|
point mouse_position() const { return _mouse_position; }
|
||||||
int mouse_button() const { return _mouse_button; }
|
int mouse_button() const { return _mouse_button; }
|
||||||
|
std::string input_string() const { return _input_string; }
|
||||||
|
|
||||||
|
|
||||||
~input() = default;
|
~input() = default;
|
||||||
|
|
||||||
|
enum mouse_button_state {
|
||||||
|
pressed,
|
||||||
|
released
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
friend class window;
|
friend class window;
|
||||||
|
@ -27,6 +34,9 @@ private:
|
||||||
point _mouse_position;
|
point _mouse_position;
|
||||||
int _mouse_button;
|
int _mouse_button;
|
||||||
|
|
||||||
|
std::string _input_string;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "pw/system/input.hpp"
|
#include "pw/system/input.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <locale>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -16,7 +18,7 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,55 +38,59 @@ struct window::impl {
|
||||||
|
|
||||||
GLFWwindow *_window = nullptr;
|
GLFWwindow *_window = nullptr;
|
||||||
|
|
||||||
// window_context _context;
|
// window_context _context;
|
||||||
|
|
||||||
static void drop_callback(GLFWwindow* window, int count, const char** paths)
|
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++)
|
// for (int i = 0; i < count; i++)
|
||||||
// std::cout << "\t" << paths[i] << std::endl;
|
// std::cout << "\t" << paths[i] << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
std::cout << __FUNCTION__ << std::endl;
|
std::cout << __FUNCTION__ << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
input::get()._mouse_button = button;
|
input::get()._mouse_button = button;
|
||||||
|
|
||||||
std::cout << __FUNCTION__ << " " << button << " " << action << " " << mods << std::endl;
|
std::cout << __FUNCTION__ << " " << button << " " << action << " " << mods << std::endl;
|
||||||
// input::get()._mouse_position
|
// input::get()._mouse_position
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
|
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
{
|
{
|
||||||
input::get()._mouse_position = point(xpos,ypos);
|
input::get()._mouse_position = point(xpos,ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
|
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 character_callback(GLFWwindow* window, unsigned int codepoint)
|
// static void character_callback(GLFWwindow* window, unsigned int codepoint)
|
||||||
{
|
// {
|
||||||
std::cout << __FUNCTION__ << std::endl;
|
// std::cout << __FUNCTION__ << std::endl;
|
||||||
}
|
// }
|
||||||
|
|
||||||
static void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods)
|
static void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods)
|
||||||
{
|
{
|
||||||
std::cout << __FUNCTION__ << std::endl;
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||||
{
|
{
|
||||||
window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window));
|
window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window));
|
||||||
// impl->on_resize(width,height);
|
// impl->on_resize(width,height);
|
||||||
|
|
||||||
// std::cout << "framebuffer " << width << "x" << height << std::endl;
|
// std::cout << "framebuffer " << width << "x" << height << std::endl;
|
||||||
// glViewport(0, 0, width, height);
|
// glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl()
|
impl()
|
||||||
|
@ -96,23 +102,23 @@ struct window::impl {
|
||||||
glfwSetWindowUserPointer(_window,this);
|
glfwSetWindowUserPointer(_window,this);
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
|
||||||
glfwSetKeyCallback(_window, window::impl::key_callback);
|
glfwSetKeyCallback(_window, window::impl::key_callback);
|
||||||
glfwSetCharCallback(_window, character_callback);
|
// glfwSetCharCallback(_window, character_callback);
|
||||||
glfwSetCharModsCallback(_window, charmods_callback);
|
glfwSetCharModsCallback(_window, charmods_callback);
|
||||||
glfwSetScrollCallback(_window, scroll_callback);
|
glfwSetScrollCallback(_window, scroll_callback);
|
||||||
|
|
||||||
glfwSetDropCallback(_window, drop_callback);
|
glfwSetDropCallback(_window, drop_callback);
|
||||||
|
|
||||||
glfwSetCursorPosCallback(_window, cursor_pos_callback);
|
glfwSetCursorPosCallback(_window, cursor_pos_callback);
|
||||||
glfwSetMouseButtonCallback(_window, mouse_button_callback);
|
glfwSetMouseButtonCallback(_window, mouse_button_callback);
|
||||||
glfwSetScrollCallback(_window, scroll_callback);
|
glfwSetScrollCallback(_window, scroll_callback);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
glfwMakeContextCurrent(_window);
|
glfwMakeContextCurrent(_window);
|
||||||
|
|
||||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -156,10 +162,10 @@ struct window::impl {
|
||||||
|
|
||||||
::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
|
||||||
{
|
{
|
||||||
|
@ -172,6 +178,11 @@ struct window::impl {
|
||||||
{
|
{
|
||||||
glfwSetWindowPos(_window,x,y);
|
glfwSetWindowPos(_window,x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_fullscreen()
|
||||||
|
{
|
||||||
|
// glfwSetWindow
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue