mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:37:35 +00:00
LibGfx: Use "try_" prefix for static factory functions
Also mark them as [[nodiscard]].
This commit is contained in:
parent
f0409081f5
commit
c7d891765c
131 changed files with 422 additions and 421 deletions
|
@ -194,7 +194,7 @@ Result<void, String> Image::write_to_file(const String& file_path) const
|
|||
|
||||
RefPtr<Gfx::Bitmap> Image::try_compose_bitmap(Gfx::BitmapFormat format) const
|
||||
{
|
||||
auto bitmap = Gfx::Bitmap::create(format, m_size);
|
||||
auto bitmap = Gfx::Bitmap::try_create(format, m_size);
|
||||
if (!bitmap)
|
||||
return nullptr;
|
||||
GUI::Painter painter(*bitmap);
|
||||
|
|
|
@ -19,7 +19,7 @@ RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size
|
|||
if (size.width() > 16384 || size.height() > 16384)
|
||||
return nullptr;
|
||||
|
||||
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size);
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size);
|
||||
if (!bitmap)
|
||||
return nullptr;
|
||||
|
||||
|
@ -97,7 +97,7 @@ RefPtr<Gfx::Bitmap> Layer::try_copy_bitmap(Selection const& selection) const
|
|||
}
|
||||
auto selection_rect = selection.bounding_rect();
|
||||
|
||||
auto result = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, selection_rect.size());
|
||||
auto result = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, selection_rect.size());
|
||||
VERIFY(result->has_alpha_channel());
|
||||
|
||||
for (int y = selection_rect.top(); y <= selection_rect.bottom(); y++) {
|
||||
|
|
|
@ -103,7 +103,7 @@ void MoveTool::on_context_menu(Layer& layer, GUI::ContextMenuEvent& event)
|
|||
m_editor));
|
||||
m_context_menu->add_separator();
|
||||
m_context_menu->add_action(GUI::Action::create(
|
||||
"&Delete Layer", Gfx::Bitmap::load_from_file("/res/icons/16x16/delete.png"), [this](auto&) {
|
||||
"&Delete Layer", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png"), [this](auto&) {
|
||||
m_editor->image().remove_layer(*m_context_menu_layer);
|
||||
// FIXME: This should not be done imperatively here. Perhaps a Image::Client interface that ImageEditor can implement?
|
||||
if (m_editor->active_layer() == m_context_menu_layer)
|
||||
|
|
|
@ -50,7 +50,7 @@ ToolboxWidget::~ToolboxWidget()
|
|||
void ToolboxWidget::setup_tools()
|
||||
{
|
||||
auto add_tool = [&](String name, StringView const& icon_name, GUI::Shortcut const& shortcut, NonnullOwnPtr<Tool> tool) {
|
||||
auto action = GUI::Action::create_checkable(move(name), shortcut, Gfx::Bitmap::load_from_file(String::formatted("/res/icons/pixelpaint/{}.png", icon_name)),
|
||||
auto action = GUI::Action::create_checkable(move(name), shortcut, Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/pixelpaint/{}.png", icon_name)),
|
||||
[this, tool = tool.ptr()](auto& action) {
|
||||
if (action.is_checked())
|
||||
on_tool_selection(tool);
|
||||
|
|
|
@ -90,7 +90,7 @@ int main(int argc, char** argv)
|
|||
};
|
||||
|
||||
auto new_image_action = GUI::Action::create(
|
||||
"&New Image...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](auto&) {
|
||||
"&New Image...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"), [&](auto&) {
|
||||
auto dialog = PixelPaint::CreateNewImageDialog::construct(window);
|
||||
if (dialog->exec() == GUI::Dialog::ExecOK) {
|
||||
auto image = PixelPaint::Image::try_create_with_size(dialog->image_size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue