1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:27:45 +00:00

LibCards: Support highlighting cards of interest

For example, in Solitaire, when dragging a card around, it's common for
other implementations to highlight the card underneath the dragged card
if that other card is a valid drop target. This implementation will draw
a rounded rectangle within the edges of the highlighted card, using a
rudimentary complementary color of the board background color.
This commit is contained in:
Timothy Flynn 2023-01-04 18:25:23 -05:00 committed by Sam Atkins
parent eeb6072f15
commit 2a09807f2e
5 changed files with 54 additions and 1 deletions

View file

@ -9,6 +9,7 @@
#include <AK/Array.h>
#include <LibCards/Card.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Color.h>
namespace Cards {
@ -20,8 +21,10 @@ public:
NonnullRefPtr<Gfx::Bitmap> card_back();
NonnullRefPtr<Gfx::Bitmap> card_front_inverted(Suit, Rank);
NonnullRefPtr<Gfx::Bitmap> card_back_inverted();
NonnullRefPtr<Gfx::Bitmap> card_front_highlighted(Suit, Rank);
void set_background_image_path(DeprecatedString path);
void set_background_color(Color);
private:
CardPainter();
@ -29,13 +32,16 @@ private:
void paint_card_front(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);
Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards;
Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards_inverted;
Array<Array<RefPtr<Gfx::Bitmap>, to_underlying(Rank::__Count)>, to_underlying(Suit::__Count)> m_cards_highlighted;
RefPtr<Gfx::Bitmap> m_card_back;
RefPtr<Gfx::Bitmap> m_card_back_inverted;
DeprecatedString m_background_image_path;
Color m_background_color;
};
}