diff options
Diffstat (limited to 'scene/gui/dialogs.cpp')
-rw-r--r-- | scene/gui/dialogs.cpp | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index cf5321e907..627bc96fb1 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -53,25 +53,34 @@ void WindowDialog::_fix_size() { Size2i viewport_size = get_viewport_rect().size; // Windows require additional padding to keep the window chrome visible. - Ref<StyleBoxTexture> panel = get_stylebox("panel", "WindowDialog"); - + Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); + float top = 0; + float left = 0; + float bottom = 0; + float right = 0; // Check validity, because the theme could contain a different type of StyleBox - if (panel.is_valid()) { - float top = panel->get_expand_margin_size(MARGIN_TOP); - float left = panel->get_expand_margin_size(MARGIN_LEFT); - float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM); - float right = panel->get_expand_margin_size(MARGIN_RIGHT); - - pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); - pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); - set_global_position(pos); - - // Also resize the window to fit if a resize should be possible at all. - if (resizable) { - size.x = MIN(size.x, viewport_size.x - left - right); - size.y = MIN(size.y, viewport_size.y - top - bottom); - set_size(size); - } + if (panel->get_class() == "StyleBoxTexture") { + Ref<StyleBoxTexture> panel_texture = panel->cast_to<StyleBoxTexture>(); + top = panel_texture->get_expand_margin_size(MARGIN_TOP); + left = panel_texture->get_expand_margin_size(MARGIN_LEFT); + bottom = panel_texture->get_expand_margin_size(MARGIN_BOTTOM); + right = panel_texture->get_expand_margin_size(MARGIN_RIGHT); + } else if (panel->get_class() == "StyleBoxFlat") { + Ref<StyleBoxFlat> panel_flat = panel->cast_to<StyleBoxFlat>(); + top = panel_flat->_get_additional_border_size(MARGIN_TOP); + left = panel_flat->_get_additional_border_size(MARGIN_LEFT); + bottom = panel_flat->_get_additional_border_size(MARGIN_BOTTOM); + right = panel_flat->_get_additional_border_size(MARGIN_RIGHT); + } + + pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); + pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); + set_global_position(pos); + + if (resizable) { + size.x = MIN(size.x, viewport_size.x - left - right); + size.y = MIN(size.y, viewport_size.y - top - bottom); + set_size(size); } } @@ -96,29 +105,33 @@ bool WindowDialog::has_point(const Point2 &p_point) const { return r.has_point(p_point); } -void WindowDialog::_gui_input(const InputEvent &p_event) { +void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) { - if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_LEFT) { + Ref<InputEventMouseButton> mb = p_event; - if (p_event.mouse_button.pressed) { + if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { + + if (mb->is_pressed()) { // Begin a possible dragging operation. - drag_type = _drag_hit_test(Point2(p_event.mouse_button.x, p_event.mouse_button.y)); + drag_type = _drag_hit_test(Point2(mb->get_pos().x, mb->get_pos().y)); if (drag_type != DRAG_NONE) drag_offset = get_global_mouse_position() - get_position(); drag_offset_far = get_position() + get_size() - get_global_mouse_position(); - } else if (drag_type != DRAG_NONE && !p_event.mouse_button.pressed) { + } else if (drag_type != DRAG_NONE && !mb->is_pressed()) { // End a dragging operation. drag_type = DRAG_NONE; } } - if (p_event.type == InputEvent::MOUSE_MOTION) { + Ref<InputEventMouseMotion> mm = p_event; + + if (mm.is_valid()) { if (drag_type == DRAG_NONE) { // Update the cursor while moving along the borders. CursorShape cursor = CURSOR_ARROW; if (resizable) { - int preview_drag_type = _drag_hit_test(Point2(p_event.mouse_button.x, p_event.mouse_button.y)); + int preview_drag_type = _drag_hit_test(Point2(mm->get_pos().x, mm->get_pos().y)); switch (preview_drag_type) { case DRAG_RESIZE_TOP: case DRAG_RESIZE_BOTTOM: @@ -200,7 +213,7 @@ void WindowDialog::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { close_button->set_normal_texture(get_icon("close", "WindowDialog")); close_button->set_pressed_texture(get_icon("close", "WindowDialog")); - close_button->set_hover_texture(get_icon("close_hilite", "WindowDialog")); + close_button->set_hover_texture(get_icon("close_highlight", "WindowDialog")); close_button->set_anchor(MARGIN_LEFT, ANCHOR_END); close_button->set_begin(Point2(get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog"))); } break; |