Commit for 2021.06.27 00-42-22.7z

This commit is contained in:
mrq 2021-06-27 00:42:00 -05:00
parent b513d322b5
commit 7fc997cc18
13 changed files with 593 additions and 697 deletions

View File

@ -84,8 +84,7 @@
"minima": [ null, -1.0, null ], "minima": [ null, -1.0, null ],
"maxima": [ null, 1.0, null ], "maxima": [ null, 1.0, null ],
"current":[ null, 0, null ]
"current": [ null, 0, null ]
}, },
"settings": { "settings": {
"fov" : 90, "fov" : 90,

View File

@ -8,24 +8,13 @@
#include <uf/utils/hook/hook.h> #include <uf/utils/hook/hook.h>
#include <uf/utils/thread/thread.h> #include <uf/utils/thread/thread.h>
#include <uf/utils/renderer/renderer.h> #include <uf/utils/renderer/renderer.h>
#include <uf/utils/window/payloads.h>
bool client::ready = false; bool client::ready = false;
bool client::terminated = false; bool client::terminated = false;
uf::Window client::window; uf::Window client::window;
uf::Serializer client::config; uf::Serializer client::config;
namespace pod {
namespace payloads {
struct windowMouseMoved {
std::string invoker = "";
pod::Vector2i delta;
pod::Vector2ui position;
pod::Vector2ui size;
int_fast8_t state;
};
}
}
void client::initialize() { void client::initialize() {
uf::IoStream::ncurses = true; uf::IoStream::ncurses = true;
uf::renderer::device.window = &client::window; uf::renderer::device.window = &client::window;
@ -157,11 +146,16 @@ void client::tick() {
} }
#endif #endif
uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{ uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{
.invoker = "client", "window:Mouse.Moved",
.delta = previous - current, "client",
.position = current, {
.size = size, pod::Vector2ui{ size.x, size.y },
.state = 0 },
{
current,
previous - current,
0
}
}); });
} }
} }

View File

@ -25,42 +25,41 @@ namespace spec {
std::queue<Event> m_events; std::queue<Event> m_events;
public: public:
// C-tors // C-tors
/*virtual*/ void UF_API_CALL create( const spec::uni::Window::vector_t& size, const spec::uni::Window::title_t& title = L"Window" ) {} ;// = 0; void create( const spec::uni::Window::vector_t& size, const spec::uni::Window::title_t& title = L"Window" ) {} ;// = 0;
// D-tors // D-tors
/*virtual*/ void UF_API_CALL terminate();/* = 0;*/ void terminate();/* = 0;*/
// Gets // Gets
/*virtual*/ spec::uni::Window::vector_t UF_API_CALL getPosition() const;/* = 0;*/ spec::uni::Window::vector_t getPosition() const;/* = 0;*/
/*virtual*/ spec::uni::Window::vector_t UF_API_CALL getSize() const;/* = 0;*/ spec::uni::Window::vector_t getSize() const;/* = 0;*/
/*virtual*/ size_t UF_API_CALL getRefreshRate() const;/* = 0;*/ size_t getRefreshRate() const;/* = 0;*/
// Attribute modifiers // Attribute modifiers
/*virtual*/ void UF_API_CALL setPosition( const spec::uni::Window::vector_t& position );/* = 0;*/ void setPosition( const spec::uni::Window::vector_t& position );/* = 0;*/
/*virtual*/ void UF_API_CALL centerWindow();/* = 0;*/ void centerWindow();/* = 0;*/
/*virtual*/ void UF_API_CALL setMousePosition( const spec::uni::Window::vector_t& position );/* = 0;*/ void setMousePosition( const spec::uni::Window::vector_t& position );/* = 0;*/
/*virtual*/ void UF_API_CALL setSize( const spec::uni::Window::vector_t& size );/* = 0;*/ void setSize( const spec::uni::Window::vector_t& size );/* = 0;*/
/*virtual*/ void UF_API_CALL setTitle( const spec::uni::Window::title_t& title );/* = 0;*/ void setTitle( const spec::uni::Window::title_t& title );/* = 0;*/
/*virtual*/ void UF_API_CALL setIcon( const spec::uni::Window::vector_t& size, uint8_t* pixels );/* = 0;*/ void setIcon( const spec::uni::Window::vector_t& size, uint8_t* pixels );/* = 0;*/
/*virtual*/ void UF_API_CALL setVisible( bool visibility );/* = 0;*/ void setVisible( bool visibility );/* = 0;*/
/*virtual*/ void UF_API_CALL setCursorVisible( bool visibility );/* = 0;*/ void setCursorVisible( bool visibility );/* = 0;*/
/*virtual*/ void UF_API_CALL setKeyRepeatEnabled( bool state );/* = 0;*/ void setKeyRepeatEnabled( bool state );/* = 0;*/
/*virtual*/ void UF_API_CALL setMouseGrabbed( bool state );/* = 0;*/ void setMouseGrabbed( bool state );/* = 0;*/
/*virtual*/ void UF_API_CALL requestFocus();/* = 0;*/ void requestFocus();/* = 0;*/
/*virtual*/ bool UF_API_CALL hasFocus() const;/* = 0;*/ bool hasFocus() const;/* = 0;*/
// Update // Update
/*virtual*/ void UF_API_CALL processEvents();/* = 0;*/ void processEvents();/* = 0;*/
/*
void UF_API_CALL pushEvent( const uf::ReadableHook::name_t& name, const uf::ReadableHook::argument_t& argument ); void pushEvent( const uf::Hooks::name_t& name, const std::string& payload );
void UF_API_CALL pushEvent( const uf::OptimalHook::name_t& name, const uf::OptimalHook::argument_t& argument ); void pushEvent( const uf::Hooks::name_t& name, const ext::json::Value& payload );
void UF_API_CALL pushEvent( const uf::ReadableHook::argument_t& serialized ); void pushEvent( const uf::Hooks::name_t& name, const uf::Serializer& payload );
void UF_API_CALL pushEvent( const uf::OptimalHook::argument_t& userdata ); void pushEvent( const uf::Hooks::name_t& name, const uf::Hooks::argument_t& payload );
*/ void pushEvent( const uf::Hooks::argument_t& payload );
void UF_API_CALL pushEvent( const uf::Hooks::name_t& name, const std::string& payload ); template<typename T> void pushEvent( const uf::Hooks::name_t& name, const T& payload );
void UF_API_CALL pushEvent( const uf::Hooks::name_t& name, const ext::json::Value& payload );
void UF_API_CALL pushEvent( const uf::Hooks::name_t& name, const uf::Serializer& payload ); bool pollEvents( bool block = false );
void UF_API_CALL pushEvent( const uf::Hooks::name_t& name, const uf::Hooks::argument_t& payload ); static bool isKeyPressed( const std::string& );
void UF_API_CALL pushEvent( const uf::Hooks::argument_t& payload );
bool UF_API_CALL pollEvents( bool block = false );
static bool UF_API_CALL isKeyPressed( const std::string& );
}; };
} }
} }
#include "universal.inl"

View File

@ -0,0 +1,6 @@
template<typename T>
void spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, const T& payload ) {
pod::Hook::userdata_t userdata;
userdata.create<T>( payload );
this->pushEvent( name, userdata );
}

View File

@ -169,15 +169,19 @@ pod::Transform<T>& /*UF_API*/ uf::transform::decode( const ext::json::Value& _js
// transform.position = uf::vector::decode<T, 3>(json["position"], transform.position); // transform.position = uf::vector::decode<T, 3>(json["position"], transform.position);
// transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale); // transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale);
// transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation); // transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation);
if ( ext::json::isArray(json["position"]) || ext::json::isObject(json["position"]) ) transform.position = uf::vector::decode<T, 3>(json["position"], transform.position); // if ( ext::json::isArray(json["position"]) || ext::json::isObject(json["position"]) )
if ( ext::json::isArray(json["scale"]) || ext::json::isObject(json["scale"]) ) transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale); transform.position = uf::vector::decode<T, 3>(json["position"], transform.position);
if ( ext::json::isArray(json["orientation"]) || ext::json::isObject(json["orientation"]) ) transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation); // if ( ext::json::isArray(json["scale"]) || ext::json::isObject(json["scale"]) )
transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale);
// if ( ext::json::isArray(json["orientation"]) || ext::json::isObject(json["orientation"]) )
transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation);
if ( ext::json::isObject(json["rotation"]) && !ext::json::isNull(json["rotation"]["axis"]) && !ext::json::isNull(json["rotation"]["angle"]) ) { if ( ext::json::isObject(json["rotation"]) && !ext::json::isNull(json["rotation"]["axis"]) && !ext::json::isNull(json["rotation"]["angle"]) ) {
pod::Vector3t<T> axis = uf::vector::decode<T, 3>(json["rotation"]["axis"]); pod::Vector3t<T> axis = uf::vector::decode<T, 3>(json["rotation"]["axis"]);
T angle = json["rotation"]["angle"].as<T>(); T angle = json["rotation"]["angle"].as<T>();
transform.orientation = uf::quaternion::axisAngle( axis, angle ); transform.orientation = uf::quaternion::axisAngle( axis, angle );
} }
if ( ext::json::isArray(json["model"]) ) transform.model = uf::matrix::decode<T, 4, 4>(json["model"]); // if ( ext::json::isArray(json["model"]) )
transform.model = uf::matrix::decode<T, 4, 4>(json["model"], transform.model);
return transform; return transform;
} }
template<typename T> template<typename T>
@ -187,14 +191,18 @@ pod::Transform<T> /*UF_API*/ uf::transform::decode( const ext::json::Value& _jso
// transform.position = uf::vector::decode<T, 3>(json["position"], transform.position); // transform.position = uf::vector::decode<T, 3>(json["position"], transform.position);
// transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale); // transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale);
// transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation); // transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation);
if ( ext::json::isArray(json["position"]) || ext::json::isObject(json["position"]) ) transform.position = uf::vector::decode<T, 3>(json["position"], transform.position); // if ( ext::json::isArray(json["position"]) || ext::json::isObject(json["position"]) )
if ( ext::json::isArray(json["scale"]) || ext::json::isObject(json["scale"]) ) transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale); transform.position = uf::vector::decode<T, 3>(json["position"], transform.position);
if ( ext::json::isArray(json["orientation"]) || ext::json::isObject(json["orientation"]) ) transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation); // if ( ext::json::isArray(json["scale"]) || ext::json::isObject(json["scale"]) )
transform.scale = uf::vector::decode<T, 3>(json["scale"], transform.scale);
// if ( ext::json::isArray(json["orientation"]) || ext::json::isObject(json["orientation"]) )
transform.orientation = uf::vector::decode<T, 4>(json["orientation"], transform.orientation);
if ( ext::json::isObject(json["rotation"]) && !ext::json::isNull(json["rotation"]["axis"]) && !ext::json::isNull(json["rotation"]["angle"]) ) { if ( ext::json::isObject(json["rotation"]) && !ext::json::isNull(json["rotation"]["axis"]) && !ext::json::isNull(json["rotation"]["angle"]) ) {
pod::Vector3t<T> axis = uf::vector::decode<T, 3>(json["rotation"]["axis"]); pod::Vector3t<T> axis = uf::vector::decode<T, 3>(json["rotation"]["axis"]);
T angle = json["rotation"]["angle"].as<T>(); T angle = json["rotation"]["angle"].as<T>();
transform.orientation = uf::quaternion::axisAngle( axis, angle ); transform.orientation = uf::quaternion::axisAngle( axis, angle );
} }
if ( ext::json::isArray(json["model"]) ) transform.model = uf::matrix::decode<T, 4, 4>(json["model"]); // if ( ext::json::isArray(json["model"]) )
transform.model = uf::matrix::decode<T, 4, 4>(json["model"], transform.model);
return transform; return transform;
} }

View File

@ -407,11 +407,14 @@ pod::Vector<T,N>& /*UF_API*/ uf::vector::decode( const ext::json::Value& json, p
if ( ext::json::isArray(json) ) if ( ext::json::isArray(json) )
#pragma unroll // GCC unroll T::size #pragma unroll // GCC unroll T::size
for ( uint_fast8_t i = 0; i < N; ++i ) for ( uint_fast8_t i = 0; i < N; ++i )
v[i] = json[i].as<T>(); v[i] = json[i].as<T>(v[i]);
else if ( ext::json::isObject(json) ) { else if ( ext::json::isObject(json) ) {
uint_fast8_t i = 0; uint_fast8_t i = 0;
ext::json::forEach(json, [&](const ext::json::Value& c){ ext::json::forEach(json, [&](const ext::json::Value& c){
if ( i < N ) v[i++] = uf::math::unquantize( c.as<T>() ); if ( i < N ) {
v[i] = uf::math::unquantize( c.as<T>(v[i]) );
++i;
}
}); });
} }
return v; return v;
@ -422,11 +425,14 @@ pod::Vector<T,N> /*UF_API*/ uf::vector::decode( const ext::json::Value& json, co
if ( ext::json::isArray(json) ) if ( ext::json::isArray(json) )
#pragma unroll // GCC unroll T::size #pragma unroll // GCC unroll T::size
for ( uint_fast8_t i = 0; i < N; ++i ) for ( uint_fast8_t i = 0; i < N; ++i )
v[i] = json[i].as<T>(); v[i] = json[i].as<T>(_v[i]);
else if ( ext::json::isObject(json) ) { else if ( ext::json::isObject(json) ) {
uint_fast8_t i = 0; uint_fast8_t i = 0;
ext::json::forEach(json, [&](const ext::json::Value& c){ ext::json::forEach(json, [&](const ext::json::Value& c){
if ( i < N ) v[i++] = c.as<T>(); if ( i < N ) {
v[i] = c.as<T>(_v[i]);
++i;
}
}); });
} }
return v; return v;

View File

@ -0,0 +1,67 @@
#pragma once
#include <uf/config.h>
#include <string>
#include <uf/utils/math/vector.h>
namespace pod {
namespace payloads {
struct windowEvent {
std::string type = "";
std::string invoker = "";
};
struct windowResized : public windowEvent {
struct {
pod::Vector2ui size{};
} window;
};
struct windowFocusedChanged : public windowEvent {
struct {
int_fast8_t state{};
} window;
};
struct windowTextEntered : public windowEvent {
struct {
uint32_t utf32;
std::string unicode;
} text;
};
struct windowKey : public windowEvent {
struct {
std::string code;
uint32_t raw;
int_fast8_t state = -1;
bool async;
struct {
bool alt;
bool ctrl;
bool shift;
bool sys;
} modifier;
} key;
};
struct windowMouseWheel : public windowEvent {
struct {
pod::Vector2ui position{};
float delta = 0;
} mouse;
};
struct windowMouseClick : public windowEvent {
struct {
pod::Vector2i position = {};
pod::Vector2i delta = {};
std::string button = "";
int_fast8_t state = 0;
} mouse;
};
struct windowMouseMoved : public windowResized {
struct {
pod::Vector2ui position{};
pod::Vector2i delta{};
int_fast8_t state{};
} mouse;
};
}
}

View File

@ -17,44 +17,44 @@ namespace uf {
// C-tors // C-tors
UF_API_CALL Window(); UF_API_CALL Window();
UF_API_CALL Window( const spec::uni::Window::vector_t& size, const spec::uni::Window::title_t& title = L"Window", const spec::Context::Settings& settings = spec::Context::Settings() ); UF_API_CALL Window( const spec::uni::Window::vector_t& size, const spec::uni::Window::title_t& title = L"Window", const spec::Context::Settings& settings = spec::Context::Settings() );
/*virtual*/ void UF_API_CALL create( const spec::uni::Window::vector_t& size, const spec::uni::Window::title_t& title = L"Window", const spec::Context::Settings& settings = spec::Context::Settings() ); void UF_API_CALL create( const spec::uni::Window::vector_t& size, const spec::uni::Window::title_t& title = L"Window", const spec::Context::Settings& settings = spec::Context::Settings() );
// D-tors // D-tors
/*virtual*/ ~Window(); ~Window();
/*virtual*/ void UF_API_CALL terminate(); void UF_API_CALL terminate();
// Gets // Gets
/*virtual*/ spec::uni::Window::vector_t UF_API_CALL getPosition() const; spec::uni::Window::vector_t UF_API_CALL getPosition() const;
/*virtual*/ spec::uni::Window::vector_t UF_API_CALL getSize() const; spec::uni::Window::vector_t UF_API_CALL getSize() const;
/*virtual*/ size_t UF_API_CALL getRefreshRate() const; size_t UF_API_CALL getRefreshRate() const;
// Attribute modifiers // Attribute modifiers
/*virtual*/ void UF_API_CALL setPosition( const spec::uni::Window::vector_t& position ); void UF_API_CALL setPosition( const spec::uni::Window::vector_t& position );
/*virtual*/ void UF_API_CALL centerWindow(); void UF_API_CALL centerWindow();
/*virtual*/ void UF_API_CALL setMousePosition( const spec::uni::Window::vector_t& position ); void UF_API_CALL setMousePosition( const spec::uni::Window::vector_t& position );
/*virtual*/ spec::uni::Window::vector_t UF_API_CALL getMousePosition(); spec::uni::Window::vector_t UF_API_CALL getMousePosition();
/*virtual*/ void UF_API_CALL setSize( const spec::uni::Window::vector_t& size ); void UF_API_CALL setSize( const spec::uni::Window::vector_t& size );
/*virtual*/ void UF_API_CALL setTitle( const spec::uni::Window::title_t& title ); void UF_API_CALL setTitle( const spec::uni::Window::title_t& title );
/*virtual*/ void UF_API_CALL setIcon( const spec::uni::Window::vector_t& size, uint8_t* pixels ); void UF_API_CALL setIcon( const spec::uni::Window::vector_t& size, uint8_t* pixels );
/*virtual*/ void UF_API_CALL setVisible( bool visibility ); void UF_API_CALL setVisible( bool visibility );
/*virtual*/ void UF_API_CALL setCursorVisible( bool visibility ); void UF_API_CALL setCursorVisible( bool visibility );
/*virtual*/ void UF_API_CALL setKeyRepeatEnabled( bool state ); void UF_API_CALL setKeyRepeatEnabled( bool state );
/*virtual*/ void UF_API_CALL setMouseGrabbed( bool state ); void UF_API_CALL setMouseGrabbed( bool state );
/*virtual*/ void UF_API_CALL requestFocus(); void UF_API_CALL requestFocus();
/*virtual*/ bool UF_API_CALL hasFocus() const; bool UF_API_CALL hasFocus() const;
static pod::Vector2ui UF_API_CALL getResolution(); static pod::Vector2ui UF_API_CALL getResolution();
/*virtual*/ void UF_API_CALL switchToFullscreen( bool borderless = false ); void UF_API_CALL switchToFullscreen( bool borderless = false );
// Update // Update
#if defined(UF_USE_VULKAN) && UF_USE_VULKAN == 1 #if defined(UF_USE_VULKAN) && UF_USE_VULKAN == 1
std::vector<std::string> getExtensions( bool validationEnabled = true ); std::vector<std::string> getExtensions( bool validationEnabled = true );
void createSurface( VkInstance instance, VkSurfaceKHR& surface ); void createSurface( VkInstance instance, VkSurfaceKHR& surface );
#endif #endif
static bool focused; static bool focused;
static /*virtual*/ bool UF_API_CALL isKeyPressed(const std::string&); static bool UF_API_CALL isKeyPressed(const std::string&);
/*virtual*/ void UF_API_CALL processEvents(); void UF_API_CALL processEvents();
/*virtual*/ bool UF_API_CALL pollEvents(bool block = false); bool UF_API_CALL pollEvents(bool block = false);
/*virtual*/ bool UF_API_CALL setActive( bool active = true ); bool UF_API_CALL setActive( bool active = true );
/*virtual*/ void UF_API_CALL display(); void UF_API_CALL display();
/*virtual*/ Window::window_t* UF_API_CALL getHandle(); Window::window_t* UF_API_CALL getHandle();
/*virtual*/ const Window::window_t* UF_API_CALL getHandle() const; const Window::window_t* UF_API_CALL getHandle() const;
}; };
} }
#elif UF_USE_SFML #elif UF_USE_SFML

