summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwyneth Lowe <GlaceGwyneth@gmail.com>2019-06-23 22:43:52 -0500
committerGwyneth Lowe <GlaceGwyneth@gmail.com>2019-06-24 20:00:05 -0500
commit45f78d786a76001325bd598ec6a330117831e07f (patch)
tree45fb9a1225300795a2a5de0a2cddb05c3c520df2
parentf07e5ac1533ed5563b3ffc75a243e3444c2645b8 (diff)
Give TextEdit a custom color for font when read only is set
Previously there was some transparency hard coded into TextEdit when in read only mode. This change adds a custom color for adjusting the font in read only mode. It also applies when syntax highlighting is on.
-rw-r--r--scene/gui/text_edit.cpp19
-rw-r--r--scene/gui/text_edit.h1
-rw-r--r--scene/resources/default_theme/default_theme.cpp1
3 files changed, 7 insertions, 14 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 4e86e4bb1e..9d457e989c 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -662,10 +662,8 @@ void TextEdit::_notification(int p_what) {
int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT);
//let's do it easy for now:
cache.style_normal->draw(ci, Rect2(Point2(), size));
- float readonly_alpha = 1.0; // used to set the input text color when in read-only mode
if (readonly) {
cache.style_readonly->draw(ci, Rect2(Point2(), size));
- readonly_alpha = .5;
draw_caret = false;
}
if (has_focus())
@@ -675,8 +673,7 @@ void TextEdit::_notification(int p_what) {
int visible_rows = get_visible_rows() + 1;
- Color color = cache.font_color;
- color.a *= readonly_alpha;
+ Color color = readonly ? cache.font_color_readonly : cache.font_color;
if (syntax_coloring) {
if (cache.background_color.a > 0.01) {
@@ -871,10 +868,7 @@ void TextEdit::_notification(int p_what) {
color_map = _get_line_syntax_highlighting(line);
}
// ensure we at least use the font color
- Color current_color = cache.font_color;
- if (readonly) {
- current_color.a *= readonly_alpha;
- }
+ Color current_color = readonly ? cache.font_color_readonly : cache.font_color;
bool underlined = false;
@@ -1061,10 +1055,7 @@ void TextEdit::_notification(int p_what) {
if (syntax_coloring) {
if (color_map.has(last_wrap_column + j)) {
- current_color = color_map[last_wrap_column + j].color;
- if (readonly) {
- current_color.a *= readonly_alpha;
- }
+ current_color = readonly ? cache.font_color_readonly : color_map[last_wrap_column + j].color;
}
color = current_color;
}
@@ -1252,8 +1243,7 @@ void TextEdit::_notification(int p_what) {
if (cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index && block_caret && draw_caret && !insert_mode) {
color = cache.caret_background_color;
} else if (!syntax_coloring && block_caret) {
- color = cache.font_color;
- color.a *= readonly_alpha;
+ color = readonly ? cache.font_color_readonly : cache.font_color;
}
if (str[j] >= 32) {
@@ -4555,6 +4545,7 @@ void TextEdit::_update_caches() {
cache.safe_line_number_color = get_color("safe_line_number_color");
cache.font_color = get_color("font_color");
cache.font_color_selected = get_color("font_color_selected");
+ cache.font_color_readonly = get_color("font_color_readonly");
cache.keyword_color = get_color("keyword_color");
cache.function_color = get_color("function_color");
cache.member_variable_color = get_color("member_variable_color");
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index c721cf992e..30956ccb23 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -185,6 +185,7 @@ private:
Color safe_line_number_color;
Color font_color;
Color font_color_selected;
+ Color font_color_readonly;
Color keyword_color;
Color number_color;
Color function_color;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 42b445b59c..4e2fe1f9b2 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -440,6 +440,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("completion_font_color", "TextEdit", Color::html("aaaaaa"));
theme->set_color("font_color", "TextEdit", control_font_color);
theme->set_color("font_color_selected", "TextEdit", Color(0, 0, 0));
+ theme->set_color("font_color_readonly", "TextEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f));
theme->set_color("selection_color", "TextEdit", font_color_selection);
theme->set_color("mark_color", "TextEdit", Color(1.0, 0.4, 0.4, 0.4));
theme->set_color("bookmark_color", "TextEdit", Color(0.08, 0.49, 0.98));