/* * Copyright (c) 2022-2023, Sam Atkins * Copyright (c) 2023, David Ganz * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Cards { class CardPainter { public: static CardPainter& the(); NonnullRefPtr card_front(Suit, Rank); NonnullRefPtr card_back(); NonnullRefPtr card_front_inverted(Suit, Rank); NonnullRefPtr card_back_inverted(); NonnullRefPtr card_front_highlighted(Suit, Rank); NonnullRefPtr card_front_disabled(Suit, Rank); NonnullRefPtr card_back_disabled(); void set_back_image_path(StringView path); void set_front_images_set_name(StringView path); void set_background_color(Color); private: using PaintCache = Array, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)>; CardPainter(); NonnullRefPtr get_bitmap_or_create(Suit, Rank, PaintCache&, Function); NonnullRefPtr create_card_bitmap(); void paint_card_front(Gfx::Bitmap&, Suit, Rank); void paint_card_front_pips(Gfx::Bitmap&, Suit, Rank); void paint_card_back(Gfx::Bitmap&); void paint_inverted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_invert); void paint_highlighted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_highlight); void paint_disabled_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_disable); Array, to_underlying(Suit::__Count)> m_suit_pips; Array, to_underlying(Suit::__Count)> m_suit_pips_flipped_vertically; PaintCache m_cards; PaintCache m_cards_inverted; PaintCache m_cards_highlighted; PaintCache m_cards_disabled; RefPtr m_card_back; RefPtr m_card_back_inverted; RefPtr m_card_back_disabled; String m_back_image_path; String m_front_images_set_name; Color m_background_color; }; }