mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 10:35:03 +00:00
Use vierual keyboard in ImeUi and ImeDialogUi
Added some spam to log. Some files added, CMakeList modified.
This commit is contained in:
parent
c93706616f
commit
569ab0c87f
@ -446,6 +446,8 @@ 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_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"
|
||||
|
||||
@ -341,91 +342,17 @@ void ImeDialogUi::DrawMultiLineInputText() {
|
||||
}
|
||||
|
||||
void ImeDialogUi::DrawKeyboard() {
|
||||
static bool shift_enabled = false;
|
||||
static KeyboardMode kb_mode = KeyboardMode::Letters;
|
||||
static bool shift_enabled = false;
|
||||
|
||||
const char* row1_letters = "QWERTYUIOP";
|
||||
const char* row2_letters = "ASDFGHJKL";
|
||||
const char* row3_letters = "ZXCVBNM";
|
||||
|
||||
const char* row1_symbols = "1234567890";
|
||||
const char* row2_symbols = "!@#$%^&*()";
|
||||
const char* row3_symbols = "-_=+[]{}";
|
||||
|
||||
auto draw_row = [&](const char* row, float offset_x) {
|
||||
SetCursorPosX(offset_x);
|
||||
for (int i = 0; row[i] != '\0'; ++i) {
|
||||
char ch = shift_enabled ? row[i] : (char)tolower(row[i]);
|
||||
std::string key(1, ch);
|
||||
if (ImGui::Button(key.c_str(), ImVec2(35, 35))) {
|
||||
char* buffer = state->current_text.begin();
|
||||
size_t len = strlen(buffer);
|
||||
if (len + 1 < state->max_text_length * 4) {
|
||||
buffer[len] = ch;
|
||||
buffer[len + 1] = '\0';
|
||||
state->input_changed = true;
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::NewLine();
|
||||
};
|
||||
|
||||
// SHIFT status label
|
||||
if (shift_enabled) {
|
||||
SetCursorPosX(20.0f);
|
||||
TextColored(ImVec4(0.2f, 0.6f, 1.0f, 1.0f), "SHIFT ENABLED");
|
||||
static bool has_logged = false;
|
||||
if (!has_logged) {
|
||||
LOG_INFO(Lib_ImeDialog, "Virtual keyboard used from ImeDialog");
|
||||
has_logged = true;
|
||||
}
|
||||
|
||||
draw_row(kb_mode == KeyboardMode::Letters ? row1_letters : row1_symbols, 20.0f);
|
||||
draw_row(kb_mode == KeyboardMode::Letters ? row2_letters : row2_symbols, 35.0f);
|
||||
draw_row(kb_mode == KeyboardMode::Letters ? row3_letters : row3_symbols, 80.0f);
|
||||
|
||||
SetCursorPosX(20.0f);
|
||||
|
||||
// Fix: safely push/pop style only if shift was enabled before clicking
|
||||
bool highlight = shift_enabled;
|
||||
if (highlight) {
|
||||
PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.6f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
if (Button("SHIFT", ImVec2(75, 35))) {
|
||||
shift_enabled = !shift_enabled;
|
||||
}
|
||||
|
||||
if (highlight) {
|
||||
PopStyleColor();
|
||||
}
|
||||
|
||||
SameLine();
|
||||
|
||||
if (Button("SPACE", ImVec2(100, 35))) {
|
||||
char* buffer = state->current_text.begin();
|
||||
size_t len = strlen(buffer);
|
||||
if (len + 1 < state->max_text_length * 4) {
|
||||
buffer[len] = ' ';
|
||||
buffer[len + 1] = '\0';
|
||||
state->input_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
SameLine();
|
||||
|
||||
if (Button("DELETE", ImVec2(75, 35))) {
|
||||
char* buffer = state->current_text.begin();
|
||||
size_t len = strlen(buffer);
|
||||
if (len > 0) {
|
||||
buffer[len - 1] = '\0';
|
||||
state->input_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
SameLine();
|
||||
|
||||
if (Button(kb_mode == KeyboardMode::Letters ? "123" : "ABC", ImVec2(60, 35))) {
|
||||
kb_mode =
|
||||
(kb_mode == KeyboardMode::Letters) ? KeyboardMode::Symbols : KeyboardMode::Letters;
|
||||
}
|
||||
DrawVirtualKeyboard(state->current_text.begin(), state->max_text_length * 4,
|
||||
&state->input_changed, kb_mode, shift_enabled);
|
||||
}
|
||||
|
||||
int ImeDialogUi::InputTextCallback(ImGuiInputTextCallbackData* data) {
|
||||
|
@ -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 {
|
||||
@ -62,8 +63,6 @@ class ImeDialogUi final : public ImGui::Layer {
|
||||
bool first_render = true;
|
||||
std::mutex draw_mutex;
|
||||
|
||||
enum class KeyboardMode { Letters, Symbols };
|
||||
|
||||
public:
|
||||
explicit ImeDialogUi(ImeDialogState* state = nullptr, OrbisImeDialogStatus* status = nullptr,
|
||||
OrbisImeDialogResult* result = nullptr);
|
||||
|
96
src/core/libraries/ime/ime_keyboard_ui.cpp
Normal file
96
src/core/libraries/ime/ime_keyboard_ui.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <imgui.h>
|
||||
#include "ime_keyboard_ui.h"
|
||||
|
||||
void DrawVirtualKeyboard(char* buffer, std::size_t buffer_capacity, bool* input_changed,
|
||||
KeyboardMode& kb_mode, bool& shift_enabled) {
|
||||
const char* row1_letters = "QWERTYUIOP";
|
||||
const char* row2_letters = "ASDFGHJKL";
|
||||
const char* row3_letters = "ZXCVBNM";
|
||||
|
||||
const char* row1_symbols = "1234567890";
|
||||
const char* row2_symbols = "!@#$%^&*()";
|
||||
const char* row3_symbols = "-_=+[]{}";
|
||||
|
||||
auto draw_row = [&](const char* row, float offset_x) {
|
||||
ImGui::SetCursorPosX(offset_x);
|
||||
for (int i = 0; row[i] != '\0'; ++i) {
|
||||
char ch = shift_enabled ? row[i] : static_cast<char>(tolower(row[i]));
|
||||
std::string key(1, ch);
|
||||
if (ImGui::Button(key.c_str(), ImVec2(35, 35))) {
|
||||
size_t len = std::strlen(buffer);
|
||||
if (len + 1 < buffer_capacity) {
|
||||
buffer[len] = ch;
|
||||
buffer[len + 1] = '\0';
|
||||
if (input_changed) {
|
||||
*input_changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::NewLine();
|
||||
};
|
||||
|
||||
// SHIFT status label
|
||||
if (shift_enabled) {
|
||||
ImGui::SetCursorPosX(20.0f);
|
||||
ImGui::TextColored(ImVec4(0.2f, 0.6f, 1.0f, 1.0f), "SHIFT ENABLED");
|
||||
}
|
||||
|
||||
draw_row(kb_mode == KeyboardMode::Letters ? row1_letters : row1_symbols, 20.0f);
|
||||
draw_row(kb_mode == KeyboardMode::Letters ? row2_letters : row2_symbols, 35.0f);
|
||||
draw_row(kb_mode == KeyboardMode::Letters ? row3_letters : row3_symbols, 80.0f);
|
||||
|
||||
ImGui::SetCursorPosX(20.0f);
|
||||
|
||||
bool highlight = shift_enabled;
|
||||
if (highlight) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.6f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
if (ImGui::Button("SHIFT", ImVec2(75, 35))) {
|
||||
shift_enabled = !shift_enabled;
|
||||
}
|
||||
|
||||
if (highlight) {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("SPACE", ImVec2(100, 35))) {
|
||||
size_t len = std::strlen(buffer);
|
||||
if (len + 1 < buffer_capacity) {
|
||||
buffer[len] = ' ';
|
||||
buffer[len + 1] = '\0';
|
||||
if (input_changed) {
|
||||
*input_changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("DELETE", ImVec2(75, 35))) {
|
||||
size_t len = std::strlen(buffer);
|
||||
if (len > 0) {
|
||||
buffer[len - 1] = '\0';
|
||||
if (input_changed) {
|
||||
*input_changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button(kb_mode == KeyboardMode::Letters ? "123" : "ABC", ImVec2(60, 35))) {
|
||||
kb_mode =
|
||||
(kb_mode == KeyboardMode::Letters) ? KeyboardMode::Symbols : KeyboardMode::Letters;
|
||||
}
|
||||
}
|
9
src/core/libraries/ime/ime_keyboard_ui.h
Normal file
9
src/core/libraries/ime/ime_keyboard_ui.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/cstring.h"
|
||||
#include "common/types.h"
|
||||
|
||||
enum class KeyboardMode { Letters, Symbols };
|
||||
|
||||
void DrawVirtualKeyboard(char* buffer, std::size_t buffer_capacity, bool* input_changed,
|
||||
KeyboardMode& kb_mode, bool& shift_enabled);
|
@ -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,20 @@ void ImeUi::DrawInputText() {
|
||||
}
|
||||
}
|
||||
|
||||
void ImeUi::DrawKeyboard() {
|
||||
static KeyboardMode kb_mode = KeyboardMode::Letters;
|
||||
static bool shift_enabled = false;
|
||||
|
||||
static bool has_logged = false;
|
||||
if (!has_logged) {
|
||||
LOG_INFO(Lib_ImeDialog, "Virtual keyboard used from Ime");
|
||||
has_logged = true;
|
||||
}
|
||||
|
||||
DrawVirtualKeyboard(state->current_text.begin(), ime_param->maxTextLength * 4, nullptr, kb_mode,
|
||||
shift_enabled);
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user