From fb099ad38b13d61ca89187cda9f21a1ebfae25e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sibille?= Date: Sun, 1 Aug 2021 11:59:47 +0200 Subject: [PATCH] PixelPaint: Show image coordinates in the status bar --- Userland/Applications/PixelPaint/ImageEditor.cpp | 10 ++++++++++ Userland/Applications/PixelPaint/ImageEditor.h | 5 +++++ Userland/Applications/PixelPaint/main.cpp | 15 +++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 5e525ed5e4c..db97609c46f 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -207,6 +207,10 @@ void ImageEditor::mousemove_event(GUI::MouseEvent& event) auto image_event = event_with_pan_and_scale_applied(event); m_active_tool->on_mousemove(*m_active_layer, layer_event, image_event); + + if (on_image_mouse_position_change) { + on_image_mouse_position_change(image_event.position()); + } } void ImageEditor::mouseup_event(GUI::MouseEvent& event) @@ -249,6 +253,12 @@ void ImageEditor::keyup_event(GUI::KeyEvent& event) m_active_tool->on_keyup(event); } +void ImageEditor::leave_event(Core::Event&) +{ + if (on_leave) + on_leave(); +} + void ImageEditor::set_active_layer(Layer* layer) { if (m_active_layer == layer) diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index 28dcd15747d..52959e07dd0 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -66,6 +66,10 @@ public: Function on_image_title_change; + Function on_image_mouse_position_change; + + Function on_leave; + Gfx::FloatRect layer_rect_to_editor_rect(Layer const&, Gfx::IntRect const&) const; Gfx::FloatRect image_rect_to_editor_rect(Gfx::IntRect const&) const; Gfx::FloatRect editor_rect_to_image_rect(Gfx::IntRect const&) const; @@ -86,6 +90,7 @@ private: virtual void keyup_event(GUI::KeyEvent&) override; virtual void context_menu_event(GUI::ContextMenuEvent&) override; virtual void resize_event(GUI::ResizeEvent&) override; + virtual void leave_event(Core::Event&) override; virtual void image_did_change(Gfx::IntRect const&) override; virtual void image_select_layer(Layer*) override; diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index 0fd9dd8ea5f..d89ece85961 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -572,6 +572,21 @@ int main(int argc, char** argv) tab_widget.set_tab_title(image_editor, title); }; + auto& statusbar = *main_widget.find_descendant_of_type_named("statusbar"); + image_editor.on_image_mouse_position_change = [&](auto const& mouse_position) { + auto const& image_size = current_image_editor()->image().size(); + auto image_rectangle = Gfx::IntRect { 0, 0, image_size.width(), image_size.height() }; + if (image_rectangle.contains(mouse_position)) { + statusbar.set_override_text(mouse_position.to_string()); + } else { + statusbar.set_override_text({}); + } + }; + + image_editor.on_leave = [&]() { + statusbar.set_override_text({}); + }; + // NOTE: We invoke the above hook directly here to make sure the tab title is set up. image_editor.on_image_title_change(image->title());