feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -33,6 +33,7 @@
#include "core/input/input_map.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/string/translation_server.h"
#include "scene/gui/label.h"
#include "scene/main/window.h"
#include "scene/theme/theme_db.h"
@ -399,7 +400,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
if (context_menu_enabled) {
_update_context_menu();
menu->set_position(get_screen_position() + get_local_mouse_position());
menu->set_position(get_screen_transform().xform(get_local_mouse_position()));
menu->reset_size();
menu->popup();
}
@ -486,6 +487,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
if (!pass && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CLIPBOARD_PRIMARY)) {
DisplayServer::get_singleton()->clipboard_set_primary(text);
}
queue_accessibility_update();
} else if (b->is_double_click()) {
// Double-click select word.
last_dblclk = OS::get_singleton()->get_ticks_msec();
@ -500,6 +502,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
selection.creating = true;
selection.start_column = caret_column;
set_caret_column(selection.end);
queue_accessibility_update();
break;
}
}
@ -630,7 +633,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
if (k->is_action("ui_menu", true)) {
_update_context_menu();
Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2);
menu->set_position(get_screen_position() + pos);
menu->set_position(get_screen_transform().xform(pos));
menu->reset_size();
menu->popup();
menu->grab_focus();
@ -668,13 +671,14 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
return;
}
// Start Unicode input (hold).
// Start Unicode Alt input (hold).
if (k->is_alt_pressed() && k->get_keycode() == Key::KP_ADD && !alt_start && !alt_start_no_hold) {
if (selection.enabled) {
selection_delete();
}
alt_start = true;
alt_code = 0;
alt_mode = ALT_INPUT_UNICODE;
ime_text = "u";
ime_selection = Vector2i(0, -1);
_shape();
@ -690,6 +694,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
}
alt_start_no_hold = true;
alt_code = 0;
alt_mode = ALT_INPUT_UNICODE;
ime_text = "u";
ime_selection = Vector2i(0, -1);
_shape();
@ -698,37 +703,101 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
return;
}
// Start OEM Alt input (hold).
if (k->is_alt_pressed() && k->get_keycode() >= Key::KP_1 && k->get_keycode() <= Key::KP_9 && !alt_start && !alt_start_no_hold) {
if (selection.enabled) {
selection_delete();
}
alt_start = true;
alt_code = (uint32_t)(k->get_keycode() - Key::KP_0);
alt_mode = ALT_INPUT_OEM;
ime_text = vformat("o%s", String::num_int64(alt_code, 10));
ime_selection = Vector2i(0, -1);
_shape();
queue_redraw();
accept_event();
return;
}
// Start Windows Alt input (hold).
if (k->is_alt_pressed() && k->get_keycode() == Key::KP_0 && !alt_start && !alt_start_no_hold) {
if (selection.enabled) {
selection_delete();
}
alt_start = true;
alt_mode = ALT_INPUT_WIN;
alt_code = 0;
ime_text = "w";
ime_selection = Vector2i(0, -1);
_shape();
queue_redraw();
accept_event();
return;
}
// Update Unicode input.
if (k->is_pressed() && ((k->is_alt_pressed() && alt_start) || alt_start_no_hold)) {
if (k->get_keycode() >= Key::KEY_0 && k->get_keycode() <= Key::KEY_9) {
alt_code = alt_code << 4;
if (alt_mode == ALT_INPUT_UNICODE) {
alt_code = alt_code << 4;
} else {
alt_code = alt_code * 10;
}
alt_code += (uint32_t)(k->get_keycode() - Key::KEY_0);
} else if (k->get_keycode() >= Key::KP_0 && k->get_keycode() <= Key::KP_9) {
alt_code = alt_code << 4;
if (alt_mode == ALT_INPUT_UNICODE) {
alt_code = alt_code << 4;
} else {
alt_code = alt_code * 10;
}
alt_code += (uint32_t)(k->get_keycode() - Key::KP_0);
} else if (k->get_keycode() >= Key::A && k->get_keycode() <= Key::F) {
} else if (alt_mode == ALT_INPUT_UNICODE && k->get_keycode() >= Key::A && k->get_keycode() <= Key::F) {
alt_code = alt_code << 4;
alt_code += (uint32_t)(k->get_keycode() - Key::A) + 10;
} else if ((Key)k->get_unicode() >= Key::KEY_0 && (Key)k->get_unicode() <= Key::KEY_9) {
alt_code = alt_code << 4;
if (alt_mode == ALT_INPUT_UNICODE) {
alt_code = alt_code << 4;
} else {
alt_code = alt_code * 10;
}
alt_code += (uint32_t)((Key)k->get_unicode() - Key::KEY_0);
} else if ((Key)k->get_unicode() >= Key::A && (Key)k->get_unicode() <= Key::F) {
} else if (alt_mode == ALT_INPUT_UNICODE && (Key)k->get_unicode() >= Key::A && (Key)k->get_unicode() <= Key::F) {
alt_code = alt_code << 4;
alt_code += (uint32_t)((Key)k->get_unicode() - Key::A) + 10;
} else if (k->get_physical_keycode() >= Key::KEY_0 && k->get_physical_keycode() <= Key::KEY_9) {
alt_code = alt_code << 4;
if (alt_mode == ALT_INPUT_UNICODE) {
alt_code = alt_code << 4;
} else {
alt_code = alt_code * 10;
}
alt_code += (uint32_t)(k->get_physical_keycode() - Key::KEY_0);
}
if (k->get_keycode() == Key::BACKSPACE) {
alt_code = alt_code >> 4;
if (alt_mode == ALT_INPUT_UNICODE) {
alt_code = alt_code >> 4;
} else {
alt_code = alt_code / 10;
}
}
if (alt_code > 0x10ffff) {
alt_code = 0x10ffff;
}
if (alt_code > 0) {
ime_text = vformat("u%s", String::num_int64(alt_code, 16, true));
if (alt_mode == ALT_INPUT_UNICODE) {
ime_text = vformat("u%s", String::num_int64(alt_code, 16, true));
} else if (alt_mode == ALT_INPUT_OEM) {
ime_text = vformat("o%s", String::num_int64(alt_code, 10));
} else if (alt_mode == ALT_INPUT_WIN) {
ime_text = vformat("w%s", String::num_int64(alt_code, 10));
}
} else {
ime_text = "u";
if (alt_mode == ALT_INPUT_UNICODE) {
ime_text = "u";
} else if (alt_mode == ALT_INPUT_OEM) {
ime_text = "o";
} else if (alt_mode == ALT_INPUT_WIN) {
ime_text = "w";
}
}
ime_selection = Vector2i(0, -1);
_shape();
@ -741,11 +810,32 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
if ((!k->is_pressed() && alt_start && k->get_keycode() == Key::ALT) || (alt_start_no_hold && (k->is_action("ui_text_submit", true) || k->is_action("ui_accept", true)))) {
alt_start = false;
alt_start_no_hold = false;
if ((alt_code > 0x31 && alt_code < 0xd800) || (alt_code > 0xdfff && alt_code <= 0x10ffff)) {
if ((alt_code > 0x31 && alt_code < 0xd800) || (alt_code > 0xdfff)) {
ime_text = String();
ime_selection = Vector2i();
char32_t ucodestr[2] = { (char32_t)alt_code, 0 };
insert_text_at_caret(ucodestr);
if (alt_mode == ALT_INPUT_UNICODE) {
if ((alt_code > 0x31 && alt_code < 0xd800) || (alt_code > 0xdfff)) {
char32_t ucodestr[2] = { (char32_t)alt_code, 0 };
insert_text_at_caret(ucodestr);
}
} else if (alt_mode == ALT_INPUT_OEM) {
if (alt_code > 0x00 && alt_code <= 0xff) {
char32_t ucodestr[2] = { alt_code_oem437[alt_code], 0 };
insert_text_at_caret(ucodestr);
} else if ((alt_code > 0xff && alt_code < 0xd800) || (alt_code > 0xdfff)) {
char32_t ucodestr[2] = { (char32_t)alt_code, 0 };
insert_text_at_caret(ucodestr);
}
} else if (alt_mode == ALT_INPUT_WIN) {
if (alt_code > 0x00 && alt_code <= 0xff) {
char32_t ucodestr[2] = { alt_code_cp1252[alt_code], 0 };
insert_text_at_caret(ucodestr);
} else if ((alt_code > 0xff && alt_code < 0xd800) || (alt_code > 0xdfff)) {
char32_t ucodestr[2] = { (char32_t)alt_code, 0 };
insert_text_at_caret(ucodestr);
}
}
alt_mode = ALT_INPUT_NONE;
} else {
ime_text = String();
ime_selection = Vector2i();
@ -760,6 +850,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
if (alt_start_no_hold && k->is_action("ui_cancel", true)) {
alt_start = false;
alt_start_no_hold = false;
alt_mode = ALT_INPUT_NONE;
ime_text = String();
ime_selection = Vector2i();
_shape();
@ -973,7 +1064,9 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
if (p_data.is_string() && is_editable()) {
apply_ime();
set_caret_at_pixel_pos(p_point.x);
if (p_point != Vector2(Math::INF, Math::INF)) {
set_caret_at_pixel_pos(p_point.x);
}
int caret_column_tmp = caret_column;
bool is_inside_sel = selection.enabled && caret_column >= selection.begin && caret_column <= selection.end;
if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
@ -1009,6 +1102,7 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
}
text_changed_dirty = true;
}
queue_accessibility_update();
queue_redraw();
}
}
@ -1035,6 +1129,33 @@ void LineEdit::_update_theme_item_cache() {
theme_cache.base_scale = get_theme_default_base_scale();
}
void LineEdit::_accessibility_action_set_selection(const Variant &p_data) {
Dictionary new_selection = p_data;
int sel_start_pos = new_selection["start_char"];
int sel_end_pos = new_selection["end_char"];
select(sel_start_pos, sel_end_pos);
}
void LineEdit::_accessibility_action_replace_selected(const Variant &p_data) {
String new_text = p_data;
insert_text_at_caret(new_text);
}
void LineEdit::_accessibility_action_set_value(const Variant &p_data) {
String new_text = p_data;
set_text(new_text);
}
void LineEdit::_accessibility_action_menu(const Variant &p_data) {
_update_context_menu();
Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2);
menu->set_position(get_screen_position() + pos);
menu->reset_size();
menu->popup();
menu->grab_focus();
}
void LineEdit::_notification(int p_what) {
switch (p_what) {
#ifdef TOOLS_ENABLED
@ -1049,6 +1170,98 @@ void LineEdit::_notification(int p_what) {
}
} break;
#endif
case NOTIFICATION_EXIT_TREE:
case NOTIFICATION_ACCESSIBILITY_INVALIDATE: {
accessibility_text_root_element = RID();
} break;
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
RID ae = get_accessibility_element();
ERR_FAIL_COND(ae.is_null());
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_TEXT_FIELD);
bool using_placeholder = text.is_empty() && ime_text.is_empty();
if (using_placeholder && !placeholder.is_empty()) {
DisplayServer::get_singleton()->accessibility_update_set_placeholder(ae, atr(placeholder));
}
if (!placeholder.is_empty() && get_accessibility_name().is_empty()) {
DisplayServer::get_singleton()->accessibility_update_set_name(ae, atr(placeholder));
}
DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_READONLY, !editable);
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SET_TEXT_SELECTION, callable_mp(this, &LineEdit::_accessibility_action_set_selection));
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_REPLACE_SELECTED_TEXT, callable_mp(this, &LineEdit::_accessibility_action_replace_selected));
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SET_VALUE, callable_mp(this, &LineEdit::_accessibility_action_set_value));
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU, callable_mp(this, &LineEdit::_accessibility_action_menu));
if (!language.is_empty()) {
DisplayServer::get_singleton()->accessibility_update_set_language(ae, language);
} else {
DisplayServer::get_singleton()->accessibility_update_set_language(ae, TranslationServer::get_singleton()->get_tool_locale());
}
bool rtl = is_layout_rtl();
Ref<StyleBox> style = theme_cache.normal;
Ref<Font> font = theme_cache.font;
Size2 size = get_size();
int x_ofs = 0;
float text_width = TS->shaped_text_get_size(text_rid).x;
float text_height = TS->shaped_text_get_size(text_rid).y;
int y_area = size.height - style->get_minimum_size().height;
int y_ofs = style->get_offset().y + (y_area - text_height) / 2;
switch (alignment) {
case HORIZONTAL_ALIGNMENT_FILL:
case HORIZONTAL_ALIGNMENT_LEFT: {
if (rtl) {
x_ofs = MAX(style->get_margin(SIDE_LEFT), int(size.width - Math::ceil(style->get_margin(SIDE_RIGHT) + (text_width))));
} else {
x_ofs = style->get_offset().x;
}
} break;
case HORIZONTAL_ALIGNMENT_CENTER: {
if (!Math::is_zero_approx(scroll_offset)) {
x_ofs = style->get_offset().x;
} else {
x_ofs = MAX(style->get_margin(SIDE_LEFT), int(size.width - (text_width)) / 2);
}
} break;
case HORIZONTAL_ALIGNMENT_RIGHT: {
if (rtl) {
x_ofs = style->get_offset().x;
} else {
x_ofs = MAX(style->get_margin(SIDE_LEFT), int(size.width - Math::ceil(style->get_margin(SIDE_RIGHT) + (text_width))));
}
} break;
}
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
Ref<Texture2D> r_icon = display_clear_icon ? theme_cache.clear_icon : right_icon;
if (alignment == HORIZONTAL_ALIGNMENT_CENTER) {
if (Math::is_zero_approx(scroll_offset)) {
x_ofs = MAX(style->get_margin(SIDE_LEFT), int(size.width - text_width - r_icon->get_width() - style->get_margin(SIDE_RIGHT) * 2) / 2);
}
} else {
x_ofs = MAX(style->get_margin(SIDE_LEFT), x_ofs - r_icon->get_width() - style->get_margin(SIDE_RIGHT));
}
}
float text_off_x = x_ofs + scroll_offset;
if (accessibility_text_root_element.is_null()) {
accessibility_text_root_element = DisplayServer::get_singleton()->accessibility_create_sub_text_edit_elements(ae, using_placeholder ? RID() : text_rid, text_height);
}
Transform2D text_xform;
text_xform.set_origin(Vector2i(text_off_x, y_ofs));
DisplayServer::get_singleton()->accessibility_update_set_transform(accessibility_text_root_element, text_xform);
if (selection.enabled) {
DisplayServer::get_singleton()->accessibility_update_set_text_selection(ae, accessibility_text_root_element, selection.begin, accessibility_text_root_element, selection.end);
} else {
DisplayServer::get_singleton()->accessibility_update_set_text_selection(ae, accessibility_text_root_element, caret_column, accessibility_text_root_element, caret_column);
}
} break;
case NOTIFICATION_RESIZED: {
_fit_to_width();
@ -1202,12 +1415,14 @@ void LineEdit::_notification(int p_what) {
if (rect.position.x < x_ofs) {
rect.size.x -= (x_ofs - rect.position.x);
rect.position.x = x_ofs;
} else if (rect.position.x + rect.size.x > ofs_max) {
}
if (rect.position.x + rect.size.x > ofs_max) {
rect.size.x = ofs_max - rect.position.x;
}
RenderingServer::get_singleton()->canvas_item_add_rect(ci, rect, selection_color);
}
}
const Glyph *glyphs = TS->shaped_text_get_glyphs(text_rid);
int gl_size = TS->shaped_text_get_glyph_count(text_rid);
@ -1733,7 +1948,7 @@ void LineEdit::_validate_caret_can_draw() {
draw_caret = true;
caret_blink_timer = 0.0;
}
caret_can_draw = editing && (window_has_focus || (menu && menu->has_focus())) && (has_focus() || caret_force_displayed);
caret_can_draw = (caret_force_displayed && !is_part_of_edited_scene()) || (editing && (window_has_focus || (menu && menu->has_focus())) && has_focus());
}
void LineEdit::delete_char() {
@ -1920,6 +2135,8 @@ void LineEdit::set_caret_column(int p_column) {
caret_column = p_column;
queue_accessibility_update();
// Fit to window.
if (!is_inside_tree()) {
@ -1988,6 +2205,7 @@ void LineEdit::set_caret_column(int p_column) {
scroll_offset = MIN(0, scroll_offset);
queue_accessibility_update();
queue_redraw();
}
@ -2016,7 +2234,7 @@ void LineEdit::insert_text_at_caret(String p_text) {
}
}
String pre = text.substr(0, caret_column);
String post = text.substr(caret_column, text.length() - caret_column);
String post = text.substr(caret_column);
text = pre + p_text + post;
_shape();
TextServer::Direction dir = TS->shaped_text_get_dominant_direction_in_range(text_rid, caret_column, caret_column + p_text.length());
@ -2082,6 +2300,7 @@ void LineEdit::deselect() {
selection.enabled = false;
selection.creating = false;
selection.double_click = false;
queue_accessibility_update();
queue_redraw();
}
@ -2140,6 +2359,7 @@ void LineEdit::selection_fill_at_caret() {
}
selection.enabled = (selection.begin != selection.end);
queue_accessibility_update();
}
void LineEdit::select_all() {
@ -2155,6 +2375,7 @@ void LineEdit::select_all() {
selection.begin = 0;
selection.end = text.length();
selection.enabled = true;
queue_accessibility_update();
queue_redraw();
}
@ -2172,6 +2393,7 @@ void LineEdit::set_editable(bool p_editable) {
_validate_caret_can_draw();
update_minimum_size();
queue_accessibility_update();
queue_redraw();
}
@ -2241,6 +2463,7 @@ void LineEdit::select(int p_from, int p_to) {
selection.end = p_to;
selection.creating = false;
selection.double_click = false;
queue_accessibility_update();
queue_redraw();
}
@ -2611,7 +2834,7 @@ void LineEdit::_shape() {
t = s.repeat(text.length() + ime_text.length());
} else {
if (!ime_text.is_empty()) {
t = text.substr(0, caret_column) + ime_text + text.substr(caret_column, text.length());
t = text.substr(0, caret_column) + ime_text + text.substr(caret_column);
} else {
t = text;
}
@ -2634,6 +2857,13 @@ void LineEdit::_shape() {
if ((expand_to_text_length && old_size.x != size.x) || (old_size.y != size.y)) {
update_minimum_size();
}
if (accessibility_text_root_element.is_valid()) {
DisplayServer::get_singleton()->accessibility_free_element(accessibility_text_root_element);
accessibility_text_root_element = RID();
}
queue_accessibility_update();
}
void LineEdit::_fit_to_width() {
@ -2707,7 +2937,6 @@ Key LineEdit::_get_menu_action_accelerator(const String &p_action) {
void LineEdit::_generate_context_menu() {
menu = memnew(PopupMenu);
add_child(menu, false, INTERNAL_MODE_FRONT);
menu->force_parent_owned();
menu_dir = memnew(PopupMenu);
menu_dir->add_radio_check_item(ETR("Same as Layout Direction"), MENU_DIR_INHERITED);