Browse Source

Platform: ability to set window size in Sdl2 and GlfwApplication.

It had the min/max size setters added in 2019.10 but this was missing.
pull/405/head
Vladimír Vondruš 6 years ago
parent
commit
e67526abf0
  1. 2
      doc/changelog.dox
  2. 7
      src/Magnum/Platform/GlfwApplication.cpp
  3. 18
      src/Magnum/Platform/GlfwApplication.h
  4. 7
      src/Magnum/Platform/Sdl2Application.cpp
  5. 21
      src/Magnum/Platform/Sdl2Application.h
  6. 3
      src/Magnum/Platform/Test/GlfwApplicationTest.cpp
  7. 5
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

2
doc/changelog.dox

@ -72,6 +72,8 @@ See also:
@ref Platform::GlfwApplication::setCursor() and @ref Platform::GlfwApplication::setCursor() and
@ref Platform::EmscriptenApplication::setCursor() (see @ref Platform::EmscriptenApplication::setCursor() (see
[mosra/magnum#383](https://github.com/mosra/magnum/pull/383)) [mosra/magnum#383](https://github.com/mosra/magnum/pull/383))
- Added @ref Platform::GlfwApplication::setWindowSize() and
@ref Platform::Sdl2Application::setWindowSize()
- Window icon management using @ref Platform::Sdl2Application::setWindowIcon() - Window icon management using @ref Platform::Sdl2Application::setWindowIcon()
and @ref Platform::GlfwApplication::setWindowIcon() (see and @ref Platform::GlfwApplication::setWindowIcon() (see
[mosra/magnum#393](https://github.com/mosra/magnum/issues/393)) [mosra/magnum#393](https://github.com/mosra/magnum/issues/393))

7
src/Magnum/Platform/GlfwApplication.cpp

@ -647,6 +647,13 @@ Vector2i GlfwApplication::windowSize() const {
return size; return size;
} }
void GlfwApplication::setWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::GlfwApplication::setWindowSize(): no window opened", );
const Vector2i newSize = _dpiScaling*size;
glfwSetWindowSize(_window, newSize.x(), newSize.y());
}
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
void GlfwApplication::setMinWindowSize(const Vector2i& size) { void GlfwApplication::setMinWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::GlfwApplication::setMinWindowSize(): no window opened", ); CORRADE_ASSERT(_window, "Platform::GlfwApplication::setMinWindowSize(): no window opened", );

18
src/Magnum/Platform/GlfwApplication.h

@ -355,6 +355,18 @@ class GlfwApplication {
*/ */
Vector2i windowSize() const; Vector2i windowSize() const;
/**
* @brief Set window size
* @param size The size, in screen coordinates
* @m_since_latest
*
* To make the sizing work independently of the display DPI, @p size is
* internally multiplied with @ref dpiScaling() before getting applied.
* Expects that a window is already created.
* @see @ref setMinWindowSize(), @ref setMaxWindowSize()
*/
void setWindowSize(const Vector2i& size);
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 || defined(DOXYGEN_GENERATING_OUTPUT) #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 || defined(DOXYGEN_GENERATING_OUTPUT)
/** /**
* @brief Set window minimum size * @brief Set window minimum size
@ -364,8 +376,9 @@ class GlfwApplication {
* If a value is set to @cpp -1 @ce, it will disable/remove the * If a value is set to @cpp -1 @ce, it will disable/remove the
* corresponding limit. To make the sizing work independently of the * corresponding limit. To make the sizing work independently of the
* display DPI, @p size is internally multiplied with @ref dpiScaling() * display DPI, @p size is internally multiplied with @ref dpiScaling()
* before getting applied. * before getting applied. Expects that a window is already created.
* @note Supported since GLFW 3.2. * @note Supported since GLFW 3.2.
* @see @ref setMaxWindowSize(), @ref setWindowSize()
*/ */
void setMinWindowSize(const Vector2i& size = {-1, -1}); void setMinWindowSize(const Vector2i& size = {-1, -1});
@ -377,8 +390,9 @@ class GlfwApplication {
* If a value is set to @cpp -1 @ce, it will disable/remove the * If a value is set to @cpp -1 @ce, it will disable/remove the
* corresponding limit. To make the sizing work independently of the * corresponding limit. To make the sizing work independently of the
* display DPI, @p size is internally multiplied with @ref dpiScaling() * display DPI, @p size is internally multiplied with @ref dpiScaling()
* before getting applied. * before getting applied. Expects that a window is already created.
* @note Supported since GLFW 3.2. * @note Supported since GLFW 3.2.
* @see @ref setMinWindowSize(), @ref setMaxWindowSize()
*/ */
void setMaxWindowSize(const Vector2i& size = {-1, -1}); void setMaxWindowSize(const Vector2i& size = {-1, -1});
#endif #endif

7
src/Magnum/Platform/Sdl2Application.cpp

@ -639,6 +639,13 @@ Vector2i Sdl2Application::windowSize() const {
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
void Sdl2Application::setWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::Sdl2Application::setWindowSize(): no window opened", );
const Vector2i newSize = _dpiScaling*size;
SDL_SetWindowSize(_window, newSize.x(), newSize.y());
}
void Sdl2Application::setMinWindowSize(const Vector2i& size) { void Sdl2Application::setMinWindowSize(const Vector2i& size) {
CORRADE_ASSERT(_window, "Platform::Sdl2Application::setMinWindowSize(): no window opened", ); CORRADE_ASSERT(_window, "Platform::Sdl2Application::setMinWindowSize(): no window opened", );

21
src/Magnum/Platform/Sdl2Application.h

@ -637,6 +637,19 @@ class Sdl2Application {
Vector2i windowSize() const; Vector2i windowSize() const;
#if !defined(CORRADE_TARGET_EMSCRIPTEN) || defined(DOXYGEN_GENERATING_OUTPUT) #if !defined(CORRADE_TARGET_EMSCRIPTEN) || defined(DOXYGEN_GENERATING_OUTPUT)
/**
* @brief Set window size
* @param size The size, in screen coordinates
* @m_since_latest
*
* To make the sizing work independently of the display DPI, @p size is
* internally multiplied with @ref dpiScaling() before getting applied.
* Expects that a window is already created.
* @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten".
* @see @ref setMinWindowSize(), @ref setMaxWindowSize()
*/
void setWindowSize(const Vector2i& size);
/** /**
* @brief Set minimum window size * @brief Set minimum window size
* @param size The minimum size, in screen coordinates * @param size The minimum size, in screen coordinates
@ -645,8 +658,10 @@ class Sdl2Application {
* Note that, unlike in @ref GlfwApplication, SDL2 doesn't have a way * Note that, unlike in @ref GlfwApplication, SDL2 doesn't have a way
* to disable/remove a size limit. To make the sizing work * to disable/remove a size limit. To make the sizing work
* independently of the display DPI, @p size is internally multiplied * independently of the display DPI, @p size is internally multiplied
* with @ref dpiScaling() before getting applied. * with @ref dpiScaling() before getting applied. Expects that a window
* is already created.
* @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten". * @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten".
* @see @ref setMaxWindowSize(), @ref setWindowSize()
*/ */
void setMinWindowSize(const Vector2i& size); void setMinWindowSize(const Vector2i& size);
@ -658,8 +673,10 @@ class Sdl2Application {
* Note that, unlike in @ref GlfwApplication, SDL2 doesn't have a way * Note that, unlike in @ref GlfwApplication, SDL2 doesn't have a way
* to disable/remove a size limit. To make the sizing work * to disable/remove a size limit. To make the sizing work
* independently of the display DPI, @p size is internally multiplied * independently of the display DPI, @p size is internally multiplied
* with @ref dpiScaling() before getting applied. * with @ref dpiScaling() before getting applied. Expects that a window
* is already created.
* @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten". * @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten".
* @see @ref setMinWindowSize(), @ref setMaxWindowSize()
*/ */
void setMaxWindowSize(const Vector2i& size); void setMaxWindowSize(const Vector2i& size);
#endif #endif

3
src/Magnum/Platform/Test/GlfwApplicationTest.cpp

@ -61,6 +61,9 @@ struct GlfwApplicationTest: Platform::Application {
} else if(event.key() == KeyEvent::Key::T) { } else if(event.key() == KeyEvent::Key::T) {
Debug{} << "setting window title"; Debug{} << "setting window title";
setWindowTitle("This is a UTF-8 Window Title™!"); setWindowTitle("This is a UTF-8 Window Title™!");
} else if(event.key() == KeyEvent::Key::S) {
Debug{} << "setting window size, which should trigger a viewport event";
setWindowSize(Vector2i{300, 200});
} }
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
else if(event.key() == KeyEvent::Key::W) { else if(event.key() == KeyEvent::Key::W) {

5
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -87,7 +87,10 @@ struct Sdl2ApplicationTest: Platform::Application {
setWindowTitle("This is a UTF-8 Window Title™!"); setWindowTitle("This is a UTF-8 Window Title™!");
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
else if(event.key() == KeyEvent::Key::W) { else if(event.key() == KeyEvent::Key::S) {
Debug{} << "setting window size, which should trigger a viewport event";
setWindowSize(Vector2i{300, 200});
} else if(event.key() == KeyEvent::Key::W) {
Debug{} << "setting max window size, which should trigger a viewport event"; Debug{} << "setting max window size, which should trigger a viewport event";
setMaxWindowSize(Vector2i{700, 500}); setMaxWindowSize(Vector2i{700, 500});
} }

Loading…
Cancel
Save