mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
PixelPaint: Let Tools have different cursors
This adds support for the Tools in PixelPaint to use different cursors within ImageEditor. For now most of them get the crosshair cursor since it's the most fitting, but in the future we will want to add custom cursors.
This commit is contained in:
parent
657fbc1e6c
commit
b1b6a6d6e8
14 changed files with 28 additions and 3 deletions
|
@ -19,6 +19,7 @@ public:
|
|||
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
RefPtr<GUI::Widget> m_properties_widget;
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override;
|
||||
virtual void on_keydown(GUI::KeyEvent&) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
enum class Mode {
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
virtual void on_context_menu(Layer&, GUI::ContextMenuEvent&) override;
|
||||
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
RefPtr<Guide> closest_guide(Gfx::IntPoint const&);
|
||||
|
|
|
@ -181,6 +181,7 @@ void ImageEditor::mousedown_event(GUI::MouseEvent& event)
|
|||
if (event.button() == GUI::MouseButton::Middle) {
|
||||
m_click_position = event.position();
|
||||
m_saved_pan_origin = m_pan_origin;
|
||||
set_override_cursor(Gfx::StandardCursor::Drag);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -227,6 +228,8 @@ void ImageEditor::mousemove_event(GUI::MouseEvent& event)
|
|||
|
||||
void ImageEditor::mouseup_event(GUI::MouseEvent& event)
|
||||
{
|
||||
set_override_cursor(m_active_cursor);
|
||||
|
||||
if (!m_active_layer || !m_active_tool)
|
||||
return;
|
||||
auto layer_event = event_adjusted_for_layer(event, *m_active_layer);
|
||||
|
@ -265,8 +268,15 @@ void ImageEditor::keyup_event(GUI::KeyEvent& event)
|
|||
m_active_tool->on_keyup(event);
|
||||
}
|
||||
|
||||
void ImageEditor::enter_event(Core::Event&)
|
||||
{
|
||||
set_override_cursor(m_active_cursor);
|
||||
}
|
||||
|
||||
void ImageEditor::leave_event(Core::Event&)
|
||||
{
|
||||
set_override_cursor(Gfx::StandardCursor::None);
|
||||
|
||||
if (on_leave)
|
||||
on_leave();
|
||||
}
|
||||
|
@ -304,8 +314,10 @@ void ImageEditor::set_active_tool(Tool* tool)
|
|||
|
||||
m_active_tool = tool;
|
||||
|
||||
if (m_active_tool)
|
||||
if (m_active_tool) {
|
||||
m_active_tool->setup(*this);
|
||||
m_active_cursor = m_active_tool->cursor();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageEditor::layers_did_change()
|
||||
|
|
|
@ -100,6 +100,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 enter_event(Core::Event&) override;
|
||||
virtual void leave_event(Core::Event&) override;
|
||||
|
||||
virtual void image_did_change(Gfx::IntRect const&) override;
|
||||
|
@ -130,6 +131,8 @@ private:
|
|||
Gfx::FloatPoint m_saved_pan_origin;
|
||||
Gfx::IntPoint m_click_position;
|
||||
|
||||
Gfx::StandardCursor m_active_cursor { Gfx::StandardCursor::None };
|
||||
|
||||
Selection m_selection;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override;
|
||||
virtual void on_keydown(GUI::KeyEvent&) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
RefPtr<GUI::Widget> m_properties_widget;
|
||||
|
|
|
@ -32,7 +32,6 @@ void MoveTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEven
|
|||
m_layer_being_moved = layer;
|
||||
m_event_origin = image_event.position();
|
||||
m_layer_origin = layer.location();
|
||||
m_editor->window()->set_cursor(Gfx::StandardCursor::Move);
|
||||
}
|
||||
|
||||
void MoveTool::on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent& image_event)
|
||||
|
@ -49,7 +48,6 @@ void MoveTool::on_mouseup(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
|
|||
if (event.button() != GUI::MouseButton::Left)
|
||||
return;
|
||||
m_layer_being_moved = nullptr;
|
||||
m_editor->window()->set_cursor(Gfx::StandardCursor::None);
|
||||
m_editor->did_complete_action();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public:
|
|||
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual void on_keydown(GUI::KeyEvent&) override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Move; }
|
||||
|
||||
private:
|
||||
RefPtr<Layer> m_layer_being_moved;
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
Gfx::IntPoint m_last_drawing_event_position { -1, -1 };
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
virtual ~PickerTool() override;
|
||||
|
||||
virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
virtual void on_keyup(GUI::KeyEvent&) override;
|
||||
virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
enum class MovingMode {
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override;
|
||||
virtual void on_keydown(GUI::KeyEvent&) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
enum class Mode {
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
private:
|
||||
void paint_it();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <LibGUI/Event.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGfx/StandardCursor.h>
|
||||
|
||||
namespace PixelPaint {
|
||||
|
||||
|
@ -27,6 +28,7 @@ public:
|
|||
virtual void on_keydown(GUI::KeyEvent&) { }
|
||||
virtual void on_keyup(GUI::KeyEvent&) { }
|
||||
virtual GUI::Widget* get_properties_widget() { return nullptr; }
|
||||
virtual Gfx::StandardCursor cursor() { return Gfx::StandardCursor::None; }
|
||||
|
||||
void clear() { m_editor = nullptr; }
|
||||
void setup(ImageEditor&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue