diff --git a/SDL2pp/AudioDevice.cc b/SDL2pp/AudioDevice.cc index f06a872..6d2bba0 100644 --- a/SDL2pp/AudioDevice.cc +++ b/SDL2pp/AudioDevice.cc @@ -1,6 +1,6 @@ /* libSDL2pp - C++11 bindings/wrapper for SDL2 - Copyright (C) 2014 Dmitry Marakasov + Copyright (C) 2014-2015 Dmitry Marakasov This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -88,19 +88,22 @@ SDL_AudioDeviceID AudioDevice::Get() const { return device_id_; } -void AudioDevice::Pause(bool pause_on) { +AudioDevice& AudioDevice::Pause(bool pause_on) { SDL_PauseAudioDevice(device_id_, pause_on ? 1 : 0); + return *this; } SDL_AudioStatus AudioDevice::GetStatus() const { return SDL_GetAudioDeviceStatus(device_id_); } -void AudioDevice::ChangeCallback(AudioDevice::AudioCallback&& callback) { +AudioDevice& AudioDevice::ChangeCallback(AudioDevice::AudioCallback&& callback) { // make sure callback is not called while it's being replaced LockHandle lock = Lock(); callback_ = std::move(callback); + + return *this; } AudioDevice::LockHandle AudioDevice::Lock() { @@ -108,13 +111,15 @@ AudioDevice::LockHandle AudioDevice::Lock() { } #ifdef SDL2PP_WITH_2_0_4 -void AudioDevice::QueueAudio(const void* data, Uint32 len) { +AudioDevice& AudioDevice::QueueAudio(const void* data, Uint32 len) { if (SDL_QueueAudio(device_id_, data, len) == 0) throw Exception("SDL_QueueAudio failed"); + return *this; } -void AudioDevice::ClearQueuedAudio() { +AudioDevice& AudioDevice::ClearQueuedAudio() { SDL_ClearQueuedAudio(device_id_); + return *this; } Uint32 GetQueuedAudioSize() const { diff --git a/SDL2pp/AudioDevice.hh b/SDL2pp/AudioDevice.hh index ea1b712..fdf6fcc 100644 --- a/SDL2pp/AudioDevice.hh +++ b/SDL2pp/AudioDevice.hh @@ -263,10 +263,12 @@ public: /// /// \param[in] pause_on Whether audio should be paused /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_PauseAudioDevice /// //////////////////////////////////////////////////////////// - void Pause(bool pause_on); + AudioDevice& Pause(bool pause_on); //////////////////////////////////////////////////////////// /// \brief Get playback status @@ -283,8 +285,10 @@ public: /// /// \param[in] callback New audio callback /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void ChangeCallback(AudioCallback&& callback); + AudioDevice& ChangeCallback(AudioCallback&& callback); //////////////////////////////////////////////////////////// /// \brief Lock audio device to prevent it from calling audio callback @@ -307,20 +311,24 @@ public: /// \param[in] data Data to queue for later playback /// \param[in] len Data length in bytes (not samples!) /// + /// \returns Reference to self + /// /// \throws SDL2pp::Exception /// /// \see http://wiki.libsdl.org/SDL_QueueAudio /// //////////////////////////////////////////////////////////// - void QueueAudio(const void* data, Uint32 len); + AudioDevice& QueueAudio(const void* data, Uint32 len); //////////////////////////////////////////////////////////// /// \brief Drop queued audio /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_ClearQueuedAudio /// //////////////////////////////////////////////////////////// - void ClearQueuedAudio(); + AudioDevice& ClearQueuedAudio(); //////////////////////////////////////////////////////////// /// \brief Get number of bytes of still-queued audio diff --git a/SDL2pp/Font.cc b/SDL2pp/Font.cc index 4926716..86b7ec8 100644 --- a/SDL2pp/Font.cc +++ b/SDL2pp/Font.cc @@ -68,32 +68,36 @@ int Font::GetStyle() const { return TTF_GetFontStyle(font_); } -void Font::SetStyle(int style) { +Font& Font::SetStyle(int style) { TTF_SetFontStyle(font_, style); + return *this; } int Font::GetOutline() const { return TTF_GetFontOutline(font_); } -void Font::SetOutline(int outline) { +Font& Font::SetOutline(int outline) { TTF_SetFontOutline(font_, outline); + return *this; } int Font::GetHinting() const { return TTF_GetFontHinting(font_); } -void Font::SetHinting(int hinting) { +Font& Font::SetHinting(int hinting) { TTF_SetFontHinting(font_, hinting); + return *this; } bool Font::GetKerning() const { return TTF_GetFontKerning(font_); } -void Font::SetKerning(bool allowed) { +Font& Font::SetKerning(bool allowed) { TTF_SetFontKerning(font_, allowed); + return *this; } int Font::GetHeight() const { diff --git a/SDL2pp/Font.hh b/SDL2pp/Font.hh index 52ec454..e932c84 100644 --- a/SDL2pp/Font.hh +++ b/SDL2pp/Font.hh @@ -177,10 +177,12 @@ public: /// In this case, you should probably turn off these styles and draw your /// own strikethroughs and underlines. /// + /// \returns Reference to self + /// /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC22 /// //////////////////////////////////////////////////////////// - void SetStyle(int style = TTF_STYLE_NORMAL); + Font& SetStyle(int style = TTF_STYLE_NORMAL); //////////////////////////////////////////////////////////// /// \brief Get the current outline size of the loaded font @@ -202,10 +204,12 @@ public: /// glyphs, even if there is no change in outline size, so it may be best /// to check the current outline size by using GetOutline() first /// + /// \returns Reference to self + /// /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC24 /// //////////////////////////////////////////////////////////// - void SetOutline(int outline = 0); + Font& SetOutline(int outline = 0); //////////////////////////////////////////////////////////// /// \brief Get the current hinting setting of the loaded font @@ -235,10 +239,12 @@ public: /// glyphs, even if there is no change in hinting, so it may be best /// to check the current hinting by using GetHinting() first /// + /// \returns Reference to self + /// /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC26 /// //////////////////////////////////////////////////////////// - void SetHinting(int hinting = TTF_HINTING_NORMAL); + Font& SetHinting(int hinting = TTF_HINTING_NORMAL); //////////////////////////////////////////////////////////// /// \brief Get the current kerning setting of the loaded font @@ -264,10 +270,12 @@ public: /// is not working for a specific font, resulting in overlapping /// glyphs or abnormal spacing within words. /// + /// \returns Reference to self + /// /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC28 /// //////////////////////////////////////////////////////////// - void SetKerning(bool allowed = true); + Font& SetKerning(bool allowed = true); //////////////////////////////////////////////////////////// /// \brief Get the maximum pixel height of all glyphs of the loaded font diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 0e91b76..6f66298 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -50,16 +50,18 @@ int Point::GetX() const { return x; } -void Point::SetX(int nx) { +Point& Point::SetX(int nx) { x = nx; + return *this; } int Point::GetY() const { return y; } -void Point::SetY(int ny) { +Point& Point::SetY(int ny) { y = ny; + return *this; } Point Point::operator+(const Point& other) const { diff --git a/SDL2pp/Point.hh b/SDL2pp/Point.hh index 883c521..bf883be 100644 --- a/SDL2pp/Point.hh +++ b/SDL2pp/Point.hh @@ -129,8 +129,10 @@ public: /// /// \param[in] nx New X coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetX(int nx); + Point& SetX(int nx); //////////////////////////////////////////////////////////// /// \brief Get Y coordinate of the point @@ -145,8 +147,10 @@ public: /// /// \param[in] ny New Y coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetY(int ny); + Point& SetY(int ny); //////////////////////////////////////////////////////////// /// \brief Get point's memberwise addition with another point diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index 70529a8..89962f8 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -84,31 +84,34 @@ int Rect::GetX() const { return x; } -void Rect::SetX(int nx) { +Rect& Rect::SetX(int nx) { x = nx; + return *this; } int Rect::GetY() const { return y; } -void Rect::SetY(int ny) { +Rect& Rect::SetY(int ny) { y = ny; + return *this; } int Rect::GetW() const { return w; } -void Rect::SetW(int nw) { +Rect& Rect::SetW(int nw) { w = nw; + return *this; } int Rect::GetH() const { return h; } -void Rect::SetH(int nh) { +Rect& Rect::SetH(int nh) { h = nh; } @@ -116,16 +119,18 @@ int Rect::GetX2() const { return x + w - 1; } -void Rect::SetX2(int x2) { +Rect& Rect::SetX2(int x2) { w = x2 - x + 1; + return *this; } int Rect::GetY2() const { return y + h - 1; } -void Rect::SetY2(int y2) { +Rect& Rect::SetY2(int y2) { h = y2 - y + 1; + return *this; } bool Rect::Contains(int px, int py) const { diff --git a/SDL2pp/Rect.hh b/SDL2pp/Rect.hh index aaf272f..6cd7b71 100644 --- a/SDL2pp/Rect.hh +++ b/SDL2pp/Rect.hh @@ -186,8 +186,10 @@ public: /// /// \param[in] nx New X coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetX(int nx); + Rect& SetX(int nx); //////////////////////////////////////////////////////////// /// \brief Get Y coordinate of the rect corner @@ -202,8 +204,10 @@ public: /// /// \param[in] ny New Y coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetY(int ny); + Rect& SetY(int ny); //////////////////////////////////////////////////////////// /// \brief Get width of the rect @@ -218,8 +222,10 @@ public: /// /// \param[in] nw New width of the rect /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetW(int nw); + Rect& SetW(int nw); //////////////////////////////////////////////////////////// /// \brief Get height of the rect @@ -234,8 +240,10 @@ public: /// /// \param[in] nh New height of the rect /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetH(int nh); + Rect& SetH(int nh); //////////////////////////////////////////////////////////// /// \brief Get X coordinate of the rect second corner @@ -250,8 +258,10 @@ public: /// /// \param[in] x2 New X coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetX2(int x2); + Rect& SetX2(int x2); //////////////////////////////////////////////////////////// /// \brief Get Y coordinate of the rect second corner @@ -270,8 +280,10 @@ public: /// /// This modifies rectangle height internally /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetY2(int y2); + Rect& SetY2(int y2); //////////////////////////////////////////////////////////// /// \brief Check whether the rect contains given point diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index ec3de13..bef5db0 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -75,58 +75,69 @@ int Window::GetHeight() const { return h; } -void Window::SetTitle(const std::string& title) { +Window& Window::SetTitle(const std::string& title) { SDL_SetWindowTitle(window_, title.c_str()); + return *this; } std::string Window::GetTitle() const { return SDL_GetWindowTitle(window_); } -void Window::Maximize() { +Window& Window::Maximize() { SDL_MaximizeWindow(window_); + return *this; } -void Window::Minimize() { +Window& Window::Minimize() { SDL_MinimizeWindow(window_); + return *this; } -void Window::Hide() { +Window& Window::Hide() { SDL_HideWindow(window_); + return *this; } -void Window::Restore() { +Window& Window::Restore() { SDL_RestoreWindow(window_); + return *this; } -void Window::Raise() { +Window& Window::Raise() { SDL_RaiseWindow(window_); + return *this; } -void Window::Show() { +Window& Window::Show() { SDL_ShowWindow(window_); + return *this; } -void Window::SetFullscreen(int flags) { +Window& Window::SetFullscreen(int flags) { if (SDL_SetWindowFullscreen(window_, flags) != 0) 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); + return *this; } -void Window::SetSize(const Point& size) { +Window& Window::SetSize(const Point& size) { SDL_SetWindowSize(window_, size.x, size.y); + return *this; } float Window::GetBrightness() const { return SDL_GetWindowBrightness(window_); } -void Window::SetBrightness(float brightness) { +Window& Window::SetBrightness(float brightness) { if (SDL_SetWindowBrightness(window_, brightness) != 0) throw Exception("SDL_SetWindowBrightness failed"); + return *this; } Point Window::GetPosition() const { @@ -135,12 +146,14 @@ Point Window::GetPosition() const { return Point(x, y); } -void Window::SetPosition(int x, int y) { +Window& Window::SetPosition(int x, int 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); + return *this; } Point Window::GetMinimumSize() const { @@ -149,12 +162,14 @@ Point Window::GetMinimumSize() const { return Point(w, h); } -void Window::SetMinimumSize(int w, int h) { +Window& Window::SetMinimumSize(int w, int 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); + return *this; } Point Window::GetMaximumSize() const { @@ -163,20 +178,23 @@ Point Window::GetMaximumSize() const { return Point(w, h); } -void Window::SetMaximumSize(int w, int h) { +Window& Window::SetMaximumSize(int w, int 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); + return *this; } bool Window::GetGrab() const { return SDL_GetWindowGrab(window_) == SDL_TRUE; } -void Window::SetGrab(bool grabbed) { +Window& Window::SetGrab(bool grabbed) { SDL_SetWindowGrab(window_, grabbed ? SDL_TRUE : SDL_FALSE); + return *this; } } diff --git a/SDL2pp/Window.hh b/SDL2pp/Window.hh index d0d7e6c..48ec252 100644 --- a/SDL2pp/Window.hh +++ b/SDL2pp/Window.hh @@ -175,10 +175,12 @@ public: /// /// \param[in] title New window title in UTF-8 encoding /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_SetWindowTitle /// //////////////////////////////////////////////////////////// - void SetTitle(const std::string& title); + Window& SetTitle(const std::string& title); //////////////////////////////////////////////////////////// /// \brief Get window title @@ -193,62 +195,76 @@ public: //////////////////////////////////////////////////////////// /// \brief Make a window as large as possible /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_MaximizeWindow /// //////////////////////////////////////////////////////////// - void Maximize(); + Window& Maximize(); //////////////////////////////////////////////////////////// /// \brief Minimize a window to an iconic representation /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_MinimizeWindow /// //////////////////////////////////////////////////////////// - void Minimize(); + Window& Minimize(); //////////////////////////////////////////////////////////// /// \brief Hide a window /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_HideWindow /// //////////////////////////////////////////////////////////// - void Hide(); + Window& Hide(); //////////////////////////////////////////////////////////// /// \brief Restore the size and position of a minimized or maximized window /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_RestoreWindow /// //////////////////////////////////////////////////////////// - void Restore(); + Window& Restore(); //////////////////////////////////////////////////////////// /// \brief Raise a window above other windows and set the input focus /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_RaiseWindow /// //////////////////////////////////////////////////////////// - void Raise(); + Window& Raise(); //////////////////////////////////////////////////////////// /// \brief Show a window /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_ShowWindow /// //////////////////////////////////////////////////////////// - void Show(); + Window& Show(); //////////////////////////////////////////////////////////// /// \brief Set a window's fullscreen state /// /// \param[in] flags SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP or 0 /// + /// \returns Reference to self + /// /// \throws SDL2pp::Exception /// /// \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 @@ -256,20 +272,24 @@ public: /// \param[in] w Width 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 /// //////////////////////////////////////////////////////////// - void SetSize(int w, int h); + Window& SetSize(int w, int h); //////////////////////////////////////////////////////////// /// \brief Set the size of a window's client area /// /// \param[in] size Point representing window dimensions /// + /// \returns Reference to self + /// /// \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 @@ -286,12 +306,14 @@ public: /// /// \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 /// /// \see http://wiki.libsdl.org/SDL_SetWindowBrightness /// //////////////////////////////////////////////////////////// - void SetBrightness(float brightness); + Window& SetBrightness(float brightness); //////////////////////////////////////////////////////////// /// \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] y Y coordinate of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED /// + /// \returns Reference to self + /// /// \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 /// /// \param[in] pos Point representin position of the a window /// + /// \returns Reference to self + /// /// \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 @@ -340,20 +366,24 @@ public: /// \param[in] w Minimum width 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 /// //////////////////////////////////////////////////////////// - void SetMinimumSize(int w, int h); + Window& SetMinimumSize(int w, int h); //////////////////////////////////////////////////////////// /// \brief Set the minimum size of a window's client area /// /// \param[in] size Minimum area of the window in pixels /// + /// \returns Reference to self + /// /// \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 @@ -371,20 +401,24 @@ public: /// \param[in] w Maximum width 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 /// //////////////////////////////////////////////////////////// - void SetMaximumSize(int w, int h); + Window& SetMaximumSize(int w, int h); //////////////////////////////////////////////////////////// /// \brief Set the maximum size of a window's client area /// /// \param[in] size Maximum area of the window in pixels /// + /// \returns Reference to self + /// /// \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 @@ -401,10 +435,12 @@ public: /// /// \param[in] grabbed True to grab input, false to release input /// + /// \returns Reference to self + /// /// \see http://wiki.libsdl.org/SDL_SetWindowGrab /// //////////////////////////////////////////////////////////// - void SetGrab(bool grabbed); + Window& SetGrab(bool grabbed); }; }