mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Added love.window.close (resolves issue #1059), and renamed love.window.isCreated to love.window.isOpen.
This commit is contained in:
@@ -52,7 +52,7 @@ namespace sdl
|
||||
{
|
||||
|
||||
Window::Window()
|
||||
: created(false)
|
||||
: open(false)
|
||||
, mouseGrabbed(false)
|
||||
, window(nullptr)
|
||||
, context(nullptr)
|
||||
@@ -65,17 +65,7 @@ Window::Window()
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
if (context)
|
||||
{
|
||||
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
|
||||
if (gfx != nullptr)
|
||||
gfx->unSetMode();
|
||||
|
||||
SDL_GL_DeleteContext(context);
|
||||
}
|
||||
|
||||
if (window)
|
||||
SDL_DestroyWindow(window);
|
||||
close();
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
}
|
||||
@@ -345,22 +335,12 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
|
||||
}
|
||||
}
|
||||
|
||||
if (context)
|
||||
{
|
||||
SDL_GL_DeleteContext(context);
|
||||
context = nullptr;
|
||||
}
|
||||
|
||||
if (window)
|
||||
{
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_FlushEvent(SDL_WINDOWEVENT);
|
||||
window = nullptr;
|
||||
}
|
||||
close();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
open = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -439,33 +419,11 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
||||
x = y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(f.display);
|
||||
}
|
||||
|
||||
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
|
||||
if (gfx != nullptr)
|
||||
gfx->unSetMode();
|
||||
|
||||
if (context)
|
||||
{
|
||||
SDL_GL_DeleteContext(context);
|
||||
context = nullptr;
|
||||
}
|
||||
|
||||
if (window)
|
||||
{
|
||||
SDL_DestroyWindow(window);
|
||||
window = nullptr;
|
||||
|
||||
// The old window may have generated pending events which are no longer
|
||||
// relevant. Destroy them all!
|
||||
SDL_FlushEvent(SDL_WINDOWEVENT);
|
||||
}
|
||||
|
||||
created = false;
|
||||
close();
|
||||
|
||||
if (!createWindowAndContext(x, y, width, height, sdlflags, f.msaa, f.sRGB))
|
||||
return false;
|
||||
|
||||
created = true;
|
||||
|
||||
// Make sure the window keeps any previously set icon.
|
||||
setIcon(curMode.icon.get());
|
||||
|
||||
@@ -484,6 +442,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
||||
|
||||
updateSettings(f);
|
||||
|
||||
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
|
||||
if (gfx != nullptr)
|
||||
gfx->setMode(curMode.pixelwidth, curMode.pixelheight, curMode.settings.sRGB);
|
||||
|
||||
@@ -584,6 +543,31 @@ void Window::getWindow(int &width, int &height, WindowSettings &settings)
|
||||
settings = curMode.settings;
|
||||
}
|
||||
|
||||
void Window::close()
|
||||
{
|
||||
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
|
||||
if (gfx != nullptr)
|
||||
gfx->unSetMode();
|
||||
|
||||
if (context)
|
||||
{
|
||||
SDL_GL_DeleteContext(context);
|
||||
context = nullptr;
|
||||
}
|
||||
|
||||
if (window)
|
||||
{
|
||||
SDL_DestroyWindow(window);
|
||||
window = nullptr;
|
||||
|
||||
// The old window may have generated pending events which are no longer
|
||||
// relevant. Destroy them all!
|
||||
SDL_FlushEvent(SDL_WINDOWEVENT);
|
||||
}
|
||||
|
||||
open = false;
|
||||
}
|
||||
|
||||
bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
|
||||
{
|
||||
if (!window)
|
||||
@@ -730,9 +714,9 @@ void Window::getPosition(int &x, int &y, int &displayindex)
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::isCreated() const
|
||||
bool Window::isOpen() const
|
||||
{
|
||||
return created;
|
||||
return open;
|
||||
}
|
||||
|
||||
void Window::setWindowTitle(const std::string &title)
|
||||
|
||||
Reference in New Issue
Block a user