mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:37:35 +00:00
LibGfx: Use ErrorOr<T> for Bitmap::try_load_from_file()
This was used in a lot of places, so this patch makes liberal use of ErrorOr<T>::release_value_but_fixme_should_propagate_errors().
This commit is contained in:
parent
16f064d9be
commit
235f39e449
104 changed files with 412 additions and 397 deletions
|
@ -373,7 +373,7 @@ static RefPtr<Gfx::Bitmap> get_piece(const StringView& set, const StringView& im
|
|||
builder.append(set);
|
||||
builder.append('/');
|
||||
builder.append(image);
|
||||
return Gfx::Bitmap::try_load_from_file(builder.build());
|
||||
return Gfx::Bitmap::try_load_from_file(builder.build()).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
void ChessWidget::set_piece_set(const StringView& set)
|
||||
|
|
|
@ -155,7 +155,7 @@ int main(int argc, char** argv)
|
|||
GUI::ActionGroup board_theme_action_group;
|
||||
board_theme_action_group.set_exclusive(true);
|
||||
auto& board_theme_menu = style_menu.add_submenu("Board Theme");
|
||||
board_theme_menu.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/chess/mini-board.png"));
|
||||
board_theme_menu.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/chess/mini-board.png").release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
for (auto& theme : Vector({ "Beige", "Green", "Blue" })) {
|
||||
auto action = GUI::Action::create_checkable(theme, [&](auto& action) {
|
||||
|
|
|
@ -43,8 +43,8 @@ private:
|
|||
const float x { 50 };
|
||||
const float radius { 16 };
|
||||
const float starting_y { 200 };
|
||||
const RefPtr<Gfx::Bitmap> falling_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/falling.png") };
|
||||
const RefPtr<Gfx::Bitmap> flapping_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/flapping.png") };
|
||||
NonnullRefPtr<Gfx::Bitmap> falling_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/falling.png").release_value_but_fixme_should_propagate_errors() };
|
||||
NonnullRefPtr<Gfx::Bitmap> flapping_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/flapping.png").release_value_but_fixme_should_propagate_errors() };
|
||||
float y {};
|
||||
float velocity {};
|
||||
|
||||
|
@ -106,10 +106,10 @@ private:
|
|||
};
|
||||
|
||||
struct Cloud {
|
||||
const Vector<RefPtr<Gfx::Bitmap>> cloud_bitmaps {
|
||||
Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_0.png"),
|
||||
Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_1.png"),
|
||||
Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_2.png"),
|
||||
Vector<NonnullRefPtr<Gfx::Bitmap>> const cloud_bitmaps {
|
||||
Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_0.png").release_value_but_fixme_should_propagate_errors(),
|
||||
Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_1.png").release_value_but_fixme_should_propagate_errors(),
|
||||
Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_2.png").release_value_but_fixme_should_propagate_errors(),
|
||||
};
|
||||
float x {};
|
||||
float y {};
|
||||
|
@ -147,7 +147,7 @@ private:
|
|||
float m_last_score {};
|
||||
float m_difficulty {};
|
||||
float m_restart_cooldown {};
|
||||
const RefPtr<Gfx::Bitmap> m_background_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/background.png") };
|
||||
NonnullRefPtr<Gfx::Bitmap> m_background_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/background.png").release_value_but_fixme_should_propagate_errors() };
|
||||
const Gfx::IntRect m_score_rect { 10, 10, 20, 20 };
|
||||
const Gfx::IntRect m_text_rect { game_width / 2 - 80, game_height / 2 - 40, 160, 80 };
|
||||
};
|
||||
|
|
|
@ -96,8 +96,8 @@ int main(int argc, char** argv)
|
|||
|
||||
interval_spinbox.set_value(150);
|
||||
|
||||
auto paused_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png");
|
||||
auto play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png");
|
||||
auto paused_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png").release_value_but_fixme_should_propagate_errors();
|
||||
auto play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png").release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
auto toggle_running_action = GUI::Action::create("&Toggle Running", { Mod_None, Key_Return }, *play_icon, [&](GUI::Action&) {
|
||||
board_widget.set_running(!board_widget.is_running());
|
||||
|
@ -106,27 +106,27 @@ int main(int argc, char** argv)
|
|||
toggle_running_action->set_checkable(true);
|
||||
auto& toggle_running_toolbar_button = main_toolbar.add_action(toggle_running_action);
|
||||
|
||||
auto run_one_generation_action = GUI::Action::create("Run &Next Generation", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"), [&](const GUI::Action&) {
|
||||
auto run_one_generation_action = GUI::Action::create("Run &Next Generation", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [&](const GUI::Action&) {
|
||||
statusbar.set_text(click_tip);
|
||||
board_widget.run_generation();
|
||||
});
|
||||
main_toolbar.add_action(run_one_generation_action);
|
||||
|
||||
auto clear_board_action = GUI::Action::create("&Clear board", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png"), [&](auto&) {
|
||||
auto clear_board_action = GUI::Action::create("&Clear board", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
statusbar.set_text(click_tip);
|
||||
board_widget.clear_cells();
|
||||
board_widget.update();
|
||||
});
|
||||
main_toolbar.add_action(clear_board_action);
|
||||
|
||||
auto randomize_cells_action = GUI::Action::create("&Randomize board", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"), [&](auto&) {
|
||||
auto randomize_cells_action = GUI::Action::create("&Randomize board", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
statusbar.set_text(click_tip);
|
||||
board_widget.randomize_cells();
|
||||
board_widget.update();
|
||||
});
|
||||
main_toolbar.add_action(randomize_cells_action);
|
||||
|
||||
auto rotate_pattern_action = GUI::Action::create("&Rotate pattern", { 0, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/redo.png"), [&](auto&) {
|
||||
auto rotate_pattern_action = GUI::Action::create("&Rotate pattern", { 0, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/redo.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
board_widget.selected_pattern()->rotate_clockwise();
|
||||
});
|
||||
rotate_pattern_action->set_enabled(false);
|
||||
|
|
|
@ -117,15 +117,15 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b
|
|||
m_time_label.set_text(String::formatted("{}.{}", m_time_elapsed / 10, m_time_elapsed % 10));
|
||||
};
|
||||
m_timer->set_interval(100);
|
||||
m_mine_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/mine.png");
|
||||
m_flag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png");
|
||||
m_badflag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/badflag.png");
|
||||
m_consider_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/consider.png");
|
||||
m_default_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-default.png");
|
||||
m_good_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-good.png");
|
||||
m_bad_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-bad.png");
|
||||
m_mine_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/mine.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_flag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_badflag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/badflag.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_consider_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/consider.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_default_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-default.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_good_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-good.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_bad_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-bad.png").release_value_but_fixme_should_propagate_errors();
|
||||
for (int i = 0; i < 8; ++i)
|
||||
m_number_bitmap[i] = Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/minesweeper/{}.png", i + 1));
|
||||
m_number_bitmap[i] = Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/minesweeper/{}.png", i + 1)).release_value_but_fixme_should_propagate_errors();
|
||||
// Square with mine will be filled with background color later, i.e. red
|
||||
m_mine_palette.set_color(Gfx::ColorRole::Base, Color::from_rgb(0xff4040));
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ int main(int argc, char** argv)
|
|||
container.layout()->add_spacer();
|
||||
|
||||
auto& flag_image = container.add<GUI::Label>();
|
||||
flag_image.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png"));
|
||||
flag_image.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png").release_value_but_fixme_should_propagate_errors());
|
||||
flag_image.set_fixed_width(16);
|
||||
|
||||
auto& flag_label = container.add<GUI::Label>();
|
||||
|
@ -85,7 +85,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto& time_image = container.add<GUI::Label>();
|
||||
time_image.set_fixed_width(16);
|
||||
time_image.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/timer.png"));
|
||||
time_image.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/timer.png").release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
auto& time_label = container.add<GUI::Label>();
|
||||
time_label.set_fixed_width(50);
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
SnakeGame::SnakeGame()
|
||||
{
|
||||
set_font(Gfx::FontDatabase::default_fixed_width_font().bold_variant());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/paprika.png"));
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/eggplant.png"));
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/cauliflower.png"));
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/tomato.png"));
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/paprika.png").release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/eggplant.png").release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/cauliflower.png").release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/tomato.png").release_value_but_fixme_should_propagate_errors());
|
||||
reset();
|
||||
|
||||
m_high_score = Config::read_i32("Snake", "Snake", "HighScore", 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue