diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-12-21 11:57:35 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-12-21 11:57:35 +0200 |
commit | cc4d6eb7f6be529f6fabc1242e363a460e39abdc (patch) | |
tree | d95e027a07187845a668f05a2fabcb641da8b303 | |
parent | 784f869f0f36a9e4d600fca2523a6200b648fbbd (diff) |
Improve fill aligned text hit testing.
-rw-r--r-- | servers/text_server.cpp | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/servers/text_server.cpp b/servers/text_server.cpp index 68864980e2..fa39185ac0 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -1038,31 +1038,36 @@ int TextServer::shaped_text_hit_test_position(RID p_shaped, float p_coords) cons float off = 0.0f; for (int i = 0; i < v_size; i++) { - for (int k = 0; k < glyphs[i].repeat; k++) { - if (glyphs[i].count > 0) { - float advance = 0.f; - for (int j = 0; j < glyphs[i].count; j++) { - advance += glyphs[i + j].advance; + if (glyphs[i].count > 0) { + float advance = 0.f; + for (int j = 0; j < glyphs[i].count; j++) { + advance += glyphs[i + j].advance * glyphs[i + j].repeat; + } + if (((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) == GRAPHEME_IS_VIRTUAL) && (p_coords >= off && p_coords < off + advance)) { + if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { + return glyphs[i].end; + } else { + return glyphs[i].start; } - // Place caret to the left of clicked grapheme. - if (p_coords >= off && p_coords < off + advance / 2) { - if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { - return glyphs[i].end; - } else { - return glyphs[i].start; - } + } + // Place caret to the left of clicked grapheme. + if (p_coords >= off && p_coords < off + advance / 2) { + if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { + return glyphs[i].end; + } else { + return glyphs[i].start; } - // Place caret to the right of clicked grapheme. - if (p_coords >= off + advance / 2 && p_coords < off + advance) { - if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { - return glyphs[i].start; - } else { - return glyphs[i].end; - } + } + // Place caret to the right of clicked grapheme. + if (p_coords >= off + advance / 2 && p_coords < off + advance) { + if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { + return glyphs[i].start; + } else { + return glyphs[i].end; } } - off += glyphs[i].advance; } + off += glyphs[i].advance * glyphs[i].repeat; } return 0; } |