mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
Magnifier: Add option to display grid over the image
This commit is contained in:
parent
df30440117
commit
2b635b5330
3 changed files with 45 additions and 1 deletions
|
@ -32,6 +32,14 @@ void MagnifierWidget::lock_location(bool lock)
|
||||||
m_locked_location = {};
|
m_locked_location = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MagnifierWidget::show_grid(bool new_value)
|
||||||
|
{
|
||||||
|
if (m_show_grid == new_value)
|
||||||
|
return;
|
||||||
|
m_show_grid = new_value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void MagnifierWidget::set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter> color_filter)
|
void MagnifierWidget::set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter> color_filter)
|
||||||
{
|
{
|
||||||
m_color_filter = move(color_filter);
|
m_color_filter = move(color_filter);
|
||||||
|
@ -75,10 +83,37 @@ void MagnifierWidget::paint_event(GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
GUI::Frame::paint_event(event);
|
GUI::Frame::paint_event(event);
|
||||||
|
|
||||||
|
if (!m_grabbed_bitmap)
|
||||||
|
return;
|
||||||
|
|
||||||
GUI::Painter painter(*this);
|
GUI::Painter painter(*this);
|
||||||
|
|
||||||
if (m_grabbed_bitmap)
|
if (m_grabbed_bitmap)
|
||||||
painter.draw_scaled_bitmap(frame_inner_rect(), *m_grabbed_bitmap, m_grabbed_bitmap->rect());
|
painter.draw_scaled_bitmap(frame_inner_rect(), *m_grabbed_bitmap, m_grabbed_bitmap->rect(), 1.0, Gfx::Painter::ScalingMode::NearestFractional);
|
||||||
|
|
||||||
|
if (m_show_grid) {
|
||||||
|
auto line_color = Color(Color::NamedColor::Magenta);
|
||||||
|
line_color.set_alpha(100);
|
||||||
|
|
||||||
|
auto grid_rect = frame_inner_rect();
|
||||||
|
if (m_grabbed_bitmap)
|
||||||
|
grid_rect = frame_inner_rect().intersected({ 0,
|
||||||
|
0,
|
||||||
|
m_grabbed_bitmap->rect().width() * m_scale_factor,
|
||||||
|
m_grabbed_bitmap->rect().height() * m_scale_factor });
|
||||||
|
|
||||||
|
int start_y = grid_rect.top(),
|
||||||
|
start_x = grid_rect.left();
|
||||||
|
|
||||||
|
int end_y = grid_rect.bottom(),
|
||||||
|
end_x = grid_rect.right();
|
||||||
|
|
||||||
|
for (int current_y = start_y; current_y <= end_y; current_y += m_scale_factor)
|
||||||
|
painter.draw_line({ start_x, current_y }, { end_x, current_y }, line_color);
|
||||||
|
|
||||||
|
for (int current_x = start_y; current_x <= end_x; current_x += m_scale_factor)
|
||||||
|
painter.draw_line({ current_x, start_y }, { current_x, end_y }, line_color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MagnifierWidget::second_paint_event(GUI::PaintEvent&)
|
void MagnifierWidget::second_paint_event(GUI::PaintEvent&)
|
||||||
|
|
|
@ -21,6 +21,8 @@ public:
|
||||||
virtual ~MagnifierWidget() override = default;
|
virtual ~MagnifierWidget() override = default;
|
||||||
void set_scale_factor(int scale_factor);
|
void set_scale_factor(int scale_factor);
|
||||||
virtual void set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter>) override;
|
virtual void set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter>) override;
|
||||||
|
void show_grid(bool);
|
||||||
|
|
||||||
void pause_capture(bool pause)
|
void pause_capture(bool pause)
|
||||||
{
|
{
|
||||||
m_pause_capture = pause;
|
m_pause_capture = pause;
|
||||||
|
@ -47,4 +49,5 @@ private:
|
||||||
ssize_t m_frame_offset_from_head { 0 };
|
ssize_t m_frame_offset_from_head { 0 };
|
||||||
bool m_pause_capture { false };
|
bool m_pause_capture { false };
|
||||||
Optional<Gfx::IntPoint> m_locked_location {};
|
Optional<Gfx::IntPoint> m_locked_location {};
|
||||||
|
bool m_show_grid { false };
|
||||||
};
|
};
|
||||||
|
|
|
@ -116,6 +116,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
magnifier->lock_location(action.is_checked());
|
magnifier->lock_location(action.is_checked());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
auto show_grid_action = GUI::Action::create_checkable(
|
||||||
|
"Show &Grid", { Key_G }, [&](auto& action) {
|
||||||
|
magnifier->show_grid(action.is_checked());
|
||||||
|
});
|
||||||
|
|
||||||
size_action_group->add_action(two_x_action);
|
size_action_group->add_action(two_x_action);
|
||||||
size_action_group->add_action(four_x_action);
|
size_action_group->add_action(four_x_action);
|
||||||
size_action_group->add_action(eight_x_action);
|
size_action_group->add_action(eight_x_action);
|
||||||
|
@ -130,6 +135,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
TRY(view_menu->try_add_separator());
|
TRY(view_menu->try_add_separator());
|
||||||
TRY(view_menu->try_add_action(pause_action));
|
TRY(view_menu->try_add_action(pause_action));
|
||||||
TRY(view_menu->try_add_action(lock_location_action));
|
TRY(view_menu->try_add_action(lock_location_action));
|
||||||
|
TRY(view_menu->try_add_action(show_grid_action));
|
||||||
|
|
||||||
auto timeline_menu = TRY(window->try_add_menu("&Timeline"));
|
auto timeline_menu = TRY(window->try_add_menu("&Timeline"));
|
||||||
auto previous_frame_action = GUI::Action::create(
|
auto previous_frame_action = GUI::Action::create(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue