summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/dialogs.cpp1
-rw-r--r--scene/gui/line_edit.cpp2
-rw-r--r--scene/gui/texture_button.cpp42
-rw-r--r--scene/gui/texture_button.h9
-rw-r--r--scene/gui/tree.cpp8
-rw-r--r--scene/gui/tree.h4
-rw-r--r--scene/main/scene_tree.cpp5
-rw-r--r--scene/main/scene_tree.h2
-rw-r--r--scene/main/viewport.cpp44
-rw-r--r--scene/main/viewport.h5
-rw-r--r--scene/main/window.cpp8
-rw-r--r--scene/main/window.h5
12 files changed, 112 insertions, 23 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index bacc65c7bf..faef979090 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -298,6 +298,7 @@ AcceptDialog::AcceptDialog() {
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/line_edit.cpp b/scene/gui/line_edit.cpp
index 251f31ce4e..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();
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 34161a9e80..1ed5b9e598 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) {
@@ -3839,7 +3839,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..511565619a 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;
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index a418883506..d6159e089b 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -939,10 +939,6 @@ int64_t SceneTree::get_frame() const {
return current_frame;
}
-int64_t SceneTree::get_event_count() const {
- return current_event;
-}
-
Array SceneTree::_get_nodes_in_group(const StringName &p_group) {
Array ret;
Map<StringName, Group>::Element *E = group_map.find(p_group);
@@ -1362,7 +1358,6 @@ SceneTree::SceneTree() {
root = nullptr;
pause = false;
current_frame = 0;
- current_event = 0;
tree_changed_name = "tree_changed";
node_added_name = "node_added";
node_removed_name = "node_removed";
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 57b6b4dcfa..bea29c7605 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -110,7 +110,6 @@ private:
StringName node_renamed_name;
int64_t current_frame;
- int64_t current_event;
int node_count;
#ifdef TOOLS_ENABLED
@@ -300,7 +299,6 @@ public:
int get_collision_debug_contact_count() { return collision_debug_contacts; }
int64_t get_frame() const;
- int64_t get_event_count() const;
int get_node_count() const;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 0d5d222f5e..65a72267b1 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2450,6 +2450,22 @@ void Viewport::_gui_remove_control(Control *p_control) {
}
}
+Window *Viewport::get_base_window() const {
+ Viewport *v = const_cast<Viewport *>(this);
+ Window *w = Object::cast_to<Window>(v);
+ while (!w) {
+ v = v->get_parent_viewport();
+ w = Object::cast_to<Window>(v);
+ }
+
+ return w;
+}
+void Viewport::_gui_remove_focus_for_window(Node *p_window) {
+ if (get_base_window() == p_window) {
+ _gui_remove_focus();
+ }
+}
+
void Viewport::_gui_remove_focus() {
if (gui.key_focus) {
Node *f = gui.key_focus;
@@ -2467,7 +2483,7 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
if (gui.key_focus && gui.key_focus == p_control) {
return;
}
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus");
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus_for_window", (Node *)get_base_window());
gui.key_focus = p_control;
emit_signal("gui_focus_changed", p_control);
p_control->notification(Control::NOTIFICATION_FOCUS_ENTER);
@@ -2685,6 +2701,27 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
if (gui.subwindow_drag == SUB_WINDOW_DRAG_MOVE) {
Vector2 diff = mm->get_position() - gui.subwindow_drag_from;
Rect2i new_rect(gui.subwindow_drag_pos + diff, gui.subwindow_focused->get_size());
+
+ if (gui.subwindow_focused->is_clamped_to_embedder()) {
+ Size2i limit = get_visible_rect().size;
+ if (new_rect.position.x + new_rect.size.x > limit.x) {
+ new_rect.position.x = limit.x - new_rect.size.x;
+ }
+ if (new_rect.position.y + new_rect.size.y > limit.y) {
+ new_rect.position.y = limit.y - new_rect.size.y;
+ }
+
+ if (new_rect.position.x < 0) {
+ new_rect.position.x = 0;
+ }
+
+ int title_height = gui.subwindow_focused->get_flag(Window::FLAG_BORDERLESS) ? 0 : gui.subwindow_focused->get_theme_constant("title_height");
+
+ if (new_rect.position.y < title_height) {
+ new_rect.position.y = title_height;
+ }
+ }
+
gui.subwindow_focused->_rect_changed_callback(new_rect);
}
if (gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE) {
@@ -2924,6 +2961,8 @@ void Viewport::input(const Ref<InputEvent> &p_event, bool p_local_coords) {
if (!is_input_handled()) {
_gui_input_event(ev);
}
+
+ event_count++;
//get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",ev); //special one for GUI, as controls use their own process check
}
@@ -3305,8 +3344,7 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input);
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);
- ClassDB::bind_method(D_METHOD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip);
- ClassDB::bind_method(D_METHOD("_gui_remove_focus"), &Viewport::_gui_remove_focus);
+ ClassDB::bind_method(D_METHOD("_gui_remove_focus_for_window"), &Viewport::_gui_remove_focus_for_window);
ClassDB::bind_method(D_METHOD("_post_gui_grab_click_focus"), &Viewport::_post_gui_grab_click_focus);
ClassDB::bind_method(D_METHOD("set_shadow_atlas_size", "size"), &Viewport::set_shadow_atlas_size);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index d45b321f73..09ef4354c5 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -392,6 +392,7 @@ private:
void _gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control);
void _gui_set_drag_preview(Control *p_base, Control *p_control);
+ void _gui_remove_focus_for_window(Node *p_window);
void _gui_remove_focus();
void _gui_unfocus_control(Control *p_control);
bool _gui_control_has_focus(const Control *p_control);
@@ -442,6 +443,7 @@ private:
SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point);
virtual bool _can_consume_input_events() const { return true; }
+ uint64_t event_count = 0;
protected:
void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated);
@@ -455,6 +457,8 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
+ uint64_t get_processed_events_count() const { return event_count; }
+
Listener3D *get_listener() const;
Camera3D *get_camera() const;
@@ -572,6 +576,7 @@ public:
bool is_embedding_subwindows() const;
Viewport *get_parent_viewport() const;
+ Window *get_base_window() const;
void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 8604bb78ac..0463615d4d 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1251,6 +1251,14 @@ Rect2i Window::get_parent_rect() const {
}
}
+void Window::set_clamp_to_embedder(bool p_enable) {
+ clamp_to_embedder = p_enable;
+}
+
+bool Window::is_clamped_to_embedder() const {
+ return clamp_to_embedder;
+}
+
void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title);
diff --git a/scene/main/window.h b/scene/main/window.h
index 89c94753da..5fd59e06f5 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -92,6 +92,7 @@ private:
bool exclusive = false;
bool wrap_controls = false;
bool updating_child_controls = false;
+ bool clamp_to_embedder = false;
void _update_child_controls();
@@ -134,7 +135,6 @@ private:
protected:
Viewport *_get_embedder() const;
-
virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }
virtual void _post_popup() {}
@@ -196,6 +196,9 @@ public:
void set_exclusive(bool p_exclusive);
bool is_exclusive() const;
+ void set_clamp_to_embedder(bool p_enable);
+ bool is_clamped_to_embedder() const;
+
bool can_draw() const;
void set_ime_active(bool p_active);