summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibCards/Card.cpp5
-rw-r--r--Userland/Libraries/LibCards/Card.h2
-rw-r--r--Userland/Libraries/LibCards/CardGame.cpp3
-rw-r--r--Userland/Libraries/LibCards/CardPainter.cpp39
-rw-r--r--Userland/Libraries/LibCards/CardPainter.h6
5 files changed, 54 insertions, 1 deletions
diff --git a/Userland/Libraries/LibCards/Card.cpp b/Userland/Libraries/LibCards/Card.cpp
index 6da1df4015..46c16aefee 100644
--- a/Userland/Libraries/LibCards/Card.cpp
+++ b/Userland/Libraries/LibCards/Card.cpp
@@ -26,7 +26,10 @@ void Card::paint(GUI::Painter& painter) const
auto bitmap = [&]() {
if (m_inverted)
return m_upside_down ? card_painter.card_back_inverted() : card_painter.card_front_inverted(m_suit, m_rank);
-
+ if (m_highlighted) {
+ VERIFY(!m_upside_down);
+ return card_painter.card_front_highlighted(m_suit, m_rank);
+ }
return m_upside_down ? card_painter.card_back() : card_painter.card_front(m_suit, m_rank);
}();
painter.blit(position(), bitmap, bitmap->rect());
diff --git a/Userland/Libraries/LibCards/Card.h b/Userland/Libraries/LibCards/Card.h
index 72251ecdf8..5cfd9d53cc 100644
--- a/Userland/Libraries/LibCards/Card.h
+++ b/Userland/Libraries/LibCards/Card.h
@@ -104,6 +104,7 @@ public:
void set_moving(bool moving) { m_moving = moving; }
void set_upside_down(bool upside_down) { m_upside_down = upside_down; }
void set_inverted(bool inverted) { m_inverted = inverted; }
+ void set_highlighted(bool highlighted) { m_highlighted = highlighted; }
void save_old_position();
@@ -122,6 +123,7 @@ private:
bool m_moving { false };
bool m_upside_down { false };
bool m_inverted { false };
+ bool m_highlighted { false };
};
enum class Shuffle {
diff --git a/Userland/Libraries/LibCards/CardGame.cpp b/Userland/Libraries/LibCards/CardGame.cpp
index c95e401c6b..f910003a8d 100644
--- a/Userland/Libraries/LibCards/CardGame.cpp
+++ b/Userland/Libraries/LibCards/CardGame.cpp
@@ -126,5 +126,8 @@ void CardGame::set_background_color(Gfx::Color color)
auto new_palette = palette();
new_palette.set_color(Gfx::ColorRole::Background, color);
set_palette(new_palette);
+
+ CardPainter::the().set_background_color(color);
}
+
}
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));
+}
+
}
diff --git a/Userland/Libraries/LibCards/CardPainter.h b/Userland/Libraries/LibCards/CardPainter.h
index 6911f361a4..c31df0a8e9 100644
--- a/Userland/Libraries/LibCards/CardPainter.h
+++ b/Userland/Libraries/LibCards/CardPainter.h
@@ -9,6 +9,7 @@
#include <AK/Array.h>
#include <LibCards/Card.h>
#include <LibGfx/Bitmap.h>
+#include <LibGfx/Color.h>
namespace Cards {
@@ -20,8 +21,10 @@ public:
NonnullRefPtr<Gfx::Bitmap> card_back();
NonnullRefPtr<Gfx::Bitmap> card_front_inverted(Suit, Rank);
NonnullRefPtr<Gfx::Bitmap> card_back_inverted();
+ NonnullRefPtr<Gfx::Bitmap> card_front_highlighted(Suit, Rank);
void set_background_image_path(DeprecatedString path);
+ void set_background_color(Color);
private:
CardPainter();
@@ -29,13 +32,16 @@ private:
void paint_card_front(Gfx::Bitmap&, Suit, Rank);
void paint_card_back(Gfx::Bitmap&);
void paint_inverted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_invert);
+ void paint_highlighted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_highlight);
Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards;
Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards_inverted;
+ Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards_highlighted;
RefPtr<Gfx::Bitmap> m_card_back;
RefPtr<Gfx::Bitmap> m_card_back_inverted;
DeprecatedString m_background_image_path;
+ Color m_background_color;
};
}