mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
WindowServer: Move window geometry label into the tile overlay area
This moves the window geometry overlay into the center of the tile window overlay when it's visible or when it moves.
This commit is contained in:
parent
fe54a0ca27
commit
5a73691fe9
4 changed files with 97 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "Overlays.h"
|
||||
#include "Animation.h"
|
||||
#include "Compositor.h"
|
||||
#include "WindowManager.h"
|
||||
#include <LibGfx/StylePainter.h>
|
||||
|
@ -230,16 +231,78 @@ WindowGeometryOverlay::WindowGeometryOverlay(Window& window)
|
|||
update_rect();
|
||||
}
|
||||
|
||||
void WindowGeometryOverlay::set_actual_rect()
|
||||
{
|
||||
if (!m_move_into_overlay_rect_animation.animation) {
|
||||
set_rect(m_ideal_overlay_rect);
|
||||
return;
|
||||
}
|
||||
|
||||
auto const& starting_rect = m_move_into_overlay_rect_animation.starting_rect.value();
|
||||
m_move_into_overlay_rect_animation.current_rect = starting_rect.interpolated_to(starting_rect.centered_within(m_move_into_overlay_rect_animation.tile_overlay_rect_at_start), m_move_into_overlay_rect_animation.progress);
|
||||
set_rect(m_move_into_overlay_rect_animation.current_rect);
|
||||
}
|
||||
|
||||
void WindowGeometryOverlay::start_or_stop_move_to_tile_overlay_animation(TileWindowOverlay* tile_window_overlay)
|
||||
{
|
||||
if (!tile_window_overlay) {
|
||||
if (m_move_into_overlay_rect_animation.animation)
|
||||
m_move_into_overlay_rect_animation.animation->stop();
|
||||
m_move_into_overlay_rect_animation = {};
|
||||
return;
|
||||
}
|
||||
|
||||
auto tile_overlay_rect = tile_window_overlay->tiled_frame_rect();
|
||||
if (m_move_into_overlay_rect_animation.tile_overlay_rect_at_start != tile_overlay_rect || !m_move_into_overlay_rect_animation.starting_rect.has_value()) {
|
||||
if (!m_move_into_overlay_rect_animation.starting_rect.has_value()) {
|
||||
// The tile overlay was just started on one location, we want to move the geometry overlay from the center of the window to the center of the tile overlay,
|
||||
m_move_into_overlay_rect_animation.starting_rect = m_ideal_overlay_rect;
|
||||
m_move_into_overlay_rect_animation.current_rect = m_ideal_overlay_rect;
|
||||
} else if (m_ideal_overlay_rect.size() != m_move_into_overlay_rect_animation.starting_rect.value().size()) {
|
||||
// The geometry label size was changed. This normally would only happen when the text changes while moving the window around.
|
||||
// But because the tile overlay is visible, we don't update the geometry label with the window rect, but instead we show the prospective tile size.
|
||||
// So, the only case where the geometry label size can change is if the tile overlay rectangle was changed (e.g. from Left to Top).
|
||||
// In this case we want just update the rectangle size at where the geometry label was last rendered. We then restart the animation,
|
||||
// which causes it to move to the center of the new tile overlay rectangle.
|
||||
m_move_into_overlay_rect_animation.starting_rect = m_ideal_overlay_rect.centered_within(m_move_into_overlay_rect_animation.current_rect);
|
||||
m_move_into_overlay_rect_animation.current_rect = m_move_into_overlay_rect_animation.starting_rect.value();
|
||||
} else {
|
||||
// The geometry label size didn't change, but the tile overlay rectangle was changed (e.g. from Left to Top).
|
||||
// In this case we restart the animation by starting where we last rendered the geometry label,
|
||||
// causing it to move to the center of the new tile overlay rectangle.
|
||||
m_move_into_overlay_rect_animation.starting_rect = m_move_into_overlay_rect_animation.current_rect;
|
||||
}
|
||||
|
||||
m_move_into_overlay_rect_animation.tile_overlay_rect_at_start = tile_overlay_rect;
|
||||
m_move_into_overlay_rect_animation.progress = 0.0f;
|
||||
|
||||
if (m_move_into_overlay_rect_animation.animation) {
|
||||
m_move_into_overlay_rect_animation.animation->stop();
|
||||
} else {
|
||||
m_move_into_overlay_rect_animation.animation = Animation::create();
|
||||
m_move_into_overlay_rect_animation.animation->set_duration(150);
|
||||
}
|
||||
|
||||
m_move_into_overlay_rect_animation.animation->on_update = [this](float progress, Gfx::Painter&, Screen&, Gfx::DisjointIntRectSet&) {
|
||||
m_move_into_overlay_rect_animation.progress = progress;
|
||||
set_actual_rect();
|
||||
};
|
||||
m_move_into_overlay_rect_animation.animation->start();
|
||||
}
|
||||
}
|
||||
|
||||
void WindowGeometryOverlay::update_rect()
|
||||
{
|
||||
if (auto* window = m_window.ptr()) {
|
||||
auto& wm = WindowManager::the();
|
||||
auto* tile_window_overlay = wm.get_tile_window_overlay(*window);
|
||||
auto geometry_rect = tile_window_overlay ? tile_window_overlay->tiled_frame_rect() : window->rect();
|
||||
if (!window->size_increment().is_empty()) {
|
||||
int width_steps = (window->width() - window->base_size().width()) / window->size_increment().width();
|
||||
int height_steps = (window->height() - window->base_size().height()) / window->size_increment().height();
|
||||
m_label = DeprecatedString::formatted("{} ({}x{})", window->rect(), width_steps, height_steps);
|
||||
m_label = DeprecatedString::formatted("{} ({}x{})", geometry_rect, width_steps, height_steps);
|
||||
} else {
|
||||
m_label = window->rect().to_deprecated_string();
|
||||
m_label = geometry_rect.to_deprecated_string();
|
||||
}
|
||||
m_label_rect = Gfx::IntRect { 0, 0, static_cast<int>(ceilf(wm.font().width(m_label))) + 16, wm.font().pixel_size_rounded_up() + 10 };
|
||||
|
||||
|
@ -254,8 +317,11 @@ void WindowGeometryOverlay::update_rect()
|
|||
if (rect.bottom() > desktop_rect.bottom())
|
||||
rect.set_bottom_without_resize(desktop_rect.bottom());
|
||||
|
||||
set_rect(rect);
|
||||
m_ideal_overlay_rect = rect;
|
||||
set_actual_rect();
|
||||
invalidate_content(); // needed in case the rectangle itself doesn't change. But the contents did.
|
||||
|
||||
start_or_stop_move_to_tile_overlay_animation(tile_window_overlay);
|
||||
} else {
|
||||
set_enabled(false);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue