diff options
author | Linus Groh <mail@linusgroh.de> | 2021-05-11 13:02:46 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-11 18:01:55 +0200 |
commit | 8afcd22900406101a9a7097eb8962635dd093d78 (patch) | |
tree | 110ecc1a21f65c5dda4cceed60373b58f12e34cc /Userland/Applications/Magnifier | |
parent | 1c1b106f6c77c583a441ba3e6a2e12237b350ce0 (diff) | |
download | serenity-8afcd22900406101a9a7097eb8962635dd093d78.zip |
Magnifier: Make window resizable
Instead of having the window non-resizable, it now defaults to a frame
size of 200 x 200 pixels but is user-resizable. The shown screenshot
updates its size accordingly. :^)
Sometimes we might need a larger view, or a non-square shape.
Diffstat (limited to 'Userland/Applications/Magnifier')
-rw-r--r-- | Userland/Applications/Magnifier/MagnifierWidget.cpp | 12 | ||||
-rw-r--r-- | Userland/Applications/Magnifier/main.cpp | 5 |
2 files changed, 7 insertions, 10 deletions
diff --git a/Userland/Applications/Magnifier/MagnifierWidget.cpp b/Userland/Applications/Magnifier/MagnifierWidget.cpp index e903b28206..84ef35d0ce 100644 --- a/Userland/Applications/Magnifier/MagnifierWidget.cpp +++ b/Userland/Applications/Magnifier/MagnifierWidget.cpp @@ -8,8 +8,7 @@ #include <LibGUI/Painter.h> #include <LibGUI/Window.h> #include <LibGUI/WindowServerConnection.h> -#include <LibGfx/AffineTransform.h> -#include <math.h> +#include <LibGfx/Rect.h> MagnifierWidget::MagnifierWidget() { @@ -46,12 +45,9 @@ void MagnifierWidget::paint_event(GUI::PaintEvent&) { GUI::Painter painter(*this); - int grab_frame_size = 200; - - grab_frame_size /= m_scale_factor; - - // Paint our screenshot - Gfx::Rect region { m_mouse_position.x() - (grab_frame_size / 2), m_mouse_position.y() - (grab_frame_size / 2), grab_frame_size, grab_frame_size }; + // Grab and paint our screenshot. + Gfx::IntSize region_size { size().width() / m_scale_factor, size().height() / m_scale_factor }; + Gfx::Rect region { m_mouse_position.x() - (region_size.width() / 2), m_mouse_position.y() - (region_size.height() / 2), region_size.width(), region_size.height() }; auto map = GUI::WindowServerConnection::the().get_screen_bitmap(region); painter.draw_scaled_bitmap(rect(), *map.bitmap(), map.bitmap()->rect()); } diff --git a/Userland/Applications/Magnifier/main.cpp b/Userland/Applications/Magnifier/main.cpp index 99bb049436..6b227bb6ed 100644 --- a/Userland/Applications/Magnifier/main.cpp +++ b/Userland/Applications/Magnifier/main.cpp @@ -46,7 +46,6 @@ int main(int argc, char** argv) auto window = GUI::Window::construct(); window->set_title("Magnifier"); window->resize(window_dimensions, window_dimensions); - window->set_resizable(false); window->set_minimizable(false); window->set_icon(app_icon.bitmap_for_size(16)); auto& magnifier = window->set_main_widget<MagnifierWidget>(); @@ -80,10 +79,12 @@ int main(int argc, char** argv) auto& help_menu = menubar->add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Magnifier", app_icon, window)); - window->set_menubar(move(menubar)); + window->set_menubar(move(menubar)); window->show(); + magnifier.track_cursor_globally(); magnifier.start_timer(16); + return app->exec(); } |