Initial commit
This commit is contained in:
89
main/card_assets.c
Normal file
89
main/card_assets.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "card_assets.h"
|
||||
|
||||
static lv_color_t suit_color(tarot_suit_t suit)
|
||||
{
|
||||
switch (suit) {
|
||||
case TAROT_SUIT_WANDS:
|
||||
return lv_color_hex(0xd8743f);
|
||||
case TAROT_SUIT_CUPS:
|
||||
return lv_color_hex(0x3b83c4);
|
||||
case TAROT_SUIT_SWORDS:
|
||||
return lv_color_hex(0x8a92a6);
|
||||
case TAROT_SUIT_PENTACLES:
|
||||
return lv_color_hex(0x5fa66a);
|
||||
case TAROT_SUIT_NONE:
|
||||
default:
|
||||
return lv_color_hex(0xb88cff);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *suit_glyph(tarot_suit_t suit)
|
||||
{
|
||||
switch (suit) {
|
||||
case TAROT_SUIT_WANDS:
|
||||
return "W";
|
||||
case TAROT_SUIT_CUPS:
|
||||
return "C";
|
||||
case TAROT_SUIT_SWORDS:
|
||||
return "S";
|
||||
case TAROT_SUIT_PENTACLES:
|
||||
return "P";
|
||||
case TAROT_SUIT_NONE:
|
||||
default:
|
||||
return "M";
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_t *card_assets_create_card_art(lv_obj_t *parent, const tarot_card_t *card, bool reversed)
|
||||
{
|
||||
lv_obj_t *art = lv_obj_create(parent);
|
||||
lv_obj_set_size(art, 132, 184);
|
||||
lv_obj_clear_flag(art, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_set_style_radius(art, 8, 0);
|
||||
lv_obj_set_style_border_width(art, 2, 0);
|
||||
if (card == NULL) {
|
||||
lv_obj_set_style_border_color(art, lv_color_hex(0xb88cff), 0);
|
||||
lv_obj_set_style_bg_color(art, lv_color_hex(0xeee7d9), 0);
|
||||
lv_obj_t *missing = lv_label_create(art);
|
||||
lv_label_set_text(missing, "Card");
|
||||
lv_obj_center(missing);
|
||||
return art;
|
||||
}
|
||||
|
||||
lv_obj_set_style_border_color(art, suit_color(card->suit), 0);
|
||||
lv_obj_set_style_bg_color(art, lv_color_hex(0xeee7d9), 0);
|
||||
lv_obj_set_style_pad_all(art, 8, 0);
|
||||
|
||||
lv_obj_t *top = lv_label_create(art);
|
||||
lv_label_set_text_fmt(top, "%02u", card->id);
|
||||
lv_obj_set_style_text_color(top, lv_color_hex(0x30261f), 0);
|
||||
lv_obj_align(top, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
|
||||
lv_obj_t *arcana = lv_label_create(art);
|
||||
lv_label_set_text(arcana, card->arcana == TAROT_ARCANA_MAJOR ? "MAJOR" : suit_glyph(card->suit));
|
||||
lv_obj_set_style_text_color(arcana, suit_color(card->suit), 0);
|
||||
lv_obj_align(arcana, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
|
||||
lv_obj_t *symbol = lv_label_create(art);
|
||||
lv_label_set_text(symbol, suit_glyph(card->suit));
|
||||
lv_obj_set_style_text_color(symbol, suit_color(card->suit), 0);
|
||||
lv_obj_set_style_text_font(symbol, LV_FONT_DEFAULT, 0);
|
||||
lv_obj_align(symbol, LV_ALIGN_CENTER, 0, -16);
|
||||
|
||||
lv_obj_t *name = lv_label_create(art);
|
||||
lv_label_set_text(name, card->name);
|
||||
lv_label_set_long_mode(name, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_width(name, 108);
|
||||
lv_obj_set_style_text_align(name, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_style_text_color(name, lv_color_hex(0x30261f), 0);
|
||||
lv_obj_align(name, LV_ALIGN_CENTER, 0, 42);
|
||||
|
||||
if (reversed) {
|
||||
lv_obj_t *rev = lv_label_create(art);
|
||||
lv_label_set_text(rev, "REV");
|
||||
lv_obj_set_style_text_color(rev, lv_color_hex(0x8b1e2d), 0);
|
||||
lv_obj_align(rev, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
}
|
||||
|
||||
return art;
|
||||
}
|
||||
Reference in New Issue
Block a user