mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:27: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
|
@ -48,26 +48,26 @@ private:
|
|||
bool m_up, m_down, m_left, m_right, m_sleeping = false;
|
||||
bool m_roaming { true };
|
||||
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_alert = *Gfx::Bitmap::load_from_file("/res/icons/catdog/alert.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_erun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/erun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_erun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/erun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nerun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nerun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nerun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nerun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nrun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nwrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nwrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nwrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nwrun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_serun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/serun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_serun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/serun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_sleep1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/sleep1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_sleep2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/sleep2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_srun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/srun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_srun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/srun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_still = *Gfx::Bitmap::load_from_file("/res/icons/catdog/still.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_swrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/swrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_swrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/swrun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_wrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/wrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_wrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/wrun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_alert = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/alert.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_erun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/erun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_erun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/erun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nerun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/nerun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nerun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/nerun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nrun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/nrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nrun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/nrun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nwrun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/nwrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_nwrun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/nwrun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_serun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/serun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_serun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/serun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_sleep1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/sleep1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_sleep2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/sleep2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_srun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/srun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_srun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/srun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_still = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/still.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_swrun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/swrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_swrun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/swrun2.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_wrun1 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/wrun1.png");
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_wrun2 = *Gfx::Bitmap::try_load_from_file("/res/icons/catdog/wrun2.png");
|
||||
|
||||
AK::NonnullRefPtr<Gfx::Bitmap> m_curr_bmp = m_alert;
|
||||
CatDog()
|
||||
|
|
|
@ -60,7 +60,7 @@ private:
|
|||
|
||||
Cube::Cube()
|
||||
{
|
||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT });
|
||||
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT });
|
||||
|
||||
m_accumulated_time = 0;
|
||||
m_cycles = 0;
|
||||
|
|
|
@ -81,7 +81,7 @@ private:
|
|||
|
||||
Fire::Fire()
|
||||
{
|
||||
bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::Indexed8, { FIRE_WIDTH, FIRE_HEIGHT });
|
||||
bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::Indexed8, { FIRE_WIDTH, FIRE_HEIGHT });
|
||||
|
||||
/* Initialize fire palette */
|
||||
for (int i = 0; i < 30; i++)
|
||||
|
|
|
@ -36,7 +36,7 @@ private:
|
|||
|
||||
Canvas::Canvas()
|
||||
{
|
||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT });
|
||||
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT });
|
||||
draw();
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ void Canvas::draw()
|
|||
painter.draw_line({ 740, 140 }, { 640, 240 }, Color::Red, 5, Gfx::Painter::LineStyle::Solid);
|
||||
painter.draw_line({ 690, 140 }, { 640, 240 }, Color::Blue, 10, Gfx::Painter::LineStyle::Solid);
|
||||
|
||||
auto bg = Gfx::Bitmap::load_from_file("/res/html/misc/90s-bg.png");
|
||||
auto bg = Gfx::Bitmap::try_load_from_file("/res/html/misc/90s-bg.png");
|
||||
painter.draw_tiled_bitmap({ 20, 260, 480, 320 }, *bg);
|
||||
|
||||
painter.draw_line({ 40, 480 }, { 20, 260 }, Color::Red);
|
||||
|
@ -129,7 +129,7 @@ void Canvas::draw()
|
|||
path.close();
|
||||
painter.fill_path(path, Color::Yellow, Gfx::Painter::WindingRule::EvenOdd);
|
||||
|
||||
auto buggie = Gfx::Bitmap::load_from_file("/res/graphics/buggie.png");
|
||||
auto buggie = Gfx::Bitmap::try_load_from_file("/res/graphics/buggie.png");
|
||||
painter.blit({ 280, 280 }, *buggie, buggie->rect(), 0.5);
|
||||
painter.draw_scaled_bitmap({ 360, 280, buggie->rect().width() * 2, buggie->rect().height() * 2 }, *buggie, buggie->rect());
|
||||
|
||||
|
|
|
@ -41,15 +41,15 @@ private:
|
|||
|
||||
Canvas::Canvas()
|
||||
{
|
||||
m_bitmap_1x = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 1);
|
||||
m_bitmap_2x = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 2);
|
||||
m_bitmap_1x = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 1);
|
||||
m_bitmap_2x = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 2);
|
||||
|
||||
// m_bitmap_1x and m_bitmap_2x have the same logical size, so LibGfx will try to draw them at the same physical size:
|
||||
// When drawing on a 2x backing store it'd scale m_bitmap_1x up 2x and paint m_bitmap_2x at its physical size.
|
||||
// When drawing on a 1x backing store it'd draw m_bitmap_1x at its physical size, and it would have to scale down m_bitmap_2x to 0.5x its size.
|
||||
// But the system can't current scale down, and we want to draw the 2x bitmap at twice the size of the 1x bitmap in this particular application,
|
||||
// so make a 1x alias of the 2x bitmap to make LibGfx paint it without any scaling at paint time, mapping once pixel to one pixel.
|
||||
m_bitmap_2x_as_1x = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::BGRx8888, m_bitmap_2x->physical_size(), 1, m_bitmap_2x->pitch(), m_bitmap_2x->scanline(0));
|
||||
m_bitmap_2x_as_1x = Gfx::Bitmap::try_create_wrapper(Gfx::BitmapFormat::BGRx8888, m_bitmap_2x->physical_size(), 1, m_bitmap_2x->pitch(), m_bitmap_2x->scanline(0));
|
||||
|
||||
Gfx::Painter painter_1x(*m_bitmap_1x);
|
||||
draw(painter_1x);
|
||||
|
@ -75,14 +75,14 @@ void Canvas::paint_event(GUI::PaintEvent& event)
|
|||
|
||||
void Canvas::draw(Gfx::Painter& painter)
|
||||
{
|
||||
auto active_window_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window.png");
|
||||
auto active_window_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/window.png");
|
||||
Gfx::WindowTheme::current().paint_normal_frame(painter, Gfx::WindowTheme::WindowState::Active, { 4, 18, WIDTH - 8, HEIGHT - 29 }, "Well hello friends 🐞", *active_window_icon, palette(), { WIDTH - 20, 6, 16, 16 }, 0, false);
|
||||
|
||||
painter.draw_rect({ 20, 34, WIDTH - 40, HEIGHT - 45 }, palette().color(Gfx::ColorRole::Selection), true);
|
||||
painter.draw_rect({ 24, 38, WIDTH - 48, HEIGHT - 53 }, palette().color(Gfx::ColorRole::Selection));
|
||||
|
||||
// buggie.png has an alpha channel.
|
||||
auto buggie = Gfx::Bitmap::load_from_file("/res/graphics/buggie.png");
|
||||
auto buggie = Gfx::Bitmap::try_load_from_file("/res/graphics/buggie.png");
|
||||
painter.blit({ 25, 39 }, *buggie, { 2, 30, 62, 20 });
|
||||
painter.draw_scaled_bitmap({ 88, 39, 62 * 2, 20 * 2 }, *buggie, Gfx::IntRect { 2, 30, 62, 20 });
|
||||
painter.draw_scaled_bitmap({ 202, 39, 80, 40 }, *buggie, Gfx::IntRect { 2, 30, 62, 20 });
|
||||
|
@ -92,7 +92,7 @@ void Canvas::draw(Gfx::Painter& painter)
|
|||
painter.blit({ 25, 101 }, *buggie, { 2, 30, 3 * buggie->width(), 20 });
|
||||
|
||||
// grid does not have an alpha channel.
|
||||
auto grid = Gfx::Bitmap::load_from_file("/res/wallpapers/grid.png");
|
||||
auto grid = Gfx::Bitmap::try_load_from_file("/res/wallpapers/grid.png");
|
||||
VERIFY(!grid->has_alpha_channel());
|
||||
painter.fill_rect({ 25, 122, 62, 20 }, Color::Green);
|
||||
painter.blit({ 25, 122 }, *grid, { (grid->width() - 62) / 2, (grid->height() - 20) / 2 + 40, 62, 20 }, 0.9);
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
void resize(Gfx::IntSize const& size)
|
||||
{
|
||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, size);
|
||||
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size);
|
||||
correct_aspect();
|
||||
calculate();
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto menubar = GUI::Menubar::construct();
|
||||
auto& file_menu = menubar->add_menu("&File");
|
||||
file_menu.add_action(GUI::Action::create("&Export...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"),
|
||||
file_menu.add_action(GUI::Action::create("&Export...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/save.png"),
|
||||
[&](GUI::Action&) {
|
||||
Optional<String> export_path = GUI::FilePicker::get_save_filepath(window, "untitled", "png");
|
||||
if (!export_path.has_value())
|
||||
|
|
|
@ -35,7 +35,7 @@ private:
|
|||
|
||||
Screensaver::Screensaver(int width, int height, int interval)
|
||||
{
|
||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { width, height });
|
||||
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, height });
|
||||
srand(time(nullptr));
|
||||
stop_timer();
|
||||
start_timer(interval);
|
||||
|
|
|
@ -59,7 +59,7 @@ Starfield::Starfield(int interval)
|
|||
|
||||
void Starfield::create_stars(int width, int height, int stars)
|
||||
{
|
||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { width, height });
|
||||
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, height });
|
||||
|
||||
m_stars.grow_capacity(stars);
|
||||
for (int i = 0; i < stars; i++) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
continue;
|
||||
Cursor cursor;
|
||||
cursor.path = move(path);
|
||||
cursor.bitmap = Gfx::Bitmap::load_from_file(cursor.path);
|
||||
cursor.bitmap = Gfx::Bitmap::try_load_from_file(cursor.path);
|
||||
auto filename_split = cursor.path.split('/');
|
||||
cursor.name = filename_split[2];
|
||||
m_cursors.append(move(cursor));
|
||||
|
@ -142,7 +142,7 @@ public:
|
|||
if (!path.contains("filetype-") && !path.contains("app-"))
|
||||
continue;
|
||||
IconSet icon_set;
|
||||
icon_set.big_icon = Gfx::Bitmap::load_from_file(path);
|
||||
icon_set.big_icon = Gfx::Bitmap::try_load_from_file(path);
|
||||
auto filename_split = path.split('/');
|
||||
icon_set.name = filename_split[3];
|
||||
m_icon_sets.append(move(icon_set));
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
if (!path.contains("filetype-") && !path.contains("app-"))
|
||||
continue;
|
||||
IconSet icon_set;
|
||||
icon_set.little_icon = Gfx::Bitmap::load_from_file(path);
|
||||
icon_set.little_icon = Gfx::Bitmap::try_load_from_file(path);
|
||||
auto filename_split = path.split('/');
|
||||
icon_set.name = filename_split[3];
|
||||
for (size_t i = 0; i < big_icons_found; i++) {
|
||||
|
|
|
@ -71,9 +71,9 @@ GalleryWidget::GalleryWidget()
|
|||
m_label_frame->set_frame_thickness(value);
|
||||
};
|
||||
|
||||
m_button_icons.append(Gfx::Bitmap::load_from_file("/res/icons/16x16/book-open.png"));
|
||||
m_button_icons.append(Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
|
||||
m_button_icons.append(Gfx::Bitmap::load_from_file("/res/icons/16x16/ladybug.png"));
|
||||
m_button_icons.append(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/book-open.png"));
|
||||
m_button_icons.append(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png"));
|
||||
m_button_icons.append(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/ladybug.png"));
|
||||
|
||||
m_icon_button = basics_tab.find_descendant_of_type_named<GUI::Button>("icon_button");
|
||||
m_icon_button->set_icon(*m_button_icons[2]);
|
||||
|
@ -93,7 +93,7 @@ GalleryWidget::GalleryWidget()
|
|||
m_text_editor = basics_tab.find_descendant_of_type_named<GUI::TextEditor>("text_editor");
|
||||
|
||||
m_font_button = basics_tab.find_descendant_of_type_named<GUI::Button>("font_button");
|
||||
m_font_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"));
|
||||
m_font_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png"));
|
||||
|
||||
m_font_button->on_click = [&](auto) {
|
||||
auto picker = GUI::FontPicker::construct(window(), &m_text_editor->font(), false);
|
||||
|
@ -103,7 +103,7 @@ GalleryWidget::GalleryWidget()
|
|||
};
|
||||
|
||||
m_file_button = basics_tab.find_descendant_of_type_named<GUI::Button>("file_button");
|
||||
m_file_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"));
|
||||
m_file_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"));
|
||||
|
||||
m_file_button->on_click = [&](auto) {
|
||||
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window());
|
||||
|
@ -113,7 +113,7 @@ GalleryWidget::GalleryWidget()
|
|||
};
|
||||
|
||||
m_input_button = basics_tab.find_descendant_of_type_named<GUI::Button>("input_button");
|
||||
m_input_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"));
|
||||
m_input_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/properties.png"));
|
||||
|
||||
m_input_button->on_click = [&](auto) {
|
||||
String value;
|
||||
|
@ -131,7 +131,7 @@ GalleryWidget::GalleryWidget()
|
|||
};
|
||||
|
||||
m_msgbox_button = basics_tab.find_descendant_of_type_named<GUI::Button>("msgbox_button");
|
||||
m_msgbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-irc-client.png"));
|
||||
m_msgbox_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-irc-client.png"));
|
||||
|
||||
m_msgbox_type = GUI::MessageBox::Type::None;
|
||||
m_msgbox_input_type = GUI::MessageBox::InputType::OK;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue