summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorFrHun <28605587+frhun@users.noreply.github.com>2022-12-06 01:19:14 +0100
committerSam Atkins <atkinssj@gmail.com>2022-12-23 12:16:46 +0000
commitf413033a50854a0284e93f3441663bba56d5e468 (patch)
tree25260d98053b75bf2fee22687cdaa767f6bca80e /Userland
parent9d3debcbbe9f60710d8d88415db101dfc559296a (diff)
downloadserenity-f413033a50854a0284e93f3441663bba56d5e468.zip
Magnifier: Add ability to drag the location when it is locked
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Magnifier/MagnifierWidget.cpp26
-rw-r--r--Userland/Applications/Magnifier/MagnifierWidget.h6
2 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Applications/Magnifier/MagnifierWidget.cpp b/Userland/Applications/Magnifier/MagnifierWidget.cpp
index e5b77ea225..3c9c669708 100644
--- a/Userland/Applications/Magnifier/MagnifierWidget.cpp
+++ b/Userland/Applications/Magnifier/MagnifierWidget.cpp
@@ -156,3 +156,29 @@ void MagnifierWidget::second_paint_event(GUI::PaintEvent&)
m_color_filter->apply(*target, rect, *clone, rect);
}
+
+void MagnifierWidget::mousemove_event(GUI::MouseEvent& event)
+{
+ if (m_locked_location.has_value() && m_currently_dragging && !m_pause_capture) {
+ auto current_position = event.position();
+ auto difference = current_position - m_last_drag_position;
+ Gfx::IntPoint remainder = { difference.x() % m_scale_factor, difference.y() % m_scale_factor };
+ auto moved_by = difference / m_scale_factor;
+ m_locked_location = m_locked_location.value() - moved_by;
+ m_last_drag_position = current_position - remainder;
+ }
+}
+
+void MagnifierWidget::mousedown_event(GUI::MouseEvent& event)
+{
+ if (event.button() == GUI::MouseButton::Primary && !m_pause_capture) {
+ m_currently_dragging = true;
+ m_last_drag_position = event.position();
+ }
+}
+
+void MagnifierWidget::mouseup_event(GUI::MouseEvent& event)
+{
+ if (event.button() == GUI::MouseButton::Primary)
+ m_currently_dragging = false;
+}
diff --git a/Userland/Applications/Magnifier/MagnifierWidget.h b/Userland/Applications/Magnifier/MagnifierWidget.h
index 0e9e2400ba..99a1d757d5 100644
--- a/Userland/Applications/Magnifier/MagnifierWidget.h
+++ b/Userland/Applications/Magnifier/MagnifierWidget.h
@@ -47,6 +47,10 @@ private:
virtual void paint_event(GUI::PaintEvent&) override;
virtual void second_paint_event(GUI::PaintEvent&) override;
+ virtual void mousemove_event(GUI::MouseEvent&) override;
+ virtual void mousedown_event(GUI::MouseEvent&) override;
+ virtual void mouseup_event(GUI::MouseEvent&) override;
+
void sync();
int m_scale_factor { 2 };
@@ -55,6 +59,8 @@ private:
CircularQueue<RefPtr<Gfx::Bitmap>, 512> m_grabbed_bitmaps {};
ssize_t m_frame_offset_from_head { 0 };
bool m_pause_capture { false };
+ bool m_currently_dragging { false };
+ Gfx::IntPoint m_last_drag_position {};
Optional<Gfx::IntPoint> m_locked_location {};
bool m_show_grid { false };
Gfx::Color m_grid_color { 255, 0, 255, 100 };