diff --git a/Frostbite2D/src/frostbite2D/core/application.cpp b/Frostbite2D/src/frostbite2D/core/application.cpp index 8a95377..494bf60 100644 --- a/Frostbite2D/src/frostbite2D/core/application.cpp +++ b/Frostbite2D/src/frostbite2D/core/application.cpp @@ -149,6 +149,12 @@ bool Application::initCoreModules() { return false; } + window_->onResize([this](int width, int height) { + renderer_->setViewport(0, 0, width, height); + camera_->setViewport(width, height); + SDL_Log("Window resized to %dx%d", width, height); + }); + // 初始化渲染器 renderer_ = &Renderer::get(); if (!renderer_->init()) { diff --git a/Frostbite2D/src/frostbite2D/core/window.cpp b/Frostbite2D/src/frostbite2D/core/window.cpp index 400276a..1bfc9e6 100644 --- a/Frostbite2D/src/frostbite2D/core/window.cpp +++ b/Frostbite2D/src/frostbite2D/core/window.cpp @@ -134,11 +134,21 @@ void Window::close() { shouldClose_ = true; } void Window::setTitle(const std::string &title) {} void Window::setSize(int w, int h) { + if (sdlWindow_) { + SDL_SetWindowSize(sdlWindow_, w, h); + } width_ = w; height_ = h; + if (resizeCb_) { + resizeCb_(w, h); + } } -void Window::setPos(int x, int y) {} +void Window::setPos(int x, int y) { + if (sdlWindow_) { + SDL_SetWindowPosition(sdlWindow_, x, y); + } +} void Window::setFullscreen(bool fs) { fullscreen_ = fs; } @@ -154,7 +164,14 @@ Size Window::size() const { return Size{static_cast(width_), static_cast(height_)}; } -Vec2 Window::pos() const { return Vec2{0.0f, 0.0f}; } +Vec2 Window::pos() const { + if (sdlWindow_) { + int x, y; + SDL_GetWindowPosition(sdlWindow_, &x, &y); + return Vec2{static_cast(x), static_cast(y)}; + } + return Vec2{0.0f, 0.0f}; +} bool Window::fullscreen() const { return fullscreen_; } diff --git a/Game/src/main.cpp b/Game/src/main.cpp index 72a19c4..0c5d7cb 100644 --- a/Game/src/main.cpp +++ b/Game/src/main.cpp @@ -100,6 +100,18 @@ int main(int argc, char **argv) { if(ke.getButton() == 6) { Application::get().quit(); } + if (ke.getButton() == 0) { + Application::get().getWindow()->setPos(0, 0); + SDL_Log("setPos ret=%d, %d", Application::get().getWindow()->pos().x, Application::get().getWindow()->pos().y); + + Application::get().getWindow()->setSize(1920, 1080); + } + if (ke.getButton() == 1) { + Application::get().getWindow()->setPos(0, 0); + + Application::get().getWindow()->setSize(1280, 720); + } + return true; });