Serenity Operating System
at hosted 80 lines 2.9 kB view raw
1/* 2 * Copyright (c) 2020, Till Mayer <till.mayer@web.de> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include "Card.h" 30#include <AK/Vector.h> 31 32class CardStack final { 33public: 34 enum Type { 35 Invalid, 36 Stock, 37 Normal, 38 Waste, 39 Foundation 40 }; 41 42 CardStack(); 43 CardStack(const Gfx::Point& position, Type type, uint8_t shift_x, uint8_t shift_y, uint8_t step = 1); 44 45 bool is_dirty() const { return m_dirty; } 46 bool is_empty() const { return m_stack.is_empty(); } 47 bool is_focused() const { return m_focused; } 48 Type type() const { return m_type; } 49 size_t count() const { return m_stack.size(); } 50 const Card& peek() const { return m_stack.last(); } 51 Card& peek() { return m_stack.last(); } 52 const Gfx::Rect& bounding_box() const { return m_bounding_box; } 53 54 void set_focused(bool focused) { m_focused = focused; } 55 void set_dirty() { m_dirty = true; }; 56 57 void push(NonnullRefPtr<Card> card); 58 NonnullRefPtr<Card> pop(); 59 void rebound_cards(); 60 61 bool is_allowed_to_push(const Card&) const; 62 void add_all_grabbed_cards(const Gfx::Point& click_location, NonnullRefPtrVector<Card>& grabbed); 63 void draw(GUI::Painter&, const Gfx::Color& background_color); 64 void clear(); 65 66private: 67 void calculate_bounding_box(); 68 69 NonnullRefPtrVector<Card> m_stack; 70 Vector<Gfx::Point> m_stack_positions; 71 Gfx::Point m_position; 72 Gfx::Rect m_bounding_box; 73 Type m_type { Invalid }; 74 uint8_t m_shift_x { 0 }; 75 uint8_t m_shift_y { 0 }; 76 uint8_t m_step {}; 77 bool m_focused { false }; 78 bool m_dirty { false }; 79 Gfx::Rect m_base; 80};