View File

@ -362,65 +362,52 @@ void UF_API_CALL spec::dreamcast::Window::processEvents() {
if ( ::mouse.device ) ::mouse.state = (mouse_state_t*) maple_dev_status(::mouse.device); if ( ::mouse.device ) ::mouse.state = (mouse_state_t*) maple_dev_status(::mouse.device);
/* Key inputs */ if ( this->m_asyncParse ) { /* Key inputs */ if ( this->m_asyncParse ) {
std::vector<uint8_t> keys = GetKeys(); std::vector<WPARAM> keys = GetKeys();
pod::payloads::windowKey event{
"window:Key",
"os",
{
"",
0,
struct Event { -1,
std::string type = "unknown"; true,
std::string invoker = "???"; {
GetModifier(KBD_MOD_LALT) || GetModifier(KBD_MOD_RALT),
struct { GetModifier(KBD_MOD_LCTRL) || GetModifier(KBD_MOD_RCTRL),
int state; GetModifier(KBD_MOD_LSHIFT) || GetModifier(KBD_MOD_RSHIFT),
std::string code; GetModifier(KBD_MOD_S1) || GetModifier(KBD_MOD_S2),
uint32_t raw;
bool async;
struct {
bool alt;
bool ctrl;
bool shift;
bool sys;
} modifier;
} key;
};
Event event; {
event.type = "window:Key";
event.invoker = "window";
event.key.state = -1;
event.key.code = "NULL";
event.key.raw = 0;
event.key.async = true;
event.key.modifier = {
.alt = GetModifier(KBD_MOD_LALT) || GetModifier(KBD_MOD_RALT),
.ctrl = GetModifier(KBD_MOD_LCTRL) || GetModifier(KBD_MOD_RCTRL),
.shift = GetModifier(KBD_MOD_LSHIFT) || GetModifier(KBD_MOD_RSHIFT),
.sys = GetModifier(KBD_MOD_S1) || GetModifier(KBD_MOD_S2),
};
}
/* Readable (JSON) + Optimal (Userdata) event */ {
uf::Serializer json;
/* Set up JSON data*/ {
json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released");
json["invoker"] = event.invoker;
json["key"]["state"] = (event.key.state == -1) ? "Down" : "Up";
json["key"]["async"] = event.key.async;
json["key"]["modifier"]["alt"] = event.key.modifier.alt;
json["key"]["modifier"]["control"] = event.key.modifier.ctrl;
json["key"]["modifier"]["shift"] = event.key.modifier.shift;
json["key"]["modifier"]["system"] = event.key.modifier.sys;
}
/* Loop through key inputs */ {
for ( auto& key : keys ) {
auto code = GetKeyName(key);
event.key.code = code;
event.key.raw = key;
event.key.state = GetKeyState(key);
json["key"]["code"] = code;
json["key"]["raw"] = key;
this->pushEvent(event.type, json);
this->pushEvent(event.type + "." + code, json);
} }
} }
};
#if UF_USE_JSON
uf::Serializer json;
json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released");
json["invoker"] = event.invoker;
json["key"]["code"] = "";
json["key"]["raw"] = 0;
json["key"]["state"] = (event.key.state == -1) ? "Down" : "Up";
json["key"]["async"] = event.key.async;
json["key"]["modifier"]["alt"] = event.key.modifier.alt;
json["key"]["modifier"]["control"] = event.key.modifier.ctrl;
json["key"]["modifier"]["shift"] = event.key.modifier.shift;
json["key"]["modifier"]["system"] = event.key.modifier.sys;
#endif
for ( auto& key : keys ) {
const auto code = GetKeyName(key);
event.key.code = code;
event.key.raw = key;
#if UF_USE_USERDATA
this->pushEvent(event.type, event);
this->pushEvent(event.type + "." + code, event);
#endif
#if UF_USE_JSON
json["key"]["code"] = code;
json["key"]["raw"] = key;
this->pushEvent(event.type, json);
this->pushEvent(event.type + "." + code, json);
#endif
} }
} }
} }
@ -435,22 +422,14 @@ bool UF_API_CALL spec::dreamcast::Window::pollEvents( bool block ) {
auto& event = this->m_events.front(); auto& event = this->m_events.front();
if ( event.payload.is<std::string>() ) { if ( event.payload.is<std::string>() ) {
ext::json::Value payload = uf::Serializer( event.payload.as<std::string>() ); ext::json::Value payload = uf::Serializer( event.payload.as<std::string>() );
// std::cout << event.name << " (string)\t" << payload << std::endl;
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else if ( event.payload.is<uf::Serializer>() ) { } else if ( event.payload.is<uf::Serializer>() ) {
uf::Serializer& payload = event.payload.as<uf::Serializer>(); uf::Serializer& payload = event.payload.as<uf::Serializer>();
// std::cout << event.name << " (serializer)\t" << payload << std::endl;
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else if ( event.payload.is<ext::json::Value>() ) { } else if ( event.payload.is<ext::json::Value>() ) {
ext::json::Value& payload = event.payload.as<ext::json::Value>(); ext::json::Value& payload = event.payload.as<ext::json::Value>();
// std::cout << event.name << " (json)\t" << payload << std::endl;
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else { } else {
// std::cout << event.name << "(???)" << std::endl;
uf::hooks.call( "window:Event", event.payload );
uf::hooks.call( event.name, event.payload ); uf::hooks.call( event.name, event.payload );
} }
/* /*

View File

@ -2,8 +2,10 @@
#include <uf/utils/io/iostream.h> #include <uf/utils/io/iostream.h>
#include <uf/utils/string/utf.h> #include <uf/utils/string/utf.h>
#include <uf/utils/serialize/serializer.h> #include <uf/utils/serialize/serializer.h>
#include <uf/utils/window/payloads.h>
#define USE_OPTIMAL 0 #define UF_USE_USERDATA 1
#define UF_USE_JSON 1
#if UF_ENV_WINDOWS && (!UF_USE_SFML || (UF_USE_SFML && UF_USE_SFML == 0)) #if UF_ENV_WINDOWS && (!UF_USE_SFML || (UF_USE_SFML && UF_USE_SFML == 0))
namespace { namespace {
@ -772,39 +774,53 @@ void UF_API_CALL spec::win32::Window::processEvents() {
} }
/* Key inputs */ if ( this->m_asyncParse ) { /* Key inputs */ if ( this->m_asyncParse ) {
std::vector<WPARAM> keys = GetKeys(); std::vector<WPARAM> keys = GetKeys();
pod::payloads::windowKey event{
"window:Key",
"os",
{
"",
0,
struct Event { -1,
std::string type = "unknown"; true,
std::string invoker = "???"; {
HIWORD(GetAsyncKeyState(VK_MENU)) != 0,
struct { HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0,
int state; HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0,
std::string code; HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN)),
uint32_t raw; }
bool async; }
struct {
bool alt;
bool ctrl;
bool shift;
bool sys;
} modifier;
} key;
}; };
Event event; { #if UF_USE_JSON
event.type = "window:Key"; uf::Serializer json;
event.invoker = "window"; json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released");
event.key.state = -1; json["invoker"] = event.invoker;
event.key.code = "NULL"; json["key"]["code"] = "";
event.key.raw = 0; json["key"]["raw"] = 0;
event.key.async = true; json["key"]["state"] = (event.key.state == -1) ? "Down" : "Up";
event.key.modifier = { json["key"]["async"] = event.key.async;
.alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0, json["key"]["modifier"]["alt"] = event.key.modifier.alt;
.ctrl = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0, json["key"]["modifier"]["control"] = event.key.modifier.ctrl;
.shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0, json["key"]["modifier"]["shift"] = event.key.modifier.shift;
.sys = HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN)), json["key"]["modifier"]["system"] = event.key.modifier.sys;
}; #endif
for ( auto& key : keys ) {
const auto code = GetKeyName(key);
event.key.code = code;
event.key.raw = key;
#if UF_USE_USERDATA
this->pushEvent(event.type, event);
this->pushEvent(event.type + "." + code, event);
#endif
#if UF_USE_JSON
json["key"]["code"] = code;
json["key"]["raw"] = key;
this->pushEvent(event.type, json);
this->pushEvent(event.type + "." + code, json);
#endif
} }
#if 0
/* Readable (JSON) + Optimal (Userdata) event */ { /* Readable (JSON) + Optimal (Userdata) event */ {
uf::Serializer json; uf::Serializer json;
/* Set up JSON data*/ { /* Set up JSON data*/ {
@ -830,6 +846,7 @@ void UF_API_CALL spec::win32::Window::processEvents() {
} }
} }
} }
#endif
} }
} }
bool UF_API_CALL spec::win32::Window::pollEvents( bool block ) { bool UF_API_CALL spec::win32::Window::pollEvents( bool block ) {
@ -843,32 +860,16 @@ bool UF_API_CALL spec::win32::Window::pollEvents( bool block ) {
auto& event = this->m_events.front(); auto& event = this->m_events.front();
if ( event.payload.is<std::string>() ) { if ( event.payload.is<std::string>() ) {
ext::json::Value payload = uf::Serializer( event.payload.as<std::string>() ); ext::json::Value payload = uf::Serializer( event.payload.as<std::string>() );
// std::cout << event.name << " (string)\t" << payload << std::endl;
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else if ( event.payload.is<uf::Serializer>() ) { } else if ( event.payload.is<uf::Serializer>() ) {
uf::Serializer& payload = event.payload.as<uf::Serializer>(); uf::Serializer& payload = event.payload.as<uf::Serializer>();
// std::cout << event.name << " (serializer)\t" << payload << std::endl;
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else if ( event.payload.is<ext::json::Value>() ) { } else if ( event.payload.is<ext::json::Value>() ) {
ext::json::Value& payload = event.payload.as<ext::json::Value>(); ext::json::Value& payload = event.payload.as<ext::json::Value>();
// std::cout << event.name << " (json)\t" << payload << std::endl;
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else { } else {
// std::cout << event.name << "(???)" << std::endl;
uf::hooks.call( "window:Event", event.payload );
uf::hooks.call( event.name, event.payload ); uf::hooks.call( event.name, event.payload );
} }
/*
try {
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload );
} catch ( ... ) {
// Let the hook handler handle the exceptions
}
*/
this->m_events.pop(); this->m_events.pop();
} }
return true; return true;
@ -938,12 +939,13 @@ void UF_API_CALL spec::win32::Window::registerWindowClass() {
void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, LPARAM lParam) { void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, LPARAM lParam) {
if (!this->m_handle) return; if (!this->m_handle) return;
uf::Serializer json;
std::string hook = "window:Unknown"; std::string hook = "window:Unknown";
std::string serialized = ""; std::string serialized = "";
std::stringstream serializer; std::stringstream serializer;
bool labelAsDelta = true; bool labelAsDelta = true;
uf::Serializer json;
switch (message) { switch (message) {
case WM_DESTROY: case WM_DESTROY:
this->terminate(); this->terminate();
@ -952,54 +954,40 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
if (LOWORD(lParam) == HTCLIENT) SetCursor(this->m_cursor); if (LOWORD(lParam) == HTCLIENT) SetCursor(this->m_cursor);
break; break;
case WM_CLOSE: { case WM_CLOSE: {
struct Event { pod::payloads::windowEvent event{
std::string type = "unknown"; "window:Closed",
std::string invoker = "???"; "os",
}; };
Event event; { #if UF_USE_USERDATA
event.type = "window:Closed"; this->pushEvent(event.type, event);
event.invoker = "os"; #endif
}; #if UF_USE_JSON
#if USE_OPTIMAL uf::Serializer json;
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event))); json["type"] = event.type;
json["invoker"] = event.invoker;
this->pushEvent(event.type, json);
#endif #endif
{
json["type"] = event.type;
json["invoker"] = event.invoker;
this->pushEvent(event.type, json);
}
} break; } break;
case WM_SIZE: { case WM_SIZE: {
if (wParam != SIZE_MINIMIZED && !this->m_resizing && this->m_lastSize != getSize()) { if (wParam == SIZE_MINIMIZED || this->m_resizing || this->m_lastSize == getSize()) break;
this->m_lastSize = this->getSize(); this->m_lastSize = this->getSize();
struct Event { pod::payloads::windowResized event{
std::string type = "unknown"; "window:Resized",
std::string invoker = "???"; "os",
{ this->m_lastSize },
struct { };
pod::Vector2i size; #if UF_USE_USERDATA
} window; this->pushEvent(event.type, event);
}; #endif
Event event; { #if UF_USE_JSON
event.type = "window:Resized"; uf::Serializer json;
event.invoker = "os"; json["type"] = event.type;
event.window.size = this->m_lastSize; json["invoker"] = event.invoker;
}; json["window"]["size"] = uf::vector::encode(event.window.size);
#if USE_OPTIMAL this->pushEvent(event.type, json);
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event))); #endif
#endif this->grabMouse(this->m_mouseGrabbed);
{
json["type"] = event.type;
json["invoker"] = event.invoker;
json["window"]["size"] = uf::vector::encode(event.window.size);
// json["window"]["size"]["x"] = event.window.size.x;
// json["window"]["size"]["y"] = event.window.size.y;
this->pushEvent(event.type, json);
}
this->grabMouse(this->m_mouseGrabbed);
}
} break; } break;
case WM_ENTERSIZEMOVE: { case WM_ENTERSIZEMOVE: {
this->m_resizing = true; this->m_resizing = true;
@ -1007,50 +995,38 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
} break; } break;
case WM_EXITSIZEMOVE:{ case WM_EXITSIZEMOVE:{
this->m_resizing = false; this->m_resizing = false;
if(this->m_lastSize != this->getSize()) { if( this->m_lastSize != this->getSize() ) {
this->m_lastSize = this->getSize(); this->m_lastSize = this->getSize();
struct Event { pod::payloads::windowResized event = {
std::string type = "unknown"; "window:Resized",
std::string invoker = "???"; "os",
{ this->m_lastSize },
struct {
pod::Vector2i size;
} window;
}; };
Event event; { #if UF_USE_USERDATA
event.type = "window:Resized"; this->pushEvent(event.type, event);
event.invoker = "os"; #endif
event.window.size = this->m_lastSize; #if UF_USE_JSON
}; uf::Serializer json;
#if USE_OPTIMAL json["type"] = event.type;
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event))); json["invoker"] = event.invoker;
json["window"]["size"] = uf::vector::encode(event.window.size);
this->pushEvent(event.type, json);
#endif #endif
{
json["type"] = event.type;
json["invoker"] = event.invoker;
json["window"]["size"] = uf::vector::encode(event.window.size);
// json["window"]["size"]["x"] = event.window.size.x;
// json["window"]["size"]["y"] = event.window.size.y;
this->pushEvent(event.type, json);
}
} else { } else {
struct Event { pod::payloads::windowEvent event{
std::string type = "unknown"; "window:Moved",
std::string invoker = "???"; "os",
}; };
Event event; { #if UF_USE_USERDATA
event.type = "window:Moved"; this->pushEvent(event.type, event);
event.invoker = "os"; #endif
}; #if UF_USE_JSON
#if USE_OPTIMAL uf::Serializer json;
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event))); json["type"] = event.type;
json["invoker"] = event.invoker;
this->pushEvent(event.type, json);
#endif #endif
{
json["type"] = event.type;
json["invoker"] = event.invoker;
this->pushEvent(event.type, json);
}
} }
this->grabMouse(this->m_mouseGrabbed); this->grabMouse(this->m_mouseGrabbed);
} break; } break;
@ -1069,35 +1045,27 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
this->grabMouse(this->m_mouseGrabbed); this->grabMouse(this->m_mouseGrabbed);
SetCursor(this->m_cursor); SetCursor(this->m_cursor);
} }
struct Event { pod::payloads::windowFocusedChanged event{
std::string type = "unknown"; "window:Focus.Changed",
std::string invoker = "???"; "os",
struct {
int state = 0;
} window;
}; };
Event event; { switch ( message ) {
event.type = "window:Focus.Changed"; case WM_SETFOCUS: event.window.state = 1; break;
event.invoker = "os"; case WM_KILLFOCUS: event.window.state = -1; break;
switch ( message ) {
case WM_SETFOCUS: event.window.state = 1; break;
case WM_KILLFOCUS: event.window.state = -1; break;
}
};
#if USE_OPTIMAL
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event)));
#endif
{
json["type"] = event.type;
json["invoker"] = event.invoker;
switch ( message ) {
case WM_SETFOCUS: json["window"]["state"] = "Gained"; break;
case WM_KILLFOCUS: json["window"]["state"] = "Lost"; break;
}
this->pushEvent(event.type, json);
} }
#if UF_USE_USERDATA
this->pushEvent(event.type, event);
#endif
#if UF_USE_JSON
uf::Serializer json;
json["type"] = event.type;
json["invoker"] = event.invoker;
switch ( message ) {
case WM_SETFOCUS: json["window"]["state"] = "Gained"; break;
case WM_KILLFOCUS: json["window"]["state"] = "Lost"; break;
}
this->pushEvent(event.type, json);
#endif
} break; } break;
// Text event // Text event
case WM_CHAR: if ( /*true ||*/ this->m_syncParse ) { case WM_CHAR: if ( /*true ||*/ this->m_syncParse ) {
@ -1120,36 +1088,26 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
std::basic_string<uint32_t> utf32; utf32+=character; std::basic_string<uint32_t> utf32; utf32+=character;
std::basic_string<uint8_t> utf8; utf8.reserve(utf32.length()); std::basic_string<uint8_t> utf8; utf8.reserve(utf32.length());
uf::Utf32::toUtf8(utf32.begin(), utf32.end(), std::back_inserter(utf8)); uf::Utf32::toUtf8(utf32.begin(), utf32.end(), std::back_inserter(utf8));
std::stringstream to_hex;
to_hex << std::hex << character;
struct Event { pod::payloads::windowTextEntered event{
std::string type = "unknown"; "window:Text.Entered",
std::string invoker = "???"; "os",
{
struct { character,
uint32_t utf32; std::string(utf8.begin(), utf8.end()),
std::string unicode; }
} text;
}; };
Event event; { #if UF_USE_USERDATA
event.type = "window:Text.Entered"; this->pushEvent(event.type, event);
event.invoker = "os";
event.text.utf32 = character;
event.text.unicode = std::string(utf8.begin(), utf8.end());
};
#if USE_OPTIMAL
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event)));
#endif #endif
#if UF_USE_JSON
uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
json["text"]["uint32_t"] = event.text.utf32; json["text"]["uint32_t"] = event.text.utf32;
json["text"]["unicode"] = std::string(utf8.begin(), utf8.end()); json["text"]["unicode"] = event.text.unicode;
this->pushEvent(event.type, json); this->pushEvent(event.type, json);
#endif
} }
} }
} break; } break;
@ -1158,71 +1116,51 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
case WM_KEYUP: case WM_KEYUP:
case WM_SYSKEYUP: if ( /*true ||*/ this->m_syncParse ) { case WM_SYSKEYUP: if ( /*true ||*/ this->m_syncParse ) {
if (this->m_keyRepeatEnabled || ((HIWORD(lParam) & KF_REPEAT) == 0)) { if (this->m_keyRepeatEnabled || ((HIWORD(lParam) & KF_REPEAT) == 0)) {
struct Event { int_fast8_t state = 0;
std::string type = "unknown"; switch ( message ) {
std::string invoker = "???"; case WM_KEYDOWN:
case WM_SYSKEYDOWN: state = -1; break;
struct { case WM_KEYUP:
int state = -1; case WM_SYSKEYUP: state = 1; break;
std::string code;
uint32_t raw;
bool async;
struct {
bool alt;
bool ctrl;
bool shift;
bool sys;
} modifier;
} key;
};
Event event; {
event.type = "window:Key",
event.invoker = "window",
event.key.code = this->getKey(wParam, lParam),
event.key.raw = wParam,
event.key.async = false,
event.key.modifier = {
.alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0,
.ctrl = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0,
.shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0,
.sys = HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN)),
};
switch ( message ) {
case WM_KEYDOWN:
case WM_SYSKEYDOWN: event.key.state = -1; break;
case WM_KEYUP:
case WM_SYSKEYUP: event.key.state = 1; break;
}
} }
// if ( USE_OPTIMAL ) this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event))); pod::payloads::windowKey event{
// if ( USE_OPTIMAL ) this->pushEvent(event.type + "." + event.key.code, uf::Userdata(uf::userdata::create(event))); "window:Key",
json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released"); "os",
json["invoker"] = event.invoker; {
json["key"]["state"] = (event.key.state == -1) ? "Down" : "Up"; this->getKey(wParam, lParam),
json["key"]["async"] = event.key.async; wParam,
json["key"]["modifier"]["alt"] = event.key.modifier.alt; state,
json["key"]["modifier"]["control"] = event.key.modifier.ctrl; false,
json["key"]["modifier"]["shift"] = event.key.modifier.shift; {
json["key"]["modifier"]["system"] = event.key.modifier.sys; .alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0,
.ctrl = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0,
json["key"]["code"] = event.key.code; .shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0,
json["key"]["raw"] = event.key.raw; .sys = HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN)),
json["key"]["lparam"] = lParam; }
}
// don't know why things dont like things };
/* #if UF_USE_USERDATA
if (event.key.state == -1) { this->pushEvent(event.type, event);
uf::hooks.call(event.type, json); this->pushEvent(event.type + "." + event.key.code, event);
uf::hooks.call(event.type + "." + event.key.code, json); #endif
} else { #if UF_USE_JSON
uf::Serializer json;
json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released");
json["invoker"] = event.invoker;
json["key"]["state"] = (event.key.state == -1) ? "Down" : "Up";
json["key"]["async"] = event.key.async;
json["key"]["modifier"]["alt"] = event.key.modifier.alt;
json["key"]["modifier"]["control"] = event.key.modifier.ctrl;
json["key"]["modifier"]["shift"] = event.key.modifier.shift;
json["key"]["modifier"]["system"] = event.key.modifier.sys;
json["key"]["code"] = event.key.code;
json["key"]["raw"] = event.key.raw;
json["key"]["lparam"] = lParam;
this->pushEvent(event.type, json); this->pushEvent(event.type, json);
this->pushEvent(event.type + "." + event.key.code, json); this->pushEvent(event.type + "." + event.key.code, json);
} #endif
*/
this->pushEvent(event.type, json);
this->pushEvent(event.type + "." + event.key.code, json);
} }
} break; } break;
case WM_MOUSEWHEEL: { case WM_MOUSEWHEEL: {
@ -1232,38 +1170,25 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
ScreenToClient(this->m_handle, &position); ScreenToClient(this->m_handle, &position);
int16_t delta = static_cast<int16_t>(HIWORD(wParam)); int16_t delta = static_cast<int16_t>(HIWORD(wParam));
pod::payloads::windowMouseWheel event{
struct Event { "window:Mouse.Wheel",
std::string type = "unknown"; "os",
std::string invoker = "???"; {
pod::Vector2ui{ position.x, position.y },
struct { delta,
pod::Vector2ui position = {}; }
float delta = 0;
} mouse;
}; };
Event event; { #if UF_USE_USERDATA
event.type = "window:Mouse.Wheel"; this->pushEvent(event.type, event);
event.invoker = "os"; #endif
#if UF_USE_JSON
event.mouse.position.x = position.x; uf::Serializer json;
event.mouse.position.y = position.y; json["type"] = event.type;
event.mouse.delta = delta; // 120.0f; json["invoker"] = event.invoker;
}; json["mouse"]["position"] = uf::vector::encode(event.mouse.position);
#if USE_OPTIMAL json["mouse"]["delta"] = event.mouse.delta;
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event))); this->pushEvent(event.type, json);
#endif #endif
{
json["type"] = event.type;
json["invoker"] = event.invoker;
json["mouse"]["position"] = uf::vector::encode(event.mouse.position);
// json["mouse"]["position"]["x"] = event.mouse.position.x;
// json["mouse"]["position"]["y"] = event.mouse.position.y;
json["mouse"]["delta"] = event.mouse.delta;
this->pushEvent(event.type, json);
}
} break; } break;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
case WM_LBUTTONUP: case WM_LBUTTONUP:
@ -1274,187 +1199,90 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
case WM_XBUTTONDOWN: case WM_XBUTTONDOWN:
case WM_XBUTTONUP: if ( true || this->m_syncParse ) { case WM_XBUTTONUP: if ( true || this->m_syncParse ) {
static pod::Vector2i lastPosition = {}; static pod::Vector2i lastPosition = {};
struct Event {
std::string type = "unknown"; const pod::Vector2i currentPosition = pod::Vector2ui{ static_cast<int16_t>(LOWORD(lParam)), static_cast<int16_t>(HIWORD(lParam)) };
std::string invoker = "???"; std::string button = "";
int_fast8_t state = 0;
struct { switch ( message ) {
pod::Vector2i position = {}; case WM_LBUTTONDOWN:
pod::Vector2i delta = lastPosition; case WM_LBUTTONUP: button = "Left"; break;
std::string button = "???";
int state = 0; case WM_RBUTTONDOWN:
} mouse; case WM_RBUTTONUP: button = "Right"; break;
};
Event event; { case WM_MBUTTONDOWN:
event.type = "window:Mouse.Click"; case WM_MBUTTONUP: button = "Middle"; break;
event.invoker = "os";
case WM_XBUTTONDOWN:
case WM_XBUTTONUP: button = "Aux"; break;
// event.mouse.position = this->getMousePosition(); default: button = "???"; break;
event.mouse.position.x = static_cast<int16_t>(LOWORD(lParam));
event.mouse.position.y = static_cast<int16_t>(HIWORD(lParam));
event.mouse.delta = event.mouse.position - lastPosition;
switch ( message ) {
case WM_LBUTTONDOWN:
case WM_LBUTTONUP: event.mouse.button = "Left"; break;
case WM_RBUTTONDOWN:
case WM_RBUTTONUP: event.mouse.button = "Right"; break;
case WM_MBUTTONDOWN:
case WM_MBUTTONUP: event.mouse.button = "Middle"; break;
case WM_XBUTTONDOWN:
case WM_XBUTTONUP: event.mouse.button = "Aux"; break;
default: event.mouse.button = "???"; break;
}
switch ( message ) {
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_XBUTTONUP: event.mouse.state = 1; break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN: event.mouse.state = -1; break;
default: event.mouse.state = 0; break;
}
};
if ( true || this->m_syncParse ){
#if USE_OPTIMAL
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event)));
#endif
json["type"] = event.type;
json["invoker"] = event.invoker;
json["mouse"]["position"] = uf::vector::encode(event.mouse.position);
json["mouse"]["delta"] = uf::vector::encode(event.mouse.delta);
// json["mouse"]["position"]["x"] = event.mouse.position.x;
// json["mouse"]["position"]["y"] = event.mouse.position.y;
// json["mouse"]["delta"]["x"] = event.mouse.delta.x;
// json["mouse"]["delta"]["y"] = event.mouse.delta.y;
json["mouse"]["button"] = event.mouse.button;
switch (event.mouse.state) {
case 1:
json["mouse"]["state"] = "Up";
break;
case -1:
json["mouse"]["state"] = "Down";
break;
default:
json["mouse"]["state"] = "???";
break;
}
this->pushEvent(event.type, json);
} }
lastPosition = event.mouse.position; //this->getMousePosition(); switch ( message ) {
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_XBUTTONUP: state = 1; break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN: state = -1; break;
default: state = 0; break;
}
pod::payloads::windowMouseClick event{
"window:Mouse.Click",
"os",
{
currentPosition,
currentPosition - lastPosition,
button,
state
}
};
#if UF_USE_USERDATA
this->pushEvent(event.type, event);
#endif
#if UF_USE_JSON
uf::Serializer json;
json["type"] = event.type;
json["invoker"] = event.invoker;
json["mouse"]["position"] = uf::vector::encode(event.mouse.position);
json["mouse"]["delta"] = uf::vector::encode(event.mouse.delta);
json["mouse"]["button"] = event.mouse.button;
switch (event.mouse.state) {
case 1: json["mouse"]["state"] = "Up"; break;
case -1: json["mouse"]["state"] = "Down"; break;
}
this->pushEvent(event.type, json);
#endif
lastPosition = currentPosition;
} break; } break;
case WM_MOUSELEAVE: case WM_MOUSELEAVE:
if (this->m_mouseInside) { if ( this->m_mouseInside ) {
this->m_mouseInside = false; this->m_mouseInside = false;
struct Event { pod::payloads::windowMouseMoved event{
std::string type = "unknown"; "window:Mouse.Moved",
std::string invoker = "???"; "os",
{
struct { {}
int state = 0; },
} mouse; {
}; {},
Event event; { {},
event.type = "window:Mouse.Moved"; -1
event.invoker = "os";
event.mouse.state = -1;
};
#if USE_OPTIMAL
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event)));
#endif
{
json["type"] = event.type;
json["invoker"] = event.invoker;
switch (event.mouse.state) {
case 1:
json["mouse"]["state"] = "Entered";
break;
case -1:
json["mouse"]["state"] = "Left";
break;
default:
json["mouse"]["state"] = "???";
break;
} }
this->pushEvent(event.type, json); };
} #if UF_USE_USERDATA
} this->pushEvent(event.type, event);
break; #endif
case WM_MOUSEMOVE: { #if UF_USE_JSON
static pod::Vector2i lastPosition = {}; uf::Serializer json;
struct Event {
std::string type = "unknown";
std::string invoker = "???";
struct {
int state = 0;
pod::Vector2i position;
pod::Vector2i delta;
pod::Vector2i size;
} mouse;
};
Event event; {
event.type = "window:Mouse.Moved";
event.invoker = "os";
};
int x = static_cast<int16_t>(LOWORD(lParam));
int y = static_cast<int16_t>(HIWORD(lParam));
RECT area;
GetClientRect(this->m_handle, &area);
if ((wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | MK_XBUTTON1 | MK_XBUTTON2)) == 0) {
if (GetCapture() == this->m_handle) ReleaseCapture();
}
else if (GetCapture() != this->m_handle) {
SetCapture(this->m_handle);
}
if ((x < area.left) || (x > area.right) || (y < area.top) || (y > area.bottom)) {
if (this->m_mouseInside) {
this->m_mouseInside = false;
this->setTracking(false);
event.mouse.state = -1;
}
} else {
if (!this->m_mouseInside) {
this->m_mouseInside = true;
this->setTracking(true);
event.mouse.state = 1;
}
}
{
event.mouse.position.x = x;
event.mouse.position.y = y;
event.mouse.size = {area.right, area.bottom};
event.mouse.delta = event.mouse.position - lastPosition;
}
#if USE_OPTIMAL
this->pushEvent(event.type, uf::Userdata(uf::userdata::create(event)));
#endif
{
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
// json["mouse"]["position"]["x"] = event.mouse.position.x;
// json["mouse"]["position"]["y"] = event.mouse.position.y;
// json["mouse"]["delta"]["x"] = event.mouse.delta.x;
// json["mouse"]["delta"]["y"] = event.mouse.delta.y;
// json["mouse"]["size"]["x"] = event.mouse.size.x;
// json["mouse"]["size"]["y"] = event.mouse.size.y;
json["mouse"]["position"] = uf::vector::encode(event.mouse.position);
json["mouse"]["delta"] = uf::vector::encode(event.mouse.delta);
json["mouse"]["size"] = uf::vector::encode(event.mouse.size);
switch (event.mouse.state) { switch (event.mouse.state) {
case 1: case 1:
json["mouse"]["state"] = "Entered"; json["mouse"]["state"] = "Entered";
@ -1467,8 +1295,78 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
break; break;
} }
this->pushEvent(event.type, json); this->pushEvent(event.type, json);
#endif
} }
lastPosition = event.mouse.position; //this->getMousePosition(); break;
case WM_MOUSEMOVE: {
static pod::Vector2i lastPosition = {};
const pod::Vector2i currentPosition = {
static_cast<int16_t>(LOWORD(lParam)),
static_cast<int16_t>(HIWORD(lParam)),
};
RECT area;
GetClientRect(this->m_handle, &area);
if ((wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | MK_XBUTTON1 | MK_XBUTTON2)) == 0) {
if (GetCapture() == this->m_handle) ReleaseCapture();
}
else if (GetCapture() != this->m_handle) {
SetCapture(this->m_handle);
}
int_fast8_t state{};
if ((currentPosition.x < area.left) || (currentPosition.x > area.right) || (currentPosition.y < area.top) || (currentPosition.y > area.bottom)) {
if ( this->m_mouseInside ) {
this->m_mouseInside = false;
this->setTracking(false);
state = -1;
}
} else {
if ( !this->m_mouseInside ) {
this->m_mouseInside = true;
this->setTracking(true);
state = 1;
}
}
pod::payloads::windowMouseMoved event{
"window:Mouse.Moved",
"os",
{
pod::Vector2ui{ area.right, area.bottom },
},
{
currentPosition,
currentPosition - lastPosition,
state
}
};
#if UF_USE_USERDATA
this->pushEvent(event.type, event);
#endif
#if UF_USE_JSON
uf::Serializer json;
json["type"] = event.type;
json["invoker"] = event.invoker;
json["window"]["size"] = uf::vector::encode(event.window.size);
json["mouse"]["position"] = uf::vector::encode(event.mouse.position);
json["mouse"]["delta"] = uf::vector::encode(event.mouse.delta);
switch (event.mouse.state) {
case 1:
json["mouse"]["state"] = "Entered";
break;
case -1:
json["mouse"]["state"] = "Left";
break;
default:
json["mouse"]["state"] = "???";
break;
}
this->pushEvent(event.type, json);
#endif
lastPosition = currentPosition;
break; break;
} }
} }

