diff --git a/CSFML/build/VC2008/csfml-graphics-d.def b/CSFML/build/VC2008/csfml-graphics-d.def index 0734be7b..8f3f26a9 100644 --- a/CSFML/build/VC2008/csfml-graphics-d.def +++ b/CSFML/build/VC2008/csfml-graphics-d.def @@ -220,12 +220,15 @@ EXPORTS sfView_CreateFromRect sfView_Destroy sfView_SetCenter - sfView_SetHalfSize - sfView_SetFromRect + sfView_SetSize + sfView_SetRotation + sfView_SetViewport + sfView_Reset sfView_GetCenterX sfView_GetCenterY - sfView_GetHalfSizeX - sfView_GetHalfSizeY - sfView_GetRect + sfView_GetWidth + sfView_GetHeight + sfView_GetViewport sfView_Move + sfView_Rotate sfView_Zoom diff --git a/CSFML/build/VC2008/csfml-graphics.def b/CSFML/build/VC2008/csfml-graphics.def index ad5ec2d1..a8beac5e 100644 --- a/CSFML/build/VC2008/csfml-graphics.def +++ b/CSFML/build/VC2008/csfml-graphics.def @@ -220,12 +220,15 @@ EXPORTS sfView_CreateFromRect sfView_Destroy sfView_SetCenter - sfView_SetHalfSize - sfView_SetFromRect + sfView_SetSize + sfView_SetRotation + sfView_SetViewport + sfView_Reset sfView_GetCenterX sfView_GetCenterY - sfView_GetHalfSizeX - sfView_GetHalfSizeY - sfView_GetRect + sfView_GetWidth + sfView_GetHeight + sfView_GetViewport sfView_Move + sfView_Rotate sfView_Zoom diff --git a/CSFML/include/SFML/Graphics/View.h b/CSFML/include/SFML/Graphics/View.h index 2d8c7a58..c45045b1 100644 --- a/CSFML/include/SFML/Graphics/View.h +++ b/CSFML/include/SFML/Graphics/View.h @@ -66,23 +66,46 @@ CSFML_API void sfView_Destroy(sfView* View); CSFML_API void sfView_SetCenter(sfView* View, float X, float Y); //////////////////////////////////////////////////////////// -/// Change the half-size of a view +/// Change the size of a view /// -/// \param View : View to modify -/// \param HalfWidth : New half-width -/// \param HalfHeight : New half-height +/// \param View : View to modify +/// \param Width : New width +/// \param Height : New height /// //////////////////////////////////////////////////////////// -CSFML_API void sfView_SetHalfSize(sfView* View, float HalfWidth, float HalfHeight); +CSFML_API void sfView_SetSize(sfView* View, float Width, float Height); //////////////////////////////////////////////////////////// -/// Rebuild a view from a rectangle +/// Set the angle of rotation of a view /// -/// \param View : View to modify -/// \param ViewRect : Rectangle defining the position and size of the view +/// \param View : View to modify +/// \param Angle : New angle, in degrees /// //////////////////////////////////////////////////////////// -CSFML_API void sfView_SetFromRect(sfView* View, sfFloatRect ViewRect); +CSFML_API void sfView_SetRotation(sfView* View, float Angle); + +//////////////////////////////////////////////////////////// +/// Set the target viewport of a view +/// +/// The viewport is the rectangle into which the contents of the +/// view are displayed, expressed as a factor (between 0 and 1) +/// of the size of the RenderTarget to which the view is applied. +/// +/// \param View : View to modify +/// \param Viewport : New viewport +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfView_SetViewport(sfView* View, sfFloatRect Viewport); + +//////////////////////////////////////////////////////////// +/// Reset a view to the given rectangle. +/// Note: this function resets the rotation angle to 0. +/// +/// \param View : View to modify +/// \param Rectangle : Rectangle defining the position and size of the view +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfView_Reset(sfView* View, sfFloatRect Rectangle); //////////////////////////////////////////////////////////// /// Get the X coordinate of the center of a view @@ -105,34 +128,44 @@ CSFML_API float sfView_GetCenterX(sfView* View); CSFML_API float sfView_GetCenterY(sfView* View); //////////////////////////////////////////////////////////// -/// Get the half-width of the view +/// Get the width of the view /// /// \param View : View to read /// -/// \return Half-width of the view +/// \return Width of the view /// //////////////////////////////////////////////////////////// -CSFML_API float sfView_GetHalfSizeX(sfView* View); +CSFML_API float sfView_GetWidth(sfView* View); //////////////////////////////////////////////////////////// -/// Get the half-height of the view +/// Get the height of the view /// /// \param View : View to read /// -/// \return Half-height of the view +/// \return Height of the view /// //////////////////////////////////////////////////////////// -CSFML_API float sfView_GetHalfSizeY(sfView* View); +CSFML_API float sfView_GetHeight(sfView* View); //////////////////////////////////////////////////////////// -/// Get the bounding rectangle of a view +/// Get the current rotation of a view /// /// \param View : View to read /// -/// \return Bounding rectangle of the view +/// \return Rotation of the view, in degrees /// //////////////////////////////////////////////////////////// -CSFML_API sfFloatRect sfView_GetRect(sfView* View); +CSFML_API float sfView_GetRotation(sfView* View); + +//////////////////////////////////////////////////////////// +/// Get the target viewport of a view +/// +/// \param View : View to read +/// +/// \return Viewport rectangle, expressed as a factor of the target size +/// +//////////////////////////////////////////////////////////// +CSFML_API sfFloatRect sfView_GetViewport(sfView* View); //////////////////////////////////////////////////////////// /// Move a view @@ -144,6 +177,15 @@ CSFML_API sfFloatRect sfView_GetRect(sfView* View); //////////////////////////////////////////////////////////// CSFML_API void sfView_Move(sfView* View, float OffsetX, float OffsetY); +//////////////////////////////////////////////////////////// +/// Rotate a view +/// +/// \param View : View to rotate +/// \param Angle : Angle in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfView_Rotate(sfView* View, float Angle); + //////////////////////////////////////////////////////////// /// Resize a view rectangle to simulate a zoom / unzoom effect /// diff --git a/CSFML/src/SFML/Graphics/Rect.cpp b/CSFML/src/SFML/Graphics/Rect.cpp index 6defef06..3166ce79 100644 --- a/CSFML/src/SFML/Graphics/Rect.cpp +++ b/CSFML/src/SFML/Graphics/Rect.cpp @@ -80,7 +80,7 @@ sfBool sfFloatRect_Intersects(sfFloatRect* Rect1, sfFloatRect* Rect2, sfFloatRec if (OverlappingRect) { sf::FloatRect Overlap; - bool Intersect = SFMLRect1.Intersects(SFMLRect2, &Overlap); + bool Intersect = SFMLRect1.Intersects(SFMLRect2, Overlap); OverlappingRect->Left = Overlap.Left; OverlappingRect->Top = Overlap.Top; @@ -105,7 +105,7 @@ sfBool sfIntRect_Intersects(sfIntRect* Rect1, sfIntRect* Rect2, sfIntRect* Overl if (OverlappingRect) { sf::IntRect Overlap; - bool Intersect = SFMLRect1.Intersects(SFMLRect2, &Overlap); + bool Intersect = SFMLRect1.Intersects(SFMLRect2, Overlap); OverlappingRect->Left = Overlap.Left; OverlappingRect->Top = Overlap.Top; diff --git a/CSFML/src/SFML/Graphics/RenderWindow.cpp b/CSFML/src/SFML/Graphics/RenderWindow.cpp index ebe0c1a0..3eebcb94 100644 --- a/CSFML/src/SFML/Graphics/RenderWindow.cpp +++ b/CSFML/src/SFML/Graphics/RenderWindow.cpp @@ -429,7 +429,11 @@ void sfRenderWindow_ConvertCoords(sfRenderWindow* RenderWindow, unsigned int Win { CSFML_CHECK(RenderWindow); - sf::Vector2f Point = RenderWindow->This.ConvertCoords(WindowX, WindowY, TargetView ? TargetView->This : NULL); + sf::Vector2f Point; + if (TargetView) + Point = RenderWindow->This.ConvertCoords(WindowX, WindowY, *TargetView->This); + else + Point = RenderWindow->This.ConvertCoords(WindowX, WindowY); if (ViewX) *ViewX = Point.x; if (ViewY) *ViewY = Point.y; diff --git a/CSFML/src/SFML/Graphics/View.cpp b/CSFML/src/SFML/Graphics/View.cpp index d5070a79..ac199201 100644 --- a/CSFML/src/SFML/Graphics/View.cpp +++ b/CSFML/src/SFML/Graphics/View.cpp @@ -67,20 +67,39 @@ void sfView_SetCenter(sfView* View, float X, float Y) //////////////////////////////////////////////////////////// -/// Change the half-size of a view +/// Change the size of a view //////////////////////////////////////////////////////////// -void sfView_SetHalfSize(sfView* View, float HalfWidth, float HalfHeight) +void sfView_SetSize(sfView* View, float Width, float Height) { - CSFML_CALL_PTR(View, SetHalfSize(HalfWidth, HalfHeight)); + CSFML_CALL_PTR(View, SetSize(Width, Height)); } //////////////////////////////////////////////////////////// -/// Rebuild a view from a rectangle +/// Set the angle of rotation of a view //////////////////////////////////////////////////////////// -void sfView_SetFromRect(sfView* View, sfFloatRect ViewRect) +void sfView_SetRotation(sfView* View, float Angle) { - CSFML_CALL_PTR(View, SetFromRect(sf::FloatRect(ViewRect.Left, ViewRect.Top, ViewRect.Right, ViewRect.Bottom))); + CSFML_CALL_PTR(View, SetRotation(Angle)); +} + + +//////////////////////////////////////////////////////////// +/// Set the target viewport of a view +//////////////////////////////////////////////////////////// +void sfView_SetViewport(sfView* View, sfFloatRect Viewport) +{ + CSFML_CALL_PTR(View, SetViewport(sf::FloatRect(Viewport.Left, Viewport.Top, Viewport.Right, Viewport.Bottom))); +} + + +//////////////////////////////////////////////////////////// +/// Reset a view to the given rectangle. +/// Note: this function resets the rotation angle to 0. +//////////////////////////////////////////////////////////// +void sfView_Reset(sfView* View, sfFloatRect Rectangle) +{ + CSFML_CALL_PTR(View, Reset(sf::FloatRect(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom))); } @@ -107,36 +126,45 @@ float sfView_GetCenterY(sfView* View) //////////////////////////////////////////////////////////// -/// Get the half-width of the view +/// Get the width of the view //////////////////////////////////////////////////////////// -float sfView_GetHalfSizeY(sfView* View) +float sfView_GetWidth(sfView* View) { CSFML_CHECK_RETURN(View, 0.f); - return View->This->GetHalfSize().x; + return View->This->GetSize().x; } //////////////////////////////////////////////////////////// -/// Get the half-height of the view +/// Get the height of the view //////////////////////////////////////////////////////////// -float sfView_GetHalfSizeX(sfView* View) +float sfView_GetHeight(sfView* View) { CSFML_CHECK_RETURN(View, 0.f); - return View->This->GetHalfSize().y; + return View->This->GetSize().y; } //////////////////////////////////////////////////////////// -/// Get the bounding rectangle of a view +/// Get the current rotation of a view //////////////////////////////////////////////////////////// -sfFloatRect sfView_GetRect(sfView* View) +float sfView_GetRotation(sfView* View) +{ + CSFML_CALL_PTR_RETURN(View, GetRotation(), 0.f); +} + + +//////////////////////////////////////////////////////////// +/// Get the target viewport of a view +//////////////////////////////////////////////////////////// +sfFloatRect sfView_GetViewport(sfView* View) { sfFloatRect Rect = {0, 0, 0, 0}; CSFML_CHECK_RETURN(View, Rect); - sf::FloatRect SFMLRect = View->This->GetRect(); + sf::FloatRect SFMLRect = View->This->GetViewport(); Rect.Left = SFMLRect.Left; Rect.Top = SFMLRect.Top; Rect.Right = SFMLRect.Right; @@ -155,6 +183,15 @@ void sfView_Move(sfView* View, float OffsetX, float OffsetY) } +//////////////////////////////////////////////////////////// +/// Rotate a view +//////////////////////////////////////////////////////////// +void sfView_Rotate(sfView* View, float Angle) +{ + CSFML_CALL_PTR(View, Rotate(Angle)); +} + + //////////////////////////////////////////////////////////// /// Resize a view rectangle to simulate a zoom / unzoom effect //////////////////////////////////////////////////////////// diff --git a/dotnet/build/vc2005/SFML.net.sln b/dotnet/build/vc2008/SFML.net.sln similarity index 96% rename from dotnet/build/vc2005/SFML.net.sln rename to dotnet/build/vc2008/SFML.net.sln index 2dc845cb..58dac7a9 100644 --- a/dotnet/build/vc2005/SFML.net.sln +++ b/dotnet/build/vc2008/SFML.net.sln @@ -1,6 +1,6 @@  -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C# Express 2005 +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sfml-window", "..\..\src\Window\sfml-window.csproj", "{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sfml-graphics", "..\..\src\Graphics\sfml-graphics.csproj", "{46786269-57B9-48E7-AA4F-8F4D84609FE6}" diff --git a/dotnet/extlibs/csfml-audio.dll b/dotnet/extlibs/csfml-audio.dll index f7f58656..1a9fa5e8 100644 Binary files a/dotnet/extlibs/csfml-audio.dll and b/dotnet/extlibs/csfml-audio.dll differ diff --git a/dotnet/extlibs/csfml-graphics.dll b/dotnet/extlibs/csfml-graphics.dll index 2220aa13..9101c0ad 100644 Binary files a/dotnet/extlibs/csfml-graphics.dll and b/dotnet/extlibs/csfml-graphics.dll differ diff --git a/dotnet/extlibs/csfml-window.dll b/dotnet/extlibs/csfml-window.dll index 941b29b3..0d8fdf60 100644 Binary files a/dotnet/extlibs/csfml-window.dll and b/dotnet/extlibs/csfml-window.dll differ diff --git a/dotnet/samples/opengl/sample-opengl.csproj b/dotnet/samples/opengl/sample-opengl.csproj index f15c6b99..62d16952 100644 --- a/dotnet/samples/opengl/sample-opengl.csproj +++ b/dotnet/samples/opengl/sample-opengl.csproj @@ -1,4 +1,4 @@ - + Debug AnyCPU @@ -11,6 +11,11 @@ opengl + + + 2.0 + + true diff --git a/dotnet/samples/post-fx/sample-postfx.csproj b/dotnet/samples/post-fx/sample-postfx.csproj index 11e5ae41..e81c9f58 100644 --- a/dotnet/samples/post-fx/sample-postfx.csproj +++ b/dotnet/samples/post-fx/sample-postfx.csproj @@ -1,4 +1,4 @@ - + Debug AnyCPU @@ -9,6 +9,11 @@ Properties sample_postfx post-fx + + + 2.0 + + true diff --git a/dotnet/samples/sound/sample-sound.csproj b/dotnet/samples/sound/sample-sound.csproj index 55a1453d..b354e87c 100644 --- a/dotnet/samples/sound/sample-sound.csproj +++ b/dotnet/samples/sound/sample-sound.csproj @@ -1,4 +1,4 @@ - + Debug AnyCPU @@ -11,6 +11,11 @@ sound + + + 2.0 + + true diff --git a/dotnet/samples/sound_capture/sample-soundcapture.csproj b/dotnet/samples/sound_capture/sample-soundcapture.csproj index 5b50efc8..3805abfa 100644 --- a/dotnet/samples/sound_capture/sample-soundcapture.csproj +++ b/dotnet/samples/sound_capture/sample-soundcapture.csproj @@ -1,4 +1,4 @@ - + Debug AnyCPU @@ -11,6 +11,11 @@ sound-capture + + + 2.0 + + true diff --git a/dotnet/samples/window/sample-window.csproj b/dotnet/samples/window/sample-window.csproj index a830d154..ebe1ca5e 100644 --- a/dotnet/samples/window/sample-window.csproj +++ b/dotnet/samples/window/sample-window.csproj @@ -1,4 +1,4 @@ - + Debug AnyCPU @@ -9,6 +9,11 @@ Properties sample_window window + + + 2.0 + + true diff --git a/dotnet/src/Audio/sfml-audio.csproj b/dotnet/src/Audio/sfml-audio.csproj index d5b29bd9..e0c831a2 100644 --- a/dotnet/src/Audio/sfml-audio.csproj +++ b/dotnet/src/Audio/sfml-audio.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -12,6 +12,11 @@ sfmlnet-audio + + + 2.0 + + true diff --git a/dotnet/src/Graphics/View.cs b/dotnet/src/Graphics/View.cs index 419ba9a9..10ca5019 100644 --- a/dotnet/src/Graphics/View.cs +++ b/dotnet/src/Graphics/View.cs @@ -16,7 +16,7 @@ namespace SFML { //////////////////////////////////////////////////////////// /// - /// Create a default view (1000x1000, centered on origin) + /// Create a default view (1000x1000) /// //////////////////////////////////////////////////////////// public View() : @@ -37,16 +37,16 @@ namespace SFML //////////////////////////////////////////////////////////// /// - /// Construct the view from its center and half-size + /// Construct the view from its center and size /// /// Center of the view - /// Half-size of the view (from center to corner) + /// Size of the view //////////////////////////////////////////////////////////// - public View(Vector2 center, Vector2 halfSize) : + public View(Vector2 center, Vector2 size) : base(sfView_Create()) { - this.Center = center; - this.HalfSize = halfSize; + this.Center = center; + this.Size = size; } //////////////////////////////////////////////////////////// @@ -65,32 +65,44 @@ namespace SFML /// Half-size of the view /// //////////////////////////////////////////////////////////// - public Vector2 HalfSize + public Vector2 Size { - get {return new Vector2(sfView_GetHalfSizeX(This), sfView_GetHalfSizeY(This));} - set {sfView_SetHalfSize(This, value.X, value.Y);} + get {return new Vector2(sfView_GetWidth(This), sfView_GetHeight(This));} + set {sfView_SetSize(This, value.X, value.Y);} + } + + //////////////////////////////////////////////////////////// + /// + /// Rotation of the view, in degrees + /// + //////////////////////////////////////////////////////////// + public float Rotation + { + get { return sfView_GetRotation(This); } + set { sfView_SetRotation(This, value); } + } + + //////////////////////////////////////////////////////////// + /// + /// Target viewport of the view, defined as a factor of the + /// size of the target to which the view is applied + /// + //////////////////////////////////////////////////////////// + public FloatRect Viewport + { + get { return sfView_GetViewport(This); } + set { sfView_SetViewport(This, value); } } //////////////////////////////////////////////////////////// /// /// Rebuild the view from a rectangle /// - /// Rectangle defining the position and size of the view + /// Rectangle defining the position and size of the view //////////////////////////////////////////////////////////// - public void SetFromRect(FloatRect viewRect) + public void Reset(FloatRect rectangle) { - sfView_SetFromRect(This, viewRect); - } - - //////////////////////////////////////////////////////////// - /// - /// Get the rectangle defining the view - /// - /// Rectangle of the view - //////////////////////////////////////////////////////////// - public FloatRect GetRect() - { - return sfView_GetRect(This); + sfView_Reset(This, rectangle); } //////////////////////////////////////////////////////////// @@ -104,6 +116,17 @@ namespace SFML sfView_Move(This, offset.X, offset.Y); } + //////////////////////////////////////////////////////////// + /// + /// Rotate the view + /// + /// Angle of rotation, in degrees + //////////////////////////////////////////////////////////// + public void Rotate(float angle) + { + sfView_Rotate(This, angle); + } + //////////////////////////////////////////////////////////// /// /// Resize the view rectangle to simulate a zoom / unzoom effect @@ -151,10 +174,16 @@ namespace SFML static extern void sfView_SetCenter(IntPtr View, float X, float Y); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] - static extern void sfView_SetHalfSize(IntPtr View, float HalfWidth, float HalfHeight); + static extern void sfView_SetSize(IntPtr View, float Width, float Height); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] - static extern void sfView_SetFromRect(IntPtr View, FloatRect ViewRect); + static extern void sfView_SetRotation(IntPtr View, float Angle); + + [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] + static extern void sfView_SetViewport(IntPtr View, FloatRect Viewport); + + [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] + static extern void sfView_Reset(IntPtr View, FloatRect Rectangle); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] static extern float sfView_GetCenterX(IntPtr View); @@ -163,17 +192,23 @@ namespace SFML static extern float sfView_GetCenterY(IntPtr View); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] - static extern float sfView_GetHalfSizeX(IntPtr View); + static extern float sfView_GetWidth(IntPtr View); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] - static extern float sfView_GetHalfSizeY(IntPtr View); + static extern float sfView_GetHeight(IntPtr View); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] - static extern FloatRect sfView_GetRect(IntPtr View); + static extern float sfView_GetRotation(IntPtr View); + + [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] + static extern FloatRect sfView_GetViewport(IntPtr View); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] static extern void sfView_Move(IntPtr View, float OffsetX, float OffsetY); + [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] + static extern void sfView_Rotate(IntPtr View, float Angle); + [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] static extern void sfView_Zoom(IntPtr View, float Factor); diff --git a/dotnet/src/Graphics/sfml-graphics.csproj b/dotnet/src/Graphics/sfml-graphics.csproj index 476de7a1..f1331f74 100644 --- a/dotnet/src/Graphics/sfml-graphics.csproj +++ b/dotnet/src/Graphics/sfml-graphics.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -12,6 +12,11 @@ sfmlnet-graphics + + + 2.0 + + true diff --git a/dotnet/src/Window/sfml-window.csproj b/dotnet/src/Window/sfml-window.csproj index 8711c8c4..33c095f9 100644 --- a/dotnet/src/Window/sfml-window.csproj +++ b/dotnet/src/Window/sfml-window.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -12,6 +12,11 @@ sfmlnet-window + + + 2.0 + + true diff --git a/include/SFML/Graphics/RenderWindow.hpp b/include/SFML/Graphics/RenderWindow.hpp index 5e7c0c53..bd66376b 100644 --- a/include/SFML/Graphics/RenderWindow.hpp +++ b/include/SFML/Graphics/RenderWindow.hpp @@ -104,15 +104,28 @@ public : //////////////////////////////////////////////////////////// /// Convert a point in window coordinates into view coordinates + /// This version uses the current view of the window /// - /// \param WindowX : X coordinate of the point to convert, relative to the window - /// \param WindowY : Y coordinate of the point to convert, relative to the window - /// \param TargetView : Target view to convert the point to (NULL by default -- uses the current view) + /// \param WindowX : X coordinate of the point to convert, relative to the window + /// \param WindowY : Y coordinate of the point to convert, relative to the window /// /// \return Converted point /// //////////////////////////////////////////////////////////// - sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View* TargetView = NULL) const; + sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY) const; + + //////////////////////////////////////////////////////////// + /// Convert a point in window coordinates into view coordinates + /// This version uses the given view + /// + /// \param WindowX : X coordinate of the point to convert, relative to the window + /// \param WindowY : Y coordinate of the point to convert, relative to the window + /// \param TargetView : Target view to convert the point to + /// + /// \return Converted point + /// + //////////////////////////////////////////////////////////// + sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View& TargetView) const; private : diff --git a/include/SFML/Graphics/View.hpp b/include/SFML/Graphics/View.hpp index 70195dd9..c163739b 100644 --- a/include/SFML/Graphics/View.hpp +++ b/include/SFML/Graphics/View.hpp @@ -116,6 +116,21 @@ public : //////////////////////////////////////////////////////////// void SetRotation(float Angle); + //////////////////////////////////////////////////////////// + /// Set the target viewport + /// + /// The viewport is the rectangle into which the contents of the + /// view are displayed, expressed as a factor (between 0 and 1) + /// of the size of the RenderTarget to which the view is applied. + /// + /// For example, a view which takes the left side of the target would + /// be defined with View.SetViewport(sf::FloatRect(0, 0, 0.5, 1)). + /// + /// \param Viewport : New viewport + /// + //////////////////////////////////////////////////////////// + void SetViewport(const FloatRect& Viewport); + //////////////////////////////////////////////////////////// /// Reset the view to the given rectangle. /// Note: this function resets the rotation angle to 0. @@ -141,6 +156,22 @@ public : //////////////////////////////////////////////////////////// const Vector2f& GetSize() const; + //////////////////////////////////////////////////////////// + /// Get the current rotation + /// + /// \return Rotation of the view, in degrees + /// + //////////////////////////////////////////////////////////// + float GetRotation() const; + + //////////////////////////////////////////////////////////// + /// Get the target viewport + /// + /// \return Viewport rectangle, expressed as a factor of the target size + /// + //////////////////////////////////////////////////////////// + const FloatRect& GetViewport() const; + //////////////////////////////////////////////////////////// /// Move the view /// @@ -198,6 +229,7 @@ private : Vector2f myCenter; ///< Center of the view, in scene coordinates Vector2f mySize; ///< Size of the view, in scene coordinates float myRotation; ///< Angle of rotation of the view rectangle, in degrees + FloatRect myViewport; ///< Viewport rectangle, expressed as a factor of the render-target's size mutable Matrix3 myMatrix; ///< Precomputed projection matrix corresponding to the view mutable Matrix3 myInverseMatrix; ///< Precomputed inverse projection matrix corresponding to the view mutable bool myNeedUpdate; ///< Internal state telling if the matrix needs to be updated diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 9c2bda3c..17a25187 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -93,10 +93,19 @@ void RenderTarget::Draw(const Drawable& Object) SetRenderStates(); } - // Set the window viewport and transform matrices - GLCheck(glViewport(0, 0, GetWidth(), GetHeight())); - GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glLoadMatrixf(myCurrentView->GetMatrix().Get4x4Elements())); - GLCheck(glMatrixMode(GL_MODELVIEW)); GLCheck(glLoadIdentity()); + // Setup the viewport + const FloatRect& Viewport = myCurrentView->GetViewport(); + int Left = static_cast(0.5f + GetWidth() * Viewport.Left); + int Top = static_cast(0.5f + GetHeight() * (1.f - Viewport.Bottom)); + int Width = static_cast(0.5f + GetWidth() * Viewport.GetSize().x); + int Height = static_cast(0.5f + GetHeight() * Viewport.GetSize().y); + GLCheck(glViewport(Left, Top, Width, Height)); + + // Setup the transform matrices + GLCheck(glMatrixMode(GL_PROJECTION)); + GLCheck(glLoadMatrixf(myCurrentView->GetMatrix().Get4x4Elements())); + GLCheck(glMatrixMode(GL_MODELVIEW)); + GLCheck(glLoadIdentity()); // Let the object draw itself Object.Draw(*this); diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index c28e69f7..5280521f 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -135,22 +135,33 @@ Image RenderWindow::Capture() const //////////////////////////////////////////////////////////// /// Convert a point in window coordinates into view coordinates +/// This version uses the current view of the window //////////////////////////////////////////////////////////// -sf::Vector2f RenderWindow::ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View* TargetView) const +sf::Vector2f RenderWindow::ConvertCoords(unsigned int WindowX, unsigned int WindowY) const { - // Use the current view if none has been passed - if (!TargetView) - TargetView = &GetView(); + return ConvertCoords(WindowX, WindowY, GetView()); +} + + +//////////////////////////////////////////////////////////// +/// Convert a point in window coordinates into view coordinates +/// This version uses the given view +//////////////////////////////////////////////////////////// +sf::Vector2f RenderWindow::ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View& TargetView) const +{ + // First, convert from viewport coordinates to homogeneous coordinates + const FloatRect& Viewport = TargetView.GetViewport(); + int Left = static_cast(0.5f + GetWidth() * Viewport.Left); + int Top = static_cast(0.5f + GetHeight() * Viewport.Top); + int Width = static_cast(0.5f + GetWidth() * Viewport.GetSize().x); + int Height = static_cast(0.5f + GetHeight() * Viewport.GetSize().y); - // First, convert from viewport coordinates to homogeneous coordinates: - // --> [0, Width] to [-1, 1] - // --> [0, Height] to [1, -1] Vector2f Coords; - Coords.x = -1.f + 2.f * WindowX / GetWidth(); - Coords.y = 1.f - 2.f * WindowY / GetHeight(); + Coords.x = -1.f + 2.f * (static_cast(WindowX) - Left) / Width; + Coords.y = 1.f - 2.f * (static_cast(WindowY) - Top) / Height; // Then transform by the inverse of the view matrix - return TargetView->GetInverseMatrix().Transform(Coords); + return TargetView.GetInverseMatrix().Transform(Coords); } diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index 7f819885..fc3006cc 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -38,6 +38,7 @@ View::View() : myCenter (), mySize (), myRotation (0), +myViewport (0, 0, 1, 1), myNeedUpdate (true), myNeedInvUpdate(true) { @@ -52,6 +53,7 @@ View::View(const FloatRect& Rectangle) : myCenter (), mySize (), myRotation (0), +myViewport (0, 0, 1, 1), myNeedUpdate (true), myNeedInvUpdate(true) { @@ -66,6 +68,7 @@ View::View(const Vector2f& Center, const Vector2f& Size) : myCenter (Center), mySize (Size), myRotation (0), +myViewport (0, 0, 1, 1), myNeedUpdate (true), myNeedInvUpdate(true) { @@ -125,6 +128,15 @@ void View::SetRotation(float Angle) } +//////////////////////////////////////////////////////////// +/// Set the target viewport +//////////////////////////////////////////////////////////// +void View::SetViewport(const FloatRect& Viewport) +{ + myViewport = Viewport; +} + + //////////////////////////////////////////////////////////// /// Reset the view to the given rectangle //////////////////////////////////////////////////////////// @@ -155,6 +167,24 @@ const Vector2f& View::GetSize() const } +//////////////////////////////////////////////////////////// +/// Get the current rotation +//////////////////////////////////////////////////////////// +float View::GetRotation() const +{ + return myRotation; +} + + +//////////////////////////////////////////////////////////// +/// Get the target viewport +//////////////////////////////////////////////////////////// +const FloatRect& View::GetViewport() const +{ + return myViewport; +} + + //////////////////////////////////////////////////////////// /// Move the view ////////////////////////////////////////////////////////////