1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:58:12 +00:00

PixelPaint: Introduce new mask features

This patch adds a new Editing-Mask type to layers. This kind of mask
is used to restrict changes on the content bitmap only to areas where
the mask is drawn. The intensity of a pixel change is controlled by the
alpha-value of the mask.

Furthermore a function to invert and clear masks has been introduced.
When a new mask is created for a layer the edit mode of the layer is
also changed to Mask so that the user can immediately start to draw the
mask.
This commit is contained in:
Torstennator 2023-05-12 16:07:51 +02:00 committed by Jelle Raaijmakers
parent 7e5f1fa895
commit e3509efc1b
6 changed files with 147 additions and 7 deletions

View file

@ -83,4 +83,35 @@ Gfx::IntPoint Tool::constrain_line_angle(Gfx::IntPoint start_pos, Gfx::IntPoint
start_pos.y() + (int)(AK::sin(constrained_angle) * line_length) };
}
template<>
void Tool::set_pixel_with_possible_mask<Gfx::StorageFormat::BGRA8888>(int x, int y, Gfx::Color color, Gfx::Bitmap& bitmap)
{
if (!m_editor || !m_editor->active_layer())
return;
switch (m_editor->active_layer()->edit_mode()) {
case Layer::EditMode::Content:
bitmap.set_pixel<Gfx::StorageFormat::BGRA8888>(x, y, m_editor->active_layer()->modify_pixel_with_editing_mask(x, y, color, bitmap.get_pixel(x, y)));
break;
case Layer::EditMode::Mask:
bitmap.set_pixel<Gfx::StorageFormat::BGRA8888>(x, y, color);
break;
}
}
void Tool::set_pixel_with_possible_mask(int x, int y, Gfx::Color color, Gfx::Bitmap& bitmap)
{
if (!m_editor || !m_editor->active_layer())
return;
switch (m_editor->active_layer()->edit_mode()) {
case Layer::EditMode::Content:
bitmap.set_pixel(x, y, m_editor->active_layer()->modify_pixel_with_editing_mask(x, y, color, bitmap.get_pixel(x, y)));
break;
case Layer::EditMode::Mask:
bitmap.set_pixel(x, y, color);
break;
}
}
}