summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-09-28 12:48:01 +0100
committerSam Atkins <atkinssj@gmail.com>2022-10-10 16:16:01 +0100
commit21a818ab50248139e30f77aa8378be7c92e29caf (patch)
tree09e7578ba9eac5ec59a785aa750fa6217d09ac10
parentbfa9ae809f28d3480858c391928b05a44f432f3e (diff)
downloadserenity-21a818ab50248139e30f77aa8378be7c92e29caf.zip
LibCards: Combine CardStack constructors
And while I'm at it, clarify the name of `associated_stack` to `covered_stack`. It's used in exactly one way, so we can make the code clearer by giving it a less generic name.
-rw-r--r--Userland/Libraries/LibCards/CardStack.cpp16
-rw-r--r--Userland/Libraries/LibCards/CardStack.h8
2 files changed, 8 insertions, 16 deletions
diff --git a/Userland/Libraries/LibCards/CardStack.cpp b/Userland/Libraries/LibCards/CardStack.cpp
index ad01cc9736..b6e0348e4f 100644
--- a/Userland/Libraries/LibCards/CardStack.cpp
+++ b/Userland/Libraries/LibCards/CardStack.cpp
@@ -15,18 +15,8 @@ CardStack::CardStack()
{
}
-CardStack::CardStack(Gfx::IntPoint const& position, Type type)
- : m_position(position)
- , m_type(type)
- , m_rules(rules_for_type(type))
- , m_base(m_position, { Card::width, Card::height })
-{
- VERIFY(type != Type::Invalid);
- calculate_bounding_box();
-}
-
-CardStack::CardStack(Gfx::IntPoint const& position, Type type, NonnullRefPtr<CardStack> associated_stack)
- : m_associated_stack(move(associated_stack))
+CardStack::CardStack(Gfx::IntPoint const& position, Type type, RefPtr<CardStack> covered_stack)
+ : m_covered_stack(move(covered_stack))
, m_position(position)
, m_type(type)
, m_rules(rules_for_type(type))
@@ -49,7 +39,7 @@ void CardStack::paint(GUI::Painter& painter, Gfx::Color const& background_color)
for (const auto& card : m_stack)
number_of_moving_cards += card.is_moving();
- if (m_associated_stack && !m_associated_stack->is_empty())
+ if (m_covered_stack && !m_covered_stack->is_empty())
return false;
if (!is_empty() && (m_stack.size() != number_of_moving_cards))
return false;
diff --git a/Userland/Libraries/LibCards/CardStack.h b/Userland/Libraries/LibCards/CardStack.h
index 390ff2e850..9c96513f06 100644
--- a/Userland/Libraries/LibCards/CardStack.h
+++ b/Userland/Libraries/LibCards/CardStack.h
@@ -31,8 +31,7 @@ public:
};
CardStack();
- CardStack(Gfx::IntPoint const& position, Type type);
- CardStack(Gfx::IntPoint const& position, Type type, NonnullRefPtr<CardStack> associated_stack);
+ CardStack(Gfx::IntPoint const& position, Type type, RefPtr<CardStack> covered_stack = nullptr);
bool is_empty() const { return m_stack.is_empty(); }
bool is_focused() const { return m_focused; }
@@ -83,7 +82,10 @@ private:
void calculate_bounding_box();
- RefPtr<CardStack> m_associated_stack;
+ // An optional stack that this stack is painted on top of.
+ // eg, in Solitaire the Play stack is positioned over the Waste stack.
+ RefPtr<CardStack> m_covered_stack;
+
NonnullRefPtrVector<Card> m_stack;
Vector<Gfx::IntPoint> m_stack_positions;
Gfx::IntPoint m_position;