@@ -69,11 +69,15 @@ void CodeEdit::_notification(int p_what) {
69
69
} break ;
70
70
71
71
case NOTIFICATION_DRAW: {
72
- RID ci = get_canvas_item ();
72
+ RID ci = get_text_canvas_item ();
73
+ RenderingServer *rs = RenderingServer::get_singleton ();
73
74
const bool caret_visible = is_caret_visible ();
74
75
const bool rtl = is_layout_rtl ();
75
76
const int row_height = get_line_height ();
76
77
78
+ rs->canvas_item_clear (code_completion_ci);
79
+ rs->canvas_item_set_visibility_layer (code_completion_ci, get_visibility_layer ());
80
+
77
81
if (caret_visible) {
78
82
const bool draw_code_completion = code_completion_active && !code_completion_options.is_empty ();
79
83
const bool draw_code_hint = !code_hint.is_empty ();
@@ -103,7 +107,7 @@ void CodeEdit::_notification(int p_what) {
103
107
hint_ofs.y -= (code_hint_minsize.y + row_height) - theme_cache.line_spacing ;
104
108
}
105
109
106
- draw_style_box ( theme_cache.code_hint_style , Rect2 (hint_ofs, code_hint_minsize));
110
+ theme_cache.code_hint_style -> draw (ci , Rect2 (hint_ofs, code_hint_minsize));
107
111
108
112
int yofs = 0 ;
109
113
for (int i = 0 ; i < line_count; i++) {
@@ -118,17 +122,17 @@ void CodeEdit::_notification(int p_what) {
118
122
119
123
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);
120
124
round_ofs = round_ofs.round ();
121
- draw_string ( theme_cache.font , round_ofs, line.remove_char (0xFFFF ), HORIZONTAL_ALIGNMENT_LEFT, -1 , theme_cache.font_size , theme_cache.code_hint_color );
125
+ 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 );
122
126
if (end > 0 ) {
123
127
// Draw an underline for the currently edited function parameter.
124
128
const Vector2 b = hint_ofs + theme_cache.code_hint_style ->get_offset () + Vector2 (begin, font_height + font_height * i + yofs);
125
- draw_line ( b, b + Vector2 (end - begin, 0 ), theme_cache.code_hint_color , 2 );
129
+ rs-> canvas_item_add_line (ci, b, b + Vector2 (end - begin, 0 ), theme_cache.code_hint_color , 2 );
126
130
127
131
// Draw a translucent text highlight as well.
128
132
const Rect2 highlight_rect = Rect2 (
129
133
b - Vector2 (0 , font_height),
130
134
Vector2 (end - begin, font_height));
131
- draw_rect ( highlight_rect, theme_cache.code_hint_color * Color (1 , 1 , 1 , 0.2 ));
135
+ rs-> canvas_item_add_rect (ci, highlight_rect, theme_cache.code_hint_color * Color (1 , 1 , 1 , 0.2 ));
132
136
}
133
137
yofs += theme_cache.line_spacing ;
134
138
}
@@ -177,16 +181,16 @@ void CodeEdit::_notification(int p_what) {
177
181
code_completion_rect.position .x = caret_pos.x - code_completion_base_width;
178
182
}
179
183
180
- 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 )));
184
+ theme_cache.code_completion_style -> draw (code_completion_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 )));
181
185
if (theme_cache.code_completion_background_color .a > 0.01 ) {
182
- 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 );
186
+ rs ->canvas_item_add_rect (code_completion_ci , Rect2 (code_completion_rect.position , code_completion_rect.size + Size2 (scroll_width, 0 )), theme_cache.code_completion_background_color );
183
187
}
184
188
185
189
code_completion_scroll_rect.position = code_completion_rect.position + Vector2 (code_completion_rect.size .width , 0 );
186
190
code_completion_scroll_rect.size = Vector2 (scroll_width, code_completion_rect.size .height );
187
191
188
192
code_completion_line_ofs = CLAMP ((code_completion_force_item_center < 0 ? code_completion_current_selected : code_completion_force_item_center) - lines / 2 , 0 , code_completion_options_count - lines);
189
- RenderingServer::get_singleton () ->canvas_item_add_rect (ci , Rect2 (Point2 (code_completion_rect.position .x , code_completion_rect.position .y + (code_completion_current_selected - code_completion_line_ofs) * row_height), Size2 (code_completion_rect.size .width , row_height)), theme_cache.code_completion_selected_color );
193
+ rs ->canvas_item_add_rect (code_completion_ci , Rect2 (Point2 (code_completion_rect.position .x , code_completion_rect.position .y + (code_completion_current_selected - code_completion_line_ofs) * row_height), Size2 (code_completion_rect.size .width , row_height)), theme_cache.code_completion_selected_color );
190
194
191
195
for (int i = 0 ; i < lines; i++) {
192
196
int l = code_completion_line_ofs + i;
@@ -204,25 +208,25 @@ void CodeEdit::_notification(int p_what) {
204
208
Rect2 icon_area (code_completion_rect.position .x , code_completion_rect.position .y + i * row_height, icon_area_size.width , icon_area_size.height );
205
209
if (icon.is_valid ()) {
206
210
Size2 icon_size = icon_area.size * 0.7 ;
207
- icon->draw_rect (ci , Rect2 (icon_area.position + (icon_area.size - icon_size) / 2 , icon_size));
211
+ icon->draw_rect (code_completion_ci , Rect2 (icon_area.position + (icon_area.size - icon_size) / 2 , icon_size));
208
212
}
209
213
title_pos.x = icon_area.position .x + icon_area.size .width + theme_cache.code_completion_icon_separation ;
210
214
211
215
tl->set_width (code_completion_rect.size .width - (icon_area_size.x + theme_cache.code_completion_icon_separation ));
212
216
if (rtl) {
213
217
if (code_completion_options[l].default_value .get_type () == Variant::COLOR) {
214
- draw_rect ( Rect2 (Point2 (code_completion_rect.position .x , icon_area.position .y ), icon_area_size), (Color)code_completion_options[l].default_value );
218
+ rs-> canvas_item_add_rect (code_completion_ci, Rect2 (Point2 (code_completion_rect.position .x , icon_area.position .y ), icon_area_size), (Color)code_completion_options[l].default_value );
215
219
}
216
220
tl->set_horizontal_alignment (HORIZONTAL_ALIGNMENT_RIGHT);
217
221
} else {
218
222
if (code_completion_options[l].default_value .get_type () == Variant::COLOR) {
219
223
const Color color = code_completion_options[l].default_value ;
220
224
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);
221
225
if (color.a < 1.0 ) {
222
- draw_texture_rect (theme_cache. completion_color_bg , rect, true );
226
+ rs-> canvas_item_add_texture_rect (code_completion_ci , rect, theme_cache. completion_color_bg -> get_rid () , true );
223
227
}
224
228
225
- draw_rect ( rect, color);
229
+ rs-> canvas_item_add_rect (code_completion_ci, rect, color);
226
230
}
227
231
tl->set_horizontal_alignment (HORIZONTAL_ALIGNMENT_LEFT);
228
232
}
@@ -234,9 +238,9 @@ void CodeEdit::_notification(int p_what) {
234
238
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 ;
235
239
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 ;
236
240
237
- draw_rect ( Rect2 (match_pos + Point2 (match_offset, 0 ), Size2 (match_len, row_height)), theme_cache.code_completion_existing_color );
241
+ rs-> canvas_item_add_rect (code_completion_ci, Rect2 (match_pos + Point2 (match_offset, 0 ), Size2 (match_len, row_height)), theme_cache.code_completion_existing_color );
238
242
}
239
- tl->draw (ci , title_pos, code_completion_options[l].font_color );
243
+ tl->draw (code_completion_ci , title_pos, code_completion_options[l].font_color );
240
244
}
241
245
242
246
/* Draw a small scroll rectangle to show a position in the options. */
@@ -245,7 +249,7 @@ void CodeEdit::_notification(int p_what) {
245
249
246
250
float r = (float )theme_cache.code_completion_max_lines / code_completion_options_count;
247
251
float o = (float )code_completion_line_ofs / code_completion_options_count;
248
- 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);
252
+ rs-> canvas_item_add_rect (code_completion_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);
249
253
}
250
254
}
251
255
}
@@ -268,21 +272,22 @@ void CodeEdit::_draw_guidelines() {
268
272
269
273
RID ci = get_canvas_item ();
270
274
const Size2 size = get_size ();
271
- const bool rtl = is_layout_rtl ();
275
+ RenderingServer *rs = RenderingServer::get_singleton ();
272
276
273
- const int xmargin_beg = theme_cache.style_normal ->get_margin (SIDE_LEFT) + get_total_gutter_width ();
274
- const int xmargin_end = size.width - theme_cache.style_normal ->get_margin (SIDE_RIGHT) - (is_drawing_minimap () ? get_minimap_width () : 0 );
277
+ Ref<StyleBox> style = is_editable () ? theme_cache.style_normal : theme_cache.style_readonly ;
278
+ const int xmargin_beg = style->get_margin (SIDE_LEFT) + get_total_gutter_width ();
279
+ const int xmargin_end = size.width - style->get_margin (SIDE_RIGHT) - (is_drawing_minimap () ? get_minimap_width () : 0 );
275
280
276
281
for (int i = 0 ; i < line_length_guideline_columns.size (); i++) {
277
282
const int column_pos = theme_cache.font ->get_string_size (String (" 0" ).repeat ((int )line_length_guideline_columns[i]), HORIZONTAL_ALIGNMENT_LEFT, -1 , theme_cache.font_size ).x ;
278
283
const int xoffset = xmargin_beg + column_pos - get_h_scroll ();
279
284
if (xoffset > xmargin_beg && xoffset < xmargin_end) {
280
285
Color guideline_color = (i == 0 ) ? theme_cache.line_length_guideline_color : theme_cache.line_length_guideline_color * Color (1 , 1 , 1 , 0.5 );
281
- if (rtl ) {
282
- RenderingServer::get_singleton () ->canvas_item_add_line (ci, Point2 (size.width - xoffset, 0 ), Point2 (size.width - xoffset, size.height ), guideline_color);
286
+ if (is_layout_rtl () ) {
287
+ rs ->canvas_item_add_line (ci, Point2 (size.width - xoffset, 0 ), Point2 (size.width - xoffset, size.height ), guideline_color);
283
288
continue ;
284
289
}
285
- RenderingServer::get_singleton () ->canvas_item_add_line (ci, Point2 (xoffset, 0 ), Point2 (xoffset, size.height ), guideline_color);
290
+ rs ->canvas_item_add_line (ci, Point2 (xoffset, 0 ), Point2 (xoffset, size.height ), guideline_color);
286
291
}
287
292
}
288
293
}
@@ -1341,6 +1346,7 @@ bool CodeEdit::is_drawing_executing_lines_gutter() const {
1341
1346
1342
1347
void CodeEdit::_main_gutter_draw_callback (int p_line, int p_gutter, const Rect2 &p_region) {
1343
1348
bool hovering = get_hovered_gutter () == Vector2i (main_gutter, p_line);
1349
+ RID ci = get_text_canvas_item ();
1344
1350
if (draw_breakpoints && theme_cache.breakpoint_icon .is_valid ()) {
1345
1351
bool breakpointed = is_line_breakpointed (p_line);
1346
1352
bool shift_pressed = Input::get_singleton ()->is_key_pressed (Key::SHIFT);
@@ -1355,7 +1361,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
1355
1361
Rect2 icon_region = p_region;
1356
1362
icon_region.position += Point2 (padding, padding);
1357
1363
icon_region.size -= Point2 (padding, padding) * 2 ;
1358
- theme_cache.breakpoint_icon ->draw_rect (get_canvas_item () , icon_region, false , use_color);
1364
+ theme_cache.breakpoint_icon ->draw_rect (ci , icon_region, false , use_color);
1359
1365
}
1360
1366
}
1361
1367
@@ -1374,7 +1380,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
1374
1380
Rect2 icon_region = p_region;
1375
1381
icon_region.position += Point2 (horizontal_padding, 0 );
1376
1382
icon_region.size -= Point2 (horizontal_padding * 1.1 , vertical_padding);
1377
- theme_cache.bookmark_icon ->draw_rect (get_canvas_item () , icon_region, false , use_color);
1383
+ theme_cache.bookmark_icon ->draw_rect (ci , icon_region, false , use_color);
1378
1384
}
1379
1385
}
1380
1386
@@ -1385,7 +1391,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
1385
1391
Rect2 icon_region = p_region;
1386
1392
icon_region.position += Point2 (horizontal_padding, vertical_padding);
1387
1393
icon_region.size -= Point2 (horizontal_padding, vertical_padding) * 2 ;
1388
- theme_cache.executing_line_icon ->draw_rect (get_canvas_item () , icon_region, false , theme_cache.executing_line_color );
1394
+ theme_cache.executing_line_icon ->draw_rect (ci , icon_region, false , theme_cache.executing_line_color );
1389
1395
}
1390
1396
}
1391
1397
@@ -1546,7 +1552,7 @@ void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2
1546
1552
number_color = theme_cache.line_number_color ;
1547
1553
}
1548
1554
1549
- TS->shaped_text_draw (text_rid, get_canvas_item (), ofs, -1 , -1 , number_color);
1555
+ TS->shaped_text_draw (text_rid, get_text_canvas_item (), ofs, -1 , -1 , number_color);
1550
1556
}
1551
1557
1552
1558
void CodeEdit::_clear_line_number_text_cache () {
@@ -1575,6 +1581,7 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
1575
1581
return ;
1576
1582
}
1577
1583
set_line_gutter_clickable (p_line, fold_gutter, true );
1584
+ RID ci = get_text_canvas_item ();
1578
1585
1579
1586
int horizontal_padding = p_region.size .x / 10 ;
1580
1587
int vertical_padding = p_region.size .y / 6 ;
@@ -1588,17 +1595,17 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
1588
1595
Color region_icon_color = theme_cache.folded_code_region_color ;
1589
1596
region_icon_color.a = MAX (region_icon_color.a , 0 .4f );
1590
1597
if (can_fold) {
1591
- theme_cache.can_fold_code_region_icon ->draw_rect (get_canvas_item () , p_region, false , region_icon_color);
1598
+ theme_cache.can_fold_code_region_icon ->draw_rect (ci , p_region, false , region_icon_color);
1592
1599
} else {
1593
- theme_cache.folded_code_region_icon ->draw_rect (get_canvas_item () , p_region, false , region_icon_color);
1600
+ theme_cache.folded_code_region_icon ->draw_rect (ci , p_region, false , region_icon_color);
1594
1601
}
1595
1602
return ;
1596
1603
}
1597
1604
if (can_fold) {
1598
- theme_cache.can_fold_icon ->draw_rect (get_canvas_item () , p_region, false , theme_cache.code_folding_color );
1605
+ theme_cache.can_fold_icon ->draw_rect (ci , p_region, false , theme_cache.code_folding_color );
1599
1606
return ;
1600
1607
}
1601
- theme_cache.folded_icon ->draw_rect (get_canvas_item () , p_region, false , theme_cache.code_folding_color );
1608
+ theme_cache.folded_icon ->draw_rect (ci , p_region, false , theme_cache.code_folding_color );
1602
1609
}
1603
1610
1604
1611
/* Line Folding */
@@ -3008,6 +3015,7 @@ void CodeEdit::_bind_methods() {
3008
3015
3009
3016
/* Other visuals */
3010
3017
BIND_THEME_ITEM_CUSTOM (Theme::DATA_TYPE_STYLEBOX, CodeEdit, style_normal, " normal" );
3018
+ BIND_THEME_ITEM_CUSTOM (Theme::DATA_TYPE_STYLEBOX, CodeEdit, style_readonly, " read_only" );
3011
3019
3012
3020
BIND_THEME_ITEM (Theme::DATA_TYPE_COLOR, CodeEdit, brace_mismatch_color);
3013
3021
@@ -3838,6 +3846,11 @@ void CodeEdit::_text_changed() {
3838
3846
}
3839
3847
3840
3848
CodeEdit::CodeEdit () {
3849
+ /* Code Completion */
3850
+ code_completion_ci = RenderingServer::get_singleton ()->canvas_item_create ();
3851
+ RenderingServer::get_singleton ()->canvas_item_set_parent (code_completion_ci, get_canvas_item ());
3852
+ RenderingServer::get_singleton ()->canvas_item_set_use_parent_material (code_completion_ci, true );
3853
+
3841
3854
/* Indent management */
3842
3855
auto_indent_prefixes.insert (' :' );
3843
3856
auto_indent_prefixes.insert (' {' );
@@ -3909,6 +3922,7 @@ CodeEdit::CodeEdit() {
3909
3922
3910
3923
CodeEdit::~CodeEdit () {
3911
3924
_clear_line_number_text_cache ();
3925
+ RenderingServer::get_singleton ()->free (code_completion_ci);
3912
3926
}
3913
3927
3914
3928
// Return true if l should come before r
0 commit comments