mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 12:01:50 +00:00
fix utf8 input
This commit is contained in:
parent
d896d2debb
commit
ad5834b1e1
3 changed files with 15 additions and 15 deletions
|
|
@ -9,9 +9,10 @@
|
|||
#include <SDL3/SDL_scancode.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "debug/Logger.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "window/detail/window_sdl.hpp"
|
||||
#include "window/input.hpp"
|
||||
|
||||
|
|
@ -132,6 +133,9 @@ void input_sdl::pollEvents() {
|
|||
codepoints.clear();
|
||||
pressedKeys.clear();
|
||||
|
||||
std::string text {};
|
||||
uint size {};
|
||||
|
||||
bool prevPressed = false;
|
||||
|
||||
static SDL_Event event;
|
||||
|
|
@ -184,15 +188,13 @@ void input_sdl::pollEvents() {
|
|||
window.setSize({event.window.data1, event.window.data2});
|
||||
break;
|
||||
case SDL_EVENT_TEXT_INPUT:
|
||||
std::vector<char> vec(
|
||||
event.text.text,
|
||||
event.text.text + std::strlen(event.text.text)
|
||||
);
|
||||
std::copy(
|
||||
vec.begin(), vec.end(), std::back_inserter(codepoints)
|
||||
);
|
||||
text += event.text.text;
|
||||
}
|
||||
}
|
||||
if (!text.empty()) {
|
||||
codepoints.push_back(util::decode_utf8(size, text.c_str()));
|
||||
}
|
||||
|
||||
for (auto& [_, binding] : bindings.getAll()) {
|
||||
if (!binding.enabled) {
|
||||
binding.state = false;
|
||||
|
|
@ -288,6 +290,6 @@ const std::vector<Keycode>& input_sdl::getPressedKeys() const {
|
|||
return pressedKeys;
|
||||
}
|
||||
|
||||
const std::vector<char>& input_sdl::getCodepoints() const {
|
||||
const std::vector<std::uint32_t>& input_sdl::getCodepoints() const {
|
||||
return codepoints;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public:
|
|||
ObserverHandler addKeyCallback(Keycode key, KeyCallback callback) override;
|
||||
|
||||
const std::vector<Keycode>& getPressedKeys() const override;
|
||||
const std::vector<char>& getCodepoints() const override;
|
||||
const std::vector<std::uint32_t>& getCodepoints() const override;
|
||||
private:
|
||||
glm::vec2 delta;
|
||||
glm::vec2 cursor;
|
||||
|
|
@ -49,7 +49,7 @@ private:
|
|||
bool cursorLocked = false;
|
||||
bool cursorDrag = false;
|
||||
Bindings bindings;
|
||||
std::vector<char> codepoints;
|
||||
std::vector<std::uint32_t> codepoints;
|
||||
std::vector<Keycode> pressedKeys;
|
||||
std::unordered_map<Keycode, util::HandlersList<>> keyCallbacks;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "util/HandlersList.hpp"
|
||||
|
||||
|
||||
namespace dv {
|
||||
class value;
|
||||
}
|
||||
|
|
@ -124,7 +123,6 @@ inline Mousecode mousecodes_all[] {
|
|||
Mousecode::BUTTON_5,
|
||||
};
|
||||
|
||||
|
||||
namespace input_util {
|
||||
void initialize();
|
||||
Keycode keycode_from(const std::string& name);
|
||||
|
|
@ -134,7 +132,7 @@ namespace input_util {
|
|||
std::string to_string(Keycode code);
|
||||
/// @return Mouse button label by keycode
|
||||
std::string to_string(Mousecode code);
|
||||
|
||||
|
||||
/// @return Key name by keycode
|
||||
std::string get_name(Keycode code);
|
||||
/// @return Mouse button name by keycode
|
||||
|
|
@ -282,7 +280,7 @@ public:
|
|||
) = 0;
|
||||
|
||||
virtual const std::vector<Keycode>& getPressedKeys() const = 0;
|
||||
virtual const std::vector<char>& getCodepoints() const = 0;
|
||||
virtual const std::vector<std::uint32_t>& getCodepoints() const = 0;
|
||||
|
||||
ObserverHandler addCallback(const std::string& name, KeyCallback callback) {
|
||||
return getBindings().require(name).onactived.add(callback);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue