Merge pull request #4822 from Paulb23/breakpoint_marker_issue_4750

Added breakpoint markers, issue 4750
This commit is contained in:
Rémi Verschelde 2016-05-29 18:34:13 +02:00
commit d3b46b6bf2
4 changed files with 67 additions and 6 deletions

View File

@ -314,6 +314,10 @@ void TextEdit::_update_scrollbars() {
if (line_numbers)
total_width += cache.line_number_w;
if (draw_breakpoint_gutter) {
total_width += cache.breakpoint_gutter_width;
}
bool use_hscroll=true;
bool use_vscroll=true;
@ -415,6 +419,12 @@ void TextEdit::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
if (draw_breakpoint_gutter) {
cache.breakpoint_gutter_width = breakpoint_gutter_width;
} else {
cache.breakpoint_gutter_width = 0;
}
int line_number_char_count=0;
{
@ -439,7 +449,7 @@ void TextEdit::_notification(int p_what) {
RID ci = get_canvas_item();
int xmargin_beg=cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w;
int xmargin_beg=cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w+cache.breakpoint_gutter_width;
int xmargin_end=cache.size.width-cache.style_normal->get_margin(MARGIN_RIGHT);
//let's do it easy for now:
cache.style_normal->draw(ci,Rect2(Point2(),cache.size));
@ -696,7 +706,7 @@ void TextEdit::_notification(int p_what) {
fc="0"+fc;
}
cache.font->draw(ci,Point2(cache.style_normal->get_margin(MARGIN_LEFT),ofs_y+cache.font->get_ascent()),fc,cache.line_number_color);
cache.font->draw(ci,Point2(cache.style_normal->get_margin(MARGIN_LEFT)+cache.breakpoint_gutter_width,ofs_y+cache.font->get_ascent()),fc,cache.line_number_color);
}
const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(line);
@ -710,6 +720,14 @@ void TextEdit::_notification(int p_what) {
if (text.is_breakpoint(line)) {
VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.breakpoint_color);
// draw breakpoint marker
if (draw_breakpoint_gutter) {
int vertical_gap = cache.breakpoint_gutter_width / 2;
int marker_size = cache.breakpoint_gutter_width - vertical_gap;
// no transparency on marker
VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + 1, ofs_y + vertical_gap ,marker_size, marker_size),Color(cache.breakpoint_color.r, cache.breakpoint_color.g, cache.breakpoint_color.b));
}
}
@ -1376,7 +1394,7 @@ void TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) co
col=text[row].size();
} else {
col=p_mouse.x-(cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w);
col=p_mouse.x-(cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w+cache.breakpoint_gutter_width);
col+=cursor.x_ofs;
col=get_char_pos_for( col, get_line(row) );
}
@ -1450,6 +1468,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
int row,col;
_get_mouse_pos(Point2i(mb.x,mb.y), row,col);
// toggle breakpoint on gutter click
if (draw_breakpoint_gutter) {
int gutter=cache.style_normal->get_margin(MARGIN_LEFT);
if (mb.x > gutter && mb.x <= gutter + cache.breakpoint_gutter_width + 3) {
set_line_as_breakpoint(row, !is_line_set_as_breakpoint(row));
return;
}
}
int prev_col=cursor.column;
int prev_line=cursor.line;
@ -2876,7 +2903,7 @@ void TextEdit::adjust_viewport_to_cursor() {
if (cursor.line_ofs>cursor.line)
cursor.line_ofs=cursor.line;
int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w;
int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w-cache.breakpoint_gutter_width;
if (v_scroll->is_visible())
visible_width-=v_scroll->get_combined_minimum_size().width;
visible_width-=20; // give it a little more space
@ -3105,7 +3132,8 @@ void TextEdit::insert_text_at_cursor(const String& p_text) {
}
Control::CursorShape TextEdit::get_cursor_shape(const Point2& p_pos) const {
if(completion_active && completion_rect.has_point(p_pos)) {
int gutter=cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w+cache.breakpoint_gutter_width;
if((completion_active && completion_rect.has_point(p_pos)) || p_pos.x < gutter) {
return CURSOR_ARROW;
}
return CURSOR_IBEAM;
@ -4225,6 +4253,24 @@ void TextEdit::set_show_line_numbers(bool p_show) {
update();
}
void TextEdit::set_draw_breakpoint_gutter(bool p_draw) {
draw_breakpoint_gutter = p_draw;
update();
}
bool TextEdit::is_drawing_breakpoint_gutter() const {
return draw_breakpoint_gutter;
}
void TextEdit::set_breakpoint_gutter_width(int p_gutter_width) {
breakpoint_gutter_width = p_gutter_width;
update();
}
int TextEdit::get_breakpoint_gutter_width() const {
return cache.breakpoint_gutter_width;
}
bool TextEdit::is_text_field() const {
return true;
@ -4366,6 +4412,8 @@ TextEdit::TextEdit() {
cache.row_height=1;
cache.line_spacing=1;
cache.line_number_w=1;
cache.breakpoint_gutter_width=0;
breakpoint_gutter_width = 0;
tab_size=4;
text.set_tab_size(tab_size);
@ -4447,6 +4495,7 @@ TextEdit::TextEdit() {
completion_line_ofs=0;
tooltip_obj=NULL;
line_numbers=false;
draw_breakpoint_gutter=false;
next_operation_is_complex=false;
scroll_past_end_of_file_enabled=false;
auto_brace_completion_enabled=false;

View File

@ -94,6 +94,7 @@ class TextEdit : public Control {
int row_height;
int line_spacing;
int line_number_w;
int breakpoint_gutter_width;
Size2 size;
} cache;
@ -224,6 +225,8 @@ class TextEdit : public Control {
bool text_changed_dirty;
bool undo_enabled;
bool line_numbers;
bool draw_breakpoint_gutter;
int breakpoint_gutter_width;
bool highlight_all_occurrences;
bool scroll_past_end_of_file_enabled;
@ -462,6 +465,12 @@ public:
void set_show_line_numbers(bool p_show);
void set_draw_breakpoint_gutter(bool p_draw);
bool is_drawing_breakpoint_gutter() const;
void set_breakpoint_gutter_width(int p_gutter_width);
int get_breakpoint_gutter_width() const;
void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata);
void set_completion(bool p_enabled,const Vector<String>& p_prefixes);

View File

@ -473,6 +473,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
set("text_editor/draw_tabs", true);
set("text_editor/show_line_numbers", true);
set("text_editor/show_breakpoint_gutter", true);
set("text_editor/trim_trailing_whitespace_on_save", false);
set("text_editor/idle_parse_delay",2);

View File

@ -588,7 +588,7 @@ void ScriptTextEditor::_bind_methods() {
}
ScriptTextEditor::ScriptTextEditor() {
get_text_edit()->set_breakpoint_gutter_width(12);
}
/*** SCRIPT EDITOR ******/
@ -2037,6 +2037,7 @@ void ScriptEditor::edit(const Ref<Script>& p_script) {
ste->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
ste->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
ste->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
ste->get_text_edit()->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/show_breakpoint_gutter"));
ste->get_text_edit()->set_callhint_settings(
EditorSettings::get_singleton()->get("text_editor/put_callhint_tooltip_below_current_line"),
EditorSettings::get_singleton()->get("text_editor/callhint_tooltip_offset"));
@ -2193,6 +2194,7 @@ void ScriptEditor::_editor_settings_changed() {
ste->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
ste->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
ste->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
ste->get_text_edit()->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/show_breakpoint_gutter"));
}
}