final commit for today - still searching to get the mouse_button

This commit is contained in:
Hartmut Seichter 2019-01-09 19:58:03 +01:00
parent f840d51f4f
commit fdf7714d11
6 changed files with 55 additions and 16 deletions

View file

@ -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}
)

View file

@ -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>("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>("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)
);
}
}

View file

@ -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

View file

@ -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;
};

View file

@ -3,6 +3,7 @@
#include <pw/core/globals.hpp>
#include <pw/core/size.hpp>
#include <pw/core/point.hpp>
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:

View file

@ -6,11 +6,14 @@
#include "pw/visual/context.hpp"
#include "pw/system/input.hpp"
#include <cmath>
#include <iostream>
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<int>(std::round(s.width)),static_cast<int>(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();
}