Browse Source

Platform: improve {Glfw,Sdl2}Application.

Two new methods, setMinWindowSize() and setMaxWindowSize(), were added.
They use the underlying library's API to achieve their purpose.
pull/335/head
Guillaume Jacquemin 7 years ago
parent
commit
fcb1a6af1f
  1. 14
      src/Magnum/Platform/GlfwApplication.cpp
  2. 19
      src/Magnum/Platform/GlfwApplication.h
  3. 12
      src/Magnum/Platform/Sdl2Application.cpp
  4. 18
      src/Magnum/Platform/Sdl2Application.h

14
src/Magnum/Platform/GlfwApplication.cpp

@ -534,6 +534,20 @@ Vector2i GlfwApplication::windowSize() const {
return size; return size;
} }
void GlfwApplication::setMinWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::GlfwApplication::setMinWindowSize(): no window opened", );
glfwSetWindowSizeLimits(_window, size.x(), size.y(), _maxWindowSize.x(), _maxWindowSize.y());
_minWindowSize = size;
}
void GlfwApplication::setMaxWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::GlfwApplication::setMaxWindowSize(): no window opened", );
glfwSetWindowSizeLimits(_window, _minWindowSize.x(), _minWindowSize.y(), size.x(), size.y());
_maxWindowSize = size;
}
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
Vector2i GlfwApplication::framebufferSize() const { Vector2i GlfwApplication::framebufferSize() const {
CORRADE_ASSERT(_window, "Platform::GlfwApplication::framebufferSize(): no window opened", {}); CORRADE_ASSERT(_window, "Platform::GlfwApplication::framebufferSize(): no window opened", {});

19
src/Magnum/Platform/GlfwApplication.h

@ -336,6 +336,22 @@ class GlfwApplication {
*/ */
Vector2i windowSize() const; Vector2i windowSize() const;
/**
* @brief Set window minimum size
* @param size The minimum size, in screen coordinates.
*
* If a value is set to -1, it will disable/remove the corresponding limit.
*/
void setMinWindowSize(const Vector2i& size = {-1, -1});
/**
* @brief Set window maximum size
* @param size The maximum size, in screen coordinates.
*
* If a value is set to -1, it will disable/remove the corresponding limit.
*/
void setMaxWindowSize(const Vector2i& size = {-1, -1});
#if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT) #if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT)
/** /**
* @brief Framebuffer size * @brief Framebuffer size
@ -552,6 +568,9 @@ class GlfwApplication {
Containers::Pointer<Platform::GLContext> _context; Containers::Pointer<Platform::GLContext> _context;
#endif #endif
int _exitCode; int _exitCode;
Vector2i _minWindowSize;
Vector2i _maxWindowSize;
}; };
CORRADE_ENUMSET_OPERATORS(GlfwApplication::Flags) CORRADE_ENUMSET_OPERATORS(GlfwApplication::Flags)

12
src/Magnum/Platform/Sdl2Application.cpp

@ -550,6 +550,18 @@ Vector2i Sdl2Application::windowSize() const {
return size; return size;
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN
void Sdl2Application::setMinWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::Sdl2Application::setMinWindowSize(): no window opened", );
SDL_SetWindowMinimumSize(_window, size.x(), size.y());
}
void Sdl2Application::setMaxWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::Sdl2Application::setMaxWindowSize(): no window opened", );
SDL_SetWindowMaximumSize(_window, size.x(), size.y());
}
#endif
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
Vector2i Sdl2Application::framebufferSize() const { Vector2i Sdl2Application::framebufferSize() const {
Vector2i size; Vector2i size;

18
src/Magnum/Platform/Sdl2Application.h

@ -639,6 +639,24 @@ class Sdl2Application {
*/ */
Vector2i windowSize() const; Vector2i windowSize() const;
#if !defined(CORRADE_TARGET_EMSCRIPTEN) || defined(DOXYGEN_GENERATING_OUTPUT)
/**
* @brief Set minimum window size
* @param size The minimum size for the window, in screen coordinates.
*
* Note that SDL2 doesn't have a way to disable/remove a size limit.
*/
void setMinWindowSize(const Vector2i& size);
/**
* @brief Set maximal window size
* @param size The maximum size for the window, in screen coordinates.
*
* Note that SDL2 doesn't have a way to disable/remove a size limit.
*/
void setMaxWindowSize(const Vector2i& size);
#endif
#if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT) #if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT)
/** /**
* @brief Framebuffer size * @brief Framebuffer size

Loading…
Cancel
Save