So while the framebuffer works but don't like the whole drop out of gui just to run my gui..
Was actually trying to get SDL2 working and had troubles so I got the framebuffer working..
Success today and thinking it's easier than all the trouble I went through..
First I installed libsdl2-2.0-0 using the Synaptic Package Manager, no issues..
Got stopped trying to install the dev package, got a conflict with dependent lib that has a new qcom version installed..
I downloaded the source tar.gz from gitHub SDL release-2.32.4..
extracted to my /projects/libs/ folder and renamed it to SDL2
opened a terminal to the SDL2 folder..
cmake -S . -B build
cmake --build build
took a while but got a clean build..
I moved my LovyanGFX folder to the /libs/ folder too..
Copied the /libs/LovyAnGFX/examples_for_PC/CMake_SDL to the /projects folder..
fixed up the cmakelists file and got a clean compile..
ported solitaire and nesso mazes..
mazes still a work in progress as i need to try and figure out mcu access..
here's the user_code.cpp..
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <LGFX_AUTODETECT.hpp>
#include <string>
//#include "cards.h"
#include "bigcards.h"
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720
LGFX Display(1280, 720);
LGFX_Sprite Sprite(&Display);
int8_t ButtonWidth = 60;
int8_t ButtonHeight = 30;
int8_t CardWidth = 72;
int8_t CardHeight = 110;
int8_t CardBack = 52;
int8_t CardOL = 30;
int8_t Border = 20;
int8_t Gap = 30;
int TableWidth = (CardWidth * 7) + (Gap * 6) + (Border * 2);
int TableHeight = (CardHeight * 2) + (Border * 2) + (CardOL * 12) + (Gap *2) + ButtonHeight;
int TableLeft = (SCREEN_WIDTH - TableWidth) / 2;
int TableTop = (SCREEN_HEIGHT - TableHeight) / 2;
int8_t Deck[52];
int8_t HiddenTabs[6][6];
int8_t Tableau[7][13];
int8_t Foundations[4][13];
int8_t Stock[24];
int8_t Waste[24];
int8_t StockCount = 0;
int8_t WasteCount = 0;
int8_t CurrentCard = 0;
int8_t TableauCounts[7] = {0, 0, 0, 0, 0, 0, 0};
int8_t HiddenCounts[7] = {0, 0, 0, 0, 0, 0, 0};
int8_t FoundationCounts[4] = {0, 0, 0, 0};
int8_t SelectedCard = -1;
int8_t SelectedArea = -1;
int8_t SelectCount = 0;
struct TouchSpot
{
int x;
int y;
int w;
int h;
int area;
};
TouchSpot Spots[13];
TouchSpot Button;
struct SelectionRect
{
int x;
int y;
int w;
int h;
};
SelectionRect SelectRect;
SelectionRect BattLevelRect,BattVoltageRect,BattChargingRect;
unsigned long lastTouch;
unsigned long touchDebounce = 200;
unsigned long now;
unsigned long lastBattCheck;
unsigned long battCheckInterval = 1000;
bool debug = true;
// forward declarations..
void CutDeck(int8_t *deck, int size);
void shuffle(int8_t *array, int size);
unsigned long millis();
void SetupTable();
void StockFlip();
bool TouchArea(int px, int py, int x, int y, int w, int h);
void CheckScreenTouch(int tx, int ty);
void HandleTouch(int spot, int y);
bool CheckFoundationMove(int f);
void MoveToFoundations(int f);
void SelectFoundation(int f);
int GetCardColor(int acard);
int GetCardNumber(int acard);
bool CheckTableauMove(int a);
void MoveToTableau(int a);
void SelectTableau(int a, int y);
void DrawSelection();
unsigned long millis()
{
unsigned long ms;
ms = lgfx::millis();
return ms;
}
void SetupTable()
{
// clear out the old values..
memset(HiddenTabs, -1, sizeof(HiddenTabs));
memset(Tableau, -1, sizeof(Tableau));
memset(Foundations, -1, sizeof(Foundations));
memset(Stock, -1, sizeof(Stock));
memset(Waste, -1, sizeof(Waste));
memset(HiddenCounts, 0, sizeof(HiddenCounts));
StockCount = 0;
WasteCount = 0;
CurrentCard = 0;
for (int i = 0; i < sizeof(TableauCounts); i++)
{
TableauCounts[i] = 1;
if (i < sizeof(FoundationCounts))
FoundationCounts[i] = 0;
}
shuffle(Deck, sizeof(Deck));
CutDeck(Deck,sizeof(Deck));
shuffle(Deck, sizeof(Deck));
CutDeck(Deck,sizeof(Deck));
// fill the tableau
int c = 0;
for (int j = 0; j < 7; j++)
{
Tableau[j][0] = Deck[c];
c++;
for (int i = j; i < 6; i++)
{
HiddenTabs[i][j] = Deck[c];
HiddenCounts[i + 1]++;
c++;
}
}
// fill stock
StockCount = 52 - c;
int p = 0;
for (int i = c; i < 52; i++)
{
Stock[p] = Deck[c];
p++;
c++;
}
printf("Card #:%d \n", c);
printf("Stock Count : %d \n", StockCount);
printf("Size of HiddenTabs: %d \n", sizeof(HiddenTabs));
printf("Size of spots: %d\n", sizeof(Spots) / sizeof(Spots[0]));
for (int i = 0; i < sizeof(HiddenCounts); i++)
{
printf("Count # %d = %d\n", i + 1, HiddenCounts[i]);
}
Sprite.fillSprite(TFT_DARKGREEN);
int sw, sh, x, y;
sw = Display.width();
sh = Display.height();
y = Border;
x = sw - (200 + Border);
BattLevelRect.x = x;
BattLevelRect.y = y;
BattLevelRect.w = 200;
BattLevelRect.h = 60;
Sprite.setFont(&fonts::FreeSansBold9pt7b);
Sprite.setTextSize(1);
Sprite.setTextColor(TFT_BLACK);
Sprite.fillRoundRect(x,y,200,60,4,TFT_WHITE);
Sprite.drawRoundRect(x,y,200,60,4,TFT_YELLOW);
Sprite.setTextColor(TFT_BLACK);
Sprite.setColor(TFT_WHITE);
//Sprite.setTextFont(1);
Sprite.setFont(&fonts::FreeSansBold9pt7b);
Sprite.setTextSize(1);
//Sprite.drawString("Is Charging",x+3,y+3);
//Sprite.drawString("Yes",x+3,y+30);
y+= 60+ Gap;
//x -= (200 + Gap);
BattVoltageRect.x = x;
BattVoltageRect.y = y;
BattVoltageRect.w = 200;
BattVoltageRect.h = 60;
Sprite.fillRoundRect(x,y,200,60,4,TFT_WHITE);
Sprite.drawRoundRect(x,y,200,60,4,TFT_YELLOW);
y+= 60 + Gap;
//x -= (200 + Gap);
BattChargingRect.x = x;
BattChargingRect.y = y;
BattChargingRect.w = 200;
BattChargingRect.h = 60;
Sprite.fillRoundRect(x,y,200,60,4,TFT_WHITE);
Sprite.drawRoundRect(x,y,200,60,4,TFT_YELLOW);
x = Border + TableLeft;
y = Border + TableTop;
Button.x = x;
Button.y = y;
Button.w = ButtonWidth;
Button.h = ButtonHeight;
Sprite.fillRoundRect(x,y, ButtonWidth, ButtonHeight, 8 , TFT_LIGHTGRAY);
Sprite.setTextColor(TFT_BLACK);
Sprite.drawString("New",x+3,y+6);
Sprite.drawRoundRect(x, y, ButtonWidth, ButtonHeight,8, TFT_YELLOW);
y+=ButtonHeight+Gap;
Spots[0].y = y;
Spots[0].x = x;
Spots[0].h = CardHeight;
Spots[0].w = CardWidth;
Spots[0].area = 1;
Sprite.pushImage(x, y, CardWidth, CardHeight, card[CardBack]);
Sprite.drawRect(x, y, CardWidth, CardHeight, TFT_YELLOW);
x += CardWidth + Gap;
Spots[1].y = y;
Spots[1].x = x;
Spots[1].h = CardHeight;
Spots[1].w = CardWidth;
Spots[1].area = 2;
Sprite.drawRect(x, y, CardWidth, CardHeight, TFT_YELLOW);
x += (CardWidth + Gap) * 2;
for (int i = 0; i < 4; i++)
{
Spots[i + 2].y = y;
Spots[i + 2].x = x;
Spots[i + 2].h = CardHeight;
Spots[i + 2].w = CardWidth;
Spots[i + 2].area = i + 3;
Sprite.drawRect(x, y, CardWidth, CardHeight, TFT_YELLOW);
x += CardWidth + Gap;
}
x = Border + TableLeft;
y = CardHeight + Border + Gap + TableTop+ButtonHeight+Gap;
for (int i = 0; i < 7; i++)
{
Spots[i + 6].y = y;
Spots[i + 6].x = x;
Spots[i + 6].h = CardHeight;
Spots[i + 6].w = CardWidth;
Spots[i + 6].area = i + 7;
if (i > 0)
{
Sprite.pushImage(x, y, CardWidth, CardHeight, card[CardBack]);
}
Sprite.drawRect(x, y, CardWidth, CardHeight, TFT_YELLOW);
Sprite.pushImage(x, y + CardOL, CardWidth, CardHeight, card[Tableau[i][0]]);
Sprite.drawRect(x, y + CardOL, CardWidth, CardHeight, TFT_YELLOW);
x += CardWidth + Gap;
}
// show it..
//Sprite.pushImage(2, 2 , 72, 110, KS);
Sprite.pushSprite(0, 0);
}
void StockFlip()
{
if (SelectedCard > -1){
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
DrawSelection();
}
if (StockCount == 0)
{
// restock..
int flip = WasteCount - 1;
for (int i = 0; i < WasteCount; i++)
{
Stock[i] = Waste[flip--];
}
StockCount = WasteCount;
WasteCount = 0;
Sprite.pushImage(Spots[0].x, Spots[0].y, CardWidth, CardHeight, card[CardBack]);
Sprite.drawRoundRect(Spots[0].x, Spots[0].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
// flip the next stock card over..
Waste[WasteCount] = Stock[StockCount - 1];
WasteCount++;
Stock[StockCount - 1] = -1;
if (StockCount > 0)
StockCount--;
if (StockCount == 0)
{
// no more stock..
Sprite.fillRect(Spots[0].x, Spots[0].y, CardWidth, CardHeight, TFT_DARKGREEN);
Sprite.drawRoundRect(Spots[0].x, Spots[0].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
printf("card:%d\n", Waste[WasteCount - 1]);
Sprite.pushImage(Spots[1].x, Spots[1].y, CardWidth, CardHeight, card[Waste[WasteCount - 1]]);
Sprite.drawRoundRect(Spots[1].x, Spots[1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
Sprite.pushSprite(0, 0);
}
void SelectWaste()
{
if (WasteCount > 0)
{
printf("Waste Card Selected: %d\n", Waste[WasteCount - 1]);
SelectedCard = Waste[WasteCount - 1];
SelectedArea = 2;
SelectCount = 1;
SelectRect.x = Spots[1].x;
SelectRect.y = Spots[1].y;
SelectRect.w = Spots[1].w;
SelectRect.h = Spots[1].h;
DrawSelection();
}
else
printf("No Waste..\n");
}
bool CheckFoundationMove(int f)
{
bool result = false;
int nextCard;
if (FoundationCounts[f - 3] > 0)
{
if (FoundationCounts[f - 3] == 1)
{
// it's the ace..
nextCard = Foundations[f - 3][FoundationCounts[f - 3] - 1] - 12;
}
else
{
nextCard = Foundations[f - 3][FoundationCounts[f - 3] - 1] + 1;
}
if (SelectedCard == nextCard)
result = true;
}
else
{
// looking for an ace
switch (SelectedCard)
{
case 12:
case 25:
case 38:
case 51:
result = true;
break;
}
}
return result;
}
void MoveToFoundations(int f)
{
//
printf("Move to Foundation. Card:%d Area:%d\n", SelectedCard, SelectedArea);
if (SelectedArea == 2 && SelectedCard > -1)
{
// move a waste card..
Foundations[f - 3][FoundationCounts[f - 3]] = Waste[WasteCount - 1];
FoundationCounts[f - 3]++;
Waste[WasteCount - 1] = -1;
WasteCount--;
if (WasteCount < 1)
{
Sprite.fillRect(Spots[1].x, Spots[1].y, CardWidth, CardHeight, TFT_DARKGREEN);
Sprite.drawRoundRect(Spots[1].x, Spots[1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
else
{
Sprite.pushImage(Spots[1].x, Spots[1].y, CardWidth, CardHeight, card[Waste[WasteCount - 1]]);
Sprite.drawRoundRect(Spots[1].x, Spots[1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
Sprite.pushImage(Spots[f - 1].x, Spots[f - 1].y, CardWidth, CardHeight, card[Foundations[f - 3][FoundationCounts[f - 3] - 1]]);
Sprite.drawRoundRect(Spots[f - 1].x, Spots[f - 1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
Sprite.pushSprite(0, 0);
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
DrawSelection();
}
else
{
if (SelectedArea > 6)
{
// moving from the tasbleau
if (SelectedCard == Tableau[SelectedArea - 7][TableauCounts[SelectedArea - 7] - 1])
{
// can only move a top card..
Foundations[f - 3][FoundationCounts[f - 3]] = Tableau[SelectedArea - 7][TableauCounts[SelectedArea - 7] - 1];
FoundationCounts[f - 3]++;
Tableau[SelectedArea - 7][TableauCounts[SelectedArea - 7] - 1] = -1;
TableauCounts[SelectedArea - 7]--;
int newy = CardOL * TableauCounts[SelectedArea - 7];
Spots[SelectedArea - 1].h = CardHeight + newy;
printf("Table Count: %d newy: %d\n", TableauCounts[SelectedArea - 7], newy);
// erase old card first
Sprite.fillRect(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy + CardOL, CardWidth, CardHeight, TFT_DARKGREEN);
// redraw last card in pile..
if (TableauCounts[SelectedArea - 7] > 0)
Sprite.pushImage(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy, CardWidth, CardHeight, card[Tableau[SelectedArea - 7][TableauCounts[SelectedArea - 7] - 1]]);
else if (SelectedArea > 7 && HiddenCounts[SelectedArea - 7] > 0) // do we have something??
Sprite.pushImage(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy, CardWidth, CardHeight, card[CardBack]);
Sprite.drawRoundRect(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy, CardWidth, CardHeight, 4, TFT_YELLOW);
// draw card in foundation
Sprite.pushImage(Spots[f - 1].x, Spots[f - 1].y, CardWidth, CardHeight, card[Foundations[f - 3][FoundationCounts[f - 3] - 1]]);
Sprite.drawRoundRect(Spots[f - 1].x, Spots[f - 1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
Sprite.pushSprite(0, 0);
SelectedCard = -1;
SelectedArea = -1;
}
else
{
// just unselect pile
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
DrawSelection();
}
}
else
{
// just unselect pile
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
DrawSelection();
}
}
}
void SelectFoundation(int f)
{
// select a foundation card..
if (FoundationCounts[f - 3] > 0)
{
SelectedCard = Foundations[f - 3][FoundationCounts[f - 3] - 1];
SelectedArea = f;
SelectCount = 1;
SelectRect.x = Spots[f - 1].x;
SelectRect.y = Spots[f - 1].y;
SelectRect.w = Spots[f - 1].w;
SelectRect.h = Spots[f - 1].h;
DrawSelection();
printf("Foundation %d Card %d selected\n", SelectedArea - 2, SelectedCard);
}
}
int GetCardColor(int acard)
{
int result = -1;
if (acard < 13)
result = 0;
else if (acard < 39)
result = 1;
else
result = 0;
return result;
}
int GetCardNumber(int acard)
{
int result = -1;
// get ordinal postion within suit..
if (acard < 13)
result = acard+2;
else if (acard < 26)
result = acard - 11;
else if (acard < 39)
result = acard - 24;
else
result = acard - 37;
printf("Orig #: %d new #: %d\n",acard,result);
return result;
}
bool CheckTableauMove(int a)
{
// check for valid move
bool result = false;
// no cards on table, any card should do..
if (TableauCounts[a - 7] == 0)
{
result = true;
return result; // outa here
}
int pileColor = GetCardColor(Tableau[a - 7][TableauCounts[a - 7] - 1]);
if (GetCardColor(SelectedCard) == pileColor)
{
int acolor = GetCardColor(SelectedCard);
printf("wrong colors..pile color: %d select color: %d\n", pileColor,acolor);
result = false;
return result;
}
int pileCard = GetCardNumber(Tableau[a - 7][TableauCounts[a - 7] - 1]);
// next card should be one less than the current pile card..
result = pileCard == (GetCardNumber(SelectedCard) + 1);
if (!result) printf("wrong card # pile:%d select:%d\n",pileCard,GetCardNumber(SelectedCard));
return result;
}
void MoveToTableau(int a)
{
if (SelectedArea == 2)
{
// moving from waste..
Tableau[a - 7][TableauCounts[a - 7]] = Waste[WasteCount - 1];
TableauCounts[a - 7]++;
Waste[WasteCount - 1] = -1;
WasteCount--;
if (WasteCount < 1)
{
Sprite.fillRect(Spots[1].x, Spots[1].y, CardWidth, CardHeight, TFT_DARKGREEN);
Sprite.drawRoundRect(Spots[1].x, Spots[1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
else
{
Sprite.pushImage(Spots[1].x, Spots[1].y, CardWidth, CardHeight, card[Waste[WasteCount - 1]]);
Sprite.drawRoundRect(Spots[1].x, Spots[1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
int newy = CardOL * TableauCounts[a - 7];
Spots[a - 1].h = CardHeight + newy;
printf("Table Count: %d newy: %d\n", TableauCounts[a - 7], newy);
Sprite.pushImage(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, card[Tableau[a - 7][TableauCounts[a - 7] - 1]]);
Sprite.drawRoundRect(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, 4, TFT_YELLOW);
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
DrawSelection();
}
else if (SelectedArea > 2 && SelectedArea < 7)
{
// moving from foundations..
Tableau[a - 7][TableauCounts[a - 7]] = Foundations[SelectedArea - 3][FoundationCounts[SelectedArea - 3] - 1];
TableauCounts[a - 7]++;
Foundations[SelectedArea - 3][FoundationCounts[SelectedArea - 3] - 1] = -1;
FoundationCounts[SelectedArea - 3]--;
if (FoundationCounts[SelectedArea - 3] < 1)
{
Sprite.fillRect(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y, CardWidth, CardHeight, TFT_DARKGREEN);
Sprite.drawRoundRect(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
else
{
Sprite.pushImage(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y, CardWidth, CardHeight, card[Foundations[SelectedArea - 3][FoundationCounts[SelectedArea - 3] - 1]]);
Sprite.drawRoundRect(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
int newy = CardOL * TableauCounts[a - 7];
Spots[a - 1].h = CardHeight + newy;
printf("Table Count: %d newy: %d\n", TableauCounts[a - 7], newy);
Sprite.pushImage(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, card[Tableau[a - 7][TableauCounts[a - 7] - 1]]);
Sprite.drawRoundRect(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, 4, TFT_YELLOW);
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
DrawSelection();
// Sprite.pushSprite(0, 0);
}
else if (SelectedArea > 6 && SelectedArea < 14 && SelectedArea != a)
{
// moving from pile to pile..
int c = SelectCount;
int newy;
for (int i = 0; i < SelectCount; i++)
{
// add cards
printf("Tab Count: %d c: %d\n", TableauCounts[SelectedArea - 7], c);
Tableau[a - 7][TableauCounts[a - 7]] = Tableau[SelectedArea - 7][(TableauCounts[SelectedArea - 7] - c)];
TableauCounts[a - 7]++;
newy = CardOL * TableauCounts[a - 7];
Spots[a - 1].h = CardHeight + newy;
printf("Table Count: %d newy: %d\n", TableauCounts[a - 7], newy);
Sprite.pushImage(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, card[Tableau[a - 7][TableauCounts[a - 7] - 1]]);
Sprite.drawRoundRect(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, 4, TFT_YELLOW);
c--;
}
c = SelectCount;
// newy = Spots[a-1].h;
for (int i = 0; i < SelectCount; i++)
{
// remove cards
Tableau[SelectedArea - 7][(TableauCounts[SelectedArea - 7] - c)] = -1;
TableauCounts[SelectedArea - 7]--;
newy = CardOL * TableauCounts[SelectedArea - 7];
// newy-= CardOL;
if (TableauCounts[SelectedArea -7]>1)
Spots[SelectedArea - 1].h = CardHeight + newy; else
Spots[SelectedArea - 1].h = CardHeight;
printf("Table Count: %d newy: %d\n", TableauCounts[SelectedArea - 7], newy);
// erase old card first
Sprite.fillRect(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy + CardOL, CardWidth, CardHeight, TFT_DARKGREEN);
// redraw last card in pile..
if (TableauCounts[SelectedArea - 7] > 0)
Sprite.pushImage(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy, CardWidth, CardHeight, card[Tableau[SelectedArea - 7][TableauCounts[SelectedArea - 7] - 1]]);
else if (SelectedArea > 7 && HiddenCounts[SelectedArea - 7] > 0) // do we have something??
Sprite.pushImage(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy, CardWidth, CardHeight, card[CardBack]);
Sprite.drawRoundRect(Spots[SelectedArea - 1].x, Spots[SelectedArea - 1].y + newy, CardWidth, CardHeight, 4, TFT_YELLOW);
c--;
}
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
Sprite.pushSprite(0, 0);
}
else
{
SelectedCard = -1;
SelectedArea = -1;
SelectCount = 0;
DrawSelection();
}
}
void SelectTableau(int a, int y)
{
if (TableauCounts[a - 7] > 0)
{
if (TableauCounts[a - 7] > 1)
{
int newy = Spots[a - 1].y + (TableauCounts[a - 7] * CardOL);
for (int i = 0; i < TableauCounts[a - 7]; i++)
{
printf("NewY: %d Y: %d\n", newy, y);
if (y >= newy)
{
SelectedCard = Tableau[a - 7][(TableauCounts[a - 7] - 1) - i];
SelectedArea = a;
SelectCount = i + 1;
printf("Multi-Selected Card : %d Num of Cards: %d\n", SelectedCard, SelectCount);
break;
}
newy -= CardOL;
}
SelectRect.x = Spots[a - 1].x;
SelectRect.y = Spots[a - 1].y + (CardOL * TableauCounts[a - 7]) - (SelectCount * CardOL) + CardOL;
SelectRect.w = CardWidth;
SelectRect.h = CardHeight + (CardOL * SelectCount) - CardOL;
DrawSelection();
}
else
{
// only 1 card on pile..
SelectedCard = Tableau[a - 7][TableauCounts[a - 7] - 1];
SelectedArea = a;
SelectCount = 1;
SelectRect.x = Spots[a - 1].x;
SelectRect.y = Spots[a - 1].y + CardOL;
SelectRect.w = Spots[a - 1].w;
SelectRect.h = CardHeight; // Spots[a - 1].h;
DrawSelection();
printf("Single-Selected Card : %d\n", SelectedCard);
}
}
else
{
// no cards on tableau, see if we have any hidden..
if (HiddenCounts[a - 7] > 0)
{
// flip the hidden card..
Tableau[a - 7][0] = HiddenTabs[a - 8][HiddenCounts[a - 7] - 1];
TableauCounts[a - 7] = 1;
HiddenTabs[a - 8][HiddenCounts[a - 7] - 1] = -1;
HiddenCounts[a - 7]--;
int newy = 0;// CardOL * TableauCounts[a - 7];
Spots[a - 1].h = CardHeight + newy;
newy = CardOL;
printf("Table Count: %d newy: %d\n", TableauCounts[a - 7], newy);
if (HiddenCounts[a - 7] == 0)
{ // erase hidden placeholder..
Sprite.fillRect(Spots[a - 1].x, Spots[a - 1].y, CardWidth, CardHeight, TFT_DARKGREEN);
Sprite.drawRoundRect(Spots[a - 1].x, Spots[a - 1].y, CardWidth, CardHeight, 4, TFT_YELLOW);
}
Sprite.pushImage(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, card[Tableau[a - 7][TableauCounts[a - 7] - 1]]);
Sprite.drawRoundRect(Spots[a - 1].x, Spots[a - 1].y + newy, CardWidth, CardHeight, 4, TFT_YELLOW);
Sprite.pushSprite(0, 0);
}
}
}
void CutDeck(int8_t *deck, int size){
int8_t half[size / 2];
/*
printf("Deck Before Cut: ");
for (int i = 0 ; i < size; i++){
printf(" %d, ",deck[i]);
}
printf("\n");
*/
memcpy(half,deck,sizeof(half));
/*
printf("Half: ");
for (int i = 0 ; i < size /2; i++){
printf(" %d, ",half[i]);
}
printf("\n");
*/
memcpy(deck,&deck[(size / 2)],sizeof(half));
memcpy(&deck[(size / 2)],half,sizeof(half));
/*
printf("Deck After Cut: ");
for (int i = 0 ; i < size; i++){
printf(" %d, ",deck[i]);
}
printf("\n");
*/
}
void shuffle(int8_t *array, int size)
{
for (int i = size - 1; i > 0; i--)
{
int j = i + (rand() % (size - i));
int8_t temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
void DrawSelection()
{
if (SelectedCard > -1)
{
// selecting
Sprite.drawRoundRect(SelectRect.x + 1, SelectRect.y + 1, SelectRect.w - 3, SelectRect.h - 2, 4, TFT_GREEN);
Sprite.drawRoundRect(SelectRect.x + 2, SelectRect.y + 2, SelectRect.w - 4, SelectRect.h - 3, 4, TFT_GREEN);
Sprite.drawRoundRect(SelectRect.x, SelectRect.y, SelectRect.w, SelectRect.h, 4, TFT_GREEN);
}
else
{
Sprite.drawRoundRect(SelectRect.x + 1, SelectRect.y + 1, SelectRect.w - 3, SelectRect.h - 2, 4, TFT_WHITE);
Sprite.drawRoundRect(SelectRect.x + 2, SelectRect.y + 2, SelectRect.w - 4, SelectRect.h - 3, 4, TFT_WHITE);
Sprite.drawRoundRect(SelectRect.x, SelectRect.y, SelectRect.w, SelectRect.h, 4, TFT_YELLOW);
// unselecting
}
Sprite.pushSprite(0, 0);
}
void UpdateBattDisplay(){
//display battery information
int x,y,w,h;
bool isCharging = true;// M5.Power.isCharging();
int battVolts =8138;// M5.Power.getBatteryVoltage();
int battLevel = 75;// M5.Power.getBatteryLevel();
x = BattLevelRect.x;
y = BattLevelRect.y;
w = BattLevelRect.w;
h = BattLevelRect.h;
Sprite.setFont(&fonts::FreeSansBold9pt7b);
Sprite.setTextSize(1);
Sprite.setTextColor(TFT_BLACK);
Sprite.fillRoundRect(x,y,w,h,4,TFT_WHITE);
Sprite.drawRoundRect(x,y,w,h,4,TFT_YELLOW);
int nw = w-4;
int cl = battLevel; // simulated batt level
if (cl < 100)
{
float multi = cl / 100.0;
nw = nw * multi;
}
Sprite.fillRect(x + 2, y + 2, nw, h - 4, TFT_GREEN);
Sprite.drawNumber(cl, x + 10, y + 20);
Sprite.setTextColor(TFT_BLACK);
Sprite.setColor(TFT_WHITE);
//Sprite.setTextFont(1);
Sprite.setFont(&fonts::FreeSansBold9pt7b);
Sprite.setTextSize(1);
//Sprite.drawString("Is Charging",x+3,y+3);
//Sprite.drawString("Yes",x+3,y+30);
//x -= (200 + Gap);
x = BattVoltageRect.x;
y = BattVoltageRect.y;
Sprite.fillRoundRect(x,y,w,h,4,TFT_WHITE);
Sprite.drawRoundRect(x,y,w,h,4,TFT_YELLOW);
Sprite.drawString("Voltage",x+3,y+3);
Sprite.drawNumber(battVolts,x+3,y+30);
x = BattChargingRect.x;
y = BattChargingRect.y;
Sprite.fillRoundRect(x,y,w,h,4,TFT_WHITE);
Sprite.drawRoundRect(x,y,w,h,4,TFT_YELLOW);
Sprite.drawString("Charging",x+3,y+3);
if (isCharging)
Sprite.drawString("Yes",x+3,y+30);
else
Sprite.drawString("No",x+3,y+30);
}
void setup()
{
Display.init();
Sprite.createSprite(1280, 720);
Sprite.setSwapBytes(1);
// init the deck..
for (int i = 0; i < 52; i++)
Deck[i] = i;
// init random
srand(time(0));
// setup the table
SetupTable();
}
void loop()
{
now = millis();
if (now - lastBattCheck >= battCheckInterval){
lastBattCheck = now;
UpdateBattDisplay();
}
lgfx::touch_point_t tp;
if (Display.getTouch(&tp))
{
if (now - lastTouch >= touchDebounce)
{ // got a touch..
lastTouch = now;
CheckScreenTouch(tp.x, tp.y);
}
}
lgfx::delay(10);
}
bool TouchArea(int px, int py, int x, int y, int w, int h)
{
bool result = false;
int x2 = x + w;
int y2 = y + h;
int touch_x = px;
int touch_y = py;
if ((touch_x >= x) && (touch_x <= x2) && (touch_y >= y) && (touch_y <= y2))
result = true;
if (debug)
{
printf("Touch X: %d Y: %d\n", touch_x, touch_y);
printf("X: %d , X2: %d, Y: %d, Y2: %d\n", x, x2, y, y2);
}
return result;
}
void CheckScreenTouch(int tx, int ty)
{
printf("x: %d y: %d \n", tx, ty);
printf("Button x:%d y:%d w:%d h:%d\n",Button.x,Button.y,Button.w,Button.h);
if (TouchArea(tx,ty,Button.x,Button.y,Button.w,Button.h)){
printf("New Game\n");
SetupTable();
} else
{
for (int i = 0; i < sizeof(Spots) / sizeof(Spots[0]); i++)
{
if (TouchArea(tx, ty, Spots[i].x, Spots[i].y, Spots[i].w, Spots[i].h))
{
printf("Spot clicked:%d\n", i);
HandleTouch(i, ty);
break;
}
}
}
}
void HandleTouch(int spot, int y)
{
switch (spot)
{
case 0:
StockFlip();
break;
case 1:
SelectWaste();
break;
case 2:
case 3:
case 4:
case 5:
if (SelectedCard > -1)
{
if (CheckFoundationMove(Spots[spot].area))
{
MoveToFoundations(Spots[spot].area);
}
else
{
// invalid move unselect the selection..
SelectCount = 0;
SelectedArea = 0;
SelectedCard = -1;
DrawSelection();
}
}
else
{
SelectFoundation(Spots[spot].area);
}
break;
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
if (SelectedCard > -1)
{
if (CheckTableauMove(Spots[spot].area))
{
MoveToTableau(Spots[spot].area);
}
else
{
// invalid move, unselect
SelectCount = 0;
SelectedArea = 0;
SelectedCard = -1;
DrawSelection();
}
}
else
{
SelectTableau(Spots[spot].area, y);
}
break;
default:
break;
}
}
here’s the contents of my CMakeLists.txt..
# See how to install sdl2: https://wiki.libsdl.org/SDL2/Installation
cmake_minimum_required (VERSION 3.10)
project(LGFX_SDL)
add_definitions(-DLGFX_SDL)
file(GLOB Target_Files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS
*.cpp
/home/arduino/projects/libs/LovyanGFX/src/lgfx/Fonts/efont/*.c
/home/arduino/projects/libs/LovyanGFX/src/lgfx/Fonts/IPA/*.c
/home/arduino/projects/libs/LovyanGFX/src/lgfx/utility/*.c
/home/arduino/projects/libs/LovyanGFX/src/lgfx/v1/*.cpp
/home/arduino/projects/libs/LovyanGFX/src/lgfx/v1/misc/*.cpp
/home/arduino/projects/libs/LovyanGFX/src/lgfx/v1/panel/Panel_Device.cpp
/home/arduino/projects/libs/LovyanGFX/src/lgfx/v1/panel/Panel_FrameBufferBase.cpp
/home/arduino/projects/libs/LovyanGFX/src/lgfx/v1/platforms/sdl/*.cpp
)
add_executable (LGFX_SDL ${Target_Files})
target_include_directories(LGFX_SDL PUBLIC "/home/arduino/projects/libs/LovyanGFX/src/")
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_include_directories(LGFX_SDL PUBLIC "/home/arduino/projects/libs/SDL2/include")
target_include_directories(LGFX_SDL PUBLIC "/home/arduino/projects/libs/SDL2/src")
target_link_libraries(LGFX_SDL PUBLIC -lpthread "/lib64/libSDL2-2.0.so.0.3200.4")
# find_package(SDL2 REQUIRED SDL2)
# include_directories(${SDL2_INCLUDE_DIRS})
# target_link_libraries(LGFX_SDL -lpthread ${SDL2_LIBRARIES})
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
target_include_directories(LGFX_SDL PUBLIC "C:/SDL2/include")
target_link_libraries(LGFX_SDL PUBLIC "C:/SDL2/lib/x64/SDL2.lib")
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
find_package(SDL2 REQUIRED COMPONENTS SDL2)
target_link_libraries(LGFX_SDL PRIVATE SDL2::SDL2)
ENDIF ()
target_compile_features(LGFX_SDL PUBLIC cxx_std_17)
can grb bigcards.h from my git here..
fun stuff.. ~q


