Make the caret thicker in TextEdit and scale it with the editor scale

The caret in LineEdit is still 1 pixel thick, but it will become
2 pixels thick at editor scales higher than or equal to 150%.
This commit is contained in:
Hugo Locurcio
2018-07-26 23:41:47 +02:00
parent 03e11c13bf
commit 8d05f89bc1
2 changed files with 30 additions and 4 deletions

View File

@@ -1148,10 +1148,18 @@ void TextEdit::_notification(int p_what) {
if (ime_text.length() == 0) {
if (draw_caret) {
if (insert_mode) {
int caret_h = (block_caret) ? 4 : 1;
#ifdef TOOLS_ENABLED
int caret_h = (block_caret) ? 4 : 2 * EDSCALE;
#else
int caret_h = (block_caret) ? 4 : 2;
#endif
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, caret_h)), cache.caret_color);
} else {
caret_w = (block_caret) ? caret_w : 1;
#ifdef TOOLS_ENABLED
caret_w = (block_caret) ? caret_w : 2 * EDSCALE;
#else
caret_w = (block_caret) ? caret_w : 2;
#endif
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, get_row_height())), cache.caret_color);
}
}
@@ -1224,11 +1232,19 @@ void TextEdit::_notification(int p_what) {
if (draw_caret) {
if (insert_mode) {
int char_w = cache.font->get_char_size(' ').width;
int caret_h = (block_caret) ? 4 : 1;
#ifdef TOOLS_ENABLED
int caret_h = (block_caret) ? 4 : 2 * EDSCALE;
#else
int caret_h = (block_caret) ? 4 : 2;
#endif
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(char_w, caret_h)), cache.caret_color);
} else {
int char_w = cache.font->get_char_size(' ').width;
int caret_w = (block_caret) ? char_w : 1;
#ifdef TOOLS_ENABLED
int caret_w = (block_caret) ? char_w : 2 * EDSCALE;
#else
int caret_w = (block_caret) ? char_w : 2;
#endif
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, get_row_height())), cache.caret_color);
}
}