From b2b12b64abd7afe31b266deae1e6084dcabde756 Mon Sep 17 00:00:00 2001
From: Hartmut Seichter <hartmut@technotecture.com>
Date: Thu, 10 Jan 2019 10:51:03 +0100
Subject: [PATCH] WiP

---
 src/scripting/src/script_system.cpp    |   3 +-
 src/scripts/demos/simple_000.lua       |   2 +-
 src/system/include/pw/system/input.hpp |  10 +++
 src/system/src/window.cpp              | 109 ++++++++++++++-----------
 4 files changed, 73 insertions(+), 51 deletions(-)

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 <cmath>
+#include <locale>
+#include <codecvt>
 
 #include <iostream>
 
@@ -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<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));
-//        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
+	}
 };