mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-20 03:24:49 +00:00
Merge b483cc0ad1
into 69777e2ffa
This commit is contained in:
commit
63f8e74e13
10 changed files with 847 additions and 2 deletions
|
@ -501,6 +501,10 @@ set(IME_LIB src/core/libraries/ime/error_dialog.cpp
|
|||
src/core/libraries/ime/ime_dialog.h
|
||||
src/core/libraries/ime/ime_ui.cpp
|
||||
src/core/libraries/ime/ime_ui.h
|
||||
src/core/libraries/ime/ime_keyboard_layouts.cpp
|
||||
src/core/libraries/ime/ime_keyboard_layouts.h
|
||||
src/core/libraries/ime/ime_keyboard_ui.cpp
|
||||
src/core/libraries/ime/ime_keyboard_ui.h
|
||||
src/core/libraries/ime/ime.cpp
|
||||
src/core/libraries/ime/ime.h
|
||||
src/core/libraries/ime/ime_error.h
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "common/logging/log.h"
|
||||
#include "core/libraries/ime/ime_dialog.h"
|
||||
#include "core/libraries/ime/ime_dialog_ui.h"
|
||||
#include "core/libraries/ime/ime_keyboard_ui.h"
|
||||
#include "core/tls.h"
|
||||
#include "imgui/imgui_std.h"
|
||||
|
||||
|
@ -234,10 +235,12 @@ void ImeDialogUi::Draw() {
|
|||
|
||||
ImVec2 window_size;
|
||||
|
||||
const float keyboard_height = 200.0f;
|
||||
|
||||
if (state->is_multi_line) {
|
||||
window_size = {500.0f, 300.0f};
|
||||
window_size = {500.0f, 300.0f + keyboard_height};
|
||||
} else {
|
||||
window_size = {500.0f, 150.0f};
|
||||
window_size = {500.0f, 150.0f + keyboard_height};
|
||||
}
|
||||
|
||||
CentralizeNextWindow();
|
||||
|
@ -263,6 +266,7 @@ void ImeDialogUi::Draw() {
|
|||
} else {
|
||||
DrawInputText();
|
||||
}
|
||||
DrawKeyboard();
|
||||
|
||||
SetCursorPosY(GetCursorPosY() + 10.0f);
|
||||
|
||||
|
@ -337,6 +341,27 @@ void ImeDialogUi::DrawMultiLineInputText() {
|
|||
}
|
||||
}
|
||||
|
||||
void ImeDialogUi::DrawKeyboard() {
|
||||
static KeyboardMode kb_mode = KeyboardMode::Letters1;
|
||||
static bool shift_enabled = false;
|
||||
|
||||
static bool has_logged = false;
|
||||
if (!has_logged) {
|
||||
LOG_INFO(Lib_ImeDialog, "Virtual keyboard used from ImeDialog");
|
||||
has_logged = true;
|
||||
}
|
||||
|
||||
bool done_pressed = false;
|
||||
|
||||
DrawVirtualKeyboard(state->current_text.begin(), state->max_text_length * 4,
|
||||
&state->input_changed, kb_mode, shift_enabled, &done_pressed);
|
||||
|
||||
if (done_pressed) {
|
||||
*status = OrbisImeDialogStatus::Finished;
|
||||
result->endstatus = OrbisImeDialogEndStatus::Ok;
|
||||
}
|
||||
}
|
||||
|
||||
int ImeDialogUi::InputTextCallback(ImGuiInputTextCallbackData* data) {
|
||||
ImeDialogUi* ui = static_cast<ImeDialogUi*>(data->UserData);
|
||||
ASSERT(ui);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "common/cstring.h"
|
||||
#include "common/types.h"
|
||||
#include "core/libraries/ime/ime_dialog.h"
|
||||
#include "core/libraries/ime/ime_keyboard_ui.h"
|
||||
#include "imgui/imgui_layer.h"
|
||||
|
||||
namespace Libraries::ImeDialog {
|
||||
|
@ -78,6 +79,8 @@ private:
|
|||
void DrawInputText();
|
||||
void DrawMultiLineInputText();
|
||||
|
||||
void DrawKeyboard();
|
||||
|
||||
static int InputTextCallback(ImGuiInputTextCallbackData* data);
|
||||
};
|
||||
|
||||
|
|
493
src/core/libraries/ime/ime_keyboard_layouts.cpp
Normal file
493
src/core/libraries/ime/ime_keyboard_layouts.cpp
Normal file
|
@ -0,0 +1,493 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <imgui.h>
|
||||
#include "ime_keyboard_layouts.h"
|
||||
|
||||
constexpr auto L1 = ImGuiNavInput_FocusPrev;
|
||||
constexpr auto R1 = ImGuiNavInput_FocusNext;
|
||||
constexpr auto L2 = ImGuiNavInput_TweakSlow;
|
||||
constexpr auto R2 = ImGuiNavInput_TweakFast;
|
||||
constexpr auto L3 = ImGuiNavInput_DpadLeft; // adjust if needed
|
||||
constexpr auto R3 = ImGuiNavInput_DpadRight; // adjust if needed
|
||||
constexpr auto Up = ImGuiNavInput_DpadUp;
|
||||
constexpr auto Down = ImGuiNavInput_DpadDown;
|
||||
constexpr auto Left = ImGuiNavInput_DpadLeft;
|
||||
constexpr auto Right = ImGuiNavInput_DpadRight;
|
||||
constexpr auto Cross = ImGuiNavInput_Activate;
|
||||
constexpr auto Circle = ImGuiNavInput_Menu;
|
||||
constexpr auto Square = ImGuiNavInput_Cancel;
|
||||
constexpr auto Triangle = ImGuiNavInput_Input;
|
||||
constexpr auto TouchPad = ImGuiNavInput_Menu; // reuse if needed
|
||||
|
||||
const std::vector<Key> kLayoutEnLettersUppercase = {
|
||||
// Row 1
|
||||
{0, 0, 1, 1, "1", "", KeyType::Text, {}},
|
||||
{0, 1, 1, 1, "2", "", KeyType::Text, {}},
|
||||
{0, 2, 1, 1, "3", "", KeyType::Text, {}},
|
||||
{0, 3, 1, 1, "4", "", KeyType::Text, {}},
|
||||
{0, 4, 1, 1, "5", "", KeyType::Text, {}},
|
||||
{0, 5, 1, 1, "6", "", KeyType::Text, {}},
|
||||
{0, 6, 1, 1, "7", "", KeyType::Text, {}},
|
||||
{0, 7, 1, 1, "8", "", KeyType::Text, {}},
|
||||
{0, 8, 1, 1, "9", "", KeyType::Text, {}},
|
||||
{0, 9, 1, 1, "0", "", KeyType::Text, {}},
|
||||
|
||||
// Row 2
|
||||
{1, 0, 1, 1, "Q", "", KeyType::Text, {}},
|
||||
{1, 1, 1, 1, "W", "", KeyType::Text, {}},
|
||||
{1, 2, 1, 1, "E", "", KeyType::Text, {}},
|
||||
{1, 3, 1, 1, "R", "", KeyType::Text, {}},
|
||||
{1, 4, 1, 1, "T", "", KeyType::Text, {}},
|
||||
{1, 5, 1, 1, "Y", "", KeyType::Text, {}},
|
||||
{1, 6, 1, 1, "U", "", KeyType::Text, {}},
|
||||
{1, 7, 1, 1, "I", "", KeyType::Text, {}},
|
||||
{1, 8, 1, 1, "O", "", KeyType::Text, {}},
|
||||
{1, 9, 1, 1, "P", "", KeyType::Text, {}},
|
||||
|
||||
// Row 3
|
||||
{2, 0, 1, 1, "A", "", KeyType::Text, {}},
|
||||
{2, 1, 1, 1, "S", "", KeyType::Text, {}},
|
||||
{2, 2, 1, 1, "D", "", KeyType::Text, {}},
|
||||
{2, 3, 1, 1, "F", "", KeyType::Text, {}},
|
||||
{2, 4, 1, 1, "G", "", KeyType::Text, {}},
|
||||
{2, 5, 1, 1, "H", "", KeyType::Text, {}},
|
||||
{2, 6, 1, 1, "J", "", KeyType::Text, {}},
|
||||
{2, 7, 1, 1, "K", "", KeyType::Text, {}},
|
||||
{2, 8, 1, 1, "L", "", KeyType::Text, {}},
|
||||
{2, 9, 1, 1, "\"", "", KeyType::Text, {}},
|
||||
|
||||
// Row 4
|
||||
{3, 0, 1, 1, "Z", "", KeyType::Text, {}},
|
||||
{3, 1, 1, 1, "X", "", KeyType::Text, {}},
|
||||
{3, 2, 1, 1, "C", "", KeyType::Text, {}},
|
||||
{3, 3, 1, 1, "V", "", KeyType::Text, {}},
|
||||
{3, 4, 1, 1, "B", "", KeyType::Text, {}},
|
||||
{3, 5, 1, 1, "N", "", KeyType::Text, {}},
|
||||
{3, 6, 1, 1, "M", "", KeyType::Text, {}},
|
||||
{3, 7, 1, 1, "-", "", KeyType::Text, {}},
|
||||
{3, 8, 1, 1, "_", "", KeyType::Text, {}},
|
||||
{3, 9, 1, 1, "/", "", KeyType::Text, {}},
|
||||
|
||||
// Row 5
|
||||
{4, 0, 1, 1, "⬆", "L2", KeyType::Shift, {L2}},
|
||||
{4, 1, 1, 1, "@#:", "L2+△", KeyType::Symbols1Layout, {L3, Triangle}},
|
||||
{4, 2, 1, 1, "à", "L3", KeyType::AccentLettersLayout, {L3}},
|
||||
{4, 3, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 4, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
//{4, 5, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
//{4, 6, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 8, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
//{4, 9, 2, 1, "⇦", "□", KeyType::Backspace,{Square}},
|
||||
|
||||
// Row 6
|
||||
{5, 0, 1, 1, "▲", "", KeyType::CursorUp, {Up}},
|
||||
{5, 1, 1, 1, "▼", "", KeyType::CursorDown, {Down}},
|
||||
{5, 2, 1, 1, "◀", "L1", KeyType::CursorLeft, {L1}},
|
||||
{5, 3, 1, 1, "▶", "R1", KeyType::CursorRight, {R1}},
|
||||
{5, 4, 1, 1, "KB", "", KeyType::ToggleKeyboard, {}},
|
||||
{5, 5, 1, 1, "...", "", KeyType::MoreOptions, {}},
|
||||
{5, 6, 1, 1, "+/⊗", "R3", KeyType::ControllerAction, {R3}},
|
||||
{5, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{5, 8, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
//{5, 9, 2, 1, "Done", "R2", KeyType::Done,{R2}},
|
||||
};
|
||||
|
||||
const std::vector<Key> kLayoutEnLettersLowercase = {
|
||||
// Row 1
|
||||
{0, 0, 1, 1, "1", "", KeyType::Text, {}},
|
||||
{0, 1, 1, 1, "2", "", KeyType::Text, {}},
|
||||
{0, 2, 1, 1, "3", "", KeyType::Text, {}},
|
||||
{0, 3, 1, 1, "4", "", KeyType::Text, {}},
|
||||
{0, 4, 1, 1, "5", "", KeyType::Text, {}},
|
||||
{0, 5, 1, 1, "6", "", KeyType::Text, {}},
|
||||
{0, 6, 1, 1, "7", "", KeyType::Text, {}},
|
||||
{0, 7, 1, 1, "8", "", KeyType::Text, {}},
|
||||
{0, 8, 1, 1, "9", "", KeyType::Text, {}},
|
||||
{0, 9, 1, 1, "0", "", KeyType::Text, {}},
|
||||
|
||||
// Row 2
|
||||
{1, 0, 1, 1, "q", "", KeyType::Text, {}},
|
||||
{1, 1, 1, 1, "w", "", KeyType::Text, {}},
|
||||
{1, 2, 1, 1, "e", "", KeyType::Text, {}},
|
||||
{1, 3, 1, 1, "r", "", KeyType::Text, {}},
|
||||
{1, 4, 1, 1, "t", "", KeyType::Text, {}},
|
||||
{1, 5, 1, 1, "y", "", KeyType::Text, {}},
|
||||
{1, 6, 1, 1, "u", "", KeyType::Text, {}},
|
||||
{1, 7, 1, 1, "i", "", KeyType::Text, {}},
|
||||
{1, 8, 1, 1, "o", "", KeyType::Text, {}},
|
||||
{1, 9, 1, 1, "p", "", KeyType::Text, {}},
|
||||
|
||||
// Row 3
|
||||
{2, 0, 1, 1, "a", "", KeyType::Text, {}},
|
||||
{2, 1, 1, 1, "s", "", KeyType::Text, {}},
|
||||
{2, 2, 1, 1, "d", "", KeyType::Text, {}},
|
||||
{2, 3, 1, 1, "f", "", KeyType::Text, {}},
|
||||
{2, 4, 1, 1, "g", "", KeyType::Text, {}},
|
||||
{2, 5, 1, 1, "h", "", KeyType::Text, {}},
|
||||
{2, 6, 1, 1, "j", "", KeyType::Text, {}},
|
||||
{2, 7, 1, 1, "k", "", KeyType::Text, {}},
|
||||
{2, 8, 1, 1, "l", "", KeyType::Text, {}},
|
||||
{2, 9, 1, 1, "-", "", KeyType::Text, {}},
|
||||
|
||||
// Row 4
|
||||
{3, 0, 1, 1, "z", "", KeyType::Text, {}},
|
||||
{3, 1, 1, 1, "x", "", KeyType::Text, {}},
|
||||
{3, 2, 1, 1, "c", "", KeyType::Text, {}},
|
||||
{3, 3, 1, 1, "v", "", KeyType::Text, {}},
|
||||
{3, 4, 1, 1, "b", "", KeyType::Text, {}},
|
||||
{3, 5, 1, 1, "n", "", KeyType::Text, {}},
|
||||
{3, 6, 1, 1, "m", "", KeyType::Text, {}},
|
||||
{3, 7, 1, 1, "@", "", KeyType::Text, {}},
|
||||
{3, 8, 1, 1, ".", "", KeyType::Text, {}},
|
||||
{3, 9, 1, 1, "_", "", KeyType::Text, {}},
|
||||
|
||||
// Row 5
|
||||
{4, 0, 1, 1, "⇧", "L2", KeyType::Shift, {L2}},
|
||||
{4, 1, 1, 1, "@#:", "L2+△", KeyType::Symbols1Layout, {L2, Triangle}},
|
||||
{4, 2, 1, 1, "à", "L3", KeyType::AccentLettersLayout, {L3}},
|
||||
{4, 3, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 4, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 5, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 6, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 8, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
//{4, 8, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
|
||||
// Row 6
|
||||
{5, 0, 1, 1, "▲", "", KeyType::CursorUp, {Up}},
|
||||
{5, 1, 1, 1, "▼", "", KeyType::CursorDown, {Down}},
|
||||
{5, 2, 1, 1, "◀", "L1", KeyType::CursorLeft, {L1}},
|
||||
{5, 3, 1, 1, "▶", "R1", KeyType::CursorRight, {R1}},
|
||||
{5, 4, 1, 1, "KB", "", KeyType::ToggleKeyboard, {}},
|
||||
{5, 5, 1, 1, "...", "", KeyType::MoreOptions, {}},
|
||||
{5, 6, 1, 1, "+/⊗", "R3", KeyType::ControllerAction, {R3}},
|
||||
{5, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{5, 8, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
//{5, 9, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
};
|
||||
// From PS5
|
||||
const std::vector<Key> kLayoutEnSymbols1 = {
|
||||
// Row 1
|
||||
{0, 0, 1, 1, "!", "", KeyType::Text, {}},
|
||||
{0, 1, 1, 1, "?", "", KeyType::Text, {}},
|
||||
{0, 2, 1, 1, "\"", "", KeyType::Text, {}},
|
||||
{0, 3, 1, 1, "'", "", KeyType::Text, {}},
|
||||
{0, 4, 1, 1, "#", "", KeyType::Text, {}},
|
||||
{0, 5, 1, 1, "%", "", KeyType::Text, {}},
|
||||
{0, 6, 1, 1, "(", "", KeyType::Text, {}},
|
||||
{0, 7, 1, 1, ")", "", KeyType::Text, {}},
|
||||
{0, 8, 1, 1, "()", "", KeyType::Text, {}},
|
||||
{0, 9, 1, 1, "/", "", KeyType::Text, {}},
|
||||
|
||||
// Row 2
|
||||
{1, 0, 1, 1, "-", "", KeyType::Text, {}},
|
||||
{1, 1, 1, 1, "_", "", KeyType::Text, {}},
|
||||
{1, 2, 1, 1, ",", "", KeyType::Text, {}},
|
||||
{1, 3, 1, 1, ".", "", KeyType::Text, {}},
|
||||
{1, 4, 1, 1, ":", "", KeyType::Text, {}},
|
||||
{1, 5, 1, 1, ";", "", KeyType::Text, {}},
|
||||
{1, 6, 1, 1, "*", "", KeyType::Text, {}},
|
||||
{1, 7, 1, 1, "&", "", KeyType::Text, {}},
|
||||
{1, 8, 1, 1, "+", "", KeyType::Text, {}},
|
||||
{1, 9, 1, 1, "=", "", KeyType::Text, {}},
|
||||
|
||||
// Row 3
|
||||
{2, 0, 1, 1, "<", "", KeyType::Text, {}},
|
||||
{2, 1, 1, 1, ">", "", KeyType::Text, {}},
|
||||
{2, 2, 1, 1, "@", "", KeyType::Text, {}},
|
||||
{2, 3, 1, 1, "[", "", KeyType::Text, {}},
|
||||
{2, 4, 1, 1, "]", "", KeyType::Text, {}},
|
||||
{2, 5, 1, 1, "[]", "", KeyType::Text, {}},
|
||||
{2, 6, 1, 1, "{", "", KeyType::Text, {}},
|
||||
{2, 7, 1, 1, "}", "", KeyType::Text, {}},
|
||||
{2, 8, 1, 1, "{}", "", KeyType::Text, {}},
|
||||
{2, 9, 1, 2, "→", "", KeyType::Symbols2Layout, {}},
|
||||
|
||||
// Row 4
|
||||
{3, 0, 1, 1, "\\", "", KeyType::Text, {}},
|
||||
{3, 1, 1, 1, "|", "", KeyType::Text, {}},
|
||||
{3, 2, 1, 1, "^", "", KeyType::Text, {}},
|
||||
{3, 3, 1, 1, "`", "", KeyType::Text, {}},
|
||||
{3, 4, 1, 1, "$", "", KeyType::Text, {}},
|
||||
{3, 5, 1, 1, "€", "", KeyType::Text, {}},
|
||||
{3, 6, 1, 1, "£", "", KeyType::Text, {}},
|
||||
{3, 7, 1, 1, "¥", "", KeyType::Text, {}},
|
||||
{3, 8, 1, 1, "₩", "", KeyType::Text, {}},
|
||||
//{3, 9, 1, 2, "→", "", KeyType::Symbols2Layout,{}},
|
||||
|
||||
// Row 5
|
||||
{4, 0, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 1, 1, 1, "ABC", "L2+△", KeyType::LettersLayout, {L2, Triangle}},
|
||||
{4, 2, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 3, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 4, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 5, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 6, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 8, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
//{4, 9, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
|
||||
// Row 6
|
||||
{5, 0, 1, 1, "▲", "", KeyType::CursorUp, {Up}},
|
||||
{5, 1, 1, 1, "▼", "", KeyType::CursorDown, {Down}},
|
||||
{5, 2, 1, 1, "◀", "L1", KeyType::CursorLeft, {L1}},
|
||||
{5, 3, 1, 1, "▶", "R1", KeyType::CursorRight, {R1}},
|
||||
{5, 4, 1, 1, "KB", "", KeyType::ToggleKeyboard, {}},
|
||||
{5, 5, 1, 1, "...", "", KeyType::MoreOptions, {}},
|
||||
{5, 6, 1, 1, "+/⊗", "R3", KeyType::ControllerAction, {R3}},
|
||||
{5, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{5, 8, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
//{5, 9, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
|
||||
};
|
||||
|
||||
// From PS5
|
||||
const std::vector<Key> kLayoutEnSymbols2 = {
|
||||
// Row 1
|
||||
{0, 0, 1, 1, "“", "", KeyType::Text, {}},
|
||||
{0, 1, 1, 1, "”", "", KeyType::Text, {}},
|
||||
{0, 2, 1, 1, "„", "", KeyType::Text, {}},
|
||||
{0, 3, 1, 1, "¡", "", KeyType::Text, {}},
|
||||
{0, 4, 1, 1, "‼", "", KeyType::Text, {}},
|
||||
{0, 5, 1, 1, "¿", "", KeyType::Text, {}},
|
||||
{0, 6, 1, 1, "⁇", "", KeyType::Text, {}},
|
||||
{0, 7, 1, 1, "~", "", KeyType::Text, {}},
|
||||
{0, 8, 1, 1, "·", "", KeyType::Text, {}},
|
||||
{0, 9, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
|
||||
// Row 2
|
||||
{1, 0, 1, 1, "×", "", KeyType::Text, {}},
|
||||
{1, 1, 1, 1, "÷", "", KeyType::Text, {}},
|
||||
{1, 2, 1, 1, "‹", "", KeyType::Text, {}},
|
||||
{1, 3, 1, 1, "›", "", KeyType::Text, {}},
|
||||
{1, 4, 1, 1, "«", "", KeyType::Text, {}},
|
||||
{1, 5, 1, 1, "»", "", KeyType::Text, {}},
|
||||
{1, 6, 1, 1, "º", "", KeyType::Text, {}},
|
||||
{1, 7, 1, 1, "ª", "", KeyType::Text, {}},
|
||||
{1, 8, 1, 1, "°", "", KeyType::Text, {}},
|
||||
{1, 9, 1, 1, "§", "", KeyType::Text, {}},
|
||||
|
||||
// Row 3
|
||||
{2, 0, 1, 2, "←", "", KeyType::Symbols1Layout, {}},
|
||||
{2, 1, 1, 1, "¦", "", KeyType::Text, {}},
|
||||
{2, 2, 1, 1, "µ", "", KeyType::Text, {}},
|
||||
{2, 3, 1, 1, "¬", "", KeyType::Text, {}},
|
||||
{2, 4, 1, 1, "¹", "", KeyType::Text, {}},
|
||||
{2, 5, 1, 1, "²", "", KeyType::Text, {}},
|
||||
{2, 6, 1, 1, "³", "", KeyType::Text, {}},
|
||||
{2, 7, 1, 1, "¼", "", KeyType::Text, {}},
|
||||
{2, 8, 1, 1, "½", "", KeyType::Text, {}},
|
||||
{2, 9, 1, 1, "¾", "", KeyType::Text, {}},
|
||||
|
||||
// Row 4
|
||||
//{3, 0, 1, 1, "←", "", KeyType::Symbols1Layout, {}},
|
||||
{3, 1, 1, 1, "¢", "", KeyType::Text, {}},
|
||||
{3, 2, 1, 1, "¤", "", KeyType::Text, {}},
|
||||
{3, 3, 1, 1, "’", "", KeyType::Text, {}}, // not sure
|
||||
{3, 4, 1, 1, "‘", "", KeyType::Text, {}}, // not sure
|
||||
{3, 5, 1, 1, "‛", "", KeyType::Text, {}}, // not sure
|
||||
{3, 6, 1, 1, "‚", "", KeyType::Text, {}}, // not sure
|
||||
{3, 7, 1, 1, "№", "", KeyType::Text, {}},
|
||||
{3, 8, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{3, 9, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
|
||||
// Row 5
|
||||
{4, 0, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 1, 1, 1, "ABC", "L2+△", KeyType::LettersLayout, {L2, Triangle}},
|
||||
{4, 2, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 3, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 4, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 5, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 6, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 8, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
//{4, 9, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
|
||||
// Row 6
|
||||
{5, 0, 1, 1, "▲", "", KeyType::CursorUp, {Up}},
|
||||
{5, 1, 1, 1, "▼", "", KeyType::CursorDown, {Down}},
|
||||
{5, 2, 1, 1, "◀", "L1", KeyType::CursorLeft, {L1}},
|
||||
{5, 3, 1, 1, "▶", "R1", KeyType::CursorRight, {R1}},
|
||||
{5, 4, 1, 1, "KB", "", KeyType::ToggleKeyboard, {}},
|
||||
{5, 5, 1, 1, "...", "", KeyType::MoreOptions, {}},
|
||||
{5, 6, 1, 1, "+/⊗", "R3", KeyType::ControllerAction, {R3}},
|
||||
{5, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{5, 8, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
//{5, 9, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
|
||||
};
|
||||
|
||||
const std::vector<Key> kLayoutEnAccentLettersUppercase = {
|
||||
// Row 0
|
||||
{0, 0, 1, 1, "À", "", KeyType::Text, {}},
|
||||
{0, 1, 1, 1, "Á", "", KeyType::Text, {}},
|
||||
{0, 2, 1, 1, "Â", "", KeyType::Text, {}},
|
||||
{0, 3, 1, 1, "Ã", "", KeyType::Text, {}},
|
||||
{0, 4, 1, 1, "Ä", "", KeyType::Text, {}},
|
||||
{0, 5, 1, 1, "Å", "", KeyType::Text, {}},
|
||||
{0, 6, 1, 1, "Ą", "", KeyType::Text, {}},
|
||||
{0, 7, 1, 1, "Æ", "", KeyType::Text, {}},
|
||||
{0, 8, 1, 1, "Ç", "", KeyType::Text, {}},
|
||||
{0, 9, 1, 1, "Ć", "", KeyType::Text, {}},
|
||||
|
||||
// Row 1
|
||||
{1, 0, 1, 1, "È", "", KeyType::Text, {}},
|
||||
{1, 1, 1, 1, "É", "", KeyType::Text, {}},
|
||||
{1, 2, 1, 1, "Ê", "", KeyType::Text, {}},
|
||||
{1, 3, 1, 1, "Ë", "", KeyType::Text, {}},
|
||||
{1, 4, 1, 1, "Ę", "", KeyType::Text, {}},
|
||||
{1, 5, 1, 1, "Ğ", "", KeyType::Text, {}},
|
||||
{1, 6, 1, 1, "Ì", "", KeyType::Text, {}},
|
||||
{1, 7, 1, 1, "Í", "", KeyType::Text, {}},
|
||||
{1, 8, 1, 1, "Î", "", KeyType::Text, {}},
|
||||
{1, 9, 1, 1, "Ï", "", KeyType::Text, {}},
|
||||
|
||||
// Row 2
|
||||
{2, 0, 1, 1, "İ", "", KeyType::Text, {}},
|
||||
{2, 1, 1, 1, "Ł", "", KeyType::Text, {}},
|
||||
{2, 2, 1, 1, "Ñ", "", KeyType::Text, {}},
|
||||
{2, 3, 1, 1, "Ń", "", KeyType::Text, {}},
|
||||
{2, 4, 1, 1, "Ò", "", KeyType::Text, {}},
|
||||
{2, 5, 1, 1, "Ó", "", KeyType::Text, {}},
|
||||
{2, 6, 1, 1, "Ô", "", KeyType::Text, {}},
|
||||
{2, 7, 1, 1, "Õ", "", KeyType::Text, {}},
|
||||
{2, 8, 1, 1, "Ö", "", KeyType::Text, {}},
|
||||
{2, 9, 1, 1, "Ø", "", KeyType::Text, {}},
|
||||
|
||||
// Row 3
|
||||
{3, 0, 1, 1, "Œ", "", KeyType::Text, {}},
|
||||
{3, 1, 1, 1, "Ś", "", KeyType::Text, {}},
|
||||
{3, 2, 1, 1, "Ş", "", KeyType::Text, {}},
|
||||
{3, 3, 1, 1, "Š", "", KeyType::Text, {}},
|
||||
{3, 4, 1, 1, "ß", "", KeyType::Text, {}},
|
||||
{3, 5, 1, 1, "Ù", "", KeyType::Text, {}},
|
||||
{3, 6, 1, 1, "Ú", "", KeyType::Text, {}},
|
||||
{3, 7, 1, 1, "Û", "", KeyType::Text, {}},
|
||||
{3, 8, 1, 1, "Ü", "", KeyType::Text, {}},
|
||||
{3, 9, 1, 1, "Ý", "", KeyType::Text, {}},
|
||||
|
||||
// Row 4
|
||||
{4, 0, 1, 1, "Ÿ", "", KeyType::Text, {}},
|
||||
{4, 1, 1, 1, "Ź", "", KeyType::Text, {}},
|
||||
{4, 2, 1, 1, "Ż", "", KeyType::Text, {}},
|
||||
{4, 3, 1, 1, "Ž", "", KeyType::Text, {}},
|
||||
{4, 4, 1, 1, "Ð", "", KeyType::Text, {}},
|
||||
{4, 5, 1, 1, "Þ", "", KeyType::Text, {}},
|
||||
{4, 6, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 8, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 9, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
|
||||
// Row 5
|
||||
{5, 0, 1, 1, "⬆", "L2", KeyType::Shift, {L2}},
|
||||
{5, 1, 1, 1, "@#:", "L2+△", KeyType::Symbols1Layout, {L3, Triangle}},
|
||||
{5, 2, 1, 1, "à", "L3", KeyType::AccentLettersLayout, {L3}},
|
||||
{5, 3, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 4, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
//{4, 5, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
//{4, 6, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{5, 8, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
//{4, 9, 2, 1, "⇦", "□", KeyType::Backspace,{Square}},
|
||||
|
||||
// Row 6
|
||||
{6, 0, 1, 1, "▲", "", KeyType::CursorUp, {Up}},
|
||||
{6, 1, 1, 1, "▼", "", KeyType::CursorDown, {Down}},
|
||||
{6, 2, 1, 1, "◀", "L1", KeyType::CursorLeft, {L1}},
|
||||
{6, 3, 1, 1, "▶", "R1", KeyType::CursorRight, {R1}},
|
||||
{6, 4, 1, 1, "KB", "", KeyType::ToggleKeyboard, {}},
|
||||
{6, 5, 1, 1, "...", "", KeyType::MoreOptions, {}},
|
||||
{6, 6, 1, 1, "+/⊗", "R3", KeyType::ControllerAction, {R3}},
|
||||
{5, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{6, 8, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
//{5, 9, 2, 1, "Done", "R2", KeyType::Done,{R2}},
|
||||
};
|
||||
|
||||
const std::vector<Key> kLayoutEnAccentLettersLowercase = {
|
||||
// Row 0
|
||||
{0, 0, 1, 1, "à", "", KeyType::Text, {}},
|
||||
{0, 1, 1, 1, "á", "", KeyType::Text, {}},
|
||||
{0, 2, 1, 1, "â", "", KeyType::Text, {}},
|
||||
{0, 3, 1, 1, "ã", "", KeyType::Text, {}},
|
||||
{0, 4, 1, 1, "ä", "", KeyType::Text, {}},
|
||||
{0, 5, 1, 1, "å", "", KeyType::Text, {}},
|
||||
{0, 6, 1, 1, "ą", "", KeyType::Text, {}},
|
||||
{0, 7, 1, 1, "æ", "", KeyType::Text, {}},
|
||||
{0, 8, 1, 1, "ç", "", KeyType::Text, {}},
|
||||
{0, 9, 1, 1, "ć", "", KeyType::Text, {}},
|
||||
|
||||
// Row 1
|
||||
{1, 0, 1, 1, "è", "", KeyType::Text, {}},
|
||||
{1, 1, 1, 1, "é", "", KeyType::Text, {}},
|
||||
{1, 2, 1, 1, "ê", "", KeyType::Text, {}},
|
||||
{1, 3, 1, 1, "ë", "", KeyType::Text, {}},
|
||||
{1, 4, 1, 1, "ę", "", KeyType::Text, {}},
|
||||
{1, 5, 1, 1, "ğ", "", KeyType::Text, {}},
|
||||
{1, 6, 1, 1, "ì", "", KeyType::Text, {}},
|
||||
{1, 7, 1, 1, "í", "", KeyType::Text, {}},
|
||||
{1, 8, 1, 1, "î", "", KeyType::Text, {}},
|
||||
{1, 9, 1, 1, "ï", "", KeyType::Text, {}},
|
||||
|
||||
// Row 2
|
||||
{2, 0, 1, 1, "ı", "", KeyType::Text, {}},
|
||||
{2, 1, 1, 1, "ł", "", KeyType::Text, {}},
|
||||
{2, 2, 1, 1, "ñ", "", KeyType::Text, {}},
|
||||
{2, 3, 1, 1, "ń", "", KeyType::Text, {}},
|
||||
{2, 4, 1, 1, "ò", "", KeyType::Text, {}},
|
||||
{2, 5, 1, 1, "ó", "", KeyType::Text, {}},
|
||||
{2, 6, 1, 1, "ô", "", KeyType::Text, {}},
|
||||
{2, 7, 1, 1, "õ", "", KeyType::Text, {}},
|
||||
{2, 8, 1, 1, "ö", "", KeyType::Text, {}},
|
||||
{2, 9, 1, 1, "ø", "", KeyType::Text, {}},
|
||||
|
||||
// Row 3
|
||||
{3, 0, 1, 1, "œ", "", KeyType::Text, {}},
|
||||
{3, 1, 1, 1, "ś", "", KeyType::Text, {}},
|
||||
{3, 2, 1, 1, "ş", "", KeyType::Text, {}},
|
||||
{3, 3, 1, 1, "š", "", KeyType::Text, {}},
|
||||
{3, 4, 1, 1, "ß", "", KeyType::Text, {}},
|
||||
{3, 5, 1, 1, "ù", "", KeyType::Text, {}},
|
||||
{3, 6, 1, 1, "ú", "", KeyType::Text, {}},
|
||||
{3, 7, 1, 1, "û", "", KeyType::Text, {}},
|
||||
{3, 8, 1, 1, "ü", "", KeyType::Text, {}},
|
||||
{3, 9, 1, 1, "ý", "", KeyType::Text, {}},
|
||||
|
||||
// Row 4
|
||||
{4, 0, 1, 1, "ÿ", "", KeyType::Text, {}},
|
||||
{4, 1, 1, 1, "ź", "", KeyType::Text, {}},
|
||||
{4, 2, 1, 1, "ż", "", KeyType::Text, {}},
|
||||
{4, 3, 1, 1, "ž", "", KeyType::Text, {}},
|
||||
{4, 4, 1, 1, "ð", "", KeyType::Text, {}},
|
||||
{4, 5, 1, 1, "þ", "", KeyType::Text, {}},
|
||||
{4, 6, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 8, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{4, 9, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
|
||||
// Row 5
|
||||
{5, 0, 1, 1, "⬆", "L2", KeyType::Shift, {L2}},
|
||||
{5, 1, 1, 1, "@#:", "L2+△", KeyType::Symbols1Layout, {L3, Triangle}},
|
||||
{5, 2, 1, 1, "à", "L3", KeyType::AccentLettersLayout, {L3}},
|
||||
{5, 3, 4, 1, "Space", "△", KeyType::Space, {Triangle}},
|
||||
//{4, 4, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
//{4, 5, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
//{4, 6, 4, 1, "Space", "△", KeyType::Space,{Triangle}},
|
||||
{4, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{5, 8, 2, 1, "⇦", "□", KeyType::Backspace, {Square}},
|
||||
//{4, 9, 2, 1, "⇦", "□", KeyType::Backspace,{Square}},
|
||||
|
||||
// Row 6
|
||||
{6, 0, 1, 1, "▲", "", KeyType::CursorUp, {Up}},
|
||||
{6, 1, 1, 1, "▼", "", KeyType::CursorDown, {Down}},
|
||||
{6, 2, 1, 1, "◀", "L1", KeyType::CursorLeft, {L1}},
|
||||
{6, 3, 1, 1, "▶", "R1", KeyType::CursorRight, {R1}},
|
||||
{6, 4, 1, 1, "KB", "", KeyType::ToggleKeyboard, {}},
|
||||
{6, 5, 1, 1, "...", "", KeyType::MoreOptions, {}},
|
||||
//{5, 5, 1, 1, "…", "", KeyType::MoreOptions,{}},
|
||||
{6, 6, 1, 1, "+/⊗", "R3", KeyType::ControllerAction, {R3}},
|
||||
{5, 7, 1, 1, "", "", KeyType::Disabled, {}},
|
||||
{6, 8, 2, 1, "Done", "R2", KeyType::Done, {R2}},
|
||||
//{5, 9, 2, 1, "Done", "R2", KeyType::Done,{R2}},
|
||||
};
|
48
src/core/libraries/ime/ime_keyboard_layouts.h
Normal file
48
src/core/libraries/ime/ime_keyboard_layouts.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <imgui.h>
|
||||
|
||||
enum class KeyType {
|
||||
Text, // Inserts character(s) into input buffer
|
||||
Backspace, // Deletes last character
|
||||
Space, // Adds space
|
||||
Enter, // Submits input
|
||||
Shift, // Toggle uppercase/lowercase
|
||||
Symbols1Layout, // Switch to symbols layout
|
||||
Symbols2Layout, // Switch to symbols layout
|
||||
LettersLayout, // Switch to text layout
|
||||
AccentLettersLayout, // Switch to accent text layout
|
||||
Done, // Finish and close keyboard
|
||||
CursorLeft,
|
||||
CursorRight,
|
||||
CursorUp,
|
||||
CursorDown,
|
||||
ToggleKeyboard, // Toggles keyboard layout
|
||||
MoreOptions, // "..." button
|
||||
ControllerAction, // e.g. R3 +/⊕
|
||||
Disabled, // Filler or placeholder
|
||||
UnknownFunction, // now same as disabled
|
||||
};
|
||||
|
||||
struct Key {
|
||||
int row;
|
||||
int col;
|
||||
int colspan = 1;
|
||||
int rowspan = 1;
|
||||
std::string label;
|
||||
std::string controller_hint;
|
||||
KeyType type = KeyType::Text;
|
||||
std::vector<ImGuiNavInput> bound_buttons = {}; // Now using ImGui navigation inputs
|
||||
};
|
||||
|
||||
extern const std::vector<Key> kLayoutEnLettersUppercase;
|
||||
extern const std::vector<Key> kLayoutEnLettersLowercase;
|
||||
extern const std::vector<Key> kLayoutEnAccentLettersUppercase;
|
||||
extern const std::vector<Key> kLayoutEnAccentLettersLowercase;
|
||||
extern const std::vector<Key> kLayoutEnSymbols1;
|
||||
extern const std::vector<Key> kLayoutEnSymbols2;
|
167
src/core/libraries/ime/ime_keyboard_ui.cpp
Normal file
167
src/core/libraries/ime/ime_keyboard_ui.cpp
Normal file
|
@ -0,0 +1,167 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include <imgui.h>
|
||||
#include "ime_common.h"
|
||||
#include "ime_keyboard_layouts.h"
|
||||
#include "ime_keyboard_ui.h"
|
||||
#include "ime_ui.h" // for ImeState
|
||||
|
||||
using namespace ImGui;
|
||||
|
||||
// --- UTF-8 safe backspace helper ---
|
||||
void Utf8SafeBackspace(char* buffer) {
|
||||
size_t len = std::strlen(buffer);
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
while (len > 0 && (static_cast<unsigned char>(buffer[len]) & 0b11000000) == 0b10000000) {
|
||||
--len;
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
buffer[len - 1] = '\0';
|
||||
buffer[len] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void DrawVirtualKeyboard(char* buffer, std::size_t buffer_capacity, bool* input_changed,
|
||||
KeyboardMode& kb_mode, bool& shift_enabled, bool* done_pressed) {
|
||||
const std::vector<Key>* layout = nullptr;
|
||||
|
||||
switch (kb_mode) {
|
||||
case KeyboardMode::Symbols1:
|
||||
layout = &kLayoutEnSymbols1;
|
||||
break;
|
||||
case KeyboardMode::Symbols2:
|
||||
layout = &kLayoutEnSymbols2;
|
||||
break;
|
||||
case KeyboardMode::Letters2:
|
||||
layout =
|
||||
shift_enabled ? &kLayoutEnAccentLettersUppercase : &kLayoutEnAccentLettersLowercase;
|
||||
break;
|
||||
case KeyboardMode::Letters1:
|
||||
default:
|
||||
layout = shift_enabled ? &kLayoutEnLettersUppercase : &kLayoutEnLettersLowercase;
|
||||
break;
|
||||
}
|
||||
|
||||
RenderKeyboardLayout(*layout, buffer, buffer_capacity, input_changed, kb_mode, shift_enabled,
|
||||
done_pressed);
|
||||
}
|
||||
|
||||
void RenderKeyboardLayout(const std::vector<Key>& layout, char* buffer, std::size_t buffer_capacity,
|
||||
bool* input_changed, KeyboardMode& kb_mode, bool& shift_enabled,
|
||||
bool* done_pressed) {
|
||||
const float layout_width = 485.0f;
|
||||
const float layout_height = 200.0f;
|
||||
const float cell_spacing = 4.0f;
|
||||
const float hint_padding = 2.0f;
|
||||
|
||||
int max_col = 0;
|
||||
int max_row = 0;
|
||||
for (const Key& key : layout) {
|
||||
max_col = std::max(max_col, key.col + static_cast<int>(key.colspan));
|
||||
max_row = std::max(max_row, key.row + static_cast<int>(key.rowspan));
|
||||
}
|
||||
|
||||
const float cell_width = (layout_width - (max_col - 1) * cell_spacing) / max_col;
|
||||
const float cell_height = (layout_height - (max_row - 1) * cell_spacing) / max_row;
|
||||
|
||||
const ImVec2 origin = ImGui::GetCursorScreenPos();
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
for (const Key& key : layout) {
|
||||
float x = origin.x + key.col * (cell_width + cell_spacing);
|
||||
float y = origin.y + key.row * (cell_height + cell_spacing);
|
||||
|
||||
ImVec2 pos(x, y);
|
||||
ImVec2 size(key.colspan * cell_width + (key.colspan - 1) * cell_spacing,
|
||||
key.rowspan * cell_height + (key.rowspan - 1) * cell_spacing);
|
||||
|
||||
std::string button_id =
|
||||
key.label.empty() ? "##empty_" + std::to_string(key.row) + "_" + std::to_string(key.col)
|
||||
: key.label;
|
||||
|
||||
ImGui::SetCursorScreenPos(pos);
|
||||
bool key_activated = ImGui::Button(button_id.c_str(), size);
|
||||
|
||||
if (key_activated) {
|
||||
switch (key.type) {
|
||||
case KeyType::Text:
|
||||
if (!key.label.empty()) {
|
||||
size_t len = std::strlen(buffer);
|
||||
if (len + key.label.size() < buffer_capacity) {
|
||||
std::strcat(buffer, key.label.c_str());
|
||||
if (input_changed)
|
||||
*input_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KeyType::Backspace:
|
||||
if (buffer[0] != '\0') {
|
||||
Utf8SafeBackspace(buffer);
|
||||
if (input_changed)
|
||||
*input_changed = true;
|
||||
}
|
||||
break;
|
||||
case KeyType::Space:
|
||||
if (std::strlen(buffer) + 1 < buffer_capacity) {
|
||||
std::strcat(buffer, " ");
|
||||
if (input_changed)
|
||||
*input_changed = true;
|
||||
}
|
||||
break;
|
||||
case KeyType::Enter:
|
||||
case KeyType::Done:
|
||||
if (done_pressed)
|
||||
*done_pressed = true;
|
||||
break;
|
||||
case KeyType::Shift:
|
||||
shift_enabled = !shift_enabled;
|
||||
break;
|
||||
case KeyType::Symbols1Layout:
|
||||
kb_mode = KeyboardMode::Symbols1;
|
||||
break;
|
||||
case KeyType::Symbols2Layout:
|
||||
kb_mode = KeyboardMode::Symbols2;
|
||||
break;
|
||||
case KeyType::LettersLayout:
|
||||
kb_mode = KeyboardMode::Letters1;
|
||||
break;
|
||||
case KeyType::AccentLettersLayout:
|
||||
kb_mode = KeyboardMode::Letters2;
|
||||
break;
|
||||
|
||||
case KeyType::ToggleKeyboard:
|
||||
kb_mode = (kb_mode == KeyboardMode::Letters1) ? KeyboardMode::Symbols1
|
||||
: KeyboardMode::Letters1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw controller hint label
|
||||
if (!key.controller_hint.empty()) {
|
||||
float original_font_size = ImGui::GetFontSize();
|
||||
float small_font_size = original_font_size * 0.5f;
|
||||
|
||||
ImVec2 text_size =
|
||||
ImGui::CalcTextSize(key.controller_hint.c_str(), nullptr, false, -1.0f) *
|
||||
(small_font_size / original_font_size);
|
||||
|
||||
ImVec2 text_pos = pos + ImVec2(hint_padding, hint_padding);
|
||||
ImVec2 bg_min = text_pos - ImVec2(1.0f, 1.0f);
|
||||
ImVec2 bg_max = text_pos + text_size + ImVec2(2.0f, 1.0f);
|
||||
|
||||
ImU32 bg_color = IM_COL32(0, 0, 0, 160);
|
||||
ImU32 fg_color = IM_COL32(255, 255, 255, 200);
|
||||
|
||||
draw_list->AddRectFilled(bg_min, bg_max, bg_color, 2.0f);
|
||||
draw_list->AddText(nullptr, small_font_size, text_pos, fg_color,
|
||||
key.controller_hint.c_str());
|
||||
}
|
||||
}
|
||||
}
|
23
src/core/libraries/ime/ime_keyboard_ui.h
Normal file
23
src/core/libraries/ime/ime_keyboard_ui.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "core/libraries/ime/ime.h"
|
||||
#include "core/libraries/ime/ime_common.h"
|
||||
#include "core/libraries/ime/ime_error.h"
|
||||
#include "core/libraries/ime/ime_ui.h"
|
||||
#include "core/libraries/pad/pad.h"
|
||||
#include "ime_keyboard_layouts.h"
|
||||
|
||||
enum class KeyboardMode { Letters1, Letters2, Symbols1, Symbols2 };
|
||||
|
||||
void DrawVirtualKeyboard(char* buffer, std::size_t buffer_capacity, bool* input_changed,
|
||||
KeyboardMode& kb_mode, bool& shift_enabled, bool* done_pressed);
|
||||
|
||||
void RenderKeyboardLayout(const std::vector<Key>& layout, char* buffer, std::size_t buffer_capacity,
|
||||
bool* input_changed, KeyboardMode& kb_mode, bool& shift_enabled,
|
||||
bool* done_pressed);
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "ime_keyboard_ui.h"
|
||||
#include "ime_ui.h"
|
||||
#include "imgui/imgui_std.h"
|
||||
|
||||
|
@ -150,6 +151,7 @@ void ImeUi::Draw() {
|
|||
DrawPrettyBackground();
|
||||
|
||||
DrawInputText();
|
||||
DrawKeyboard();
|
||||
SetCursorPosY(GetCursorPosY() + 10.0f);
|
||||
|
||||
const char* button_text;
|
||||
|
@ -187,6 +189,47 @@ void ImeUi::DrawInputText() {
|
|||
}
|
||||
}
|
||||
|
||||
void ImeUi::DrawKeyboard() {
|
||||
static KeyboardMode kb_mode = KeyboardMode::Letters1;
|
||||
static bool shift_enabled = false;
|
||||
|
||||
static bool has_logged = false;
|
||||
if (!has_logged) {
|
||||
LOG_INFO(Lib_Ime, "Virtual keyboard used from ImeUi");
|
||||
has_logged = true;
|
||||
}
|
||||
|
||||
bool input_changed = false;
|
||||
bool done_pressed = false;
|
||||
|
||||
DrawVirtualKeyboard(state->current_text.begin(), state->current_text.capacity(), &input_changed,
|
||||
kb_mode, shift_enabled, &done_pressed);
|
||||
|
||||
if (input_changed) {
|
||||
OrbisImeEditText eventParam{};
|
||||
eventParam.str = reinterpret_cast<char16_t*>(ime_param->work);
|
||||
eventParam.caret_index = std::strlen(state->current_text.begin());
|
||||
eventParam.area_num = 1;
|
||||
eventParam.text_area[0].mode = 1;
|
||||
eventParam.text_area[0].index = 0;
|
||||
eventParam.text_area[0].length = eventParam.caret_index;
|
||||
|
||||
state->ConvertUTF8ToOrbis(state->current_text.begin(), eventParam.caret_index,
|
||||
eventParam.str, ime_param->maxTextLength);
|
||||
state->ConvertUTF8ToOrbis(state->current_text.begin(), eventParam.caret_index,
|
||||
ime_param->inputTextBuffer, ime_param->maxTextLength);
|
||||
|
||||
OrbisImeEvent event{};
|
||||
event.id = OrbisImeEventId::UpdateText;
|
||||
event.param.text = eventParam;
|
||||
state->SendEvent(&event);
|
||||
}
|
||||
|
||||
if (done_pressed) {
|
||||
state->SendEnterEvent();
|
||||
}
|
||||
}
|
||||
|
||||
int ImeUi::InputTextCallback(ImGuiInputTextCallbackData* data) {
|
||||
ImeUi* ui = static_cast<ImeUi*>(data->UserData);
|
||||
ASSERT(ui);
|
||||
|
|
|
@ -70,6 +70,8 @@ private:
|
|||
|
||||
void DrawInputText();
|
||||
|
||||
void DrawKeyboard();
|
||||
|
||||
static int InputTextCallback(ImGuiInputTextCallbackData* data);
|
||||
};
|
||||
|
||||
|
|
|
@ -69,14 +69,51 @@ void Initialize(const ::Vulkan::Instance& instance, const Frontend::WindowSDL& w
|
|||
rb.AddRanges(io.Fonts->GetGlyphRangesKorean());
|
||||
rb.AddRanges(io.Fonts->GetGlyphRangesJapanese());
|
||||
rb.AddRanges(io.Fonts->GetGlyphRangesCyrillic());
|
||||
// For keyboard
|
||||
rb.AddChar(U'×');
|
||||
rb.AddChar(U'○');
|
||||
rb.AddChar(U'△');
|
||||
rb.AddChar(U'□');
|
||||
rb.AddChar(U'↑');
|
||||
rb.AddChar(U'↓');
|
||||
rb.AddChar(U'←');
|
||||
rb.AddChar(U'→');
|
||||
rb.AddChar(U'⊗');
|
||||
rb.AddChar(U'⮾');
|
||||
rb.AddChar(U'🗙');
|
||||
rb.AddChar(U'◀');
|
||||
rb.AddChar(U'▲');
|
||||
rb.AddChar(U'▶');
|
||||
rb.AddChar(U'▼');
|
||||
rb.AddChar(U'⇧');
|
||||
rb.AddChar(U'⬆');
|
||||
rb.AddChar(U'⇦');
|
||||
rb.AddChar(U'€');
|
||||
rb.AddChar(U'₩');
|
||||
rb.AddChar(U'“');
|
||||
rb.AddChar(U'”');
|
||||
rb.AddChar(U'„');
|
||||
rb.AddChar(U'‼');
|
||||
rb.AddChar(U'¿');
|
||||
rb.AddChar(U'⁇');
|
||||
rb.AddChar(U'‹');
|
||||
rb.AddChar(U'›');
|
||||
rb.AddChar(U'’');
|
||||
rb.AddChar(U'‘');
|
||||
rb.AddChar(U'‛');
|
||||
rb.AddChar(U'‚');
|
||||
rb.AddChar(U'№');
|
||||
|
||||
ImVector<ImWchar> ranges{};
|
||||
rb.BuildRanges(&ranges);
|
||||
ImFontConfig font_cfg{};
|
||||
font_cfg.OversampleH = 2;
|
||||
font_cfg.OversampleV = 1;
|
||||
font_cfg.MergeMode = false;
|
||||
io.FontDefault = io.Fonts->AddFontFromMemoryCompressedTTF(
|
||||
imgui_font_notosansjp_regular_compressed_data,
|
||||
imgui_font_notosansjp_regular_compressed_size, 16.0f, &font_cfg, ranges.Data);
|
||||
font_cfg.MergeMode = true;
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(imgui_font_proggyvector_regular_compressed_data,
|
||||
imgui_font_proggyvector_regular_compressed_size,
|
||||
16.0f);
|
||||
|
|
Loading…
Add table
Reference in a new issue