summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-02-23 20:52:32 +0000
committerAndreas Kling <kling@serenityos.org>2023-02-24 20:33:18 +0100
commitd62c95d7792ddc607b2b0631dc853e40bb68816a (patch)
tree43f3cbaa5f6bb286d44a309a649d238753d44b0d /Userland
parentb548a7b5ea59e1d98d4e219d695cd98348afc46a (diff)
downloadserenity-d62c95d7792ddc607b2b0631dc853e40bb68816a.zip
PixelPaint: Make "Add Mask" action fallible
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PixelPaint/Layer.cpp5
-rw-r--r--Userland/Applications/PixelPaint/Layer.h2
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.cpp7
3 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp
index 16922d2984..b1b7dd9c12 100644
--- a/Userland/Applications/PixelPaint/Layer.cpp
+++ b/Userland/Applications/PixelPaint/Layer.cpp
@@ -309,11 +309,12 @@ void Layer::update_cached_bitmap()
}
}
-void Layer::create_mask()
+ErrorOr<void> Layer::create_mask()
{
- m_mask_bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, size()));
+ m_mask_bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, size()));
m_mask_bitmap->fill(Gfx::Color::White);
update_cached_bitmap();
+ return {};
}
Gfx::Bitmap& Layer::currently_edited_bitmap()
diff --git a/Userland/Applications/PixelPaint/Layer.h b/Userland/Applications/PixelPaint/Layer.h
index a2a4046b7f..d3b76c06ca 100644
--- a/Userland/Applications/PixelPaint/Layer.h
+++ b/Userland/Applications/PixelPaint/Layer.h
@@ -45,7 +45,7 @@ public:
Gfx::Bitmap const* mask_bitmap() const { return m_mask_bitmap; }
Gfx::Bitmap* mask_bitmap() { return m_mask_bitmap; }
- void create_mask();
+ ErrorOr<void> create_mask();
Gfx::Bitmap& get_scratch_edited_bitmap();
Gfx::IntSize size() const { return content_bitmap().size(); }
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp
index 00eb19d403..6fd63d35f2 100644
--- a/Userland/Applications/PixelPaint/MainWidget.cpp
+++ b/Userland/Applications/PixelPaint/MainWidget.cpp
@@ -746,7 +746,12 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
auto active_layer = editor->active_layer();
if (!active_layer)
return;
- active_layer->create_mask();
+
+ if (auto maybe_error = active_layer->create_mask(); maybe_error.is_error()) {
+ GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Failed to create layer mask: {}", maybe_error.release_error()));
+ return;
+ }
+
editor->did_complete_action("Add Mask");
editor->update();
m_layer_list_widget->repaint();