Make setters return reference to self: Window

This commit is contained in:
Dmitry Marakasov 2015-01-19 00:52:15 +03:00
parent 40e8f71efa
commit 713f42fe1d
2 changed files with 90 additions and 36 deletions

View File

@ -75,58 +75,69 @@ int Window::GetHeight() const {
return h; return h;
} }
void Window::SetTitle(const std::string& title) { Window& Window::SetTitle(const std::string& title) {
SDL_SetWindowTitle(window_, title.c_str()); SDL_SetWindowTitle(window_, title.c_str());
return *this;
} }
std::string Window::GetTitle() const { std::string Window::GetTitle() const {
return SDL_GetWindowTitle(window_); return SDL_GetWindowTitle(window_);
} }
void Window::Maximize() { Window& Window::Maximize() {
SDL_MaximizeWindow(window_); SDL_MaximizeWindow(window_);
return *this;
} }
void Window::Minimize() { Window& Window::Minimize() {
SDL_MinimizeWindow(window_); SDL_MinimizeWindow(window_);
return *this;
} }
void Window::Hide() { Window& Window::Hide() {
SDL_HideWindow(window_); SDL_HideWindow(window_);
return *this;
} }
void Window::Restore() { Window& Window::Restore() {
SDL_RestoreWindow(window_); SDL_RestoreWindow(window_);
return *this;
} }
void Window::Raise() { Window& Window::Raise() {
SDL_RaiseWindow(window_); SDL_RaiseWindow(window_);
return *this;
} }
void Window::Show() { Window& Window::Show() {
SDL_ShowWindow(window_); SDL_ShowWindow(window_);
return *this;
} }
void Window::SetFullscreen(int flags) { Window& Window::SetFullscreen(int flags) {
if (SDL_SetWindowFullscreen(window_, flags) != 0) if (SDL_SetWindowFullscreen(window_, flags) != 0)
throw Exception("SDL_SetWindowFullscreen failed"); throw Exception("SDL_SetWindowFullscreen failed");
return *this;
} }
void Window::SetSize(int w, int h) { Window& Window::SetSize(int w, int h) {
SDL_SetWindowSize(window_, w, h); SDL_SetWindowSize(window_, w, h);
return *this;
} }
void Window::SetSize(const Point& size) { Window& Window::SetSize(const Point& size) {
SDL_SetWindowSize(window_, size.x, size.y); SDL_SetWindowSize(window_, size.x, size.y);
return *this;
} }
float Window::GetBrightness() const { float Window::GetBrightness() const {
return SDL_GetWindowBrightness(window_); return SDL_GetWindowBrightness(window_);
} }
void Window::SetBrightness(float brightness) { Window& Window::SetBrightness(float brightness) {
if (SDL_SetWindowBrightness(window_, brightness) != 0) if (SDL_SetWindowBrightness(window_, brightness) != 0)
throw Exception("SDL_SetWindowBrightness failed"); throw Exception("SDL_SetWindowBrightness failed");
return *this;
} }
Point Window::GetPosition() const { Point Window::GetPosition() const {
@ -135,12 +146,14 @@ Point Window::GetPosition() const {
return Point(x, y); return Point(x, y);
} }
void Window::SetPosition(int x, int y) { Window& Window::SetPosition(int x, int y) {
SDL_SetWindowPosition(window_, x, y); SDL_SetWindowPosition(window_, x, y);
return *this;
} }
void Window::SetPosition(const Point& pos) { Window& Window::SetPosition(const Point& pos) {
SDL_SetWindowPosition(window_, pos.x, pos.y); SDL_SetWindowPosition(window_, pos.x, pos.y);
return *this;
} }
Point Window::GetMinimumSize() const { Point Window::GetMinimumSize() const {
@ -149,12 +162,14 @@ Point Window::GetMinimumSize() const {
return Point(w, h); return Point(w, h);
} }
void Window::SetMinimumSize(int w, int h) { Window& Window::SetMinimumSize(int w, int h) {
SDL_SetWindowMinimumSize(window_, w, h); SDL_SetWindowMinimumSize(window_, w, h);
return *this;
} }
void Window::SetMinimumSize(const Point& size) { Window& Window::SetMinimumSize(const Point& size) {
SDL_SetWindowMinimumSize(window_, size.x, size.y); SDL_SetWindowMinimumSize(window_, size.x, size.y);
return *this;
} }
Point Window::GetMaximumSize() const { Point Window::GetMaximumSize() const {
@ -163,20 +178,23 @@ Point Window::GetMaximumSize() const {
return Point(w, h); return Point(w, h);
} }
void Window::SetMaximumSize(int w, int h) { Window& Window::SetMaximumSize(int w, int h) {
SDL_SetWindowMaximumSize(window_, w, h); SDL_SetWindowMaximumSize(window_, w, h);
return *this;
} }
void Window::SetMaximumSize(const Point& size) { Window& Window::SetMaximumSize(const Point& size) {
SDL_SetWindowMaximumSize(window_, size.x, size.y); SDL_SetWindowMaximumSize(window_, size.x, size.y);
return *this;
} }
bool Window::GetGrab() const { bool Window::GetGrab() const {
return SDL_GetWindowGrab(window_) == SDL_TRUE; return SDL_GetWindowGrab(window_) == SDL_TRUE;
} }
void Window::SetGrab(bool grabbed) { Window& Window::SetGrab(bool grabbed) {
SDL_SetWindowGrab(window_, grabbed ? SDL_TRUE : SDL_FALSE); SDL_SetWindowGrab(window_, grabbed ? SDL_TRUE : SDL_FALSE);
return *this;
} }
} }

View File

@ -175,10 +175,12 @@ public:
/// ///
/// \param[in] title New window title in UTF-8 encoding /// \param[in] title New window title in UTF-8 encoding
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowTitle /// \see http://wiki.libsdl.org/SDL_SetWindowTitle
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetTitle(const std::string& title); Window& SetTitle(const std::string& title);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get window title /// \brief Get window title
@ -193,62 +195,76 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Make a window as large as possible /// \brief Make a window as large as possible
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_MaximizeWindow /// \see http://wiki.libsdl.org/SDL_MaximizeWindow
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Maximize(); Window& Maximize();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Minimize a window to an iconic representation /// \brief Minimize a window to an iconic representation
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_MinimizeWindow /// \see http://wiki.libsdl.org/SDL_MinimizeWindow
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Minimize(); Window& Minimize();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Hide a window /// \brief Hide a window
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_HideWindow /// \see http://wiki.libsdl.org/SDL_HideWindow
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Hide(); Window& Hide();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Restore the size and position of a minimized or maximized window /// \brief Restore the size and position of a minimized or maximized window
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_RestoreWindow /// \see http://wiki.libsdl.org/SDL_RestoreWindow
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Restore(); Window& Restore();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Raise a window above other windows and set the input focus /// \brief Raise a window above other windows and set the input focus
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_RaiseWindow /// \see http://wiki.libsdl.org/SDL_RaiseWindow
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Raise(); Window& Raise();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Show a window /// \brief Show a window
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_ShowWindow /// \see http://wiki.libsdl.org/SDL_ShowWindow
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Show(); Window& Show();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set a window's fullscreen state /// \brief Set a window's fullscreen state
/// ///
/// \param[in] flags SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP or 0 /// \param[in] flags SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP or 0
/// ///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception /// \throws SDL2pp::Exception
/// ///
/// \see http://wiki.libsdl.org/SDL_SetWindowFullscreen /// \see http://wiki.libsdl.org/SDL_SetWindowFullscreen
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetFullscreen(int flags); Window& SetFullscreen(int flags);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the size of a window's client area /// \brief Set the size of a window's client area
@ -256,20 +272,24 @@ public:
/// \param[in] w Width of the window in pixels /// \param[in] w Width of the window in pixels
/// \param[in] h Height of the window in pixels /// \param[in] h Height of the window in pixels
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowSize /// \see http://wiki.libsdl.org/SDL_SetWindowSize
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetSize(int w, int h); Window& SetSize(int w, int h);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the size of a window's client area /// \brief Set the size of a window's client area
/// ///
/// \param[in] size Point representing window dimensions /// \param[in] size Point representing window dimensions
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowSize /// \see http://wiki.libsdl.org/SDL_SetWindowSize
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetSize(const Point& size); Window& SetSize(const Point& size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the brightness (gamma multiplier) for the display that owns a given window /// \brief Get the brightness (gamma multiplier) for the display that owns a given window
@ -286,12 +306,14 @@ public:
/// ///
/// \param[in] brightness Brightness value to set where 0.0 is completely dark and 1.0 is normal brightness /// \param[in] brightness Brightness value to set where 0.0 is completely dark and 1.0 is normal brightness
/// ///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception /// \throws SDL2pp::Exception
/// ///
/// \see http://wiki.libsdl.org/SDL_SetWindowBrightness /// \see http://wiki.libsdl.org/SDL_SetWindowBrightness
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetBrightness(float brightness); Window& SetBrightness(float brightness);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the position of a window /// \brief Get the position of a window
@ -309,20 +331,24 @@ public:
/// \param[in] x X coordinate of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED /// \param[in] x X coordinate of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
/// \param[in] y Y coordinate of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED /// \param[in] y Y coordinate of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowPosition /// \see http://wiki.libsdl.org/SDL_SetWindowPosition
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetPosition(int x, int y); Window& SetPosition(int x, int y);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the position of a window /// \brief Set the position of a window
/// ///
/// \param[in] pos Point representin position of the a window /// \param[in] pos Point representin position of the a window
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowPosition /// \see http://wiki.libsdl.org/SDL_SetWindowPosition
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetPosition(const Point& pos); Window& SetPosition(const Point& pos);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the minimum size of a window's client area /// \brief Get the minimum size of a window's client area
@ -340,20 +366,24 @@ public:
/// \param[in] w Minimum width of the window in pixels /// \param[in] w Minimum width of the window in pixels
/// \param[in] h Minimum height of the window in pixels /// \param[in] h Minimum height of the window in pixels
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowMinimumSize /// \see http://wiki.libsdl.org/SDL_SetWindowMinimumSize
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetMinimumSize(int w, int h); Window& SetMinimumSize(int w, int h);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the minimum size of a window's client area /// \brief Set the minimum size of a window's client area
/// ///
/// \param[in] size Minimum area of the window in pixels /// \param[in] size Minimum area of the window in pixels
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowMinimumSize /// \see http://wiki.libsdl.org/SDL_SetWindowMinimumSize
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetMinimumSize(const Point& size); Window& SetMinimumSize(const Point& size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the maximum size of a window's client area /// \brief Get the maximum size of a window's client area
@ -371,20 +401,24 @@ public:
/// \param[in] w Maximum width of the window in pixels /// \param[in] w Maximum width of the window in pixels
/// \param[in] h Maximum height of the window in pixels /// \param[in] h Maximum height of the window in pixels
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowMaximumSize /// \see http://wiki.libsdl.org/SDL_SetWindowMaximumSize
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetMaximumSize(int w, int h); Window& SetMaximumSize(int w, int h);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the maximum size of a window's client area /// \brief Set the maximum size of a window's client area
/// ///
/// \param[in] size Maximum area of the window in pixels /// \param[in] size Maximum area of the window in pixels
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowMaximumSize /// \see http://wiki.libsdl.org/SDL_SetWindowMaximumSize
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetMaximumSize(const Point& size); Window& SetMaximumSize(const Point& size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get a window's input grab mode /// \brief Get a window's input grab mode
@ -401,10 +435,12 @@ public:
/// ///
/// \param[in] grabbed True to grab input, false to release input /// \param[in] grabbed True to grab input, false to release input
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowGrab /// \see http://wiki.libsdl.org/SDL_SetWindowGrab
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetGrab(bool grabbed); Window& SetGrab(bool grabbed);
}; };
} }