Browse Source

Platform: replace std::string with String/StringView in GlfwApplication

Signed-off-by: Squareys <squareys@googlemail.com>
pull/559/head
Squareys 4 years ago
parent
commit
0765268465
  1. 21
      src/Magnum/Platform/GlfwApplication.cpp
  2. 24
      src/Magnum/Platform/GlfwApplication.h

21
src/Magnum/Platform/GlfwApplication.cpp

@ -101,7 +101,7 @@ GlfwApplication::GlfwApplication(const Arguments& arguments, NoCreateT):
/* Save command-line arguments */
if(args.value("log") == "verbose") _verboseLog = true;
const std::string dpiScaling = args.value("dpi-scaling");
const Containers::String dpiScaling = args.value("dpi-scaling");
if(dpiScaling == "default")
_commandLineDpiScalingPolicy = Implementation::GlfwDpiScalingPolicy::Default;
#ifdef CORRADE_TARGET_APPLE
@ -113,7 +113,7 @@ GlfwApplication::GlfwApplication(const Arguments& arguments, NoCreateT):
else if(dpiScaling == "physical")
_commandLineDpiScalingPolicy = Implementation::GlfwDpiScalingPolicy::Physical;
#endif
else if(dpiScaling.find_first_of(" \t\n") != std::string::npos)
else if(dpiScaling.find(' ') || dpiScaling.find('\t') || dpiScaling.find('\n'))
_commandLineDpiScaling = args.value<Vector2>("dpi-scaling");
else
_commandLineDpiScaling = Vector2{args.value<Float>("dpi-scaling")};
@ -243,8 +243,8 @@ Vector2 GlfwApplication::dpiScaling(const Configuration& configuration) {
#endif
}
void GlfwApplication::setWindowTitle(const std::string& title) {
glfwSetWindowTitle(_window, title.data());
void GlfwApplication::setWindowTitle(const Containers::StringView title) {
glfwSetWindowTitle(_window, String::nullTerminatedView(title).data());
}
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
@ -348,7 +348,7 @@ bool GlfwApplication::tryCreate(const Configuration& configuration) {
#endif
/* Create the window */
_window = glfwCreateWindow(scaledWindowSize.x(), scaledWindowSize.y(), configuration.title().c_str(), monitor, nullptr);
_window = glfwCreateWindow(scaledWindowSize.x(), scaledWindowSize.y(), configuration.title().data(), monitor, nullptr);
if(!_window) {
Error() << "Platform::GlfwApplication::tryCreate(): cannot create window";
glfwTerminate();
@ -505,7 +505,7 @@ bool GlfwApplication::tryCreate(const Configuration& configuration, const GLConf
glfwWindowHint(GLFW_VISIBLE, false);
else if(_verboseLog)
Warning{} << "Platform::GlfwApplication: Wayland detected, GL context has to be created with the window visible and may cause flicker on startup";
if((_window = glfwCreateWindow(scaledWindowSize.x(), scaledWindowSize.y(), configuration.title().c_str(), monitor, nullptr)))
if((_window = glfwCreateWindow(scaledWindowSize.x(), scaledWindowSize.y(), configuration.title().data(), monitor, nullptr)))
glfwMakeContextCurrent(_window);
#ifndef MAGNUM_TARGET_GLES
@ -544,7 +544,7 @@ bool GlfwApplication::tryCreate(const Configuration& configuration, const GLConf
just 2.1) and I assume on others as well. */
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, false);
_window = glfwCreateWindow(scaledWindowSize.x(), scaledWindowSize.y(), configuration.title().c_str(), monitor, nullptr);
_window = glfwCreateWindow(scaledWindowSize.x(), scaledWindowSize.y(), configuration.title().data(), monitor, nullptr);
}
#endif
@ -909,12 +909,11 @@ GlfwApplication::Configuration::Configuration():
GlfwApplication::Configuration::~Configuration() = default;
#if defined(DOXYGEN_GENERATING_OUTPUT) || GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
std::string GlfwApplication::KeyEvent::keyName(const Key key) {
/* It can return null, so beware */
return Utility::String::fromArray(glfwGetKeyName(int(key), 0));
Containers::StringView GlfwApplication::KeyEvent::keyName(const Key key) {
return glfwGetKeyName(int(key), 0);
}
std::string GlfwApplication::KeyEvent::keyName() const {
Containers::StringView GlfwApplication::KeyEvent::keyName() const {
return keyName(_key);
}
#endif

24
src/Magnum/Platform/GlfwApplication.h

@ -32,9 +32,13 @@
* @brief Class @ref Magnum::Platform::GlfwApplication, macro @ref MAGNUM_GLFWAPPLICATION_MAIN()
*/
#include <string>
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/String.h>
#ifdef MAGNUM_BUILD_DEPRECATED
/* Some APIs used to take or return a std::string before */
#include <Corrade/Containers/StringStl.h>
#endif
#include "Magnum/Magnum.h"
#include "Magnum/Tags.h"
@ -474,7 +478,7 @@ class GlfwApplication {
*
* The @p title is expected to be encoded in UTF-8.
*/
void setWindowTitle(const std::string& title);
void setWindowTitle(Containers::StringView title);
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 || defined(DOXYGEN_GENERATING_OUTPUT)
/**
@ -1219,7 +1223,7 @@ class GlfwApplication::Configuration {
~Configuration();
/** @brief Window title */
std::string title() const { return _title; }
Containers::StringView title() const { return _title; }
/**
* @brief Set window title
@ -1227,8 +1231,8 @@ class GlfwApplication::Configuration {
*
* Default is @cpp "Magnum GLFW Application" @ce.
*/
Configuration& setTitle(std::string title) {
_title = std::move(title);
Configuration& setTitle(Containers::StringView title) {
_title = Containers::String::nullTerminatedGlobalView(title);
return *this;
}
@ -1368,7 +1372,7 @@ class GlfwApplication::Configuration {
#endif
private:
std::string _title;
Containers::String _title;
Vector2i _size;
WindowFlags _windowFlags;
DpiScalingPolicy _dpiScalingPolicy;
@ -1815,10 +1819,12 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
* Human-readable localized UTF-8 name for given @p key, intended for
* displaying to the user in e.g. key binding configuration. If there
* is no name for given key, empty string is returned.
* The returned string view is valid until the keyboard layout is changed
* or the GLFW application exits.
* @see @ref keyName(Key)
* @note Supported since GLFW 3.2.
*/
static std::string keyName(Key key);
static Containers::StringView keyName(Key key);
#endif
/** @copydoc Sdl2Application::KeyEvent::key() */
@ -1832,10 +1838,12 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
* @ref key(), intended for displaying to the user in e.g.
* key binding configuration. If there is no name for that key, empty
* string is returned.
* The returned string view is valid until the keyboard layout is changed
* or the GLFW application exits.
* @see @ref keyName(Key)
* @note Supported since GLFW 3.2.
*/
std::string keyName() const;
Containers::StringView keyName() const;
#endif
/** @brief Modifiers */

Loading…
Cancel
Save