summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLenny Maiorani <lenny@serenityos.org>2022-03-17 15:01:03 -0600
committerAndreas Kling <kling@serenityos.org>2022-03-18 19:59:43 +0100
commit56046d3f9bf65591f64880b914778c291b329ade (patch)
tree823ae3637a243ee1ab5363fb6f208a55d03eb481 /Userland
parentd3893a73fbb80697bbf322398bc93c6cd21ea679 (diff)
downloadserenity-56046d3f9bf65591f64880b914778c291b329ade.zip
Libraries: Change enums to enum classes in LibCards
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Games/Solitaire/Game.cpp2
-rw-r--r--Userland/Games/Spider/Game.cpp6
-rw-r--r--Userland/Libraries/LibCards/Card.cpp8
-rw-r--r--Userland/Libraries/LibCards/Card.h4
-rw-r--r--Userland/Libraries/LibCards/CardStack.cpp46
-rw-r--r--Userland/Libraries/LibCards/CardStack.h20
6 files changed, 43 insertions, 43 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp
index 56bac80518..c46b5c3500 100644
--- a/Userland/Games/Solitaire/Game.cpp
+++ b/Userland/Games/Solitaire/Game.cpp
@@ -90,7 +90,7 @@ void Game::timer_event(Core::TimerEvent&)
void Game::create_new_animation_card()
{
- auto card = Card::construct(static_cast<Card::Type>(get_random_uniform(Card::Type::__Count)), get_random_uniform(Card::card_count));
+ auto card = Card::construct(static_cast<Card::Type>(get_random_uniform(to_underlying(Card::Type::__Count))), get_random_uniform(Card::card_count));
card->set_position({ get_random_uniform(Game::width - Card::width), get_random_uniform(Game::height / 8) });
int x_sgn = card->position().x() > (Game::width / 2) ? -1 : 1;
diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp
index f68225e494..a762419ed8 100644
--- a/Userland/Games/Spider/Game.cpp
+++ b/Userland/Games/Spider/Game.cpp
@@ -260,7 +260,7 @@ void Game::mousedown_event(GUI::MouseEvent& event)
update(top_card.rect());
}
} else if (m_focused_cards.is_empty()) {
- to_check.add_all_grabbed_cards(click_location, m_focused_cards, Cards::CardStack::Same);
+ to_check.add_all_grabbed_cards(click_location, m_focused_cards, Cards::CardStack::MovementRule::Same);
m_mouse_down_location = click_location;
if (m_focused_stack)
m_focused_stack->set_focused(false);
@@ -310,7 +310,7 @@ void Game::mouseup_event(GUI::MouseEvent& event)
if (stack.is_focused())
continue;
- if (stack.is_allowed_to_push(m_focused_cards.at(0), m_focused_cards.size(), Cards::CardStack::Any) && !stack.is_empty()) {
+ if (stack.is_allowed_to_push(m_focused_cards.at(0), m_focused_cards.size(), Cards::CardStack::MovementRule::Any) && !stack.is_empty()) {
move_focused_cards(stack);
rebound = false;
@@ -324,7 +324,7 @@ void Game::mouseup_event(GUI::MouseEvent& event)
for (auto& focused_card : m_focused_cards) {
if (stack.bounding_box().intersects(focused_card.rect())) {
- if (stack.is_allowed_to_push(m_focused_cards.at(0), m_focused_cards.size(), Cards::CardStack::Any)) {
+ if (stack.is_allowed_to_push(m_focused_cards.at(0), m_focused_cards.size(), Cards::CardStack::MovementRule::Any)) {
move_focused_cards(stack);
rebound = false;
diff --git a/Userland/Libraries/LibCards/Card.cpp b/Userland/Libraries/LibCards/Card.cpp
index b42116fa80..9378ae5964 100644
--- a/Userland/Libraries/LibCards/Card.cpp
+++ b/Userland/Libraries/LibCards/Card.cpp
@@ -112,14 +112,14 @@ Card::Card(Type type, uint8_t value)
auto const& symbol = [&]() -> Gfx::CharacterBitmap const& {
switch (m_type) {
- case Diamonds:
+ case Type::Diamonds:
return s_diamond;
- case Clubs:
+ case Type::Clubs:
return s_club;
break;
- case Spades:
+ case Type::Spades:
return s_spade;
- case Hearts:
+ case Type::Hearts:
return s_heart;
default:
VERIFY_NOT_REACHED();
diff --git a/Userland/Libraries/LibCards/Card.h b/Userland/Libraries/LibCards/Card.h
index 78e7c5fc03..babca06b7c 100644
--- a/Userland/Libraries/LibCards/Card.h
+++ b/Userland/Libraries/LibCards/Card.h
@@ -29,7 +29,7 @@ public:
"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
};
- enum Type {
+ enum class Type {
Clubs,
Diamonds,
Spades,
@@ -49,7 +49,7 @@ public:
bool is_moving() const { return m_moving; }
bool is_upside_down() const { return m_upside_down; }
bool is_inverted() const { return m_inverted; }
- Gfx::Color color() const { return (m_type == Diamonds || m_type == Hearts) ? Color::Red : Color::Black; }
+ Gfx::Color color() const { return (m_type == Type::Diamonds || m_type == Type::Hearts) ? Color::Red : Color::Black; }
void set_position(const Gfx::IntPoint p) { m_rect.set_location(p); }
void set_moving(bool moving) { m_moving = moving; }
diff --git a/Userland/Libraries/LibCards/CardStack.cpp b/Userland/Libraries/LibCards/CardStack.cpp
index dffbb41160..7726f4e554 100644
--- a/Userland/Libraries/LibCards/CardStack.cpp
+++ b/Userland/Libraries/LibCards/CardStack.cpp
@@ -10,7 +10,7 @@ namespace Cards {
CardStack::CardStack()
: m_position({ 0, 0 })
- , m_type(Invalid)
+ , m_type(Type::Invalid)
, m_base(m_position, { Card::width, Card::height })
{
}
@@ -21,7 +21,7 @@ CardStack::CardStack(const Gfx::IntPoint& position, Type type)
, m_rules(rules_for_type(type))
, m_base(m_position, { Card::width, Card::height })
{
- VERIFY(type != Invalid);
+ VERIFY(type != Type::Invalid);
calculate_bounding_box();
}
@@ -32,7 +32,7 @@ CardStack::CardStack(const Gfx::IntPoint& position, Type type, NonnullRefPtr<Car
, m_rules(rules_for_type(type))
, m_base(m_position, { Card::width, Card::height })
{
- VERIFY(type != Invalid);
+ VERIFY(type != Type::Invalid);
calculate_bounding_box();
}
@@ -59,13 +59,13 @@ void CardStack::draw(GUI::Painter& painter, const Gfx::Color& background_color)
};
switch (m_type) {
- case Stock:
+ case Type::Stock:
if (draw_background_if_empty()) {
painter.fill_rect(m_base.shrunken(Card::width / 4, Card::height / 4), background_color.lightened(1.5));
painter.fill_rect(m_base.shrunken(Card::width / 2, Card::height / 2), background_color);
}
break;
- case Foundation:
+ case Type::Foundation:
if (draw_background_if_empty()) {
for (int y = 0; y < (m_base.height() - 4) / 8; ++y) {
for (int x = 0; x < (m_base.width() - 4) / 5; ++x) {
@@ -74,11 +74,11 @@ void CardStack::draw(GUI::Painter& painter, const Gfx::Color& background_color)
}
}
break;
- case Play:
- case Normal:
+ case Type::Play:
+ case Type::Normal:
draw_background_if_empty();
break;
- case Waste:
+ case Type::Waste:
break;
default:
VERIFY_NOT_REACHED();
@@ -112,7 +112,7 @@ void CardStack::add_all_grabbed_cards(const Gfx::IntPoint& click_location, Nonnu
{
VERIFY(grabbed.is_empty());
- if (m_type != Normal) {
+ if (m_type != Type::Normal) {
auto& top_card = peek();
if (top_card.rect().contains(click_location)) {
top_card.set_moving(true);
@@ -159,13 +159,13 @@ void CardStack::add_all_grabbed_cards(const Gfx::IntPoint& click_location, Nonnu
if (i != 0) {
bool color_match;
switch (movement_rule) {
- case Alternating:
+ case MovementRule::Alternating:
color_match = card.color() != last_color;
break;
- case Same:
+ case MovementRule::Same:
color_match = card.color() == last_color;
break;
- case Any:
+ case MovementRule::Any:
color_match = true;
break;
}
@@ -189,18 +189,18 @@ void CardStack::add_all_grabbed_cards(const Gfx::IntPoint& click_location, Nonnu
bool CardStack::is_allowed_to_push(const Card& card, size_t stack_size, MovementRule movement_rule) const
{
- if (m_type == Stock || m_type == Waste || m_type == Play)
+ if (m_type == Type::Stock || m_type == Type::Waste || m_type == Type::Play)
return false;
- if (m_type == Normal && is_empty()) {
+ if (m_type == Type::Normal && is_empty()) {
// FIXME: proper solution for this
- if (movement_rule == Alternating) {
+ if (movement_rule == MovementRule::Alternating) {
return card.value() == 12;
}
return true;
}
- if (m_type == Foundation && is_empty())
+ if (m_type == Type::Foundation && is_empty())
return card.value() == 0;
if (!is_empty()) {
@@ -208,21 +208,21 @@ bool CardStack::is_allowed_to_push(const Card& card, size_t stack_size, Movement
if (top_card.is_upside_down())
return false;
- if (m_type == Foundation) {
+ if (m_type == Type::Foundation) {
// Prevent player from dragging an entire stack of cards to the foundation stack
if (stack_size > 1)
return false;
return top_card.type() == card.type() && m_stack.size() == card.value();
- } else if (m_type == Normal) {
+ } else if (m_type == Type::Normal) {
bool color_match;
switch (movement_rule) {
- case Alternating:
+ case MovementRule::Alternating:
color_match = card.color() != top_card.color();
break;
- case Same:
+ case MovementRule::Same:
color_match = card.color() == top_card.color();
break;
- case Any:
+ case MovementRule::Any:
color_match = true;
break;
}
@@ -248,7 +248,7 @@ void CardStack::push(NonnullRefPtr<Card> card)
top_most_position.translate_by(m_rules.shift_x, m_rules.shift_y);
}
- if (m_type == Stock)
+ if (m_type == Type::Stock)
card->set_upside_down(true);
card->set_position(top_most_position);
@@ -263,7 +263,7 @@ NonnullRefPtr<Card> CardStack::pop()
auto card = m_stack.take_last();
calculate_bounding_box();
- if (m_type == Stock)
+ if (m_type == Type::Stock)
card->set_upside_down(false);
m_stack_positions.take_last();
diff --git a/Userland/Libraries/LibCards/CardStack.h b/Userland/Libraries/LibCards/CardStack.h
index f79ce18336..82e39f7bf3 100644
--- a/Userland/Libraries/LibCards/CardStack.h
+++ b/Userland/Libraries/LibCards/CardStack.h
@@ -15,7 +15,7 @@ namespace Cards {
class CardStack final : public RefCounted<CardStack> {
public:
- enum Type {
+ enum class Type {
Invalid,
Stock,
Normal,
@@ -24,7 +24,7 @@ public:
Foundation
};
- enum MovementRule {
+ enum class MovementRule {
Alternating,
Same,
Any,
@@ -50,8 +50,8 @@ public:
void move_to_stack(CardStack&);
void rebound_cards();
- bool is_allowed_to_push(const Card&, size_t stack_size = 1, MovementRule movement_rule = Alternating) const;
- void add_all_grabbed_cards(const Gfx::IntPoint& click_location, NonnullRefPtrVector<Card>& grabbed, MovementRule movement_rule = Alternating);
+ bool is_allowed_to_push(const Card&, size_t stack_size = 1, MovementRule movement_rule = MovementRule::Alternating) const;
+ void add_all_grabbed_cards(const Gfx::IntPoint& click_location, NonnullRefPtrVector<Card>& grabbed, MovementRule movement_rule = MovementRule::Alternating);
void draw(GUI::Painter&, const Gfx::Color& background_color);
void clear();
@@ -66,15 +66,15 @@ private:
constexpr StackRules rules_for_type(Type stack_type)
{
switch (stack_type) {
- case Foundation:
+ case Type::Foundation:
return { 2, 1, 4, 1 };
- case Normal:
+ case Type::Normal:
return { 0, 20, 1, 3 };
- case Stock:
+ case Type::Stock:
return { 2, 1, 8, 1 };
- case Waste:
+ case Type::Waste:
return { 0, 0, 1, 0 };
- case Play:
+ case Type::Play:
return { 20, 0, 1, 0 };
default:
return {};
@@ -88,7 +88,7 @@ private:
Vector<Gfx::IntPoint> m_stack_positions;
Gfx::IntPoint m_position;
Gfx::IntRect m_bounding_box;
- Type m_type { Invalid };
+ Type m_type { Type::Invalid };
StackRules m_rules;
bool m_focused { false };
Gfx::IntRect m_base;