Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/classes/TextEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,6 @@
<member name="caret_type" type="int" setter="set_caret_type" getter="get_caret_type" enum="TextEdit.CaretType" default="0">
Set the type of caret to draw.
</member>
<member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
<member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled" default="true">
If [code]true[/code], a right-click displays the context menu.
</member>
Expand Down
7 changes: 4 additions & 3 deletions editor/script/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,10 @@ void ScriptTextEditor::_inline_object_draw(const Dictionary &p_info, const Rect2
if (color_alpha_texture.is_null()) {
color_alpha_texture = inline_color_picker->get_theme_icon("sample_bg", "ColorPicker");
}
code_editor->get_text_editor()->draw_texture_rect(color_alpha_texture, col_rect, false);
code_editor->get_text_editor()->draw_rect(col_rect, Color(p_info["color"]));
code_editor->get_text_editor()->draw_rect(col_rect, Color(1, 1, 1), false, 1);
RID text_ci = code_editor->get_text_editor()->get_text_canvas_item();
RS::get_singleton()->canvas_item_add_rect(text_ci, p_rect.grow(-3), Color(1, 1, 1));
color_alpha_texture->draw_rect(text_ci, col_rect);
RS::get_singleton()->canvas_item_add_rect(text_ci, col_rect, Color(p_info["color"]));
}
}

Expand Down
40 changes: 21 additions & 19 deletions scene/gui/code_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void CodeEdit::_notification(int p_what) {
} break;

case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
RID ci = get_text_canvas_item();
const bool caret_visible = is_caret_visible();
const bool rtl = is_layout_rtl();
const int row_height = get_line_height();
Expand Down Expand Up @@ -103,7 +103,7 @@ void CodeEdit::_notification(int p_what) {
hint_ofs.y -= (code_hint_minsize.y + row_height) - theme_cache.line_spacing;
}

draw_style_box(theme_cache.code_hint_style, Rect2(hint_ofs, code_hint_minsize));
theme_cache.code_hint_style->draw(ci, Rect2(hint_ofs, code_hint_minsize));

int yofs = 0;
for (int i = 0; i < line_count; i++) {
Expand All @@ -118,17 +118,17 @@ void CodeEdit::_notification(int p_what) {

Point2 round_ofs = hint_ofs + theme_cache.code_hint_style->get_offset() + Vector2(0, theme_cache.font->get_ascent(theme_cache.font_size) + font_height * i + yofs);
round_ofs = round_ofs.round();
draw_string(theme_cache.font, round_ofs, line.remove_char(0xFFFF), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size, theme_cache.code_hint_color);
theme_cache.font->draw_string(ci, round_ofs, line.remove_char(0xFFFF), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size, theme_cache.code_hint_color);
if (end > 0) {
// Draw an underline for the currently edited function parameter.
const Vector2 b = hint_ofs + theme_cache.code_hint_style->get_offset() + Vector2(begin, font_height + font_height * i + yofs);
draw_line(b, b + Vector2(end - begin, 0), theme_cache.code_hint_color, 2);
RS::get_singleton()->canvas_item_add_line(ci, b, b + Vector2(end - begin, 0), theme_cache.code_hint_color, 2);

// Draw a translucent text highlight as well.
const Rect2 highlight_rect = Rect2(
b - Vector2(0, font_height),
Vector2(end - begin, font_height));
draw_rect(highlight_rect, theme_cache.code_hint_color * Color(1, 1, 1, 0.2));
RS::get_singleton()->canvas_item_add_rect(ci, highlight_rect, theme_cache.code_hint_color * Color(1, 1, 1, 0.2));
}
yofs += theme_cache.line_spacing;
}
Expand Down Expand Up @@ -177,7 +177,7 @@ void CodeEdit::_notification(int p_what) {
code_completion_rect.position.x = caret_pos.x - code_completion_base_width;
}

draw_style_box(theme_cache.code_completion_style, Rect2(code_completion_rect.position - theme_cache.code_completion_style->get_offset(), code_completion_rect.size + theme_cache.code_completion_style->get_minimum_size() + Size2(scroll_width, 0)));
theme_cache.code_completion_style->draw(ci, Rect2(code_completion_rect.position - theme_cache.code_completion_style->get_offset(), code_completion_rect.size + theme_cache.code_completion_style->get_minimum_size() + Size2(scroll_width, 0)));
if (theme_cache.code_completion_background_color.a > 0.01) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(code_completion_rect.position, code_completion_rect.size + Size2(scroll_width, 0)), theme_cache.code_completion_background_color);
}
Expand Down Expand Up @@ -211,18 +211,18 @@ void CodeEdit::_notification(int p_what) {
tl->set_width(code_completion_rect.size.width - (icon_area_size.x + theme_cache.code_completion_icon_separation));
if (rtl) {
if (code_completion_options[l].default_value.get_type() == Variant::COLOR) {
draw_rect(Rect2(Point2(code_completion_rect.position.x, icon_area.position.y), icon_area_size), (Color)code_completion_options[l].default_value);
RS::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(code_completion_rect.position.x, icon_area.position.y), icon_area_size), (Color)code_completion_options[l].default_value);
}
tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
} else {
if (code_completion_options[l].default_value.get_type() == Variant::COLOR) {
const Color color = code_completion_options[l].default_value;
const Rect2 rect = Rect2(Point2(code_completion_rect.position.x + code_completion_rect.size.width - icon_area_size.x, icon_area.position.y), icon_area_size);
if (color.a < 1.0) {
draw_texture_rect(theme_cache.completion_color_bg, rect, true);
theme_cache.completion_color_bg->draw_rect(ci, rect, true);
}

draw_rect(rect, color);
RS::get_singleton()->canvas_item_add_rect(ci, rect, color);
}
tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT);
}
Expand All @@ -234,7 +234,7 @@ void CodeEdit::_notification(int p_what) {
int match_offset = theme_cache.font->get_string_size(code_completion_options[l].display.substr(0, match_segment.first), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).width;
int match_len = theme_cache.font->get_string_size(code_completion_options[l].display.substr(match_segment.first, match_segment.second), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).width;

draw_rect(Rect2(match_pos + Point2(match_offset, 0), Size2(match_len, row_height)), theme_cache.code_completion_existing_color);
RS::get_singleton()->canvas_item_add_rect(ci, Rect2(match_pos + Point2(match_offset, 0), Size2(match_len, row_height)), theme_cache.code_completion_existing_color);
}
tl->draw(ci, title_pos, code_completion_options[l].font_color);
}
Expand All @@ -245,7 +245,7 @@ void CodeEdit::_notification(int p_what) {

float r = (float)theme_cache.code_completion_max_lines / code_completion_options_count;
float o = (float)code_completion_line_ofs / code_completion_options_count;
draw_rect(Rect2(code_completion_rect.position.x + code_completion_rect.size.width, code_completion_rect.position.y + o * code_completion_rect.size.y, scroll_width, code_completion_rect.size.y * r), scroll_color);
RS::get_singleton()->canvas_item_add_rect(ci, Rect2(code_completion_rect.position.x + code_completion_rect.size.width, code_completion_rect.position.y + o * code_completion_rect.size.y, scroll_width, code_completion_rect.size.y * r), scroll_color);
}
}
}
Expand Down Expand Up @@ -1341,6 +1341,7 @@ bool CodeEdit::is_drawing_executing_lines_gutter() const {

void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2 &p_region) {
bool hovering = get_hovered_gutter() == Vector2i(main_gutter, p_line);
RID ci = get_text_canvas_item();
if (draw_breakpoints && theme_cache.breakpoint_icon.is_valid()) {
bool breakpointed = is_line_breakpointed(p_line);
bool shift_pressed = Input::get_singleton()->is_key_pressed(Key::SHIFT);
Expand All @@ -1355,7 +1356,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
Rect2 icon_region = p_region;
icon_region.position += Point2(padding, padding);
icon_region.size -= Point2(padding, padding) * 2;
theme_cache.breakpoint_icon->draw_rect(get_canvas_item(), icon_region, false, use_color);
theme_cache.breakpoint_icon->draw_rect(ci, icon_region, false, use_color);
}
}

