summary refs log tree commit diff
path: root/sol.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sol.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/sol.c b/sol.c
index c7ad5ec..a2bd7c3 100644
--- a/sol.c
+++ b/sol.c
@@ -172,27 +172,30 @@ static bool gameMove(uint dest, Card card) {
 }
 
 enum {
+	CardWidth = Cards_CardWidth,
+	CardHeight = Cards_CardHeight,
+
 	StackMarginX = 11,
 	StackMarginY = 6,
 
 	StockX = StackMarginX,
 	StockY = StackMarginY,
 
-	WasteX = StockX + Cards_Width + StackMarginX,
+	WasteX = StockX + CardWidth + StackMarginX,
 	WasteY = StackMarginY,
 
-	FoundationX = WasteX + 2 * (Cards_Width + StackMarginX),
+	FoundationX = WasteX + 2 * (CardWidth + StackMarginX),
 	FoundationY = StackMarginY,
 
 	TableauX = StackMarginX,
-	TableauY = StockY + Cards_Height + StackMarginY,
+	TableauY = StockY + CardHeight + StackMarginY,
 
 	FanRightDeltaX = 14,
 	FanDownDeltaYBack = 3,
 	FanDownDeltaYFront = 15,
 
-	WindowWidth = 7 * Cards_Width + 8 * StackMarginX,
-	WindowHeight = 2 * (StackMarginY + Cards_Height)
+	WindowWidth = 7 * CardWidth + 8 * StackMarginX,
+	WindowHeight = 2 * (StackMarginY + CardHeight)
 		+ 6 * FanDownDeltaYBack
 		+ 12 * FanDownDeltaYFront
 		+ StackMarginY,
@@ -212,31 +215,31 @@ static uint backTexture = Cards_Back1;
 static void updateLayout(void) {
 	layoutClear(&layout);
 
-	SDL_Rect stock = { StockX, StockY, Cards_Width, Cards_Height };
+	SDL_Rect stock = { StockX, StockY, CardWidth, CardHeight };
 	stackRects[Stock] = stock;
 	listPush(&layout.main, &stock, Cards_O);
 	layoutStack(&layout, &stock, &stacks[Stock], &Square);
 
-	SDL_Rect waste = { WasteX, WasteY, Cards_Width, Cards_Height };
+	SDL_Rect waste = { WasteX, WasteY, CardWidth, CardHeight };
 	layoutStack(&layout, &waste, &stacks[Waste1], &Square);
 	layoutStack(&layout, &waste, &stacks[Waste3], &FanRight);
 
-	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;
 		listPush(&layout.main, &found, Cards_Empty);
 		SDL_Rect rect = found;
 		layoutStack(&layout, &rect, &stacks[i], &Square);
-		found.x += Cards_Width + StackMarginX;
+		found.x += CardWidth + StackMarginX;
 	}
 
-	SDL_Rect table = { TableauX, TableauY, Cards_Width, Cards_Height };
+	SDL_Rect table = { TableauX, TableauY, CardWidth, CardHeight };
 	for (uint i = Tableau1; i <= Tableau7; ++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;
 	}
 }
 
@@ -300,7 +303,7 @@ static bool mouseMotion(SDL_MouseMotionEvent motion) {
 
 static SDL_Window *window;
 static SDL_Renderer *render;
-static SDL_Texture *textures[Cards_Count];
+static SDL_Texture *textures[Cards_CardCount];
 
 static void renderList(const struct List *list) {
 	for (uint i = 0; i < list->len; ++i) {
@@ -349,13 +352,15 @@ int main(void) {
 		return EXIT_FAILURE;
 	}
 
-	struct Cards *cards = Cards_Load(
+	SDL_Surface *surfaces[Cards_CardCount];
+	int error = Cards_LoadCards(
+		surfaces, Cards_CardCount,
 		rw, Cards_ColorKey | 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
 	);
@@ -365,13 +370,13 @@ int main(void) {
 	SDL_RenderSetIntegerScale(render, SDL_TRUE);
 	SDL_RenderSetLogicalSize(render, WindowWidth, WindowHeight);
 
-	for (uint i = 0; i < Cards_Count; ++i) {
+	for (uint i = 0; i < Cards_CardCount; ++i) {
 		textures[i] = NULL;
-		if (!cards->surfaces[i]) continue;
-		textures[i] = SDL_CreateTextureFromSurface(render, cards->surfaces[i]);
+		if (!surfaces[i]) continue;
+		textures[i] = SDL_CreateTextureFromSurface(render, surfaces[i]);
 		if (!textures[i]) err("SDL_CreateTextureFromSurface");
+		SDL_FreeSurface(surfaces[i]);
 	}
-	Cards_Free(cards);
 
 	srand(time(NULL));
 	backTexture = Cards_Back1 + randUniform(12);