- if(i+1 >= argc) {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a parameter for geometry switch");
- }
- if(sscanf(argv[++i], "%dx%d", &config->screenwidth, &config->screenheight)
- != 2) {
- print_usage(argv[0]);
- throw std::runtime_error("Invalid geometry spec, should be WIDTHxHEIGHT");
- }
+ i += 1;
+ if(i >= argc)
+ {
+ print_usage(argv[0]);
+ throw std::runtime_error("Need to specify a size (WIDTHxHEIGHT) for geometry argument");
+ }
+ else
+ {
+ int width, height;
+ if (sscanf(argv[i], "%dx%d", &width, &height) != 2)
+ {
+ print_usage(argv[0]);
+ throw std::runtime_error("Invalid geometry spec, should be WIDTHxHEIGHT");
+ }
+ else
+ {
+ config->window_width = width;
+ config->window_height = height;
+
+ config->fullscreen_width = width;
+ config->fullscreen_height = height;
+ }
+ }
+ } else if(arg == "--aspect" || arg == "-a") {
+ i += 1;
+ if(i >= argc)
+ {
+ print_usage(argv[0]);
+ throw std::runtime_error("Need to specify a ratio (WIDTH:HEIGHT) for aspect ratio");
+ }
+ else
+ {
+ int aspect_width = 0;
+ int aspect_height = 0;
+ if (strcmp(argv[i], "auto") == 0)
+ {
+ aspect_width = 0;
+ aspect_height = 0;
+ }
+ else if (sscanf(argv[i], "%d:%d", &aspect_width, &aspect_height) != 2)
+ {
+ print_usage(argv[0]);
+ throw std::runtime_error("Invalid aspect spec, should be WIDTH:HEIGHT or auto");
+ }
+ else
+ {
+ float aspect_ratio = static_cast<double>(config->aspect_width) /
+ static_cast<double>(config->aspect_height);
+
+ // use aspect ratio to calculate logical resolution
+ if (aspect_ratio > 1) {
+ config->aspect_width = static_cast<int> (600 * aspect_ratio + 0.5);
+ config->aspect_height = 600;
+ } else {
+ config->aspect_width = 600;
+ config->aspect_height = static_cast<int> (600 * 1/aspect_ratio + 0.5);
+ }
+ }
+ }