diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 34072dd..ff224fe 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -18,7 +18,8 @@ void script_system::load(sol::table &ns) "new", sol::no_constructor, "get",&input::get, "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) ); } diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 92770db..c6d8f37 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -76,7 +76,7 @@ w.size = pw.size.new(1200,800) while w:update() 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) end diff --git a/src/system/include/pw/system/input.hpp b/src/system/include/pw/system/input.hpp index 5dbb43a..5d32122 100644 --- a/src/system/include/pw/system/input.hpp +++ b/src/system/include/pw/system/input.hpp @@ -13,9 +13,16 @@ public: point mouse_position() const { return _mouse_position; } int mouse_button() const { return _mouse_button; } + std::string input_string() const { return _input_string; } + ~input() = default; + enum mouse_button_state { + pressed, + released + }; + protected: friend class window; @@ -27,6 +34,9 @@ private: point _mouse_position; int _mouse_button; + std::string _input_string; + + }; } diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index e1cbecd..a0f6354 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -7,6 +7,8 @@ #include "pw/system/input.hpp" #include +#include +#include #include @@ -16,7 +18,7 @@ struct window_context : context { virtual bool make_current() override; virtual void resize() override; -// virtual context::size size() override; + // virtual context::size size() override; virtual void flush() override; }; @@ -36,55 +38,59 @@ struct window::impl { 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; -// for (int i = 0; i < count; i++) -// std::cout << "\t" << paths[i] << std::endl; - } + // 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) - { - std::cout << __FUNCTION__ << std::endl; - } + static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) + { + 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; 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) - { - input::get()._mouse_position = point(xpos,ypos); - } + static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) + { + input::get()._mouse_position = point(xpos,ypos); + } - static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods) - { - std::cout << __FUNCTION__ << std::endl; - } + static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods) + { + std::cout << __FUNCTION__ << std::endl; + } - static void character_callback(GLFWwindow* window, unsigned int codepoint) - { - std::cout << __FUNCTION__ << std::endl; - } + // static void character_callback(GLFWwindow* window, unsigned int codepoint) + // { + // std::cout << __FUNCTION__ << std::endl; + // } - static void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods) - { - std::cout << __FUNCTION__ << std::endl; - } + static void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods) + { + // build the string from a Unicode code point + std::wstring_convert, 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(glfwGetWindowUserPointer(window)); -// impl->on_resize(width,height); + // impl->on_resize(width,height); -// std::cout << "framebuffer " << width << "x" << height << std::endl; - // glViewport(0, 0, width, height); + // std::cout << "framebuffer " << width << "x" << height << std::endl; + // glViewport(0, 0, width, height); } impl() @@ -96,23 +102,23 @@ struct window::impl { glfwSetWindowUserPointer(_window,this); 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); + glfwSetKeyCallback(_window, window::impl::key_callback); + // glfwSetCharCallback(_window, character_callback); + glfwSetCharModsCallback(_window, charmods_callback); + glfwSetScrollCallback(_window, scroll_callback); - glfwSetDropCallback(_window, drop_callback); + glfwSetDropCallback(_window, drop_callback); - glfwSetCursorPosCallback(_window, cursor_pos_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 - glfwMakeContextCurrent(_window); + glfwMakeContextCurrent(_window); - gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); + gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); #endif } @@ -156,10 +162,10 @@ struct window::impl { ::pw::size size() const { - int w,h; - glfwGetWindowSize(_window,&w,&h); - return ::pw::size(w,h); - } + int w,h; + glfwGetWindowSize(_window,&w,&h); + return ::pw::size(w,h); + } ::pw::point position() const { @@ -172,6 +178,11 @@ struct window::impl { { glfwSetWindowPos(_window,x,y); } + + void set_fullscreen() + { + // glfwSetWindow + } };