Keep window position and size in config
This commit is contained in:
parent
34795d2376
commit
6a6dad4cdb
1 changed files with 68 additions and 2 deletions
68
src/main.cpp
68
src/main.cpp
|
@ -1,6 +1,8 @@
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_vulkan.h>
|
#include <SDL_vulkan.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
@ -27,8 +29,70 @@ uint32_t platform::getTime() {
|
||||||
return SDL_GetTicks();
|
return SDL_GetTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int windowX = SDL_WINDOWPOS_CENTERED;
|
||||||
|
int windowY = SDL_WINDOWPOS_CENTERED;
|
||||||
|
int windowWidth = 640;
|
||||||
|
int windowHeight = 480;
|
||||||
|
|
||||||
|
int toInt(const std::string &str) {
|
||||||
|
std::stringstream ss(str);
|
||||||
|
|
||||||
|
int num;
|
||||||
|
if((ss >> num).fail())
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
void readConfig() {
|
||||||
|
std::ifstream file("config.txt");
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while(std::getline(file, line)) {
|
||||||
|
if(line.find('=') != std::string::npos) {
|
||||||
|
std::string key, value;
|
||||||
|
key = line.substr(0, line.find('='));
|
||||||
|
value = line.substr(line.find('=') + 1, line.length());
|
||||||
|
|
||||||
|
if(key == "x") {
|
||||||
|
windowX = toInt(value);
|
||||||
|
} else if(key == "y") {
|
||||||
|
windowY = toInt(value);
|
||||||
|
} else if(key == "width") {
|
||||||
|
windowWidth = toInt(value);
|
||||||
|
} else if(key == "height") {
|
||||||
|
windowHeight = toInt(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeConfig() {
|
||||||
|
std::ofstream file("config.txt");
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
SDL_GetWindowPosition(window, &x, &y);
|
||||||
|
|
||||||
|
file << "x=" << x << "\n";
|
||||||
|
file << "y=" << y << "\n";
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
SDL_GetWindowSize(window, &w, &h);
|
||||||
|
|
||||||
|
file << "width=" << w << "\n";
|
||||||
|
file << "height=" << h << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
window = SDL_CreateWindow("Graph", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
|
readConfig();
|
||||||
|
|
||||||
|
window = SDL_CreateWindow("Graph",
|
||||||
|
windowX,
|
||||||
|
windowY,
|
||||||
|
windowWidth,
|
||||||
|
windowHeight,
|
||||||
|
SDL_WINDOW_VULKAN |
|
||||||
|
SDL_WINDOW_RESIZABLE);
|
||||||
if(!window)
|
if(!window)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -88,6 +152,8 @@ int main(int, char*[]) {
|
||||||
|
|
||||||
delete renderer;
|
delete renderer;
|
||||||
|
|
||||||
|
writeConfig();
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Reference in a new issue