mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
PixelPaint: Fix gradient tool clipping issues
This ensures that the gradient does not paint over the rulers at any zoom level, and also shows the guidelines/handles even when the gradient is clipped.
This commit is contained in:
parent
efb2bed525
commit
681ed93a41
2 changed files with 11 additions and 8 deletions
|
@ -153,16 +153,14 @@ void GradientTool::on_keyup(GUI::KeyEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GradientTool::on_second_paint(Layer const* layer, GUI::PaintEvent&)
|
void GradientTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
if (!layer || !has_gradient_start_end())
|
if (!layer || !has_gradient_start_end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// FIXME: Clipping still does overwrite the ruler if we are zoomed in.
|
|
||||||
auto clipping_rect = m_editor->rect().contains(m_editor->content_rect()) ? m_editor->content_rect() : m_editor->rect();
|
|
||||||
GUI::Painter painter(*m_editor);
|
GUI::Painter painter(*m_editor);
|
||||||
painter.add_clip_rect(clipping_rect);
|
painter.add_clip_rect(event.rect());
|
||||||
draw_gradient(painter, true, m_editor->content_to_frame_position(Gfx::IntPoint(0, 0)), m_editor->scale());
|
draw_gradient(painter, true, m_editor->content_to_frame_position(Gfx::IntPoint(0, 0)), m_editor->scale(), m_editor->content_rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GradientTool::on_tool_activation()
|
void GradientTool::on_tool_activation()
|
||||||
|
@ -250,7 +248,7 @@ void GradientTool::calculate_gradient_lines()
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GradientTool::draw_gradient(GUI::Painter& painter, bool with_guidelines, const Gfx::FloatPoint drawing_offset, float scale)
|
void GradientTool::draw_gradient(GUI::Painter& painter, bool with_guidelines, const Gfx::FloatPoint drawing_offset, float scale, Optional<Gfx::IntRect const&> gradient_clip)
|
||||||
{
|
{
|
||||||
auto t_gradient_begin_line = m_gradient_begin_line.scaled(scale, scale).translated(drawing_offset);
|
auto t_gradient_begin_line = m_gradient_begin_line.scaled(scale, scale).translated(drawing_offset);
|
||||||
auto t_gradient_center_line = m_gradient_center_line.scaled(scale, scale).translated(drawing_offset);
|
auto t_gradient_center_line = m_gradient_center_line.scaled(scale, scale).translated(drawing_offset);
|
||||||
|
@ -288,7 +286,12 @@ void GradientTool::draw_gradient(GUI::Painter& painter, bool with_guidelines, co
|
||||||
auto gradient_start_color = color_to_use;
|
auto gradient_start_color = color_to_use;
|
||||||
gradient_start_color.set_alpha(0);
|
gradient_start_color.set_alpha(0);
|
||||||
|
|
||||||
|
{
|
||||||
|
Gfx::PainterStateSaver saver(painter);
|
||||||
|
if (gradient_clip.has_value())
|
||||||
|
painter.add_clip_rect(*gradient_clip);
|
||||||
painter.fill_rect_with_linear_gradient(gradient_rect, Array { Gfx::ColorStop { gradient_start_color, 0.5f - gradient_half_width_percentage_offset }, Gfx::ColorStop { color_to_use, 0.5f + gradient_half_width_percentage_offset } }, rotation_degrees);
|
painter.fill_rect_with_linear_gradient(gradient_rect, Array { Gfx::ColorStop { gradient_start_color, 0.5f - gradient_half_width_percentage_offset }, Gfx::ColorStop { color_to_use, 0.5f + gradient_half_width_percentage_offset } }, rotation_degrees);
|
||||||
|
}
|
||||||
|
|
||||||
if (with_guidelines) {
|
if (with_guidelines) {
|
||||||
Gfx::AntiAliasingPainter aa_painter = Gfx::AntiAliasingPainter(painter);
|
Gfx::AntiAliasingPainter aa_painter = Gfx::AntiAliasingPainter(painter);
|
||||||
|
|
|
@ -49,7 +49,7 @@ private:
|
||||||
Gfx::FloatLine m_gradient_end_line;
|
Gfx::FloatLine m_gradient_end_line;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void draw_gradient(GUI::Painter&, bool with_guidelines = false, const Gfx::FloatPoint drawing_offset = { 0.0f, 0.0f }, float scale = 1);
|
void draw_gradient(GUI::Painter&, bool with_guidelines = false, const Gfx::FloatPoint drawing_offset = { 0.0f, 0.0f }, float scale = 1, Optional<Gfx::IntRect const&> gradient_clip = {});
|
||||||
void rasterize_gradient();
|
void rasterize_gradient();
|
||||||
void calculate_gradient_lines();
|
void calculate_gradient_lines();
|
||||||
void update_gradient_end_and_derive_start(Gfx::IntPoint const);
|
void update_gradient_end_and_derive_start(Gfx::IntPoint const);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue