From fdf7714d11b7ff7d64adf055fdf3af3f8ceed9eb Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 9 Jan 2019 19:58:03 +0100 Subject: [PATCH] final commit for today - still searching to get the mouse_button --- src/engine/CMakeLists.txt | 2 +- src/scripting/src/script_system.cpp | 9 ++--- src/scripts/demos/simple_000.lua | 10 ++++-- src/system/include/pw/system/input.hpp | 2 ++ src/system/include/pw/system/window.hpp | 4 +++ src/system/src/window.cpp | 44 ++++++++++++++++++++----- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 247197b..b3361eb 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -3,7 +3,7 @@ set(scripts ${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua ) -add_executable(pixwerx +add_executable(pixwerx WIN32 MACOSX_BUNDLE pixwerx.cpp ${scripts} ) diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 3ca4c4a..34072dd 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -3,7 +3,6 @@ #include "pw/system/window.hpp" #include "pw/system/input.hpp" - namespace pw { void script_system::load(sol::table &ns) @@ -11,14 +10,16 @@ void script_system::load(sol::table &ns) ns.new_usertype("window", "update",&window::update, "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) ); ns.new_usertype("input", "new", sol::no_constructor, - "get",&input::get + "get",&input::get, + "mouse_position",sol::readonly_property(&input::mouse_position), + "mouse_button",sol::readonly_property(&input::mouse_button) ); - } } diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 96f7310..92770db 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -32,7 +32,6 @@ local q2 = pw.quaternion.new(0,0,0,1) qm = pw.quaternion.lerp(q,qi,0.5) print("q.m",qm.x,qm.y,qm.z,qm.w) - -- axis angle test local aa = pw.axisangle.new(v1,0.707) @@ -56,6 +55,7 @@ n_1:add_child(pw.node.create()).name = "five" print("node 1 - child count ",n_1.child_count) +-- stuff for i = 1,n_1.child_count do print(i,n_1.children[i],n_1.children[i].name) end @@ -73,9 +73,15 @@ w.title = "pixwerx 0.1" -- set size w.size = pw.size.new(1200,800) - while w:update() do + + if (pw.input:get().mouse_button > 0) then + print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y) + end + + + -- print("update") end diff --git a/src/system/include/pw/system/input.hpp b/src/system/include/pw/system/input.hpp index f5fa55c..5dbb43a 100644 --- a/src/system/include/pw/system/input.hpp +++ b/src/system/include/pw/system/input.hpp @@ -12,6 +12,7 @@ public: static input& get(); point mouse_position() const { return _mouse_position; } + int mouse_button() const { return _mouse_button; } ~input() = default; @@ -24,6 +25,7 @@ protected: private: point _mouse_position; + int _mouse_button; }; diff --git a/src/system/include/pw/system/window.hpp b/src/system/include/pw/system/window.hpp index 577c10a..06515bf 100644 --- a/src/system/include/pw/system/window.hpp +++ b/src/system/include/pw/system/window.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace pw { @@ -19,6 +20,9 @@ public: void set_size(const size& s); size size() const; + void set_position(const point& p); + point position() const; + typedef void drop_callback; protected: diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index f748880..e1cbecd 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -6,11 +6,14 @@ #include "pw/visual/context.hpp" #include "pw/system/input.hpp" +#include + #include namespace pw { -struct window_context : context { +struct window_context : context +{ virtual bool make_current() override; virtual void resize() override; // virtual context::size size() override; @@ -36,8 +39,10 @@ struct window::impl { // window_context _context; 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 scroll_callback(GLFWwindow* window, double xoffset, double yoffset) @@ -47,7 +52,9 @@ struct window::impl { static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { - std::cout << __FUNCTION__ << std::endl; + input::get()._mouse_button = button; + + std::cout << __FUNCTION__ << " " << button << " " << action << " " << mods << std::endl; // input::get()._mouse_position } @@ -147,15 +154,24 @@ struct window::impl { glfwSetWindowSize(_window,w,h); } - ::pw::size size() const { - + ::pw::size size() const + { int w,h; glfwGetWindowSize(_window,&w,&h); - return ::pw::size(w,h); } + ::pw::point position() const + { + int x,y; + glfwGetWindowPos(_window,&x,&y); + return ::pw::point(x,y); + } + void set_position(int x,int y) + { + glfwSetWindowPos(_window,x,y); + } }; @@ -180,12 +196,22 @@ void window::set_title(const std::string& title) void window::set_size(const ::pw::size& s) { - _impl->set_size(s.width,s.height); + _impl->set_size(static_cast(std::round(s.width)),static_cast(std::round(s.height))); } size window::size() const { - return _impl->size(); + return _impl->size(); +} + +void window::set_position(const point &p) +{ + _impl->set_position(p.x,p.y); +} + +point window::position() const +{ + return _impl->position(); }