mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:07:45 +00:00
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.
This commit is contained in:
parent
1c1b106f6c
commit
8afcd22900
2 changed files with 7 additions and 10 deletions
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue