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/main/viewport.cpp21
-rw-r--r--scene/main/window.cpp8
-rw-r--r--scene/main/window.h4
7 files changed, 81 insertions, 6 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/main/viewport.cpp b/scene/main/viewport.cpp
index 6bfad24b65..65a72267b1 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2701,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) {
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 4855924660..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();
@@ -195,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);