Files
WickedEngine/Editor/main_SDL2.cpp
T
Megumumpkin fc63270b6e SDL Keyboard Input, Unix File Loading and SDL Window Config (#232)
* SDL2 and Unix fix

SDL2 keyboard input, Unix filesystem fix, and SDL2 editor window config, CMake cache gitignore

* Adding comments to the SDL2 keycode fix

For a better understanding

* Slimming down SDL Unix path translation

* Static pathfile compile fix

More pathfile code fix for the compile to work

* Re: Static pathfile compile fix
2021-02-07 19:55:29 +01:00

94 lines
2.1 KiB
C++

#include "stdafx.h"
#include "Editor.h"
#include <fstream>
#include "stdafx.h"
#include <SDL2/SDL.h>
#include "sdl2.h"
using namespace std;
int sdl_loop(Editor &editor)
{
SDL_Event event;
bool quit = false;
while (!quit)
{
SDL_PumpEvents();
editor.Run();
int ret = SDL_PollEvent(&event);
if (ret < 0) {
std::cerr << "Error Peeping event: " << SDL_GetError() << std::endl;
std::cerr << "Exiting now" << std::endl;
return -1;
}
if (ret > 0) {
if (event.type == SDL_WINDOWEVENT) {
switch (event.window.event) {
case SDL_WINDOWEVENT_CLOSE: // exit game
//editor.Quit();
quit = true;
default:
break;
}
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
Editor editor;
wiStartupArguments::Parse(argc, argv);
sdl2::sdlsystem_ptr_t system = sdl2::make_sdlsystem(SDL_INIT_EVERYTHING | SDL_INIT_EVENTS);
if (!system) {
throw sdl2::SDLError("Error creating SDL2 system");
}
//TODO read config.ini
int x = 1920, y = 0, w = 1080, h = 0;
bool borderless = false;
string voidStr = "";
ifstream file("config.ini");
if (file.is_open())
{
int enabled;
file >> voidStr >> enabled;
if (enabled != 0)
{
file >> voidStr >> x >> voidStr >> y >> voidStr >> w >> voidStr >> h >> voidStr >> editor.fullscreen >> voidStr >> borderless;
}
}
file.close();
sdl2::window_ptr_t window = sdl2::make_window(
"Wicked Engine Editor",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
w, h,
SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN);
if (!window) {
throw sdl2::SDLError("Error creating window");
}
if(editor.fullscreen) SDL_SetWindowFullscreen(window.get(), SDL_TRUE);
editor.SetWindow(window.get());
int ret = sdl_loop(editor);
SDL_Quit();
return ret;
}