CardPainter.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Array.h>
  8. #include <AK/String.h>
  9. #include <LibCards/Card.h>
  10. #include <LibGfx/Bitmap.h>
  11. #include <LibGfx/Color.h>
  12. namespace Cards {
  13. class CardPainter {
  14. public:
  15. static CardPainter& the();
  16. NonnullRefPtr<Gfx::Bitmap> card_front(Suit, Rank);
  17. NonnullRefPtr<Gfx::Bitmap> card_back();
  18. NonnullRefPtr<Gfx::Bitmap> card_front_inverted(Suit, Rank);
  19. NonnullRefPtr<Gfx::Bitmap> card_back_inverted();
  20. NonnullRefPtr<Gfx::Bitmap> card_front_highlighted(Suit, Rank);
  21. void set_background_image_path(StringView path);
  22. void set_front_images_set_name(StringView path);
  23. void set_background_color(Color);
  24. private:
  25. CardPainter();
  26. NonnullRefPtr<Gfx::Bitmap> create_card_bitmap();
  27. void paint_card_front(Gfx::Bitmap&, Suit, Rank);
  28. void paint_card_front_pips(Gfx::Bitmap&, Suit, Rank);
  29. void paint_card_back(Gfx::Bitmap&);
  30. void paint_inverted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_invert);
  31. void paint_highlighted_card(Gfx::Bitmap& bitmap, Gfx::Bitmap const& source_to_highlight);
  32. Array<RefPtr<Gfx::Bitmap>, to_underlying(Suit::__Count)> m_suit_pips;
  33. Array<RefPtr<Gfx::Bitmap>, to_underlying(Suit::__Count)> m_suit_pips_flipped_vertically;
  34. Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards;
  35. Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards_inverted;
  36. Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards_highlighted;
  37. RefPtr<Gfx::Bitmap> m_card_back;
  38. RefPtr<Gfx::Bitmap> m_card_back_inverted;
  39. String m_background_image_path;
  40. String m_front_images_set_name;
  41. Color m_background_color;
  42. };
  43. }