diff options
Diffstat (limited to 'Userland/Libraries/LibCards/CardPainter.cpp')
-rw-r--r-- | Userland/Libraries/LibCards/CardPainter.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCards/CardPainter.cpp b/Userland/Libraries/LibCards/CardPainter.cpp index c2c869617a..e073f9feae 100644 --- a/Userland/Libraries/LibCards/CardPainter.cpp +++ b/Userland/Libraries/LibCards/CardPainter.cpp @@ -102,6 +102,21 @@ NonnullRefPtr<Gfx::Bitmap> CardPainter::card_back() return *m_card_back; } +NonnullRefPtr<Gfx::Bitmap> CardPainter::card_front_highlighted(Suit suit, Rank rank) +{ + auto suit_id = to_underlying(suit); + auto rank_id = to_underlying(rank); + + auto& existing_bitmap = m_cards_highlighted[suit_id][rank_id]; + if (!existing_bitmap.is_null()) + return *existing_bitmap; + + m_cards_highlighted[suit_id][rank_id] = create_card_bitmap(); + paint_highlighted_card(*m_cards_highlighted[suit_id][rank_id], card_front(suit, rank)); + + return *m_cards_highlighted[suit_id][rank_id]; +} + NonnullRefPtr<Gfx::Bitmap> CardPainter::card_front_inverted(Suit suit, Rank rank) { auto suit_id = to_underlying(suit); @@ -140,6 +155,17 @@ void CardPainter::set_background_image_path(DeprecatedString path) paint_inverted_card(*m_card_back_inverted, *m_card_back); } +void CardPainter::set_background_color(Color background_color) +{ + m_background_color = background_color; + + // Clear any cached card bitmaps that depend on the background color. + for (auto& suit_array : m_cards_highlighted) { + for (auto& rank_array : suit_array) + rank_array = nullptr; + } +} + NonnullRefPtr<Gfx::Bitmap> CardPainter::create_card_bitmap() { return Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { Card::width, Card::height }).release_value_but_fixme_should_propagate_errors(); @@ -212,4 +238,17 @@ void CardPainter::paint_inverted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& so }); } +void CardPainter::paint_highlighted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_highlight) +{ + Gfx::Painter painter { bitmap }; + auto paint_rect = source_to_highlight.rect(); + auto background_complement = m_background_color.xored(Color::White); + + painter.fill_rect_with_rounded_corners(paint_rect, Color::Black, Card::card_radius); + paint_rect.shrink(2, 2); + painter.fill_rect_with_rounded_corners(paint_rect, background_complement, Card::card_radius - 1); + paint_rect.shrink(2, 2); + painter.blit({ 4, 4 }, source_to_highlight, source_to_highlight.rect().shrunken(8, 8)); +} + } |