Archived
1
Fork 0

Specifying -1 in your window positions will make SDL center the window

This commit is contained in:
redstrate 2021-04-20 12:57:59 -04:00
parent 0935528d76
commit 4cd63997ce
2 changed files with 11 additions and 2 deletions

View file

@ -9,7 +9,7 @@ void app_main(prism::engine* engine) {
file::set_domain_path(file::Domain::App, "data");
file::set_domain_path(file::Domain::Internal, "{resource_dir}/shaders");
platform::open_window("Example", {0, 0, 1280, 720}, WindowFlags::Resizable);
platform::open_window("Example", {-1, -1, 1280, 720}, WindowFlags::Resizable);
}
void ExampleApp::initialize_render() {

View file

@ -89,7 +89,14 @@ int platform::open_window(const std::string_view title, const prism::Rectangle r
if(flags == WindowFlags::Resizable)
sdl_flags |= SDL_WINDOW_RESIZABLE;
win.window = SDL_CreateWindow(title.data(), rect.offset.x, rect.offset.y, rect.extent.width, rect.extent.height, sdl_flags);
int real_x = rect.offset.x;
int real_y = rect.offset.y;
if(rect.offset.x == -1 && rect.offset.y == -1) {
real_x = SDL_WINDOWPOS_CENTERED;
real_y = SDL_WINDOWPOS_CENTERED;
}
win.window = SDL_CreateWindow(title.data(), real_x, real_y, rect.extent.width, rect.extent.height, sdl_flags);
engine->add_window((void*)&win, win.identifier, rect.extent);
app->initialize_render();
@ -281,6 +288,8 @@ int main(int argc, char* argv[]) {
auto window = get_window_by_sdl_id(event.window.windowID);
if(window != nullptr)
engine->resize(window->identifier, {static_cast<uint32_t>(event.window.data1), static_cast<uint32_t>(event.window.data2)});
} else if(event.window.event == SDL_WINDOWEVENT_CLOSE) {
engine->quit();
}
break;
}