Expand All @@ -1374,7 +1375,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
Rect2 icon_region = p_region;
icon_region.position += Point2(horizontal_padding, 0);
icon_region.size -= Point2(horizontal_padding * 1.1, vertical_padding);
theme_cache.bookmark_icon->draw_rect(get_canvas_item(), icon_region, false, use_color);
theme_cache.bookmark_icon->draw_rect(ci, icon_region, false, use_color);
}
}

Expand All @@ -1385,7 +1386,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
Rect2 icon_region = p_region;
icon_region.position += Point2(horizontal_padding, vertical_padding);
icon_region.size -= Point2(horizontal_padding, vertical_padding) * 2;
theme_cache.executing_line_icon->draw_rect(get_canvas_item(), icon_region, false, theme_cache.executing_line_color);
theme_cache.executing_line_icon->draw_rect(ci, icon_region, false, theme_cache.executing_line_color);
}
}

Expand Down Expand Up @@ -1546,7 +1547,7 @@ void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2
number_color = theme_cache.line_number_color;
}

TS->shaped_text_draw(text_rid, get_canvas_item(), ofs, -1, -1, number_color);
TS->shaped_text_draw(text_rid, get_text_canvas_item(), ofs, -1, -1, number_color);
}

void CodeEdit::_clear_line_number_text_cache() {
Expand Down Expand Up @@ -1575,6 +1576,7 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
return;
}
set_line_gutter_clickable(p_line, fold_gutter, true);
RID ci = get_text_canvas_item();

int horizontal_padding = p_region.size.x / 10;
int vertical_padding = p_region.size.y / 6;
Expand All @@ -1588,17 +1590,17 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
Color region_icon_color = theme_cache.folded_code_region_color;
region_icon_color.a = MAX(region_icon_color.a, 0.4f);
if (can_fold) {
theme_cache.can_fold_code_region_icon->draw_rect(get_canvas_item(), p_region, false, region_icon_color);
theme_cache.can_fold_code_region_icon->draw_rect(ci, p_region, false, region_icon_color);
} else {
theme_cache.folded_code_region_icon->draw_rect(get_canvas_item(), p_region, false, region_icon_color);
theme_cache.folded_code_region_icon->draw_rect(ci, p_region, false, region_icon_color);
}
return;
}
if (can_fold) {
theme_cache.can_fold_icon->draw_rect(get_canvas_item(), p_region, false, theme_cache.code_folding_color);
theme_cache.can_fold_icon->draw_rect(ci, p_region, false, theme_cache.code_folding_color);
return;
}
theme_cache.folded_icon->draw_rect(get_canvas_item(), p_region, false, theme_cache.code_folding_color);
theme_cache.folded_icon->draw_rect(ci, p_region, false, theme_cache.code_folding_color);
}

/* Line Folding */
Expand Down
Loading
Loading