View File

@ -5,6 +5,7 @@
#include <uf/utils/serialize/serializer.h> #include <uf/utils/serialize/serializer.h>
#include <uf/utils/userdata/userdata.h> #include <uf/utils/userdata/userdata.h>
#include <uf/utils/window/window.h> #include <uf/utils/window/window.h>
#include <uf/utils/window/payloads.h>
#include <uf/utils/camera/camera.h> #include <uf/utils/camera/camera.h>
#include <uf/utils/audio/audio.h> #include <uf/utils/audio/audio.h>
#include <uf/ext/openvr/openvr.h> #include <uf/ext/openvr/openvr.h>
@ -13,18 +14,6 @@
#include <uf/utils/math/physics.h> #include <uf/utils/math/physics.h>
#include <uf/spec/controller/controller.h> #include <uf/spec/controller/controller.h>
namespace pod {
namespace payloads {
struct windowMouseMoved {
std::string invoker = "";
pod::Vector2i delta;
pod::Vector2ui position;
pod::Vector2ui size;
int_fast8_t state;
};
}
}
#include <sstream> #include <sstream>
UF_BEHAVIOR_REGISTER_CPP(ext::PlayerBehavior) UF_BEHAVIOR_REGISTER_CPP(ext::PlayerBehavior)
#define this (&self) #define this (&self)
@ -111,26 +100,20 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) {
} }
metadataJson["system"]["control"] = true; metadataJson["system"]["control"] = true;
this->addHook( "window:Mouse.CursorVisibility", [&](ext::json::Value& json){ this->addHook( "window:Mouse.CursorVisibility", [&](ext::json::Value& json){
// metadataJson["system"]["control"] = !json["state"].as<bool>();
metadata.system.control = !json["state"].as<bool>(); metadata.system.control = !json["state"].as<bool>();
}); });
// Rotate Camera // Rotate Camera
this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload ){ this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload ){
pod::Vector2 relta = { (float) payload.delta.x / payload.size.x, (float) payload.delta.y / payload.size.y }; float sensitivity = 2;
relta *= 2; pod::Vector2 relta = { (float) sensitivity * payload.mouse.delta.x / payload.window.size.x, (float) sensitivity * payload.mouse.delta.y / payload.window.size.y };
if ( (payload.delta.x == 0 && payload.delta.y == 0) || !metadata.system.control ) return; if ( (payload.mouse.delta.x == 0 && payload.mouse.delta.y == 0) || !metadata.system.control ) return;
bool updateCamera = false; bool updateCamera = false;
if ( payload.delta.x != 0 ) { if ( payload.mouse.delta.x != 0 ) {
double current, minima, maxima; { if ( metadata.camera.invert.x ) relta.x *= -1;
current = !ext::json::isNull( metadataJson["camera"]["limit"]["current"][0] ) ? metadataJson["camera"]["limit"]["current"][0].as<double>() : NAN; metadata.camera.limit.current.x += relta.x;
minima = !ext::json::isNull( metadataJson["camera"]["limit"]["minima"][0] ) ? metadataJson["camera"]["limit"]["minima"][0].as<double>() : NAN; if ( metadata.camera.limit.current.x != metadata.camera.limit.current.x || ( metadata.camera.limit.current.x < metadata.camera.limit.max.x && metadata.camera.limit.current.x > metadata.camera.limit.min.x ) ) {
maxima = !ext::json::isNull( metadataJson["camera"]["limit"]["maxima"][0] ) ? metadataJson["camera"]["limit"]["maxima"][0].as<double>() : NAN;
}
if ( metadataJson["camera"]["invert"][0].as<bool>() ) relta.x *= -1;
current += relta.x;
if ( current != current || ( current < maxima && current > minima ) ) {
if ( collider.body && !collider.shared ) { if ( collider.body && !collider.shared ) {
#if UF_USE_BULLET #if UF_USE_BULLET
ext::bullet::applyRotation( collider, transform.up, relta.x ); ext::bullet::applyRotation( collider, transform.up, relta.x );
@ -138,27 +121,19 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) {
} else { } else {
uf::transform::rotate( transform, transform.up, relta.x ), updateCamera = true; uf::transform::rotate( transform, transform.up, relta.x ), updateCamera = true;
} }
} else current -= relta.x; } else metadata.camera.limit.current.x -= relta.x;
if ( !ext::json::isNull( metadataJson["camera"]["limit"]["current"][0] ) ) metadataJson["camera"]["limit"]["current"][0] = current;
} }
if ( payload.delta.y != 0 ) { if ( payload.mouse.delta.y != 0 ) {
double current, minima, maxima; { if ( metadata.camera.invert.y ) relta.y *= -1;
current = !ext::json::isNull( metadataJson["camera"]["limit"]["current"][1] ) ? metadataJson["camera"]["limit"]["current"][1].as<double>() : NAN; metadata.camera.limit.current.y += relta.y;
minima = !ext::json::isNull( metadataJson["camera"]["limit"]["minima"][1] ) ? metadataJson["camera"]["limit"]["minima"][1].as<double>() : NAN; if ( metadata.camera.limit.current.y != metadata.camera.limit.current.y || ( metadata.camera.limit.current.y < metadata.camera.limit.max.y && metadata.camera.limit.current.y > metadata.camera.limit.min.y ) ) {
maxima = !ext::json::isNull( metadataJson["camera"]["limit"]["maxima"][1] ) ? metadataJson["camera"]["limit"]["maxima"][1].as<double>() : NAN;
}
if ( metadataJson["camera"]["invert"][1].as<bool>() ) relta.y *= -1;
current += relta.y;
if ( current != current || ( current < maxima && current > minima ) ) {
// if ( collider.body && !collider.shared ) { // if ( collider.body && !collider.shared ) {
// ext::bullet::applyRotation( collider, cameraTransform.right, relta.y ); // ext::bullet::applyRotation( collider, cameraTransform.right, relta.y );
// } else { // } else {
uf::transform::rotate( cameraTransform, cameraTransform.right, relta.y ); uf::transform::rotate( cameraTransform, cameraTransform.right, relta.y );
// } // }
updateCamera = true; updateCamera = true;
} else current -= relta.y; } else metadata.camera.limit.current.y -= relta.y;
if ( !ext::json::isNull( metadataJson["camera"]["limit"]["current"][1] ) ) metadataJson["camera"]["limit"]["current"][1] = current;
} }
if ( updateCamera ) camera.updateView(); if ( updateCamera ) camera.updateView();
}); });
@ -259,6 +234,8 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) {
auto& metadataSystem = metadataJson["system"]; auto& metadataSystem = metadataJson["system"];
auto& metadataSystemPhysics = metadataSystem["physics"]; auto& metadataSystemPhysics = metadataSystem["physics"];
auto& metadataAudioFootstep = metadataJson["audio"]["footstep"]; auto& metadataAudioFootstep = metadataJson["audio"]["footstep"];
auto& metadataCamera = metadataJson["camera"];
auto& metadataCameraLimit = metadataCamera["limit"];
metadataSystem["menu"] = metadata.system.menu; metadataSystem["menu"] = metadata.system.menu;
metadataSystem["control"] = metadata.system.control; metadataSystem["control"] = metadata.system.control;
@ -274,11 +251,17 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) {
metadataSystemPhysics["crouch"] = metadata.system.physics.crouch; metadataSystemPhysics["crouch"] = metadata.system.physics.crouch;
metadataAudioFootstep["list"] = metadata.audio.footstep.list; metadataAudioFootstep["list"] = metadata.audio.footstep.list;
metadataAudioFootstep["volume"] = metadata.audio.footstep.volume; metadataAudioFootstep["volume"] = metadata.audio.footstep.volume;
metadataCamera["invert"] = uf::vector::encode(metadata.camera.invert);
metadataCameraLimit["current"] = uf::vector::encode(metadata.camera.limit.current);
metadataCameraLimit["minima"] = uf::vector::encode(metadata.camera.limit.min);
metadataCameraLimit["maxima"] = uf::vector::encode(metadata.camera.limit.max);
}; };
metadata.deserialize = [&](){ metadata.deserialize = [&](){
auto& metadataSystem = metadataJson["system"]; auto& metadataSystem = metadataJson["system"];
auto& metadataAudioFootstep = metadataJson["audio"]["footstep"]; auto& metadataAudioFootstep = metadataJson["audio"]["footstep"];
auto& metadataSystemPhysics = metadataSystem["physics"]; auto& metadataSystemPhysics = metadataSystem["physics"];
auto& metadataCamera = metadataJson["camera"];
auto& metadataCameraLimit = metadataCamera["limit"];
metadata.system.menu = metadataSystem["menu"].as<std::string>(); metadata.system.menu = metadataSystem["menu"].as<std::string>();
metadata.system.control = metadataSystem["control"].as<bool>(); metadata.system.control = metadataSystem["control"].as<bool>();
@ -296,6 +279,15 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) {
metadata.audio.footstep.list.emplace_back(value); metadata.audio.footstep.list.emplace_back(value);
}); });
metadata.audio.footstep.volume = metadataAudioFootstep["volume"].as<float>(); metadata.audio.footstep.volume = metadataAudioFootstep["volume"].as<float>();
metadata.camera.invert = uf::vector::decode( metadataCamera["invert"], pod::Vector3t<bool>{false, false, false} );
metadata.camera.limit.current = uf::vector::decode( metadataCameraLimit["current"], pod::Vector3f{NAN, NAN, NAN} );
metadata.camera.limit.min = uf::vector::decode( metadataCameraLimit["minima"], pod::Vector3f{NAN, NAN, NAN} );
metadata.camera.limit.max = uf::vector::decode( metadataCameraLimit["maxima"], pod::Vector3f{NAN, NAN, NAN} );
// for ( uint_fast8_t i = 0; i < 3; ++i ) metadata.camera.limit.current[i] = metadataCameraLimit["current"][i].as<float>(NAN);
// for ( uint_fast8_t i = 0; i < 3; ++i ) metadata.camera.limit.min[i] = metadataCameraLimit["minima"][i].as<float>(NAN);
// for ( uint_fast8_t i = 0; i < 3; ++i ) metadata.camera.limit.max[i] = metadataCameraLimit["maxima"][i].as<float>(NAN);
}; };
this->addHook( "object:UpdateMetadata.%UID%", metadata.deserialize); this->addHook( "object:UpdateMetadata.%UID%", metadata.deserialize);
metadata.deserialize(); metadata.deserialize();

View File

@ -26,11 +26,20 @@ namespace ext {
float walk = 1.0f; float walk = 1.0f;
pod::Vector3f jump = {0,8,0}; pod::Vector3f jump = {0,8,0};
} physics; } physics;
bool control = true; bool control = true;
std::string menu = ""; std::string menu = "";
bool crouching = false; bool crouching = false;
bool noclipped = false; bool noclipped = false;
} system; } system;
struct {
struct {
pod::Vector3f current = {NAN, NAN, NAN};
pod::Vector3f min = {NAN, NAN, NAN};
pod::Vector3f max = {NAN, NAN, NAN};
} limit;
pod::Vector3t<bool> invert;
} camera;
struct { struct {
struct { struct {
std::vector<std::string> list; std::vector<std::string> list;

View File

@ -31,18 +31,6 @@
#include <regex> #include <regex>
namespace pod {
namespace payloads {
struct windowMouseMoved {
std::string invoker = "";
pod::Vector2i delta;
pod::Vector2ui position;
pod::Vector2ui size;
int_fast8_t state;
};
}
}
namespace { namespace {
#if UF_USE_FREETYPE #if UF_USE_FREETYPE
struct { struct {
@ -555,51 +543,6 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
if ( metadataJson["system"]["hoverable"].as<bool>() ) { if ( metadataJson["system"]["hoverable"].as<bool>() ) {
uf::Timer<long long> hoverTimer(false); uf::Timer<long long> hoverTimer(false);
hoverTimer.start( uf::Time<>(-1000000) ); hoverTimer.start( uf::Time<>(-1000000) );
#if 1
this->addHook( "window:Mouse.Moved", [&]( pod::payloads::windowMouseMoved& payload ){
if ( ext::json::isObject( metadataJson["events"]["hover"] ) ) {
uf::Serializer event = metadataJson["events"]["hover"];
metadataJson["events"]["hover"] = ext::json::array(); //Json::arrayValue;
metadataJson["events"]["hover"][0] = event;
} else if ( !ext::json::isArray( metadataJson["events"]["hover"] ) ) {
this->getParent().as<uf::Object>().callHook("gui:Clicked.%UID%", payload );
return;
}
for ( int i = 0; i < metadataJson["events"]["hover"].size(); ++i ) {
uf::Serializer event = metadataJson["events"]["hover"][i];
uf::Serializer payload = event["payload"];
float delay = event["delay"].as<float>();
if ( event["delay"].is<double>() ) this->queueHook(event["name"].as<std::string>(), payload, event["delay"].as<float>());
else this->callHook(event["name"].as<std::string>(), payload );
}
return;
});
this->addHook( "window:Mouse.Moved", [&]( pod::payloads::windowMouseMoved& payload ){
if ( this->getUid() == 0 || !this->hasComponent<ext::Gui::mesh_t>() || metadata.world || (!metadata.box.min && !metadata.box.max) ) return;
bool clicked = false;
bool down = payload.state < 0;
pod::Vector2f click; {
click.x = (float) payload.position.x / (float) ext::gui::size.current.x;
click.y = (float) payload.position.y / (float) ext::gui::size.current.y;
click.x = (click.x * 2.0f) - 1.0f;
click.y = (click.y * 2.0f) - 1.0f;
float x = click.x;
float y = click.y;
clicked = ( metadata.box.min.x <= x && metadata.box.min.y <= y && metadata.box.max.x >= x && metadata.box.max.y >= y );
}
metadata.hovered = clicked;
metadataJson["hovered"] = clicked;
if ( clicked && hoverTimer.elapsed().asDouble() >= 1 ) {
hoverTimer.reset();
this->callHook("gui:Hovered.%UID%", payload);
}
this->callHook("gui:Mouse.Moved.%UID%", payload);
});
#else
this->addHook( "gui:Hovered.%UID%", [&](ext::json::Value& json){ this->addHook( "gui:Hovered.%UID%", [&](ext::json::Value& json){
if ( ext::json::isObject( metadataJson["events"]["hover"] ) ) { if ( ext::json::isObject( metadataJson["events"]["hover"] ) ) {
uf::Serializer event = metadataJson["events"]["hover"]; uf::Serializer event = metadataJson["events"]["hover"];
@ -628,12 +571,9 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
if ( metadata.world ) return; if ( metadata.world ) return;
if ( !metadata.box.min && !metadata.box.max ) return; if ( !metadata.box.min && !metadata.box.max ) return;
bool down = json["mouse"]["state"].as<std::string>() == "Down";
bool clicked = false; bool clicked = false;
pod::Vector2ui position = uf::vector::decode( json["mouse"]["position"], pod::Vector2ui{} ); { bool down = json["mouse"]["state"].as<std::string>() == "Down";
// position.x = json["mouse"]["position"]["x"].as<int>() > 0 ? json["mouse"]["position"]["x"].as<size_t>() : 0; pod::Vector2ui position = uf::vector::decode( json["mouse"]["position"], pod::Vector2ui{} );
// position.y = json["mouse"]["position"]["y"].as<int>() > 0 ? json["mouse"]["position"]["y"].as<size_t>() : 0;
}
pod::Vector2f click; { pod::Vector2f click; {
click.x = (float) position.x / (float) ext::gui::size.current.x; click.x = (float) position.x / (float) ext::gui::size.current.x;
click.y = (float) position.y / (float) ext::gui::size.current.y; click.y = (float) position.y / (float) ext::gui::size.current.y;
@ -654,7 +594,6 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
} }
this->callHook("gui:Mouse.Moved.%UID%", json); this->callHook("gui:Mouse.Moved.%UID%", json);
} ); } );
#endif
} }
#if UF_USE_FREETYPE #if UF_USE_FREETYPE
if ( metadataJson["text settings"]["string"].is<std::string>() ) { if ( metadataJson["text settings"]["string"].is<std::string>() ) {