diff options
author | Linus Groh <mail@linusgroh.de> | 2023-01-28 20:12:17 +0000 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-01-28 22:41:36 +0100 |
commit | 8a884b258143fd55b77b6a4ef0922a24d956ab19 (patch) | |
tree | a6f7bb9328a9da48d737a820006d4528b384efdc | |
parent | 39f1a6eb6f9e7c8f56e3168d10c2bc565ce10257 (diff) | |
download | serenity-8a884b258143fd55b77b6a4ef0922a24d956ab19.zip |
PixelPaint: Remove `try_` prefix from fallible Image methods
-rw-r--r-- | Userland/Applications/PixelPaint/Image.cpp | 18 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/ImageEditor.cpp | 4 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Layer.cpp | 12 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Layer.h | 10 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/MainWidget.cpp | 20 |
5 files changed, 32 insertions, 32 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index fa72b928a3..8fbd4c38bf 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -75,7 +75,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Image::decode_bitmap(ReadonlyBytes bitmap_da ErrorOr<NonnullRefPtr<Image>> Image::create_from_bitmap(NonnullRefPtr<Gfx::Bitmap> const& bitmap) { auto image = TRY(create_with_size({ bitmap->width(), bitmap->height() })); - auto layer = TRY(Layer::try_create_with_bitmap(*image, *bitmap, "Background")); + auto layer = TRY(Layer::create_with_bitmap(*image, *bitmap, "Background")); image->add_layer(move(layer)); return image; } @@ -93,13 +93,13 @@ ErrorOr<NonnullRefPtr<Image>> Image::create_from_pixel_paint_json(JsonObject con auto bitmap_base64_encoded = layer_object.get_deprecated_string("bitmap"sv).value(); auto bitmap_data = TRY(decode_base64(bitmap_base64_encoded)); auto bitmap = TRY(decode_bitmap(bitmap_data)); - auto layer = TRY(Layer::try_create_with_bitmap(*image, move(bitmap), name)); + auto layer = TRY(Layer::create_with_bitmap(*image, move(bitmap), name)); if (auto const& mask_object = layer_object.get_deprecated_string("mask"sv); mask_object.has_value()) { auto mask_base64_encoded = mask_object.value(); auto mask_data = TRY(decode_base64(mask_base64_encoded)); auto mask = TRY(decode_bitmap(mask_data)); - TRY(layer->try_set_bitmaps(layer->content_bitmap(), mask)); + TRY(layer->set_bitmaps(layer->content_bitmap(), mask)); } auto width = layer_object.get_i32("width"sv).value_or(0); @@ -219,7 +219,7 @@ ErrorOr<NonnullRefPtr<Image>> Image::take_snapshot() const { auto snapshot = TRY(create_with_size(m_size)); for (auto const& layer : m_layers) { - auto layer_snapshot = TRY(Layer::try_create_snapshot(*snapshot, layer)); + auto layer_snapshot = TRY(Layer::create_snapshot(*snapshot, layer)); snapshot->add_layer(move(layer_snapshot)); } snapshot->m_selection.set_mask(m_selection.mask()); @@ -233,7 +233,7 @@ ErrorOr<void> Image::restore_snapshot(Image const& snapshot) bool layer_selected = false; for (auto const& snapshot_layer : snapshot.m_layers) { - auto layer = TRY(Layer::try_create_snapshot(*this, snapshot_layer)); + auto layer = TRY(Layer::create_snapshot(*this, snapshot_layer)); if (layer->is_selected()) { select_layer(layer.ptr()); layer_selected = true; @@ -493,7 +493,7 @@ ErrorOr<void> Image::flip(Gfx::Orientation orientation) size_t selected_layer_index = 0; for (size_t i = 0; i < m_layers.size(); ++i) { auto& layer = m_layers[i]; - auto new_layer = TRY(Layer::try_create_snapshot(*this, layer)); + auto new_layer = TRY(Layer::create_snapshot(*this, layer)); if (layer.is_selected()) selected_layer_index = i; @@ -524,7 +524,7 @@ ErrorOr<void> Image::rotate(Gfx::RotationDirection direction) size_t selected_layer_index = 0; for (size_t i = 0; i < m_layers.size(); ++i) { auto& layer = m_layers[i]; - auto new_layer = TRY(Layer::try_create_snapshot(*this, layer)); + auto new_layer = TRY(Layer::create_snapshot(*this, layer)); if (layer.is_selected()) selected_layer_index = i; @@ -556,7 +556,7 @@ ErrorOr<void> Image::crop(Gfx::IntRect const& cropped_rect) size_t selected_layer_index = 0; for (size_t i = 0; i < m_layers.size(); ++i) { auto& layer = m_layers[i]; - auto new_layer = TRY(Layer::try_create_snapshot(*this, layer)); + auto new_layer = TRY(Layer::create_snapshot(*this, layer)); if (layer.is_selected()) selected_layer_index = i; @@ -626,7 +626,7 @@ ErrorOr<void> Image::resize(Gfx::IntSize new_size, Gfx::Painter::ScalingMode sca size_t selected_layer_index = 0; for (size_t i = 0; i < m_layers.size(); ++i) { auto& layer = m_layers[i]; - auto new_layer = TRY(Layer::try_create_snapshot(*this, layer)); + auto new_layer = TRY(Layer::create_snapshot(*this, layer)); if (layer.is_selected()) selected_layer_index = i; diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 7e776e23c8..b677b2a93a 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -517,11 +517,11 @@ ErrorOr<void> ImageEditor::add_new_layer_from_selection() // save offsets of selection so we know where to place the new layer auto selection_offset = current_layer_selection.bounding_rect().location(); - auto selection_bitmap = active_layer()->try_copy_bitmap(current_layer_selection); + auto selection_bitmap = active_layer()->copy_bitmap(current_layer_selection); if (selection_bitmap.is_null()) return Error::from_string_literal("Unable to create bitmap from selection."); - auto layer_or_error = PixelPaint::Layer::try_create_with_bitmap(image(), selection_bitmap.release_nonnull(), "New Layer"sv); + auto layer_or_error = PixelPaint::Layer::create_with_bitmap(image(), selection_bitmap.release_nonnull(), "New Layer"sv); if (layer_or_error.is_error()) return Error::from_string_literal("Unable to create layer from selection."); diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp index 1b2b73707d..5682580ee1 100644 --- a/Userland/Applications/PixelPaint/Layer.cpp +++ b/Userland/Applications/PixelPaint/Layer.cpp @@ -16,7 +16,7 @@ namespace PixelPaint { -ErrorOr<NonnullRefPtr<Layer>> Layer::try_create_with_size(Image& image, Gfx::IntSize size, DeprecatedString name) +ErrorOr<NonnullRefPtr<Layer>> Layer::create_with_size(Image& image, Gfx::IntSize size, DeprecatedString name) { VERIFY(!size.is_empty()); @@ -27,7 +27,7 @@ ErrorOr<NonnullRefPtr<Layer>> Layer::try_create_with_size(Image& image, Gfx::Int return adopt_nonnull_ref_or_enomem(new (nothrow) Layer(image, move(bitmap), move(name))); } -ErrorOr<NonnullRefPtr<Layer>> Layer::try_create_with_bitmap(Image& image, NonnullRefPtr<Gfx::Bitmap> bitmap, DeprecatedString name) +ErrorOr<NonnullRefPtr<Layer>> Layer::create_with_bitmap(Image& image, NonnullRefPtr<Gfx::Bitmap> bitmap, DeprecatedString name) { VERIFY(!bitmap->size().is_empty()); @@ -37,10 +37,10 @@ ErrorOr<NonnullRefPtr<Layer>> Layer::try_create_with_bitmap(Image& image, Nonnul return adopt_nonnull_ref_or_enomem(new (nothrow) Layer(image, bitmap, move(name))); } -ErrorOr<NonnullRefPtr<Layer>> Layer::try_create_snapshot(Image& image, Layer const& layer) +ErrorOr<NonnullRefPtr<Layer>> Layer::create_snapshot(Image& image, Layer const& layer) { auto bitmap = TRY(layer.content_bitmap().clone()); - auto snapshot = TRY(try_create_with_bitmap(image, move(bitmap), layer.name())); + auto snapshot = TRY(create_with_bitmap(image, move(bitmap), layer.name())); /* We set these properties directly because calling the setters might @@ -127,7 +127,7 @@ Gfx::Bitmap& Layer::get_scratch_edited_bitmap() return *m_scratch_edited_bitmap; } -RefPtr<Gfx::Bitmap> Layer::try_copy_bitmap(Selection const& selection) const +RefPtr<Gfx::Bitmap> Layer::copy_bitmap(Selection const& selection) const { if (selection.is_empty()) { return {}; @@ -185,7 +185,7 @@ void Layer::erase_selection(Selection const& selection) did_modify_bitmap(translated_to_layer_space); } -ErrorOr<void> Layer::try_set_bitmaps(NonnullRefPtr<Gfx::Bitmap> content, RefPtr<Gfx::Bitmap> mask) +ErrorOr<void> Layer::set_bitmaps(NonnullRefPtr<Gfx::Bitmap> content, RefPtr<Gfx::Bitmap> mask) { if (mask && content->size() != mask->size()) return Error::from_string_literal("Layer content and mask must be same size"); diff --git a/Userland/Applications/PixelPaint/Layer.h b/Userland/Applications/PixelPaint/Layer.h index fe8275ed1c..a2a4046b7f 100644 --- a/Userland/Applications/PixelPaint/Layer.h +++ b/Userland/Applications/PixelPaint/Layer.h @@ -29,9 +29,9 @@ class Layer AK_MAKE_NONMOVABLE(Layer); public: - static ErrorOr<NonnullRefPtr<Layer>> try_create_with_size(Image&, Gfx::IntSize, DeprecatedString name); - static ErrorOr<NonnullRefPtr<Layer>> try_create_with_bitmap(Image&, NonnullRefPtr<Gfx::Bitmap>, DeprecatedString name); - static ErrorOr<NonnullRefPtr<Layer>> try_create_snapshot(Image&, Layer const&); + static ErrorOr<NonnullRefPtr<Layer>> create_with_size(Image&, Gfx::IntSize, DeprecatedString name); + static ErrorOr<NonnullRefPtr<Layer>> create_with_bitmap(Image&, NonnullRefPtr<Gfx::Bitmap>, DeprecatedString name); + static ErrorOr<NonnullRefPtr<Layer>> create_snapshot(Image&, Layer const&); ~Layer() = default; @@ -70,7 +70,7 @@ public: Optional<Gfx::IntRect> nonempty_content_bounding_rect() const; - ErrorOr<void> try_set_bitmaps(NonnullRefPtr<Gfx::Bitmap> content, RefPtr<Gfx::Bitmap> mask); + ErrorOr<void> set_bitmaps(NonnullRefPtr<Gfx::Bitmap> content, RefPtr<Gfx::Bitmap> mask); void did_modify_bitmap(Gfx::IntRect const& = {}, NotifyClients notify_clients = NotifyClients::Yes); @@ -83,7 +83,7 @@ public: int opacity_percent() const { return m_opacity_percent; } void set_opacity_percent(int); - RefPtr<Gfx::Bitmap> try_copy_bitmap(Selection const&) const; + RefPtr<Gfx::Bitmap> copy_bitmap(Selection const&) const; Image const& image() const { return m_image; } diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index b20923820a..e1677f9c04 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -158,7 +158,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) return; } auto image = image_result.release_value(); - auto bg_layer_result = PixelPaint::Layer::try_create_with_size(*image, image->size(), "Background"); + auto bg_layer_result = PixelPaint::Layer::create_with_size(*image, image->size(), "Background"); if (bg_layer_result.is_error()) { GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Failed to create layer with size {}, error: {}", image->size(), bg_layer_result.error())); return; @@ -285,9 +285,9 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) dbgln("Cannot cut with no active layer selected"); return; } - auto bitmap = editor->active_layer()->try_copy_bitmap(editor->image().selection()); + auto bitmap = editor->active_layer()->copy_bitmap(editor->image().selection()); if (!bitmap) { - dbgln("try_copy_bitmap() from Layer failed"); + dbgln("copy_bitmap() from Layer failed"); return; } GUI::Clipboard::the().set_bitmap(*bitmap); @@ -302,9 +302,9 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) dbgln("Cannot copy with no active layer selected"); return; } - auto bitmap = editor->active_layer()->try_copy_bitmap(editor->image().selection()); + auto bitmap = editor->active_layer()->copy_bitmap(editor->image().selection()); if (!bitmap) { - dbgln("try_copy_bitmap() from Layer failed"); + dbgln("copy_bitmap() from Layer failed"); return; } auto layer_rect = editor->active_layer()->relative_rect(); @@ -343,7 +343,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) if (!bitmap) return; - auto layer_result = PixelPaint::Layer::try_create_with_bitmap(editor->image(), *bitmap, "Pasted layer"); + auto layer_result = PixelPaint::Layer::create_with_bitmap(editor->image(), *bitmap, "Pasted layer"); if (layer_result.is_error()) { GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Could not create bitmap when pasting: {}", layer_result.error())); return; @@ -701,7 +701,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) VERIFY(editor); auto dialog = PixelPaint::CreateNewLayerDialog::construct(editor->image().size(), &window); if (dialog->exec() == GUI::Dialog::ExecResult::OK) { - auto layer_or_error = PixelPaint::Layer::try_create_with_size(editor->image(), dialog->layer_size(), dialog->layer_name()); + auto layer_or_error = PixelPaint::Layer::create_with_size(editor->image(), dialog->layer_size(), dialog->layer_name()); if (layer_or_error.is_error()) { GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Unable to create layer with size {}", dialog->size())); return; @@ -825,7 +825,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) auto& next_active_layer = editor->image().layer(active_layer_index > 0 ? active_layer_index - 1 : 0); editor->set_active_layer(&next_active_layer); } else { - auto layer_result = PixelPaint::Layer::try_create_with_size(editor->image(), editor->image().size(), "Background"); + auto layer_result = PixelPaint::Layer::create_with_size(editor->image(), editor->image().size(), "Background"); if (layer_result.is_error()) { GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Failed to create layer with size {}, error: {}", editor->image().size(), layer_result.error())); return; @@ -1115,7 +1115,7 @@ ErrorOr<void> MainWidget::create_default_image() { auto image = TRY(Image::create_with_size({ 510, 356 })); - auto bg_layer = TRY(Layer::try_create_with_size(*image, image->size(), "Background")); + auto bg_layer = TRY(Layer::create_with_size(*image, image->size(), "Background")); image->add_layer(*bg_layer); bg_layer->content_bitmap().fill(Color::Transparent); @@ -1137,7 +1137,7 @@ ErrorOr<void> MainWidget::create_image_from_clipboard() } auto image = TRY(PixelPaint::Image::create_with_size(bitmap->size())); - auto layer = TRY(PixelPaint::Layer::try_create_with_bitmap(image, *bitmap, "Pasted layer")); + auto layer = TRY(PixelPaint::Layer::create_with_bitmap(image, *bitmap, "Pasted layer")); image->add_layer(*layer); auto& editor = create_new_editor(*image); |