mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:27:43 +00:00
LibGfx+Everywhere: Change Gfx::Rect
to be endpoint exclusive
Previously, calling `.right()` on a `Gfx::Rect` would return the last column's coordinate still inside the rectangle, or `left + width - 1`. This is called 'endpoint inclusive' and does not make a lot of sense for `Gfx::Rect<float>` where a rectangle of width 5 at position (0, 0) would return 4 as its right side. This same problem exists for `.bottom()`. This changes `Gfx::Rect` to be endpoint exclusive, which gives us the nice property that `width = right - left` and `height = bottom - top`. It enables us to treat `Gfx::Rect<int>` and `Gfx::Rect<float>` exactly the same. All users of `Gfx::Rect` have been updated accordingly.
This commit is contained in:
parent
b7f4363791
commit
f391ccfe53
88 changed files with 524 additions and 518 deletions
|
@ -27,9 +27,9 @@ static void update_notification_window_locations(Gfx::IntRect const& screen_rect
|
|||
auto& window = window_entry.value;
|
||||
Gfx::IntPoint new_window_location;
|
||||
if (last_window_rect.has_value())
|
||||
new_window_location = last_window_rect.value().bottom_left().translated(0, 10);
|
||||
new_window_location = last_window_rect.value().bottom_left().moved_down(9);
|
||||
else
|
||||
new_window_location = screen_rect.top_right().translated(-window->rect().width() - 24, 7);
|
||||
new_window_location = screen_rect.top_right().translated(-window->rect().width() - 24 - 1, 7);
|
||||
if (window->rect().location() != new_window_location) {
|
||||
window->move_to(new_window_location);
|
||||
window->set_original_rect(window->rect());
|
||||
|
@ -58,10 +58,10 @@ NotificationWindow::NotificationWindow(i32 client_id, DeprecatedString const& te
|
|||
Gfx::IntRect rect;
|
||||
rect.set_width(220);
|
||||
rect.set_height(40);
|
||||
rect.set_location(GUI::Desktop::the().rect().top_right().translated(-rect.width() - 24, 7));
|
||||
rect.set_location(GUI::Desktop::the().rect().top_right().translated(-rect.width() - 24 - 1, 7));
|
||||
|
||||
if (lowest_notification_rect_on_screen.has_value())
|
||||
rect.set_location(lowest_notification_rect_on_screen.value().bottom_left().translated(0, 10));
|
||||
rect.set_location(lowest_notification_rect_on_screen.value().bottom_left().moved_down(9));
|
||||
|
||||
set_rect(rect);
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ void ClockWidget::position_calendar_window()
|
|||
{
|
||||
constexpr auto taskbar_top_padding { 4 };
|
||||
m_calendar_window->set_rect(
|
||||
screen_relative_rect().right() - m_calendar_window->width() + 1,
|
||||
screen_relative_rect().right() - m_calendar_window->width(),
|
||||
screen_relative_rect().top() - taskbar_top_padding - m_calendar_window->height(),
|
||||
m_window_size.width(),
|
||||
m_window_size.height());
|
||||
|
|
|
@ -142,7 +142,7 @@ void TaskbarWindow::toggle_show_desktop()
|
|||
void TaskbarWindow::on_screen_rects_change(Vector<Gfx::IntRect, 4> const& rects, size_t main_screen_index)
|
||||
{
|
||||
auto const& rect = rects[main_screen_index];
|
||||
Gfx::IntRect new_rect { rect.x(), rect.bottom() - taskbar_height() + 1, rect.width(), taskbar_height() };
|
||||
Gfx::IntRect new_rect { rect.x(), rect.bottom() - taskbar_height(), rect.width(), taskbar_height() };
|
||||
set_rect(new_rect);
|
||||
update_applet_area();
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ Window& Menu::ensure_menu_window(Gfx::IntPoint position)
|
|||
auto calculate_window_rect = [&]() -> Gfx::IntRect {
|
||||
int window_height_available = screen.height() - frame_thickness() * 2;
|
||||
int max_window_height = (window_height_available / item_height()) * item_height() + frame_thickness() * 2;
|
||||
int content_height = m_items.is_empty() ? 0 : (m_items.last()->rect().bottom() + 1) + frame_thickness();
|
||||
int content_height = m_items.is_empty() ? 0 : m_items.last()->rect().bottom() + frame_thickness();
|
||||
int window_height = min(max_window_height, content_height);
|
||||
if (window_height < content_height) {
|
||||
m_scrollable = true;
|
||||
|
@ -284,7 +284,7 @@ void Menu::draw(MenuItem const& item, bool is_drawing_all)
|
|||
painter.set_font(previous_font);
|
||||
if (item.is_submenu()) {
|
||||
Gfx::IntRect submenu_arrow_rect {
|
||||
item.rect().right() - static_cast<int>(s_submenu_arrow_bitmap.width()) - 2,
|
||||
item.rect().right() - static_cast<int>(s_submenu_arrow_bitmap.width()) - 3,
|
||||
0,
|
||||
s_submenu_arrow_bitmap.width(),
|
||||
s_submenu_arrow_bitmap.height()
|
||||
|
@ -313,7 +313,7 @@ void Menu::update_for_new_hovered_item(bool make_input)
|
|||
if (hovered_item->is_submenu()) {
|
||||
VERIFY(menu_window());
|
||||
MenuManager::the().close_everyone_not_in_lineage(*hovered_item->submenu());
|
||||
hovered_item->submenu()->do_popup(hovered_item->rect().top_right().translated(menu_window()->rect().location()), make_input, true);
|
||||
hovered_item->submenu()->do_popup(hovered_item->rect().top_right().translated(-1, 0).translated(menu_window()->rect().location()), make_input, true);
|
||||
} else {
|
||||
MenuManager::the().close_everyone_not_in_lineage(*this);
|
||||
VERIFY(menu_window());
|
||||
|
@ -620,10 +620,10 @@ void Menu::open_button_menu(Gfx::IntPoint position, Gfx::IntRect const& button_r
|
|||
auto& window = ensure_menu_window(position);
|
||||
Gfx::IntPoint adjusted_pos = position;
|
||||
|
||||
if (window.rect().right() > screen.width())
|
||||
adjusted_pos = adjusted_pos.translated(-(window.rect().right() - screen.width()) - 1, 0);
|
||||
if (window.rect().right() - 1 > screen.width())
|
||||
adjusted_pos = adjusted_pos.translated(-(window.rect().right() - screen.width()), 0);
|
||||
|
||||
if (window.rect().bottom() > screen.height())
|
||||
if (window.rect().bottom() - 1 > screen.height())
|
||||
adjusted_pos = adjusted_pos.translated(0, -window.rect().height() - button_rect.height() + 1);
|
||||
|
||||
window.set_rect(adjusted_pos.x(), adjusted_pos.y(), window.rect().width(), window.rect().height());
|
||||
|
@ -651,7 +651,7 @@ void Menu::do_popup(Gfx::IntPoint position, bool make_input, bool as_submenu)
|
|||
constexpr auto margin = 10;
|
||||
Gfx::IntPoint adjusted_pos = m_unadjusted_position = position;
|
||||
|
||||
if (adjusted_pos.x() + window.width() > screen.rect().right() - margin) {
|
||||
if (adjusted_pos.x() + window.width() >= screen.rect().right() - margin) {
|
||||
// Vertically translate the window by its full width, i.e. flip it at its vertical axis.
|
||||
adjusted_pos = adjusted_pos.translated(-window.width(), 0);
|
||||
// If the window is a submenu, translate to the opposite side of its immediate ancestor
|
||||
|
@ -664,7 +664,7 @@ void Menu::do_popup(Gfx::IntPoint position, bool make_input, bool as_submenu)
|
|||
// underneath the cursor and can be closed by another click at the same position.
|
||||
adjusted_pos.set_x(adjusted_pos.x() + 1);
|
||||
}
|
||||
if (adjusted_pos.y() + window.height() > screen.rect().bottom() - margin) {
|
||||
if (adjusted_pos.y() + window.height() >= screen.rect().bottom() - margin) {
|
||||
// Vertically translate the window by its full height, i.e. flip it at its horizontal axis.
|
||||
auto offset = window.height();
|
||||
// ...but if it's a submenu, go back by one menu item height to keep the menu aligned with
|
||||
|
|
|
@ -98,7 +98,7 @@ void MenuManager::event(Core::Event& event)
|
|||
else {
|
||||
auto* target_menu = previous_menu(m_current_menu);
|
||||
if (target_menu) {
|
||||
target_menu->ensure_menu_window(target_menu->rect_in_window_menubar().bottom_left().translated(wm.window_with_active_menu()->frame().rect().location()).translated(wm.window_with_active_menu()->frame().menubar_rect().location()));
|
||||
target_menu->ensure_menu_window(target_menu->rect_in_window_menubar().bottom_left().moved_up(1).translated(wm.window_with_active_menu()->frame().rect().location()).translated(wm.window_with_active_menu()->frame().menubar_rect().location()));
|
||||
open_menu(*target_menu);
|
||||
wm.window_with_active_menu()->invalidate_menubar();
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ void MenuManager::event(Core::Event& event)
|
|||
else if (m_open_menu_stack.size() <= 1 && wm.window_with_active_menu()) {
|
||||
auto* target_menu = next_menu(m_current_menu);
|
||||
if (target_menu) {
|
||||
target_menu->ensure_menu_window(target_menu->rect_in_window_menubar().bottom_left().translated(wm.window_with_active_menu()->frame().rect().location()).translated(wm.window_with_active_menu()->frame().menubar_rect().location()));
|
||||
target_menu->ensure_menu_window(target_menu->rect_in_window_menubar().bottom_left().moved_up(1).translated(wm.window_with_active_menu()->frame().rect().location()).translated(wm.window_with_active_menu()->frame().menubar_rect().location()));
|
||||
open_menu(*target_menu);
|
||||
wm.window_with_active_menu()->invalidate_menubar();
|
||||
close_everyone_not_in_lineage(*target_menu);
|
||||
|
|
|
@ -358,7 +358,7 @@ bool ScreenLayout::try_auto_add_display_connector(DeprecatedString const& device
|
|||
for (auto& screen : screens) {
|
||||
auto screen_rect = screen.virtual_rect();
|
||||
Gfx::IntRect new_screen_rect {
|
||||
screen_rect.right() + 1,
|
||||
screen_rect.right(),
|
||||
screen_rect.top(),
|
||||
(int)mode_setting.horizontal_active,
|
||||
(int)mode_setting.vertical_active
|
||||
|
|
|
@ -512,7 +512,7 @@ void Window::event(Core::Event& event)
|
|||
void Window::handle_keydown_event(KeyEvent const& event)
|
||||
{
|
||||
if (event.modifiers() == Mod_Alt && event.key() == Key_Space && type() == WindowType::Normal && !is_frameless()) {
|
||||
auto position = frame().titlebar_rect().bottom_left().translated(frame().rect().location());
|
||||
auto position = frame().titlebar_rect().bottom_left().moved_up(1).translated(frame().rect().location());
|
||||
popup_window_menu(position, WindowMenuDefaultAction::Close);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -362,7 +362,7 @@ void WindowFrame::PerScaleRenderedCache::paint(WindowFrame& frame, Gfx::Painter&
|
|||
}
|
||||
if (m_bottom_y < top_bottom_height) {
|
||||
// We have a bottom piece
|
||||
Gfx::IntRect rect_in_frame { frame_rect.x(), window_rect.bottom() + 1, frame_rect.width(), top_bottom_height - m_bottom_y };
|
||||
Gfx::IntRect rect_in_frame { frame_rect.x(), window_rect.bottom(), frame_rect.width(), top_bottom_height - m_bottom_y };
|
||||
auto src_rect = rect.intersected(rect_in_frame);
|
||||
if (!src_rect.is_empty())
|
||||
painter.blit(src_rect.location(), *m_top_bottom, src_rect.translated(-rect_in_frame.x(), -rect_in_frame.y() + m_bottom_y), frame.opacity());
|
||||
|
@ -380,7 +380,7 @@ void WindowFrame::PerScaleRenderedCache::paint(WindowFrame& frame, Gfx::Painter&
|
|||
}
|
||||
if (m_right_x < left_right_width) {
|
||||
// We have a right piece
|
||||
Gfx::IntRect rect_in_frame { window_rect.right() + 1, window_rect.y(), left_right_width - m_right_x, window_rect.height() };
|
||||
Gfx::IntRect rect_in_frame { window_rect.right(), window_rect.y(), left_right_width - m_right_x, window_rect.height() };
|
||||
auto src_rect = rect.intersected(rect_in_frame);
|
||||
if (!src_rect.is_empty())
|
||||
painter.blit(src_rect.location(), *m_left_right, src_rect.translated(-rect_in_frame.x() + m_right_x, -rect_in_frame.y()), frame.opacity());
|
||||
|
@ -525,9 +525,9 @@ void WindowFrame::PerScaleRenderedCache::render(WindowFrame& frame, Screen& scre
|
|||
Gfx::Painter top_bottom_painter(*m_top_bottom);
|
||||
top_bottom_painter.add_clip_rect({ update_location, { frame_rect_to_update.width(), top_bottom_height - update_location.y() - (frame_rect_including_shadow.bottom() - frame_rect_to_update.bottom()) } });
|
||||
if (m_bottom_y > 0)
|
||||
top_bottom_painter.blit({ 0, 0 }, *tmp_bitmap, { 0, 0, frame_rect_including_shadow.width(), m_bottom_y }, 1.0, false);
|
||||
top_bottom_painter.blit({ 0, 0 }, *tmp_bitmap, { 0, 0, frame_rect_including_shadow.width(), m_bottom_y }, 1.f, false);
|
||||
if (m_bottom_y < top_bottom_height)
|
||||
top_bottom_painter.blit({ 0, m_bottom_y }, *tmp_bitmap, { 0, frame_rect_including_shadow.height() - (frame_rect_including_shadow.bottom() - window_rect.bottom()), frame_rect_including_shadow.width(), top_bottom_height - m_bottom_y }, 1.0, false);
|
||||
top_bottom_painter.blit({ 0, m_bottom_y }, *tmp_bitmap, { 0, frame_rect_including_shadow.height() - (frame_rect_including_shadow.bottom() - window_rect.bottom()), frame_rect_including_shadow.width(), top_bottom_height - m_bottom_y }, 1.f, false);
|
||||
} else {
|
||||
m_bottom_y = 0;
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ void WindowFrame::PerScaleRenderedCache::render(WindowFrame& frame, Screen& scre
|
|||
if (m_right_x > 0)
|
||||
left_right_painter.blit({ 0, 0 }, *tmp_bitmap, { 0, m_bottom_y, m_right_x, window_rect.height() }, 1.0, false);
|
||||
if (m_right_x < left_right_width)
|
||||
left_right_painter.blit({ m_right_x, 0 }, *tmp_bitmap, { (window_rect.right() - frame_rect_including_shadow.x()) + 1, m_bottom_y, frame_rect_including_shadow.width() - (frame_rect_including_shadow.right() - window_rect.right()), window_rect.height() }, 1.0, false);
|
||||
left_right_painter.blit({ m_right_x, 0 }, *tmp_bitmap, { window_rect.right() - frame_rect_including_shadow.x(), m_bottom_y, frame_rect_including_shadow.width() - (frame_rect_including_shadow.right() - window_rect.right()), window_rect.height() }, 1.0, false);
|
||||
} else {
|
||||
m_right_x = 0;
|
||||
}
|
||||
|
@ -727,9 +727,9 @@ Optional<HitTestResult> WindowFrame::PerScaleRenderedCache::hit_test(WindowFrame
|
|||
if (m_top_bottom->rect().contains(scaled_relative_point))
|
||||
alpha = m_top_bottom->get_pixel(scaled_relative_point).alpha();
|
||||
}
|
||||
} else if (position.y() > window_rect.bottom()) {
|
||||
} else if (position.y() >= window_rect.bottom()) {
|
||||
if (m_top_bottom) {
|
||||
Gfx::IntPoint scaled_relative_point { window_relative_position.x() * m_top_bottom->scale(), m_bottom_y * m_top_bottom->scale() + position.y() - window_rect.bottom() - 1 };
|
||||
Gfx::IntPoint scaled_relative_point { window_relative_position.x() * m_top_bottom->scale(), m_bottom_y * m_top_bottom->scale() + position.y() - window_rect.bottom() };
|
||||
if (m_top_bottom->rect().contains(scaled_relative_point))
|
||||
alpha = m_top_bottom->get_pixel(scaled_relative_point).alpha();
|
||||
}
|
||||
|
@ -739,9 +739,9 @@ Optional<HitTestResult> WindowFrame::PerScaleRenderedCache::hit_test(WindowFrame
|
|||
if (m_left_right->rect().contains(scaled_relative_point))
|
||||
alpha = m_left_right->get_pixel(scaled_relative_point).alpha();
|
||||
}
|
||||
} else if (position.x() > window_rect.right()) {
|
||||
} else if (position.x() >= window_rect.right()) {
|
||||
if (m_left_right) {
|
||||
Gfx::IntPoint scaled_relative_point { m_right_x * m_left_right->scale() + position.x() - window_rect.right() - 1, (window_relative_position.y() - m_bottom_y) * m_left_right->scale() };
|
||||
Gfx::IntPoint scaled_relative_point { m_right_x * m_left_right->scale() + position.x() - window_rect.right(), (window_relative_position.y() - m_bottom_y) * m_left_right->scale() };
|
||||
if (m_left_right->rect().contains(scaled_relative_point))
|
||||
alpha = m_left_right->get_pixel(scaled_relative_point).alpha();
|
||||
}
|
||||
|
@ -769,7 +769,7 @@ bool WindowFrame::handle_titlebar_icon_mouse_event(MouseEvent const& event)
|
|||
// for the fact that we opened and closed a window in the meanwhile
|
||||
wm.system_menu_doubleclick(m_window, event);
|
||||
|
||||
m_window.popup_window_menu(titlebar_rect().bottom_left().translated(rect().location()), WindowMenuDefaultAction::Close);
|
||||
m_window.popup_window_menu(titlebar_rect().bottom_left().moved_up(1).translated(rect().location()), WindowMenuDefaultAction::Close);
|
||||
return true;
|
||||
} else if (event.type() == Event::MouseUp && event.button() == MouseButton::Primary) {
|
||||
// Since the MouseDown event opened a menu, another MouseUp
|
||||
|
@ -909,7 +909,7 @@ void WindowFrame::open_menubar_menu(Menu& menu)
|
|||
{
|
||||
auto menubar_rect = this->menubar_rect();
|
||||
MenuManager::the().close_everyone();
|
||||
auto position = menu.rect_in_window_menubar().bottom_left().translated(rect().location()).translated(menubar_rect.location());
|
||||
auto position = menu.rect_in_window_menubar().bottom_left().moved_up(1).translated(rect().location()).translated(menubar_rect.location());
|
||||
menu.set_unadjusted_position(position);
|
||||
auto& window = menu.ensure_menu_window(position);
|
||||
auto window_rect = window.rect();
|
||||
|
@ -917,13 +917,12 @@ void WindowFrame::open_menubar_menu(Menu& menu)
|
|||
auto window_border_thickness = 1;
|
||||
|
||||
// If the menu is off the right edge of the screen align its right edge with the edge of the screen.
|
||||
if (window_rect.right() > screen.width()) {
|
||||
position = position.translated(((window_rect.right() - screen.width()) * -1) - window_border_thickness, 0);
|
||||
}
|
||||
if (window_rect.right() - 1 > screen.width())
|
||||
position = position.translated(((window_rect.right() - 1 - screen.width()) * -1) - window_border_thickness, 0);
|
||||
|
||||
// If the menu is below the bottom of the screen move it to appear above the menubar.
|
||||
if (window_rect.bottom() > screen.height()) {
|
||||
if (window_rect.bottom() - 1 > screen.height())
|
||||
position = position.translated(0, (window_rect.height() * -1) - menubar_rect.height());
|
||||
}
|
||||
|
||||
window.set_rect(position.x(), position.y(), window_rect.width(), window_rect.height());
|
||||
|
||||
|
|
|
@ -887,7 +887,7 @@ bool WindowManager::process_ongoing_window_move(MouseEvent& event)
|
|||
apply_window_tile(WindowTileType::Right);
|
||||
} else if (allow_tile && event_location_relative_to_screen.y() <= secondary_deadzone + desktop_relative_to_screen.top()) {
|
||||
apply_window_tile(WindowTileType::Top);
|
||||
} else if (allow_tile && event_location_relative_to_screen.y() >= desktop_relative_to_screen.bottom() - secondary_deadzone) {
|
||||
} else if (allow_tile && event_location_relative_to_screen.y() >= desktop_relative_to_screen.bottom() - 1 - secondary_deadzone) {
|
||||
apply_window_tile(WindowTileType::Bottom);
|
||||
} else if (!m_move_window->is_tiled()) {
|
||||
apply_window_tile(WindowTileType::None);
|
||||
|
@ -971,12 +971,12 @@ bool WindowManager::process_ongoing_window_resize(MouseEvent const& event)
|
|||
constexpr auto hot_zone = 10;
|
||||
Gfx::IntRect tiling_rect = desktop_rect(cursor_screen).shrunken({ hot_zone, hot_zone });
|
||||
if ((m_resize_direction == ResizeDirection::Up || m_resize_direction == ResizeDirection::Down)
|
||||
&& (event.y() >= tiling_rect.bottom() || event.y() <= tiling_rect.top())) {
|
||||
&& (event.y() >= tiling_rect.bottom() - 1 || event.y() <= tiling_rect.top())) {
|
||||
m_resize_window->set_tiled(WindowTileType::VerticallyMaximized);
|
||||
return true;
|
||||
}
|
||||
if ((m_resize_direction == ResizeDirection::Left || m_resize_direction == ResizeDirection::Right)
|
||||
&& (event.x() >= tiling_rect.right() || event.x() <= tiling_rect.left())) {
|
||||
&& (event.x() > tiling_rect.right() || event.x() <= tiling_rect.left())) {
|
||||
m_resize_window->set_tiled(WindowTileType::HorizontallyMaximized);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -199,9 +199,9 @@ void WindowSwitcher::draw()
|
|||
Gfx::IntRect thumbnail_rect = { item_rect.location().translated(0, 5), { thumbnail_width(), thumbnail_height() } };
|
||||
if (window.backing_store())
|
||||
painter.draw_scaled_bitmap(thumbnail_rect, *window.backing_store(), window.backing_store()->rect(), 1.0f, Gfx::Painter::ScalingMode::BilinearBlend);
|
||||
Gfx::IntRect icon_rect = { thumbnail_rect.bottom_right().translated(-window.icon().width(), -window.icon().height()), { window.icon().width(), window.icon().height() } };
|
||||
Gfx::IntRect icon_rect = { thumbnail_rect.bottom_right().translated(-window.icon().width() - 1, -window.icon().height() - 1), { window.icon().width(), window.icon().height() } };
|
||||
painter.blit(icon_rect.location(), window.icon(), window.icon().rect());
|
||||
painter.draw_text(item_rect.translated(thumbnail_width() + 12, 0).translated(1, 1), window.computed_title(), WindowManager::the().window_title_font(), Gfx::TextAlignment::CenterLeft, text_color.inverted());
|
||||
painter.draw_text(item_rect.translated(thumbnail_width() + 12, 0).translated(1), window.computed_title(), WindowManager::the().window_title_font(), Gfx::TextAlignment::CenterLeft, text_color.inverted());
|
||||
painter.draw_text(item_rect.translated(thumbnail_width() + 12, 0), window.computed_title(), WindowManager::the().window_title_font(), Gfx::TextAlignment::CenterLeft, text_color);
|
||||
auto window_details = m_windows_on_multiple_stacks ? DeprecatedString::formatted("{} on {}:{}", window.rect().to_deprecated_string(), window.window_stack().row() + 1, window.window_stack().column() + 1) : window.rect().to_deprecated_string();
|
||||
painter.draw_text(item_rect, window_details, Gfx::TextAlignment::CenterRight, rect_text_color);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue