intermediate implementation with more support for input
This commit is contained in:
parent
39663f40ef
commit
dfe26d9424
9 changed files with 103 additions and 34 deletions
|
@ -10,6 +10,7 @@ set(hdrs
|
|||
include/pw/core/quaternion.hpp
|
||||
include/pw/core/serialize.hpp
|
||||
include/pw/core/image.hpp
|
||||
include/pw/core/point.hpp
|
||||
include/pw/core/size.hpp
|
||||
include/pw/core/timer.hpp
|
||||
include/pw/core/globals.hpp
|
||||
|
|
|
@ -40,13 +40,13 @@ class debug {
|
|||
public:
|
||||
|
||||
enum level {
|
||||
kNone, //!< nothing will be logged, even no errors
|
||||
kError, //!< only errors will be logged
|
||||
kWarning, //!< log warnings (non-critical errors)
|
||||
kMessage, //!< log messages (something to note but not an error)
|
||||
kNotify, //!< log some more information
|
||||
kInfo, //!< log verbose information
|
||||
kAll = 0xFF //!< log absolutely everything
|
||||
none, //!< nothing will be logged, even no errors
|
||||
error, //!< only errors will be logged
|
||||
warning, //!< log warnings (non-critical errors)
|
||||
message, //!< log messages (something to note but not an error)
|
||||
notification, //!< log some more information
|
||||
info, //!< log verbose information
|
||||
all = 0xFF //!< log absolutely everything
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -94,11 +94,11 @@ public:
|
|||
* @brief get the stream interface of the logger
|
||||
* @return return a temporary object that will write and flush the logger
|
||||
*/
|
||||
static stream s(enum level level = kInfo);
|
||||
static stream s(enum level level = info);
|
||||
|
||||
inline static stream d() { return s(debug::kInfo); }
|
||||
inline static stream e() { return s(debug::kError); }
|
||||
inline static stream w() { return s(debug::kWarning); }
|
||||
inline static stream d() { return s(debug::info); }
|
||||
inline static stream e() { return s(debug::error); }
|
||||
inline static stream w() { return s(debug::warning); }
|
||||
|
||||
/**
|
||||
* @brief returns the instance of the logger
|
||||
|
@ -115,10 +115,11 @@ public:
|
|||
typedef std::function<void(const char*)> Callback;
|
||||
typedef std::vector<Callback> CallbackList;
|
||||
|
||||
~debug();
|
||||
|
||||
protected:
|
||||
|
||||
debug();
|
||||
~debug();
|
||||
|
||||
CallbackList _callbacks;
|
||||
enum level _level;
|
||||
|
|
29
src/core/include/pw/core/point.hpp
Normal file
29
src/core/include/pw/core/point.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef PW_CORE_POINT_HPP
|
||||
#define PW_CORE_SIZE_HPP
|
||||
|
||||
#include <pw/core/globals.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
template <typename T_>
|
||||
struct point_ {
|
||||
|
||||
T_ p[2] = { 0, 0 };
|
||||
|
||||
point_() = default;
|
||||
point_(T_ x,T_ y) : p( {x,y} ) {}
|
||||
|
||||
const T_ x() { return p[0]; }
|
||||
const T_ y() { return p[1]; }
|
||||
|
||||
};
|
||||
|
||||
typedef point_<real_t> point;
|
||||
|
||||
typedef point_<int> pointi;
|
||||
typedef point_<float> pointf;
|
||||
typedef point_<float> pointd;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -35,6 +35,8 @@ struct size_ {
|
|||
|
||||
T_ dim[2] = { 0, 0 };
|
||||
|
||||
size_() = default;
|
||||
|
||||
size_(T_ w,T_ h) : dim( { w, h }) {}
|
||||
|
||||
const T_ width() { return dim[0]; }
|
||||
|
|
|
@ -60,7 +60,7 @@ struct tpFileLog {
|
|||
|
||||
|
||||
debug::debug() :
|
||||
_level(debug::kNotify)
|
||||
_level(debug::notification)
|
||||
{
|
||||
#if defined(_WINCE)
|
||||
_callbacks.add(new tpFileLog());
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "pw/core/vector.hpp"
|
||||
#include "pw/core/quaternion.hpp"
|
||||
#include "pw/core/axisangle.hpp"
|
||||
#include "pw/core/debug.hpp"
|
||||
|
||||
|
||||
namespace pw {
|
||||
|
@ -50,6 +51,13 @@ void script_core::load(sol::table &ns)
|
|||
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
|
||||
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
|
||||
);
|
||||
|
||||
|
||||
ns.new_usertype<debug>("debug",
|
||||
"new",sol::no_constructor,
|
||||
"get",&debug::get
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define PW_SYSTEM_INPUT_HPP
|
||||
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/point.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
@ -10,14 +11,19 @@ public:
|
|||
|
||||
static input& get();
|
||||
|
||||
point mouse_position() const { return _mouse_position; }
|
||||
|
||||
protected:
|
||||
|
||||
struct impl;
|
||||
std::unique_ptr<impl> _impl;
|
||||
friend class window;
|
||||
|
||||
private:
|
||||
input();
|
||||
~input() = default;
|
||||
|
||||
private:
|
||||
|
||||
point _mouse_position;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,24 +1,11 @@
|
|||
#include "pw/system/input.hpp"
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
namespace pw {
|
||||
|
||||
struct input::impl {
|
||||
|
||||
|
||||
|
||||
|
||||
GLFWwindow *_window;
|
||||
};
|
||||
|
||||
input::input()
|
||||
: _impl(new input::impl())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
input &input::get()
|
||||
{
|
||||
static input instance;
|
||||
|
@ -26,7 +13,4 @@ input &input::get()
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,15 +35,43 @@ struct window::impl {
|
|||
|
||||
// window_context _context;
|
||||
|
||||
static void drop_callback(GLFWwindow* window, int count, const char** paths)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::cout << __FUNCTION__ << std::endl;
|
||||
// input::get()._mouse_position
|
||||
}
|
||||
|
||||
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 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 framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
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);
|
||||
|
@ -62,6 +90,16 @@ struct window::impl {
|
|||
|
||||
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);
|
||||
|
||||
glfwSetDropCallback(_window, drop_callback);
|
||||
|
||||
glfwSetCursorPosCallback(_window, cursor_pos_callback);
|
||||
glfwSetMouseButtonCallback(_window, mouse_button_callback);
|
||||
glfwSetScrollCallback(_window, scroll_callback);
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue