2022-10-25 09:23:44 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2023-02-10 11:20:50 +00:00
|
|
|
#include "window.h"
|
2022-10-25 09:23:44 +00:00
|
|
|
|
2023-02-10 11:20:50 +00:00
|
|
|
bool window_load(const char *encoded, window_t **mode) {
|
2022-10-25 09:23:44 +00:00
|
|
|
float vals[4];
|
|
|
|
int i = 0;
|
|
|
|
char *token = strtok((char *)encoded, ",");
|
|
|
|
while (token != NULL) {
|
|
|
|
vals[i] = atof(token);
|
|
|
|
if (vals[i] < 0 || vals[i] > 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
token = strtok(NULL, ",");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != 4) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-02-10 11:20:50 +00:00
|
|
|
*mode = malloc(sizeof(window_t));
|
2022-10-25 09:23:44 +00:00
|
|
|
(*mode)->x = vals[0];
|
|
|
|
(*mode)->y = vals[1];
|
|
|
|
(*mode)->width = vals[2];
|
|
|
|
(*mode)->height = vals[3];
|
|
|
|
return true;
|
|
|
|
}
|