about summary refs log tree commit diff
path: root/freecell.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--freecell.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/freecell.c b/freecell.c
index f7a19cb..e8b41f6 100644
--- a/freecell.c
+++ b/freecell.c
@@ -128,6 +128,9 @@ static bool gameAuto(void) {
 }
 
 enum {
+	CardWidth = Cards_CardWidth,
+	CardHeight = Cards_CardHeight,
+
 	StackMarginX = 7,
 	StackMarginY = 10,
 
@@ -136,16 +139,16 @@ enum {
 
 	CellsMarginX = 64,
 
-	FoundationX = CellX + 4 * Cards_Width + CellsMarginX,
+	FoundationX = CellX + 4 * CardWidth + CellsMarginX,
 	FoundationY = CellY,
 
 	TableauX = StackMarginX,
-	TableauY = CellY + Cards_Height + StackMarginY,
+	TableauY = CellY + CardHeight + StackMarginY,
 
 	FanDownDeltaY = 17,
 
-	WindowWidth = 8 * Cards_Width + 9 * StackMarginX + 1,
-	WindowHeight = TableauY + Cards_Height
+	WindowWidth = 8 * CardWidth + 9 * StackMarginX + 1,
+	WindowHeight = TableauY + CardHeight
 		+ 13 * FanDownDeltaY
 		+ StackMarginY,
 };
@@ -159,27 +162,27 @@ static struct List reveal;
 static void updateLayout(void) {
 	layoutClear(&layout);
 
-	SDL_Rect cell = { CellX, CellY, Cards_Width, Cards_Height };
+	SDL_Rect cell = { CellX, CellY, CardWidth, CardHeight };
 	for (uint i = Cell1; i <= Cell4; ++i) {
 		stackRects[i] = cell;
 		layoutStack(&layout, &cell, &stacks[i], &Flat);
-		cell.x += Cards_Width;
+		cell.x += CardWidth;
 	}
 
-	SDL_Rect found = { FoundationX, FoundationY, Cards_Width, Cards_Height };
+	SDL_Rect found = { FoundationX, FoundationY, CardWidth, CardHeight };
 	for (uint i = Foundation1; i <= Foundation4; ++i) {
 		stackRects[i] = found;
 		layoutStack(&layout, &found, &stacks[i], &Flat);
-		found.x += Cards_Width;
+		found.x += CardWidth;
 	}
 
-	SDL_Rect table = { TableauX, TableauY, Cards_Width, Cards_Height };
+	SDL_Rect table = { TableauX, TableauY, CardWidth, CardHeight };
 	for (uint i = Tableau1; i <= Tableau8; ++i) {
 		stackRects[i] = table;
 		stackRects[i].h = WindowHeight;
 		SDL_Rect rect = table;
 		layoutStack(&layout, &rect, &stacks[i], &FanDown);
-		table.x += Cards_Width + StackMarginX;
+		table.x += CardWidth + StackMarginX;
 	}
 }
 
@@ -276,8 +279,8 @@ static SDL_Renderer *render;
 
 static void renderOutlines(void) {
 	for (uint i = Foundation1; i <= Cell4; ++i) {
-		int right = stackRects[i].x + Cards_Width - 1;
-		int bottom = stackRects[i].y + Cards_Height - 1;
+		int right = stackRects[i].x + CardWidth - 1;
+		int bottom = stackRects[i].y + CardHeight - 1;
 		SDL_Point black[3] = {
 			{ stackRects[i].x, bottom - 1 },
 			{ stackRects[i].x, stackRects[i].y },
@@ -343,13 +346,15 @@ int main(void) {
 		return EXIT_FAILURE;
 	}
 
-	struct Cards *cards = Cards_Load(
-		rw, Cards_ColorKey | Cards_AlphaCorners | Cards_BlackBorders
+	SDL_Surface *surfaces[Cards_Empty];
+	int error = Cards_LoadCards(
+		surfaces, Cards_Empty,
+		rw, Cards_AlphaCorners | Cards_BlackBorders
 	);
-	if (!cards) err("Cards_Load");
+	if (error) err("Cards_LoadCards");
 	SDL_RWclose(rw);
 
-	int error = SDL_CreateWindowAndRenderer(
+	error = SDL_CreateWindowAndRenderer(
 		WindowWidth, WindowHeight, SDL_WINDOW_ALLOW_HIGHDPI,
 		&window, &render
 	);
@@ -359,22 +364,22 @@ int main(void) {
 	SDL_RenderSetIntegerScale(render, SDL_TRUE);
 	SDL_RenderSetLogicalSize(render, WindowWidth, WindowHeight);
 
-	SDL_Texture *textures[Cards_Count];
-	SDL_Texture *inverted[Cards_Count];
-	for (uint i = 0; i < Cards_Count; ++i) {
+	SDL_Texture *textures[Cards_Empty];
+	SDL_Texture *inverted[Cards_Empty];
+	for (uint i = 0; i < Cards_Empty; ++i) {
 		textures[i] = NULL;
-		if (!cards->surfaces[i]) continue;
-		textures[i] = SDL_CreateTextureFromSurface(render, cards->surfaces[i]);
-		if (!textures[i]) err("SDL_CreateTextureFromSurface");
-	}
-	if (Cards_Invert(cards) < 0) err("Cards_Invert");
-	for (uint i = 0; i < Cards_Count; ++i) {
 		inverted[i] = NULL;
-		if (!cards->surfaces[i]) continue;
-		inverted[i] = SDL_CreateTextureFromSurface(render, cards->surfaces[i]);
+		if (!surfaces[i]) continue;
+
+		textures[i] = SDL_CreateTextureFromSurface(render, surfaces[i]);
+		if (!textures[i]) err("SDL_CreateTextureFromSurface");
+
+		if (Cards_InvertSurface(surfaces[i]) < 0) err("Cards_InvertSurface");
+		inverted[i] = SDL_CreateTextureFromSurface(render, surfaces[i]);
 		if (!inverted[i]) err("SDL_CreateTextureFromSurface");
+
+		SDL_FreeSurface(surfaces[i]);
 	}
-	Cards_Free(cards);
 
 	srand(time(NULL));
 	gameDeal();