mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:57:44 +00:00
LibCards+Solitaire: Elevate card highlight management to the card stack
Instead of indicating which individual cards should be highlighted, card games now indicate which stack is highlighted. This lets the stack draw empty stacks with a highlight (e.g. the Foundation stack in Solitaire). If the stack is non-empty, the stack can delegate highlighting to the top-most card.
This commit is contained in:
parent
8d8fcd0d64
commit
4cbdc747ab
6 changed files with 41 additions and 28 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue