#include "TableauColumn.h" #include "utils/RenderBuffer.h" #define max(a, b) a>b?a:b void TableauColumn::Reset() { cards->empty(); } void TableauColumn::AddCard(Card *c) { cards->add(c); } void TableauColumn::AddRange(List *hand) { for (auto *item: *hand) { cards->add(item); } } void TableauColumn::Render(uint8_t x, uint8_t y, bool selected, uint8_t selection_from_end, RenderBuffer *buffer) { // If the hand is empty FURI_LOG_D("Tableau", "%i %i, count %li", x, y, cards->count); if (cards->count == 0) { Card::RenderEmptyCard(x, y, buffer); if (selected) buffer->draw_rbox(x, y, x + 16, y + 22, Flip); return; } uint8_t selection = cards->count - selection_from_end; uint8_t loop_end = cards->count; uint8_t loop_start = max(loop_end - 4, 0); uint8_t position = 0; uint8_t first_non_flipped = FirstNonFlipped(); bool had_top = false; // Draw the first flipped and non-flipped card with adjusted visibility if (first_non_flipped <= loop_start && selection != first_non_flipped) { // Draw a card back if it is not the first card if (first_non_flipped > 0) { Card::RenderBack(x,y+position, selection == first_non_flipped, buffer); // Increment loop start index and position position += 4; loop_start++; had_top=true; } // Draw the front side of the first non-flipped card (*cards)[first_non_flipped]->Render(x, y + position, selection == first_non_flipped, buffer); position += 8; loop_start++; // Increment loop start index } // Draw the selected card with adjusted visibility if (loop_start > selection) { if(!had_top && first_non_flipped>0){ Card::RenderBack(x,y+position, selection == first_non_flipped, buffer); position+=2; loop_start++; } // Draw the front side of the selected card (*cards)[selection]->Render(x, y + position, true, buffer); position += 8; loop_start++; // Increment loop start index } //Draw the rest for (uint8_t i = loop_start; i < loop_end; i++, position += 4) { (*cards)[i]->Render(x, y + position, i == selection, buffer); if (i == selection || i == first_non_flipped) position += 4; } } int8_t TableauColumn::FirstNonFlipped() { int8_t index = -1; if (cards->count > 0) { /* ListItem *c = cards->start; while (c){ index++; if (c->data->exposed) { break; } c=c->next; }*/ for (auto *card: *cards) { index++; if (card && card->exposed) { break; } } } return index; } TableauColumn::TableauColumn() { cards = new List(); } TableauColumn::~TableauColumn() { delete cards; }