summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCards
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibCards')
-rw-r--r--Userland/Libraries/LibCards/Card.cpp8
-rw-r--r--Userland/Libraries/LibCards/Card.h6
-rw-r--r--Userland/Libraries/LibCards/CardStack.cpp22
-rw-r--r--Userland/Libraries/LibCards/CardStack.h3
4 files changed, 26 insertions, 13 deletions
diff --git a/Userland/Libraries/LibCards/Card.cpp b/Userland/Libraries/LibCards/Card.cpp
index 46c16aefee..00f85894d0 100644
--- a/Userland/Libraries/LibCards/Card.cpp
+++ b/Userland/Libraries/LibCards/Card.cpp
@@ -20,13 +20,13 @@ Card::Card(Suit suit, Rank rank)
VERIFY(to_underlying(rank) < card_count);
}
-void Card::paint(GUI::Painter& painter) const
+void Card::paint(GUI::Painter& painter, bool highlighted) const
{
auto& card_painter = CardPainter::the();
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) {
+ if (highlighted) {
VERIFY(!m_upside_down);
return card_painter.card_front_highlighted(m_suit, m_rank);
}
@@ -46,12 +46,12 @@ void Card::save_old_position()
m_old_position_valid = true;
}
-void Card::clear_and_paint(GUI::Painter& painter, Color background_color)
+void Card::clear_and_paint(GUI::Painter& painter, Color background_color, bool highlighted)
{
if (is_old_position_valid())
clear(painter, background_color);
- paint(painter);
+ paint(painter, highlighted);
save_old_position();
}
diff --git a/Userland/Libraries/LibCards/Card.h b/Userland/Libraries/LibCards/Card.h
index 5cfd9d53cc..72101ff0af 100644
--- a/Userland/Libraries/LibCards/Card.h
+++ b/Userland/Libraries/LibCards/Card.h
@@ -104,13 +104,12 @@ 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();
- void paint(GUI::Painter&) const;
+ void paint(GUI::Painter&, bool highlighted = false) const;
void clear(GUI::Painter&, Color background_color) const;
- void clear_and_paint(GUI::Painter& painter, Color background_color);
+ void clear_and_paint(GUI::Painter& painter, Color background_color, bool highlighted);
private:
Card(Suit, Rank);
@@ -123,7 +122,6 @@ 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/CardStack.cpp b/Userland/Libraries/LibCards/CardStack.cpp
index 1e0e65b4fc..9e7c297225 100644
--- a/Userland/Libraries/LibCards/CardStack.cpp
+++ b/Userland/Libraries/LibCards/CardStack.cpp
@@ -43,8 +43,18 @@ void CardStack::paint(GUI::Painter& painter, Gfx::Color background_color)
return false;
if (!is_empty() && (m_stack.size() != number_of_moving_cards))
return false;
- painter.fill_rect_with_rounded_corners(m_base, background_color.darkened(0.5), Card::card_radius);
- painter.fill_rect_with_rounded_corners(m_base.shrunken(2, 2), background_color, Card::card_radius - 1);
+
+ auto paint_rect = m_base;
+ painter.fill_rect_with_rounded_corners(paint_rect, background_color.darkened(0.5), Card::card_radius);
+ paint_rect.shrink(2, 2);
+
+ if (m_highlighted) {
+ auto background_complement = background_color.xored(Color::White);
+ painter.fill_rect_with_rounded_corners(paint_rect, background_complement, Card::card_radius - 1);
+ paint_rect.shrink(4, 4);
+ }
+
+ painter.fill_rect_with_rounded_corners(paint_rect, background_color, Card::card_radius - 1);
return true;
};
@@ -83,9 +93,11 @@ void CardStack::paint(GUI::Painter& painter, Gfx::Color background_color)
return;
}
- for (auto& card : m_stack) {
- if (!card.is_moving())
- card.clear_and_paint(painter, Gfx::Color::Transparent);
+ for (size_t i = 0; i < m_stack.size(); ++i) {
+ if (auto& card = m_stack[i]; !card.is_moving()) {
+ auto highlighted = m_highlighted && (i == m_stack.size() - 1);
+ card.clear_and_paint(painter, Gfx::Color::Transparent, highlighted);
+ }
}
}
diff --git a/Userland/Libraries/LibCards/CardStack.h b/Userland/Libraries/LibCards/CardStack.h
index b558c18a19..bebbb10a39 100644
--- a/Userland/Libraries/LibCards/CardStack.h
+++ b/Userland/Libraries/LibCards/CardStack.h
@@ -53,6 +53,8 @@ public:
void paint(GUI::Painter&, Gfx::Color background_color);
void clear();
+ void set_highlighted(bool highlighted) { m_highlighted = highlighted; }
+
private:
struct StackRules {
uint8_t shift_x { 0 };
@@ -92,6 +94,7 @@ private:
Type m_type { Type::Invalid };
StackRules m_rules;
Gfx::IntRect m_base;
+ bool m_highlighted { false };
};
}