diff options
Diffstat (limited to 'scene/gui/dialogs.cpp')
-rw-r--r-- | scene/gui/dialogs.cpp | 91 |
1 files changed, 52 insertions, 39 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index cf5321e907..60d1350405 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); } } @@ -81,44 +90,48 @@ bool WindowDialog::has_point(const Point2 &p_point) const { // Enlarge upwards for title bar. int title_height = get_constant("title_height", "WindowDialog"); - r.pos.y -= title_height; + r.position.y -= title_height; r.size.y += title_height; // Inflate by the resizable border thickness. if (resizable) { int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); - r.pos.x -= scaleborder_size; + r.position.x -= scaleborder_size; r.size.width += scaleborder_size * 2; - r.pos.y -= scaleborder_size; + r.position.y -= scaleborder_size; r.size.height += scaleborder_size * 2; } 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_position().x, mb->get_position().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_position().x, mm->get_position().y)); switch (preview_drag_type) { case DRAG_RESIZE_TOP: case DRAG_RESIZE_BOTTOM: @@ -149,28 +162,28 @@ void WindowDialog::_gui_input(const InputEvent &p_event) { Size2 min_size = get_minimum_size(); if (drag_type == DRAG_MOVE) { - rect.pos = global_pos - drag_offset; + rect.position = global_pos - drag_offset; } else { if (drag_type & DRAG_RESIZE_TOP) { - int bottom = rect.pos.y + rect.size.height; + int bottom = rect.position.y + rect.size.height; int max_y = bottom - min_size.height; - rect.pos.y = MIN(global_pos.y - drag_offset.y, max_y); - rect.size.height = bottom - rect.pos.y; + rect.position.y = MIN(global_pos.y - drag_offset.y, max_y); + rect.size.height = bottom - rect.position.y; } else if (drag_type & DRAG_RESIZE_BOTTOM) { - rect.size.height = global_pos.y - rect.pos.y + drag_offset_far.y; + rect.size.height = global_pos.y - rect.position.y + drag_offset_far.y; } if (drag_type & DRAG_RESIZE_LEFT) { - int right = rect.pos.x + rect.size.width; + int right = rect.position.x + rect.size.width; int max_x = right - min_size.width; - rect.pos.x = MIN(global_pos.x - drag_offset.x, max_x); - rect.size.width = right - rect.pos.x; + rect.position.x = MIN(global_pos.x - drag_offset.x, max_x); + rect.size.width = right - rect.position.x; } else if (drag_type & DRAG_RESIZE_RIGHT) { - rect.size.width = global_pos.x - rect.pos.x + drag_offset_far.x; + rect.size.width = global_pos.x - rect.position.x + drag_offset_far.x; } } set_size(rect.size); - set_position(rect.pos); + set_position(rect.position); } } } @@ -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; |