diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/control.cpp | 16 | ||||
-rw-r--r-- | scene/gui/dialogs.cpp | 2 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 4 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 8 | ||||
-rw-r--r-- | scene/gui/slider.cpp | 10 | ||||
-rw-r--r-- | scene/gui/tab_container.cpp | 10 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 25 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 124 | ||||
-rw-r--r-- | scene/gui/tree.h | 4 |
9 files changed, 146 insertions, 57 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 961fccc804..2d5b54257a 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -809,9 +809,9 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & // try with custom themes Control *theme_owner = data.theme_owner; - while (theme_owner) { + StringName class_name = type; - StringName class_name = type; + while (theme_owner) { while (class_name != StringName()) { if (theme_owner->data.theme->has_stylebox(p_name, class_name)) { @@ -829,6 +829,14 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & theme_owner = NULL; } + class_name = type; + + while (class_name != StringName()) { + if (Theme::get_default()->has_stylebox(p_name, class_name)) + return Theme::get_default()->get_stylebox(p_name, class_name); + + class_name = ClassDB::get_parent_class_nocheck(class_name); + } return Theme::get_default()->get_stylebox(p_name, type); } Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) const { @@ -1249,6 +1257,10 @@ void Control::_size_changed() { new_size_cache.height = MAX(minimum_size.height, new_size_cache.height); } + if (get_viewport()->is_snap_controls_to_pixels_enabled()) { + new_size_cache = new_size_cache.floor(); + new_pos_cache = new_pos_cache.floor(); + } bool pos_changed = new_pos_cache != data.pos_cache; bool size_changed = new_size_cache != data.size_cache; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 140d002387..d4912339da 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -195,7 +195,7 @@ void WindowDialog::_notification(int p_what) { RID canvas = get_canvas_item(); // Draw the background. - Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); + Ref<StyleBox> panel = get_stylebox("panel"); Size2 size = get_size(); panel->draw(canvas, Rect2(0, 0, size.x, size.y)); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 990c0f3d96..87a232e766 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -183,8 +183,8 @@ void FileDialog::_action_pressed() { String path = dir_access->get_current_dir(); path = path.replace("\\", "/"); - - if (TreeItem *item = tree->get_selected()) { + TreeItem *item = tree->get_selected(); + if (item) { Dictionary d = item->get_metadata(0); if (d["dir"]) { path = path.plus_file(d["name"]); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index ab2c2f445f..71b9c4ec72 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -540,14 +540,6 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int it = _get_next_item(it); - if (p_mode == PROCESS_POINTER && r_click_item && itp && !it && p_click_pos.y > p_ofs.y + y + lh) { - //at the end of all, return this - if (r_outside) *r_outside = true; - *r_click_item = itp; - *r_click_char = rchar; - return; - } - if (it && (p_line + 1 < p_frame->lines.size()) && p_frame->lines[p_line + 1].from == it) { if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) { diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 4661f54526..8fda5df53c 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -162,18 +162,20 @@ void Slider::_notification(int p_what) { Size2i size = get_size(); Ref<StyleBox> style = get_stylebox("slider"); Ref<StyleBox> focus = get_stylebox("focus"); + Ref<StyleBox> grabber_area = get_stylebox("grabber_area"); Ref<Texture> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled"); Ref<Texture> tick = get_icon("tick"); if (orientation == VERTICAL) { int widget_width = style->get_minimum_size().width + style->get_center_size().width; + float areasize = size.height - grabber->get_size().height; style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height))); + grabber_area->draw(ci, Rect2i(Point2i((size.width - widget_width) / 2, size.height - areasize * get_as_ratio() - grabber->get_size().height / 2), Size2i(widget_width, areasize * get_as_ratio() + grabber->get_size().width / 2))); /* if (mouse_inside||has_focus()) focus->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height))); */ - float areasize = size.height - grabber->get_size().height; if (ticks > 1) { int tickarea = size.height - tick->get_height(); for (int i = 0; i < ticks; i++) { @@ -186,13 +188,15 @@ void Slider::_notification(int p_what) { } else { int widget_height = style->get_minimum_size().height + style->get_center_size().height; - style->draw(ci, Rect2i(Point2i(0, size.height / 2 - widget_height / 2), Size2i(size.width, widget_height))); + float areasize = size.width - grabber->get_size().width; + + style->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(size.width, widget_height))); + grabber_area->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(areasize * get_as_ratio() + grabber->get_size().width / 2, widget_height))); /* if (mouse_inside||has_focus()) focus->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height))); */ - float areasize = size.width - grabber->get_size().width; if (ticks > 1) { int tickarea = size.width - tick->get_width(); for (int i = 0; i < ticks; i++) { diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 461ae3444b..98a8db336e 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -208,6 +208,9 @@ void TabContainer::_notification(int p_what) { break; } + // Draw the tab area. + panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height)); + // Draw all visible tabs. int x = 0; for (int i = 0; i < tab_widths.size(); i++) { @@ -280,9 +283,6 @@ void TabContainer::_notification(int p_what) { Point2(x, y_center - (decrement->get_height() / 2)), Color(1, 1, 1, first_tab_cache > 0 ? 1.0 : 0.5)); } - - // Draw the tab area. - panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height)); } break; case NOTIFICATION_THEME_CHANGED: { if (get_tab_count() > 0) { @@ -655,6 +655,10 @@ void TabContainer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_align", "get_tab_align"); ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible"); + + BIND_ENUM_CONSTANT(ALIGN_LEFT); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_RIGHT); } TabContainer::TabContainer() { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4f930c5139..d30e0b9f25 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -36,6 +36,10 @@ #include "project_settings.h" #include "scene/main/viewport.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_scale.h" +#endif + #define TAB_PIXELS static bool _is_text_char(CharType c) { @@ -729,15 +733,18 @@ void TextEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color); } - 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); - } - if (line == cursor.line) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_end, get_row_height()), cache.current_line_color); } + if (text.is_breakpoint(line) && !draw_breakpoint_gutter) { +#ifdef TOOLS_ENABLED + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.breakpoint_color); +#else + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.breakpoint_color); +#endif + } + // draw breakpoint marker if (text.is_breakpoint(line)) { if (draw_breakpoint_gutter) { @@ -2793,12 +2800,16 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { int ini = selection.from_line; int end = selection.to_line; for (int i = ini; i <= end; i++) { - if (text[i][0] == '#') + if (get_line(i).begins_with("#")) _remove_text(i, 0, i, 1); } } else { - if (text[cursor.line][0] == '#') + if (get_line(cursor.line).begins_with("#")) { _remove_text(cursor.line, 0, cursor.line, 1); + if (cursor.column >= get_line(cursor.line).length()) { + cursor.column = MAX(0, get_line(cursor.line).length() - 1); + } + } } update(); } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index de17416d8e..1aaea98798 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -333,6 +333,15 @@ bool TreeItem::is_collapsed() { return collapsed; } +void TreeItem::set_custom_minimum_height(int p_height) { + custom_min_height = p_height; + _changed_notify(); +} + +int TreeItem::get_custom_minimum_height() const { + return custom_min_height; +} + TreeItem *TreeItem::get_next() { return next; @@ -703,6 +712,9 @@ void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_collapsed", "enable"), &TreeItem::set_collapsed); ClassDB::bind_method(D_METHOD("is_collapsed"), &TreeItem::is_collapsed); + ClassDB::bind_method(D_METHOD("set_custom_minimum_height", "height"), &TreeItem::set_custom_minimum_height); + ClassDB::bind_method(D_METHOD("get_custom_minimum_height"), &TreeItem::get_custom_minimum_height); + ClassDB::bind_method(D_METHOD("get_next"), &TreeItem::get_next); ClassDB::bind_method(D_METHOD("get_prev"), &TreeItem::get_prev); ClassDB::bind_method(D_METHOD("get_parent"), &TreeItem::get_parent); @@ -759,6 +771,10 @@ void TreeItem::_bind_methods() { BIND_ENUM_CONSTANT(CELL_MODE_RANGE_EXPRESSION); BIND_ENUM_CONSTANT(CELL_MODE_ICON); BIND_ENUM_CONSTANT(CELL_MODE_CUSTOM); + + BIND_ENUM_CONSTANT(ALIGN_LEFT); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_RIGHT); } void TreeItem::clear_children() { @@ -780,6 +796,7 @@ TreeItem::TreeItem(Tree *p_tree) { tree = p_tree; collapsed = false; disable_folding = false; + custom_min_height = 0; parent = 0; // parent item next = 0; // next in list @@ -921,6 +938,9 @@ int Tree::compute_item_height(TreeItem *p_item) const { default: {} } } + int item_min_height = p_item->get_custom_minimum_height(); + if (height < item_min_height) + height = item_min_height; height += cache.vseparation; @@ -1990,7 +2010,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (!k->is_pressed()) return; - if (k->get_alt() || k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey()) + if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey()) return; if (!root) return; @@ -2005,48 +2025,47 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { break; \ } case KEY_RIGHT: { + bool dobreak = true; //TreeItem *next = NULL; if (!selected_item) break; - if (select_mode == SELECT_ROW) + if (select_mode == SELECT_ROW) { EXIT_BREAK; - if (selected_col >= (columns.size() - 1)) + } + if (selected_col > (columns.size() - 1)) { EXIT_BREAK; - if (select_mode == SELECT_MULTI) { - selected_col++; - emit_signal("cell_selected"); + } + if (k->get_alt()) { + selected_item->set_collapsed(false); + TreeItem *next = selected_item->get_children(); + while (next && next != selected_item->next) { + next->set_collapsed(false); + next = next->get_next_visible(); + } + } else if (selected_col == (columns.size() - 1)) { + if (selected_item->get_children() != NULL && selected_item->is_collapsed()) { + selected_item->set_collapsed(false); + } else { + selected_col = 0; + dobreak = false; // fall through to key_down + } } else { + if (select_mode == SELECT_MULTI) { + selected_col++; + emit_signal("cell_selected"); + } else { - selected_item->select(selected_col + 1); + selected_item->select(selected_col + 1); + } } - update(); ensure_cursor_is_visible(); accept_event(); - - } break; - case KEY_LEFT: { - - //TreeItem *next = NULL; - if (!selected_item) + if (dobreak) { break; - if (select_mode == SELECT_ROW) - EXIT_BREAK; - if (selected_col <= 0) - EXIT_BREAK; - if (select_mode == SELECT_MULTI) { - selected_col--; - emit_signal("cell_selected"); - } else { - - selected_item->select(selected_col - 1); } - - update(); - accept_event(); - - } break; + } case KEY_DOWN: { TreeItem *next = NULL; @@ -2093,6 +2112,48 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { accept_event(); } break; + case KEY_LEFT: { + bool dobreak = true; + + //TreeItem *next = NULL; + if (!selected_item) + break; + if (select_mode == SELECT_ROW) { + EXIT_BREAK; + } + if (selected_col < 0) { + EXIT_BREAK; + } + if (k->get_alt()) { + selected_item->set_collapsed(true); + TreeItem *next = selected_item->get_children(); + while (next && next != selected_item->next) { + next->set_collapsed(true); + next = next->get_next_visible(); + } + } else if (selected_col == 0) { + if (selected_item->get_children() != NULL && !selected_item->is_collapsed()) { + selected_item->set_collapsed(true); + } else { + selected_col = columns.size() - 1; + dobreak = false; // fall through to key_up + } + } else { + if (select_mode == SELECT_MULTI) { + selected_col--; + emit_signal("cell_selected"); + } else { + + selected_item->select(selected_col - 1); + } + } + update(); + accept_event(); + + if (dobreak) { + break; + } + } case KEY_UP: { TreeItem *prev = NULL; @@ -2304,7 +2365,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { int col, h, section; TreeItem *it = _find_item_at_pos(root, mpos, col, h, section); - if (drop_mode_flags && it != drop_mode_over || section != drop_mode_section) { + if ((drop_mode_flags && it != drop_mode_over) || section != drop_mode_section) { drop_mode_over = it; drop_mode_section = section; update(); @@ -2478,7 +2539,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { pressing_for_editor = false; blocked++; - bool handled = propagate_mouse_event(pos + cache.offset, 0, 0, b->is_doubleclick(), root, b->get_button_index(), b); + propagate_mouse_event(pos + cache.offset, 0, 0, b->is_doubleclick(), root, b->get_button_index(), b); blocked--; if (pressing_for_editor) { @@ -3593,6 +3654,7 @@ void Tree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_item_area_rect", "item", "column"), &Tree::_get_item_rect, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("get_item_at_pos", "pos"), &Tree::get_item_at_pos); ClassDB::bind_method(D_METHOD("get_column_at_pos", "pos"), &Tree::get_column_at_pos); + ClassDB::bind_method(D_METHOD("get_drop_section_at_pos", "pos"), &Tree::get_drop_section_at_pos); ClassDB::bind_method(D_METHOD("ensure_cursor_is_visible"), &Tree::ensure_cursor_is_visible); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 06d6d3ad5a..5f19558597 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -145,6 +145,7 @@ private: bool collapsed; // wont show childs bool disable_folding; + int custom_min_height; TreeItem *parent; // parent item TreeItem *next; // next in list @@ -230,6 +231,9 @@ public: void set_collapsed(bool p_collapsed); bool is_collapsed(); + void set_custom_minimum_height(int p_height); + int get_custom_minimum_height() const; + TreeItem *get_prev(); TreeItem *get_next(); TreeItem *get_parent(); |