diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-06-04 07:40:16 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-04 19:11:45 +0200 |
commit | 2b762ef94075b8a6e1ae8dd61e535b6b6cf7c064 (patch) | |
tree | cd8a6ee1dd64459b9e1f1996fbd36b4d0040e144 /Userland/Games | |
parent | 4903186cc512b884df44718a2e50586632f76197 (diff) | |
download | serenity-2b762ef94075b8a6e1ae8dd61e535b6b6cf7c064.zip |
Solitaire+LibCards: Draw card stacks with rounded corners
Now that the cards have rounded corners, draw the stack box behind the
cards with rounded corners as well. This way, the corner of the stack
box doesn't peek out from behind the cards.
The caveat here is that the "play" card stack now needs to hold a
reference to the "waste" stack beneath it so it knows when not to draw
its background on top of the waste stack. To faciliate that, the array
of card stacks is now a NonnullRefPtrVector so the play stack can store
a smart pointer to the waste stack (instead of a raw pointer or
reference).
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/Solitaire/Game.cpp | 28 | ||||
-rw-r--r-- | Userland/Games/Solitaire/Game.h | 2 |
2 files changed, 15 insertions, 15 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp index a7a99a6323..81091f242e 100644 --- a/Userland/Games/Solitaire/Game.cpp +++ b/Userland/Games/Solitaire/Game.cpp @@ -21,20 +21,20 @@ Game::Game() { srand(time(nullptr)); - m_stacks[Stock] = CardStack({ 10, 10 }, CardStack::Type::Stock); - m_stacks[Waste] = CardStack({ 10 + Card::width + 10, 10 }, CardStack::Type::Waste); - m_stacks[Play] = CardStack({ 10 + Card::width + 10, 10 }, CardStack::Type::Play); - m_stacks[Foundation4] = CardStack({ Game::width - Card::width - 10, 10 }, CardStack::Type::Foundation); - m_stacks[Foundation3] = CardStack({ Game::width - 2 * Card::width - 20, 10 }, CardStack::Type::Foundation); - m_stacks[Foundation2] = CardStack({ Game::width - 3 * Card::width - 30, 10 }, CardStack::Type::Foundation); - m_stacks[Foundation1] = CardStack({ Game::width - 4 * Card::width - 40, 10 }, CardStack::Type::Foundation); - m_stacks[Pile1] = CardStack({ 10, 10 + Card::height + 10 }, CardStack::Type::Normal); - m_stacks[Pile2] = CardStack({ 10 + Card::width + 10, 10 + Card::height + 10 }, CardStack::Type::Normal); - m_stacks[Pile3] = CardStack({ 10 + 2 * Card::width + 20, 10 + Card::height + 10 }, CardStack::Type::Normal); - m_stacks[Pile4] = CardStack({ 10 + 3 * Card::width + 30, 10 + Card::height + 10 }, CardStack::Type::Normal); - m_stacks[Pile5] = CardStack({ 10 + 4 * Card::width + 40, 10 + Card::height + 10 }, CardStack::Type::Normal); - m_stacks[Pile6] = CardStack({ 10 + 5 * Card::width + 50, 10 + Card::height + 10 }, CardStack::Type::Normal); - m_stacks[Pile7] = CardStack({ 10 + 6 * Card::width + 60, 10 + Card::height + 10 }, CardStack::Type::Normal); + m_stacks.append(adopt_ref(*new CardStack({ 10, 10 }, CardStack::Type::Stock))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + Card::width + 10, 10 }, CardStack::Type::Waste))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + Card::width + 10, 10 }, CardStack::Type::Play, m_stacks.ptr_at(Waste)))); + m_stacks.append(adopt_ref(*new CardStack({ Game::width - 4 * Card::width - 40, 10 }, CardStack::Type::Foundation))); + m_stacks.append(adopt_ref(*new CardStack({ Game::width - 3 * Card::width - 30, 10 }, CardStack::Type::Foundation))); + m_stacks.append(adopt_ref(*new CardStack({ Game::width - 2 * Card::width - 20, 10 }, CardStack::Type::Foundation))); + m_stacks.append(adopt_ref(*new CardStack({ Game::width - Card::width - 10, 10 }, CardStack::Type::Foundation))); + m_stacks.append(adopt_ref(*new CardStack({ 10, 10 + Card::height + 10 }, CardStack::Type::Normal))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + Card::width + 10, 10 + Card::height + 10 }, CardStack::Type::Normal))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + 2 * Card::width + 20, 10 + Card::height + 10 }, CardStack::Type::Normal))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + 3 * Card::width + 30, 10 + Card::height + 10 }, CardStack::Type::Normal))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + 4 * Card::width + 40, 10 + Card::height + 10 }, CardStack::Type::Normal))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + 5 * Card::width + 50, 10 + Card::height + 10 }, CardStack::Type::Normal))); + m_stacks.append(adopt_ref(*new CardStack({ 10 + 6 * Card::width + 60, 10 + Card::height + 10 }, CardStack::Type::Normal))); } Game::~Game() diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h index c782a73778..30168bd13c 100644 --- a/Userland/Games/Solitaire/Game.h +++ b/Userland/Games/Solitaire/Game.h @@ -188,7 +188,7 @@ private: LastMove m_last_move; NonnullRefPtrVector<Card> m_focused_cards; NonnullRefPtrVector<Card> m_new_deck; - CardStack m_stacks[StackLocation::__Count]; + NonnullRefPtrVector<CardStack> m_stacks; CardStack* m_focused_stack { nullptr }; Gfx::IntPoint m_mouse_down_location; |