intermediate implementation with more support for input

This commit is contained in:
Hartmut Seichter 2019-01-09 16:24:16 +01:00
parent 39663f40ef
commit dfe26d9424
9 changed files with 103 additions and 34 deletions

View file

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

View file

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

View file

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