mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:27:43 +00:00
PixelPaint: Make Layer passed to tools a pointer
Some tools (e.g. ZoomTool) doesn't need layer to work. This commit makes mouse events fire even if there is no layer. This fixes a bug that ZoomTool didn't work when there is no layers.
This commit is contained in:
parent
0224dc2882
commit
3ad9df1522
28 changed files with 202 additions and 136 deletions
|
@ -42,8 +42,11 @@ void RectangleTool::draw_using(GUI::Painter& painter, Gfx::IntRect const& rect)
|
|||
}
|
||||
}
|
||||
|
||||
void RectangleTool::on_mousedown(Layer&, MouseEvent& event)
|
||||
void RectangleTool::on_mousedown(Layer* layer, MouseEvent& event)
|
||||
{
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
auto& layer_event = event.layer_event();
|
||||
if (layer_event.button() != GUI::MouseButton::Left && layer_event.button() != GUI::MouseButton::Right)
|
||||
return;
|
||||
|
@ -57,20 +60,26 @@ void RectangleTool::on_mousedown(Layer&, MouseEvent& event)
|
|||
m_editor->update();
|
||||
}
|
||||
|
||||
void RectangleTool::on_mouseup(Layer& layer, MouseEvent& event)
|
||||
void RectangleTool::on_mouseup(Layer* layer, MouseEvent& event)
|
||||
{
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
if (event.layer_event().button() == m_drawing_button) {
|
||||
GUI::Painter painter(layer.bitmap());
|
||||
GUI::Painter painter(layer->bitmap());
|
||||
auto rect = Gfx::IntRect::from_two_points(m_rectangle_start_position, m_rectangle_end_position);
|
||||
draw_using(painter, rect);
|
||||
m_drawing_button = GUI::MouseButton::None;
|
||||
layer.did_modify_bitmap();
|
||||
layer->did_modify_bitmap();
|
||||
m_editor->did_complete_action();
|
||||
}
|
||||
}
|
||||
|
||||
void RectangleTool::on_mousemove(Layer&, MouseEvent& event)
|
||||
void RectangleTool::on_mousemove(Layer* layer, MouseEvent& event)
|
||||
{
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
if (m_drawing_button == GUI::MouseButton::None)
|
||||
return;
|
||||
|
||||
|
@ -78,16 +87,16 @@ void RectangleTool::on_mousemove(Layer&, MouseEvent& event)
|
|||
m_editor->update();
|
||||
}
|
||||
|
||||
void RectangleTool::on_second_paint(Layer const& layer, GUI::PaintEvent& event)
|
||||
void RectangleTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event)
|
||||
{
|
||||
if (m_drawing_button == GUI::MouseButton::None)
|
||||
if (!layer || m_drawing_button == GUI::MouseButton::None)
|
||||
return;
|
||||
|
||||
GUI::Painter painter(*m_editor);
|
||||
painter.add_clip_rect(event.rect());
|
||||
auto rect = Gfx::IntRect::from_two_points(
|
||||
m_editor->layer_position_to_editor_position(layer, m_rectangle_start_position).to_type<int>(),
|
||||
m_editor->layer_position_to_editor_position(layer, m_rectangle_end_position).to_type<int>());
|
||||
m_editor->layer_position_to_editor_position(*layer, m_rectangle_start_position).to_type<int>(),
|
||||
m_editor->layer_position_to_editor_position(*layer, m_rectangle_end_position).to_type<int>());
|
||||
draw_using(painter, rect);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue