diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/base_button.cpp | 5 | ||||
-rw-r--r-- | scene/gui/control.cpp | 10 | ||||
-rw-r--r-- | scene/gui/dialogs.cpp | 6 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 4 | ||||
-rw-r--r-- | scene/gui/graph_node.cpp | 4 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 6 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 2 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 4 | ||||
-rw-r--r-- | scene/gui/texture_button.cpp | 42 | ||||
-rw-r--r-- | scene/gui/texture_button.h | 9 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 51 | ||||
-rw-r--r-- | scene/gui/tree.h | 5 | ||||
-rw-r--r-- | scene/gui/video_player.cpp | 4 |
13 files changed, 126 insertions, 26 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index d8229b5f43..6fef44481a 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -271,6 +271,11 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const { } void BaseButton::set_toggle_mode(bool p_on) { + // Make sure to set 'pressed' to false if we are not in toggle mode + if (!p_on) { + set_pressed(false); + } + toggle_mode = p_on; } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 97daeceda9..2cdee4641e 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1173,7 +1173,17 @@ Rect2 Control::get_parent_anchorable_rect() const { if (data.parent_canvas_item) { parent_rect = data.parent_canvas_item->get_anchorable_rect(); } else { +#ifdef TOOLS_ENABLED + Node *edited_root = get_tree()->get_edited_scene_root(); + if (edited_root && (this == edited_root || edited_root->is_a_parent_of(this))) { + parent_rect.size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); + } else { + parent_rect = get_viewport()->get_visible_rect(); + } + +#else parent_rect = get_viewport()->get_visible_rect(); +#endif } return parent_rect; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index c6897fc684..faef979090 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -51,7 +51,9 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) { } void AcceptDialog::_parent_focused() { - _cancel_pressed(); + if (!is_exclusive()) { + _cancel_pressed(); + } } void AcceptDialog::_notification(int p_what) { @@ -295,6 +297,8 @@ AcceptDialog::AcceptDialog() { set_wrap_controls(true); set_visible(false); set_transient(true); + set_exclusive(true); + set_clamp_to_embedder(true); bg = memnew(Panel); add_child(bg); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 41ca6458af..1e0d3d9f7b 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -604,7 +604,7 @@ void FileDialog::set_current_file(const String &p_file) { file->set_text(p_file); update_dir(); invalidate(); - int lp = p_file.find_last("."); + int lp = p_file.rfind("."); if (lp != -1) { file->select(0, lp); if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) { @@ -617,7 +617,7 @@ void FileDialog::set_current_path(const String &p_path) { if (!p_path.size()) { return; } - int pos = MAX(p_path.find_last("/"), p_path.find_last("\\")); + int pos = MAX(p_path.rfind("/"), p_path.rfind("\\")); if (pos == -1) { set_current_file(p_path); } else { diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index b6a96238dc..01b54ddaa8 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -503,9 +503,7 @@ void GraphNode::_connpos_update() { } } - if (vofs > 0) { - vofs += sep; - } + vofs += sep; vofs += size.y; idx++; } diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ba55927980..27c2c70708 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -51,7 +51,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (b.is_valid()) { if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) { - menu->set_position(get_global_transform().xform(get_local_mouse_position())); + menu->set_position(get_screen_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); //menu->set_scale(get_global_transform().get_scale()); menu->popup(); @@ -688,12 +688,12 @@ void LineEdit::_notification(int p_what) { update_placeholder_width(); update(); } break; - case NOTIFICATION_WM_FOCUS_IN: { + case NOTIFICATION_WM_WINDOW_FOCUS_IN: { window_has_focus = true; draw_caret = true; update(); } break; - case NOTIFICATION_WM_FOCUS_OUT: { + case NOTIFICATION_WM_WINDOW_FOCUS_OUT: { window_has_focus = false; draw_caret = false; update(); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 5ae27081ea..22e5bd55f3 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -256,7 +256,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & lh = line < l.height_caches.size() ? l.height_caches[line] : 1; \ line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1; \ line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1; \ - if (p_mode == PROCESS_DRAW) { \ + if ((p_mode == PROCESS_DRAW) && (align != ALIGN_FILL)) { \ if (line < l.offset_caches.size()) { \ wofs = l.offset_caches[line]; \ } \ diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index c7fc8dbe43..3860ce61e9 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -603,12 +603,12 @@ void TextEdit::_notification(int p_what) { _update_wrap_at(); syntax_highlighting_cache.clear(); } break; - case NOTIFICATION_WM_FOCUS_IN: { + case NOTIFICATION_WM_WINDOW_FOCUS_IN: { window_has_focus = true; draw_caret = true; update(); } break; - case NOTIFICATION_WM_FOCUS_OUT: { + case NOTIFICATION_WM_WINDOW_FOCUS_OUT: { window_has_focus = false; draw_caret = false; update(); diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 6e86f0f299..4187d77083 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -166,9 +166,11 @@ void TextureButton::_notification(int p_what) { } break; } + Point2 ofs; + Size2 size; + if (texdraw.is_valid()) { - Point2 ofs; - Size2 size = texdraw->get_size(); + size = texdraw->get_size(); _texture_region = Rect2(Point2(), texdraw->get_size()); _tile = false; if (expand) { @@ -218,17 +220,21 @@ void TextureButton::_notification(int p_what) { } _position_rect = Rect2(ofs, size); + + size.width *= hflip ? -1.0f : 1.0f; + size.height *= vflip ? -1.0f : 1.0f; + if (_tile) { - draw_texture_rect(texdraw, _position_rect, _tile); + draw_texture_rect(texdraw, Rect2(ofs, size), _tile); } else { - draw_texture_rect_region(texdraw, _position_rect, _texture_region); + draw_texture_rect_region(texdraw, Rect2(ofs, size), _texture_region); } } else { _position_rect = Rect2(); } if (has_focus() && focused.is_valid()) { - draw_texture_rect(focused, _position_rect, false); + draw_texture_rect(focused, Rect2(ofs, size), false); }; } break; } @@ -243,6 +249,10 @@ void TextureButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_click_mask", "mask"), &TextureButton::set_click_mask); ClassDB::bind_method(D_METHOD("set_expand", "p_expand"), &TextureButton::set_expand); ClassDB::bind_method(D_METHOD("set_stretch_mode", "p_mode"), &TextureButton::set_stretch_mode); + ClassDB::bind_method(D_METHOD("set_flip_h", "enable"), &TextureButton::set_flip_h); + ClassDB::bind_method(D_METHOD("is_flipped_h"), &TextureButton::is_flipped_h); + ClassDB::bind_method(D_METHOD("set_flip_v", "enable"), &TextureButton::set_flip_v); + ClassDB::bind_method(D_METHOD("is_flipped_v"), &TextureButton::is_flipped_v); ClassDB::bind_method(D_METHOD("get_normal_texture"), &TextureButton::get_normal_texture); ClassDB::bind_method(D_METHOD("get_pressed_texture"), &TextureButton::get_pressed_texture); @@ -262,6 +272,8 @@ void TextureButton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_click_mask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_click_mask", "get_click_mask"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_expand", "get_expand"); ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_flip_h", "is_flipped_h"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_v", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_flip_v", "is_flipped_v"); BIND_ENUM_CONSTANT(STRETCH_SCALE); BIND_ENUM_CONSTANT(STRETCH_TILE); @@ -345,9 +357,29 @@ TextureButton::StretchMode TextureButton::get_stretch_mode() const { return stretch_mode; } +void TextureButton::set_flip_h(bool p_flip) { + hflip = p_flip; + update(); +} + +bool TextureButton::is_flipped_h() const { + return hflip; +} + +void TextureButton::set_flip_v(bool p_flip) { + vflip = p_flip; + update(); +} + +bool TextureButton::is_flipped_v() const { + return vflip; +} + TextureButton::TextureButton() { expand = false; stretch_mode = STRETCH_SCALE; + hflip = false; + vflip = false; _texture_region = Rect2(); _position_rect = Rect2(); diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h index a1e66203d3..bfd3d40db6 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -61,6 +61,9 @@ private: Rect2 _position_rect; bool _tile; + bool hflip; + bool vflip; + protected: virtual Size2 get_minimum_size() const; virtual bool has_point(const Point2 &p_point) const; @@ -88,6 +91,12 @@ public: void set_stretch_mode(StretchMode p_stretch_mode); StretchMode get_stretch_mode() const; + void set_flip_h(bool p_flip); + bool is_flipped_h() const; + + void set_flip_v(bool p_flip); + bool is_flipped_v() const; + TextureButton(); }; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 7b9db7c081..47761d724e 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1786,7 +1786,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool case TreeItem::CELL_MODE_STRING: { //nothing in particular - if (select_mode == SELECT_MULTI && (get_tree()->get_event_count() == focus_in_id || !already_cursor)) { + if (select_mode == SELECT_MULTI && (get_viewport()->get_processed_events_count() == focus_in_id || !already_cursor)) { bring_up_editor = false; } @@ -1861,7 +1861,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } else { editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step)); - if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) { + if (select_mode == SELECT_MULTI && get_viewport()->get_processed_events_count() == focus_in_id) { bring_up_editor = false; } } @@ -2787,7 +2787,7 @@ int Tree::_get_title_button_height() const { void Tree::_notification(int p_what) { if (p_what == NOTIFICATION_FOCUS_ENTER) { - focus_in_id = get_tree()->get_event_count(); + focus_in_id = get_viewport()->get_processed_events_count(); } if (p_what == NOTIFICATION_MOUSE_EXIT) { if (cache.hover_type != Cache::CLICK_NONE) { @@ -3410,7 +3410,7 @@ void Tree::scroll_to_item(TreeItem *p_item) { const Rect2 r = get_item_rect(p_item); - if (r.position.y < v_scroll->get_value()) { + if (r.position.y <= v_scroll->get_value()) { v_scroll->set_value(r.position.y); } else if (r.position.y + r.size.y + 2 * cache.vseparation > v_scroll->get_value() + get_size().y) { v_scroll->set_value(r.position.y + r.size.y + 2 * cache.vseparation - get_size().y); @@ -3623,6 +3623,47 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const { return nullptr; } +int Tree::get_button_id_at_position(const Point2 &p_pos) const { + if (root) { + Point2 pos = p_pos; + pos -= cache.bg->get_offset(); + pos.y -= _get_title_button_height(); + if (pos.y < 0) { + return -1; + } + + if (h_scroll->is_visible_in_tree()) { + pos.x += h_scroll->get_value(); + } + if (v_scroll->is_visible_in_tree()) { + pos.y += v_scroll->get_value(); + } + + int col, h, section; + TreeItem *it = _find_item_at_pos(root, pos, col, h, section); + + if (it) { + const TreeItem::Cell &c = it->cells[col]; + int col_width = get_column_width(col); + + for (int i = 0; i < col; i++) { + pos.x -= get_column_width(i); + } + + for (int j = c.buttons.size() - 1; j >= 0; j--) { + Ref<Texture2D> b = c.buttons[j].texture; + Size2 size = b->get_size() + cache.button_pressed->get_minimum_size(); + if (pos.x > col_width - size.width) { + return c.buttons[j].id; + } + col_width -= size.width; + } + } + } + + return -1; +} + String Tree::get_tooltip(const Point2 &p_pos) const { if (root) { Point2 pos = p_pos; @@ -3839,7 +3880,7 @@ Tree::Tree() { add_child(popup_menu); // popup_menu->set_as_toplevel(true); - popup_editor = memnew(PopupPanel); + popup_editor = memnew(Popup); popup_editor->set_wrap_controls(true); add_child(popup_editor); popup_editor_vb = memnew(VBoxContainer); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 46842e78a0..cfdc307d03 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -359,11 +359,11 @@ private: VBoxContainer *popup_editor_vb; - PopupPanel *popup_editor; + Popup *popup_editor; LineEdit *text_editor; HSlider *value_editor; bool updating_value_editor; - int64_t focus_in_id; + uint64_t focus_in_id; PopupMenu *popup_menu; Vector<ColumnInfo> columns; @@ -535,6 +535,7 @@ public: TreeItem *get_item_at_position(const Point2 &p_pos) const; int get_column_at_position(const Point2 &p_pos) const; int get_drop_section_at_position(const Point2 &p_pos) const; + int get_button_id_at_position(const Point2 &p_pos) const; void clear(); diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index 881df06d8f..e118cb0d8d 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -201,10 +201,9 @@ bool VideoPlayer::has_expand() const { void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) { stop(); + AudioServer::get_singleton()->lock(); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); - AudioServer::get_singleton()->unlock(); - stream = p_stream; if (stream.is_valid()) { stream->set_audio_track(audio_track); @@ -212,6 +211,7 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) { } else { playback = Ref<VideoStreamPlayback>(); } + AudioServer::get_singleton()->unlock(); if (!playback.is_null()) { playback->set_loop(loops); |