|
8 | 8 |
|
9 | 9 | #include "Layer.h"
|
10 | 10 | #include "Image.h"
|
| 11 | +#include "ImageEditor.h" |
11 | 12 | #include "Selection.h"
|
12 | 13 | #include <AK/RefPtr.h>
|
13 | 14 | #include <AK/Try.h>
|
| 15 | +#include <LibGUI/Painter.h> |
14 | 16 | #include <LibGfx/Bitmap.h>
|
15 | 17 | #include <LibGfx/Painter.h>
|
16 | 18 |
|
@@ -45,6 +47,7 @@ ErrorOr<NonnullRefPtr<Layer>> Layer::create_snapshot(Image& image, Layer const&
|
45 | 47 | snapshot->m_mask_bitmap = TRY(layer.mask_bitmap()->clone());
|
46 | 48 | snapshot->m_edit_mode = layer.m_edit_mode;
|
47 | 49 | snapshot->m_mask_type = layer.m_mask_type;
|
| 50 | + snapshot->m_visible_mask = layer.m_visible_mask; |
48 | 51 | }
|
49 | 52 |
|
50 | 53 | /*
|
@@ -322,6 +325,7 @@ void Layer::delete_mask()
|
322 | 325 | {
|
323 | 326 | m_mask_bitmap = nullptr;
|
324 | 327 | m_mask_type = MaskType::None;
|
| 328 | + m_visible_mask = false; |
325 | 329 | set_edit_mode(EditMode::Content);
|
326 | 330 | update_cached_bitmap();
|
327 | 331 | }
|
@@ -464,4 +468,35 @@ Layer::MaskType Layer::mask_type()
|
464 | 468 | return m_mask_type;
|
465 | 469 | }
|
466 | 470 |
|
| 471 | +void Layer::on_second_paint(ImageEditor& editor) |
| 472 | +{ |
| 473 | + if (!m_visible_mask || edit_mode() != EditMode::Mask) |
| 474 | + return; |
| 475 | + |
| 476 | + auto visible_rect = editor.active_layer_visible_rect(); |
| 477 | + if (visible_rect.width() == 0 || visible_rect.height() == 0) |
| 478 | + return; |
| 479 | + |
| 480 | + GUI::Painter painter(editor); |
| 481 | + painter.translate(visible_rect.location()); |
| 482 | + |
| 483 | + auto content_offset = editor.content_to_frame_position(location()); |
| 484 | + auto drawing_cursor_offset = visible_rect.location() - content_offset.to_type<int>(); |
| 485 | + |
| 486 | + Gfx::Color editing_mask_color = editor.primary_color(); |
| 487 | + int mask_alpha; |
| 488 | + Gfx::IntPoint mask_coordinates; |
| 489 | + |
| 490 | + for (int y = 0; y < visible_rect.height(); y++) { |
| 491 | + for (int x = 0; x < visible_rect.width(); x++) { |
| 492 | + mask_coordinates = (Gfx::FloatPoint(drawing_cursor_offset.x() + x, drawing_cursor_offset.y() + y) / editor.scale()).to_type<int>(); |
| 493 | + mask_alpha = mask_bitmap()->get_pixel(mask_coordinates).alpha(); |
| 494 | + if (!mask_alpha) |
| 495 | + continue; |
| 496 | + |
| 497 | + painter.set_pixel(x, y, editing_mask_color.with_alpha(mask_alpha), true); |
| 498 | + } |
| 499 | + } |
| 500 | +} |
| 501 | + |
467 | 502 | }
|
0 commit comments