mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
Use ImGUI for encoding/decoding
This commit is contained in:
parent
0477f74dcd
commit
8ddd0eb583
@ -770,10 +770,6 @@ if (APPLE)
|
|||||||
|
|
||||||
# Half float conversions for F16C patches
|
# Half float conversions for F16C patches
|
||||||
target_link_libraries(shadps4 PRIVATE half)
|
target_link_libraries(shadps4 PRIVATE half)
|
||||||
|
|
||||||
# Link against the iconv in macOS
|
|
||||||
find_package(Iconv REQUIRED)
|
|
||||||
target_link_libraries(shadps4 PRIVATE Iconv::Iconv)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT ENABLE_QT_GUI)
|
if (NOT ENABLE_QT_GUI)
|
||||||
|
@ -14,13 +14,6 @@
|
|||||||
#include "core/linker.h"
|
#include "core/linker.h"
|
||||||
#include "imgui/imgui_std.h"
|
#include "imgui/imgui_std.h"
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#define IME_UTF8_ENCODING "UTF-8"
|
|
||||||
#define IME_ORBIS_ENCODING "UTF-16LE"
|
|
||||||
#else
|
|
||||||
#include <Windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace ImGui;
|
using namespace ImGui;
|
||||||
|
|
||||||
static constexpr ImVec2 BUTTON_SIZE{100.0f, 30.0f};
|
static constexpr ImVec2 BUTTON_SIZE{100.0f, 30.0f};
|
||||||
@ -42,14 +35,6 @@ ImeDialogState::ImeDialogState(const OrbisImeDialogParam* param,
|
|||||||
max_text_length = param->maxTextLength;
|
max_text_length = param->maxTextLength;
|
||||||
text_buffer = param->inputTextBuffer;
|
text_buffer = param->inputTextBuffer;
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
orbis_to_utf8 = iconv_open(IME_UTF8_ENCODING, IME_ORBIS_ENCODING);
|
|
||||||
utf8_to_orbis = iconv_open(IME_ORBIS_ENCODING, IME_UTF8_ENCODING);
|
|
||||||
|
|
||||||
ASSERT_MSG(orbis_to_utf8 != (iconv_t)-1, "Failed to open iconv orbis_to_utf8");
|
|
||||||
ASSERT_MSG(utf8_to_orbis != (iconv_t)-1, "Failed to open iconv utf8_to_orbis");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (param->title) {
|
if (param->title) {
|
||||||
std::size_t title_len = std::char_traits<char16_t>::length(param->title);
|
std::size_t title_len = std::char_traits<char16_t>::length(param->title);
|
||||||
title.resize(title_len * 4 + 1);
|
title.resize(title_len * 4 + 1);
|
||||||
@ -78,10 +63,6 @@ ImeDialogState::ImeDialogState(const OrbisImeDialogParam* param,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImeDialogState::~ImeDialogState() {
|
|
||||||
Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImeDialogState::ImeDialogState(ImeDialogState&& other) noexcept
|
ImeDialogState::ImeDialogState(ImeDialogState&& other) noexcept
|
||||||
: input_changed(other.input_changed), userId(other.userId), is_multiLine(other.is_multiLine),
|
: input_changed(other.input_changed), userId(other.userId), is_multiLine(other.is_multiLine),
|
||||||
is_numeric(other.is_numeric), type(other.type), enter_label(other.enter_label),
|
is_numeric(other.is_numeric), type(other.type), enter_label(other.enter_label),
|
||||||
@ -90,21 +71,11 @@ ImeDialogState::ImeDialogState(ImeDialogState&& other) noexcept
|
|||||||
title(std::move(other.title)), placeholder(std::move(other.placeholder)),
|
title(std::move(other.title)), placeholder(std::move(other.placeholder)),
|
||||||
current_text(other.current_text) {
|
current_text(other.current_text) {
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
orbis_to_utf8 = other.orbis_to_utf8;
|
|
||||||
utf8_to_orbis = other.utf8_to_orbis;
|
|
||||||
|
|
||||||
other.orbis_to_utf8 = (iconv_t)-1;
|
|
||||||
other.utf8_to_orbis = (iconv_t)-1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
other.text_buffer = nullptr;
|
other.text_buffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImeDialogState& ImeDialogState::operator=(ImeDialogState&& other) {
|
ImeDialogState& ImeDialogState::operator=(ImeDialogState&& other) {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
Free();
|
|
||||||
|
|
||||||
input_changed = other.input_changed;
|
input_changed = other.input_changed;
|
||||||
userId = other.userId;
|
userId = other.userId;
|
||||||
is_multiLine = other.is_multiLine;
|
is_multiLine = other.is_multiLine;
|
||||||
@ -119,14 +90,6 @@ ImeDialogState& ImeDialogState::operator=(ImeDialogState&& other) {
|
|||||||
placeholder = std::move(other.placeholder);
|
placeholder = std::move(other.placeholder);
|
||||||
current_text = other.current_text;
|
current_text = other.current_text;
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
orbis_to_utf8 = other.orbis_to_utf8;
|
|
||||||
utf8_to_orbis = other.utf8_to_orbis;
|
|
||||||
|
|
||||||
other.orbis_to_utf8 = (iconv_t)-1;
|
|
||||||
other.utf8_to_orbis = (iconv_t)-1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
other.text_buffer = nullptr;
|
other.text_buffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,17 +140,6 @@ bool ImeDialogState::CallTextFilter() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImeDialogState::Free() {
|
|
||||||
#ifndef _WIN32
|
|
||||||
if (orbis_to_utf8 != (iconv_t)-1) {
|
|
||||||
iconv_close(orbis_to_utf8);
|
|
||||||
}
|
|
||||||
if (utf8_to_orbis != (iconv_t)-1) {
|
|
||||||
iconv_close(utf8_to_orbis);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImeDialogState::CallKeyboardFilter(const OrbisImeKeycode* src_keycode, u16* out_keycode,
|
bool ImeDialogState::CallKeyboardFilter(const OrbisImeKeycode* src_keycode, u16* out_keycode,
|
||||||
u32* out_status) {
|
u32* out_status) {
|
||||||
if (!keyboard_filter) {
|
if (!keyboard_filter) {
|
||||||
@ -202,60 +154,21 @@ bool ImeDialogState::CallKeyboardFilter(const OrbisImeKeycode* src_keycode, u16*
|
|||||||
|
|
||||||
bool ImeDialogState::ConvertOrbisToUTF8(const char16_t* orbis_text, std::size_t orbis_text_len,
|
bool ImeDialogState::ConvertOrbisToUTF8(const char16_t* orbis_text, std::size_t orbis_text_len,
|
||||||
char* utf8_text, std::size_t utf8_text_len) {
|
char* utf8_text, std::size_t utf8_text_len) {
|
||||||
|
|
||||||
std::fill(utf8_text, utf8_text + utf8_text_len, '\0');
|
std::fill(utf8_text, utf8_text + utf8_text_len, '\0');
|
||||||
#ifndef _WIN32
|
const ImWchar* orbis_text_ptr = reinterpret_cast<const ImWchar*>(orbis_text);
|
||||||
std::size_t orbis_text_len_bytes = orbis_text_len * sizeof(char16_t);
|
ImTextStrToUtf8(utf8_text, utf8_text_len, orbis_text_ptr, orbis_text_ptr + orbis_text_len);
|
||||||
std::size_t utf8_text_len_bytes = utf8_text_len * sizeof(char);
|
|
||||||
|
|
||||||
char16_t* orbis_text_ptr = const_cast<char16_t*>(orbis_text);
|
return true;
|
||||||
char* utf8_text_ptr = utf8_text;
|
|
||||||
|
|
||||||
std::size_t result = iconv(orbis_to_utf8, (char**)&orbis_text_ptr, &orbis_text_len_bytes,
|
|
||||||
(char**)&utf8_text_ptr, &utf8_text_len_bytes);
|
|
||||||
|
|
||||||
return result != (std::size_t)-1;
|
|
||||||
#else
|
|
||||||
int required_size =
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(orbis_text),
|
|
||||||
orbis_text_len, nullptr, 0, nullptr, nullptr);
|
|
||||||
if (required_size > utf8_text_len) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int converted_size =
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(orbis_text),
|
|
||||||
orbis_text_len, utf8_text, utf8_text_len, nullptr, nullptr);
|
|
||||||
|
|
||||||
return converted_size != 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImeDialogState::ConvertUTF8ToOrbis(const char* utf8_text, std::size_t utf8_text_len,
|
bool ImeDialogState::ConvertUTF8ToOrbis(const char* utf8_text, std::size_t utf8_text_len,
|
||||||
char16_t* orbis_text, std::size_t orbis_text_len) {
|
char16_t* orbis_text, std::size_t orbis_text_len) {
|
||||||
|
|
||||||
std::fill(orbis_text, orbis_text + orbis_text_len, u'\0');
|
std::fill(orbis_text, orbis_text + orbis_text_len, u'\0');
|
||||||
#ifndef _WIN32
|
ImTextStrFromUtf8(reinterpret_cast<ImWchar*>(orbis_text), orbis_text_len, utf8_text, nullptr);
|
||||||
std::size_t utf8_text_len_bytes = utf8_text_len * sizeof(char);
|
|
||||||
std::size_t orbis_text_len_bytes = orbis_text_len * sizeof(char16_t);
|
|
||||||
|
|
||||||
char* utf8_text_ptr = const_cast<char*>(utf8_text);
|
return true;
|
||||||
char16_t* orbis_text_ptr = orbis_text;
|
|
||||||
|
|
||||||
std::size_t result = iconv(utf8_to_orbis, (char**)&utf8_text_ptr, &utf8_text_len_bytes,
|
|
||||||
(char**)&orbis_text_ptr, &orbis_text_len_bytes);
|
|
||||||
|
|
||||||
return result != (std::size_t)-1;
|
|
||||||
#else
|
|
||||||
int required_size = MultiByteToWideChar(CP_UTF8, 0, utf8_text, utf8_text_len, nullptr, 0);
|
|
||||||
if (required_size > orbis_text_len) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int converted_size =
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, utf8_text, utf8_text_len,
|
|
||||||
reinterpret_cast<wchar_t*>(orbis_text), orbis_text_len);
|
|
||||||
|
|
||||||
return converted_size != 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImeDialogUi::ImeDialogUi(ImeDialogState* state, OrbisImeDialogStatus* status,
|
ImeDialogUi::ImeDialogUi(ImeDialogState* state, OrbisImeDialogStatus* status,
|
||||||
|
@ -5,9 +5,6 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#ifndef _WIN32
|
|
||||||
#include <iconv.h>
|
|
||||||
#endif
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "common/cstring.h"
|
#include "common/cstring.h"
|
||||||
#include "common/types.h"
|
#include "common/types.h"
|
||||||
@ -37,10 +34,7 @@ class ImeDialogState final {
|
|||||||
|
|
||||||
// A character can hold up to 4 bytes in UTF-8
|
// A character can hold up to 4 bytes in UTF-8
|
||||||
Common::CString<ORBIS_IME_DIALOG_MAX_TEXT_LENGTH * 4> current_text;
|
Common::CString<ORBIS_IME_DIALOG_MAX_TEXT_LENGTH * 4> current_text;
|
||||||
#ifndef _WIN32
|
|
||||||
iconv_t orbis_to_utf8 = (iconv_t)-1;
|
|
||||||
iconv_t utf8_to_orbis = (iconv_t)-1;
|
|
||||||
#endif
|
|
||||||
public:
|
public:
|
||||||
ImeDialogState(const OrbisImeDialogParam* param = nullptr,
|
ImeDialogState(const OrbisImeDialogParam* param = nullptr,
|
||||||
const OrbisImeParamExtended* extended = nullptr);
|
const OrbisImeParamExtended* extended = nullptr);
|
||||||
@ -48,13 +42,10 @@ public:
|
|||||||
ImeDialogState(ImeDialogState&& other) noexcept;
|
ImeDialogState(ImeDialogState&& other) noexcept;
|
||||||
ImeDialogState& operator=(ImeDialogState&& other);
|
ImeDialogState& operator=(ImeDialogState&& other);
|
||||||
|
|
||||||
~ImeDialogState();
|
|
||||||
|
|
||||||
bool CopyTextToOrbisBuffer();
|
bool CopyTextToOrbisBuffer();
|
||||||
bool CallTextFilter();
|
bool CallTextFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Free();
|
|
||||||
bool CallKeyboardFilter(const OrbisImeKeycode* src_keycode, u16* out_keycode, u32* out_status);
|
bool CallKeyboardFilter(const OrbisImeKeycode* src_keycode, u16* out_keycode, u32* out_status);
|
||||||
|
|
||||||
bool ConvertOrbisToUTF8(const char16_t* orbis_text, std::size_t orbis_text_len, char* utf8_text,
|
bool ConvertOrbisToUTF8(const char16_t* orbis_text, std::size_t orbis_text_len, char* utf8_text,
|
||||||
|
@ -21,7 +21,6 @@ extern void assert_fail_debug_msg(const char* msg);
|
|||||||
} \
|
} \
|
||||||
}())
|
}())
|
||||||
|
|
||||||
#define IMGUI_USE_WCHAR32
|
|
||||||
#define IMGUI_ENABLE_STB_TRUETYPE
|
#define IMGUI_ENABLE_STB_TRUETYPE
|
||||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
@ -29,4 +28,8 @@ extern void assert_fail_debug_msg(const char* msg);
|
|||||||
constexpr ImVec2(float _v) : x(_v), y(_v) {}
|
constexpr ImVec2(float _v) : x(_v), y(_v) {}
|
||||||
|
|
||||||
#define IM_VEC4_CLASS_EXTRA \
|
#define IM_VEC4_CLASS_EXTRA \
|
||||||
constexpr ImVec4(float _v) : x(_v), y(_v), z(_v), w(_v) {}
|
constexpr ImVec4(float _v) : x(_v), y(_v), z(_v), w(_v) {}
|
||||||
|
|
||||||
|
#ifdef IMGUI_USE_WCHAR32
|
||||||
|
#error "This project uses 16 bits wchar standard like Orbis"
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user