Skip to content

Commit 3648287

Browse files
committed
feature: implement validateRows, validateCols and getScreenResolution functions
1 parent 4323dd2 commit 3648287

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/utilities.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <string.h>
66

77
#include "../libs/main.h"
8+
#include "./macros.h"
9+
#include "./sdl/main.h"
10+
#include "./validators.h"
811

912
void getMainArguments(TMainArguments* pMainArguments, int argc, char* argv[]) {
1013
int i;
@@ -20,13 +23,13 @@ void getMainArguments(TMainArguments* pMainArguments, int argc, char* argv[]) {
2023

2124
if (strcmp(argumentName, "dashboard-rows") == 0) {
2225
sscanf(argumentValue, "%d", &argumentValueInt);
23-
if (argumentValueInt > 0) pMainArguments->dashboardRows = argumentValueInt;
26+
if (validateRows(argumentValueInt)) pMainArguments->dashboardRows = argumentValueInt;
2427

2528
free(argumentValue);
2629

2730
} else if (strcmp(argumentName, "dashboard-cols") == 0) {
2831
sscanf(argumentValue, "%d", &argumentValueInt);
29-
if (argumentValueInt > 0) pMainArguments->dashboardCols = argumentValueInt;
32+
if (validateCols(argumentValueInt)) pMainArguments->dashboardCols = argumentValueInt;
3033

3134
free(argumentValue);
3235

@@ -67,8 +70,16 @@ void getMainArguments(TMainArguments* pMainArguments, int argc, char* argv[]) {
6770
}
6871

6972
void setDefaultMainArguments(TMainArguments* pMainArguments) {
70-
pMainArguments->dashboardRows = 0;
71-
pMainArguments->dashboardCols = 0;
73+
int screenWidth;
74+
int screenHeight;
75+
76+
if (!getScreenResolution(&screenWidth, &screenHeight)) {
77+
screenWidth = 640;
78+
screenHeight = 360;
79+
};
80+
81+
pMainArguments->dashboardRows = (screenHeight / CELL_SIZE) * 0.75;
82+
pMainArguments->dashboardCols = (screenWidth / CELL_SIZE) * 0.75;
7283
pMainArguments->pattern = "";
7384
pMainArguments->maximumGeneration = 0;
7485
pMainArguments->delay = 0;

0 commit comments

Comments
 (0)