mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:18:11 +00:00
Userland: Use Rect::centered_within() where useful
This commit is contained in:
parent
43220568b0
commit
087bd7f767
9 changed files with 15 additions and 34 deletions
|
@ -126,8 +126,7 @@ void MonitorWidget::redraw_desktop_if_needed()
|
|||
auto scaled_bitmap = m_wallpaper_bitmap->scaled(sw, sh);
|
||||
|
||||
if (m_desktop_wallpaper_mode == "center") {
|
||||
Gfx::IntRect centered_rect { {}, scaled_size };
|
||||
centered_rect.center_within(m_desktop_bitmap->rect());
|
||||
auto centered_rect = Gfx::IntRect({}, scaled_size).centered_within(m_desktop_bitmap->rect());
|
||||
painter.blit(centered_rect.location(), *scaled_bitmap, scaled_bitmap->rect());
|
||||
} else if (m_desktop_wallpaper_mode == "tile") {
|
||||
painter.draw_tiled_bitmap(m_desktop_bitmap->rect(), *scaled_bitmap);
|
||||
|
|
|
@ -35,9 +35,7 @@ void DoubleClickArrowWidget::paint_event(GUI::PaintEvent& event)
|
|||
GUI::Painter painter(*this);
|
||||
painter.add_clip_rect(event.rect());
|
||||
|
||||
auto bottom_arrow_rect = m_arrow_bitmap->rect();
|
||||
bottom_arrow_rect.center_within(rect());
|
||||
bottom_arrow_rect.translate_by(0, m_arrow_bitmap->height() / 2);
|
||||
auto bottom_arrow_rect = m_arrow_bitmap->rect().centered_within(rect()).translated(0, m_arrow_bitmap->height() / 2);
|
||||
|
||||
painter.blit_filtered(bottom_arrow_rect.location(), *m_arrow_bitmap, m_arrow_bitmap->rect(), [&](Color color) {
|
||||
return m_inverted ? color.inverted() : color;
|
||||
|
|
|
@ -75,8 +75,7 @@ PaletteWidget::PaletteWidget()
|
|||
m_secondary_color_widget->set_fill_with_background_color(true);
|
||||
|
||||
m_primary_color_widget = add<GUI::Frame>();
|
||||
Gfx::IntRect rect { 0, 0, 38, 15 };
|
||||
rect.center_within(m_secondary_color_widget->relative_rect());
|
||||
auto rect = Gfx::IntRect(0, 0, 38, 15).centered_within(m_secondary_color_widget->relative_rect());
|
||||
m_primary_color_widget->set_relative_rect(rect);
|
||||
m_primary_color_widget->set_fill_with_background_color(true);
|
||||
|
||||
|
|
|
@ -137,15 +137,13 @@ void PreviewWidget::paint_event(GUI::PaintEvent& event)
|
|||
|
||||
for (auto& button : buttons) {
|
||||
Gfx::StylePainter::paint_button(painter, button.rect, m_preview_palette, Gfx::ButtonStyle::Normal, false);
|
||||
auto bitmap_rect = button.bitmap->rect();
|
||||
bitmap_rect.center_within(button.rect);
|
||||
auto bitmap_rect = button.bitmap->rect().centered_within(button.rect);
|
||||
painter.blit(bitmap_rect.location(), *button.bitmap, button.bitmap->rect());
|
||||
}
|
||||
};
|
||||
|
||||
Gfx::IntRect active_rect { 0, 0, 320, 240 };
|
||||
active_rect.center_within(frame_inner_rect());
|
||||
Gfx::IntRect inactive_rect = active_rect.translated(-20, -20);
|
||||
auto active_rect = Gfx::IntRect(0, 0, 320, 240).centered_within(frame_inner_rect());
|
||||
auto inactive_rect = active_rect.translated(-20, -20);
|
||||
|
||||
paint_window("Inactive window", inactive_rect, Gfx::WindowTheme::WindowState::Inactive, *m_active_window_icon);
|
||||
paint_window("Active window", active_rect, Gfx::WindowTheme::WindowState::Active, *m_inactive_window_icon);
|
||||
|
@ -153,9 +151,7 @@ void PreviewWidget::paint_event(GUI::PaintEvent& event)
|
|||
|
||||
void PreviewWidget::resize_event(GUI::ResizeEvent&)
|
||||
{
|
||||
Gfx::IntRect gallery_rect { 0, 0, 320, 240 };
|
||||
gallery_rect.center_within(rect());
|
||||
m_gallery->set_relative_rect(gallery_rect);
|
||||
m_gallery->set_relative_rect(Gfx::IntRect(0, 0, 320, 240).centered_within(rect()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -613,8 +613,7 @@ static RefPtr<Gfx::Bitmap> render_thumbnail(const StringView& path)
|
|||
double scale = min(32 / (double)png_bitmap->width(), 32 / (double)png_bitmap->height());
|
||||
|
||||
auto thumbnail = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 });
|
||||
Gfx::IntRect destination = Gfx::IntRect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale));
|
||||
destination.center_within(thumbnail->rect());
|
||||
auto destination = Gfx::IntRect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale)).centered_within(thumbnail->rect());
|
||||
|
||||
Painter painter(*thumbnail);
|
||||
painter.draw_scaled_bitmap(destination, *png_bitmap, png_bitmap->rect());
|
||||
|
|
|
@ -433,8 +433,7 @@ void IconView::did_change_cursor_index(const ModelIndex& old_index, const ModelI
|
|||
void IconView::get_item_rects(int item_index, ItemData& item_data, const Gfx::Font& font) const
|
||||
{
|
||||
auto item_rect = this->item_rect(item_index);
|
||||
item_data.icon_rect = { 0, 0, 32, 32 };
|
||||
item_data.icon_rect.center_within(item_rect);
|
||||
item_data.icon_rect = Gfx::IntRect(0, 0, 32, 32).centered_within(item_rect);
|
||||
item_data.icon_offset_y = -font.glyph_height() - 6;
|
||||
item_data.icon_rect.translate_by(0, item_data.icon_offset_y);
|
||||
|
||||
|
|
|
@ -286,18 +286,14 @@ void Window::set_minimum_size(const Gfx::IntSize& size)
|
|||
|
||||
void Window::center_on_screen()
|
||||
{
|
||||
auto window_rect = rect();
|
||||
window_rect.center_within(Desktop::the().rect());
|
||||
set_rect(window_rect);
|
||||
set_rect(rect().centered_within(Desktop::the().rect()));
|
||||
}
|
||||
|
||||
void Window::center_within(const Window& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return;
|
||||
auto window_rect = rect();
|
||||
window_rect.center_within(other.rect());
|
||||
set_rect(window_rect);
|
||||
set_rect(rect().centered_within(other.rect()));
|
||||
}
|
||||
|
||||
void Window::set_window_type(WindowType window_type)
|
||||
|
|
|
@ -173,8 +173,7 @@ void TaskbarWindow::update_applet_area()
|
|||
if (!main_widget())
|
||||
return;
|
||||
main_widget()->do_layout();
|
||||
Gfx::IntRect new_rect { {}, m_applet_area_size };
|
||||
new_rect.center_within(m_applet_area_container->screen_relative_rect());
|
||||
auto new_rect = Gfx::IntRect({}, m_applet_area_size).centered_within(m_applet_area_container->screen_relative_rect());
|
||||
GUI::WindowManagerServerConnection::the().async_set_applet_area_position(new_rect.location());
|
||||
}
|
||||
|
||||
|
|
|
@ -237,8 +237,7 @@ void WindowGeometryOverlay::update_rect()
|
|||
}
|
||||
m_label_rect = Gfx::IntRect { 0, 0, wm.font().width(m_label) + 16, wm.font().glyph_height() + 10 };
|
||||
|
||||
auto rect = calculate_frame_rect(m_label_rect);
|
||||
rect.center_within(window->frame().rect());
|
||||
auto rect = calculate_frame_rect(m_label_rect).centered_within(window->frame().rect());
|
||||
auto desktop_rect = wm.desktop_rect(ScreenInput::the().cursor_location_screen());
|
||||
if (rect.left() < desktop_rect.left())
|
||||
rect.set_left(desktop_rect.left());
|
||||
|
@ -314,8 +313,7 @@ RefPtr<Gfx::Bitmap> DndOverlay::create_bitmap(int scale_factor)
|
|||
void WindowStackSwitchOverlay::render_overlay_bitmap(Gfx::Painter& painter)
|
||||
{
|
||||
// We should come up with a more elegant way to get the content rectangle
|
||||
Gfx::IntRect content_rect({}, m_content_size);
|
||||
content_rect.center_within({ {}, rect().size() });
|
||||
auto content_rect = Gfx::IntRect({}, m_content_size).centered_within({ {}, rect().size() });
|
||||
auto active_color = WindowManager::the().palette().active_window_border1();
|
||||
auto inactive_color = WindowManager::the().palette().inactive_window_border1();
|
||||
for (int y = 0; y < m_rows; y++) {
|
||||
|
@ -342,9 +340,7 @@ WindowStackSwitchOverlay::WindowStackSwitchOverlay(Screen& screen, WindowStack&
|
|||
m_columns * (default_screen_rect_width + default_screen_rect_padding) - default_screen_rect_padding,
|
||||
m_rows * (default_screen_rect_height + default_screen_rect_padding) - default_screen_rect_padding,
|
||||
};
|
||||
auto rect = calculate_frame_rect(Gfx::IntRect({}, m_content_size).inflated(2 * default_screen_rect_margin, 2 * default_screen_rect_margin));
|
||||
rect.center_within(screen.rect());
|
||||
set_rect(rect);
|
||||
set_rect(calculate_frame_rect(Gfx::IntRect({}, m_content_size).inflated(2 * default_screen_rect_margin, 2 * default_screen_rect_margin)).centered_within(screen.rect()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue