Added viewport handling in sf::View

Upgraded SFML.Net project files to VS2008

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1155 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-06-26 13:24:29 +00:00
parent 1bb96087ad
commit 7cc00085d8
24 changed files with 361 additions and 102 deletions

View File

@ -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

View File

@ -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

View File

@ -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
///

View File

@ -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;

View File

@ -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;

View File

@ -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
////////////////////////////////////////////////////////////

View File

@ -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}"

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -11,6 +11,11 @@
<AssemblyName>opengl</AssemblyName>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -9,6 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>sample_postfx</RootNamespace>
<AssemblyName>post-fx</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -11,6 +11,11 @@
<AssemblyName>sound</AssemblyName>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -11,6 +11,11 @@
<AssemblyName>sound-capture</AssemblyName>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -9,6 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>sample_window</RootNamespace>
<AssemblyName>window</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -12,6 +12,11 @@
<AssemblyName>sfmlnet-audio</AssemblyName>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -16,7 +16,7 @@ namespace SFML
{
////////////////////////////////////////////////////////////
/// <summary>
/// Create a default view (1000x1000, centered on origin)
/// Create a default view (1000x1000)
/// </summary>
////////////////////////////////////////////////////////////
public View() :
@ -37,16 +37,16 @@ namespace SFML
////////////////////////////////////////////////////////////
/// <summary>
/// Construct the view from its center and half-size
/// Construct the view from its center and size
/// </summary>
/// <param name="center">Center of the view</param>
/// <param name="halfSize">Half-size of the view (from center to corner)</param>
/// <param name="size">Size of the view</param>
////////////////////////////////////////////////////////////
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
/// </summary>
////////////////////////////////////////////////////////////
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);}
}
////////////////////////////////////////////////////////////
/// <summary>
/// Rotation of the view, in degrees
/// </summary>
////////////////////////////////////////////////////////////
public float Rotation
{
get { return sfView_GetRotation(This); }
set { sfView_SetRotation(This, value); }
}
////////////////////////////////////////////////////////////
/// <summary>
/// Target viewport of the view, defined as a factor of the
/// size of the target to which the view is applied
/// </summary>
////////////////////////////////////////////////////////////
public FloatRect Viewport
{
get { return sfView_GetViewport(This); }
set { sfView_SetViewport(This, value); }
}
////////////////////////////////////////////////////////////
/// <summary>
/// Rebuild the view from a rectangle
/// </summary>
/// <param name="viewRect">Rectangle defining the position and size of the view</param>
/// <param name="rectangle">Rectangle defining the position and size of the view</param>
////////////////////////////////////////////////////////////
public void SetFromRect(FloatRect viewRect)
public void Reset(FloatRect rectangle)
{
sfView_SetFromRect(This, viewRect);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Get the rectangle defining the view
/// </summary>
/// <returns>Rectangle of the view</returns>
////////////////////////////////////////////////////////////
public FloatRect GetRect()
{
return sfView_GetRect(This);
sfView_Reset(This, rectangle);
}
////////////////////////////////////////////////////////////
@ -104,6 +116,17 @@ namespace SFML
sfView_Move(This, offset.X, offset.Y);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Rotate the view
/// </summary>
/// <param name="angle">Angle of rotation, in degrees</param>
////////////////////////////////////////////////////////////
public void Rotate(float angle)
{
sfView_Rotate(This, angle);
}
////////////////////////////////////////////////////////////
/// <summary>
/// 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);

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -12,6 +12,11 @@
<AssemblyName>sfmlnet-graphics</AssemblyName>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -12,6 +12,11 @@
<AssemblyName>sfmlnet-window</AssemblyName>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -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 :

View File

@ -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

View File

@ -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<int>(0.5f + GetWidth() * Viewport.Left);
int Top = static_cast<int>(0.5f + GetHeight() * (1.f - Viewport.Bottom));
int Width = static_cast<int>(0.5f + GetWidth() * Viewport.GetSize().x);
int Height = static_cast<int>(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);

View File

@ -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<int>(0.5f + GetWidth() * Viewport.Left);
int Top = static_cast<int>(0.5f + GetHeight() * Viewport.Top);
int Width = static_cast<int>(0.5f + GetWidth() * Viewport.GetSize().x);
int Height = static_cast<int>(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<int>(WindowX) - Left) / Width;
Coords.y = 1.f - 2.f * (static_cast<int>(WindowY) - Top) / Height;
// Then transform by the inverse of the view matrix
return TargetView->GetInverseMatrix().Transform(Coords);
return TargetView.GetInverseMatrix().Transform(Coords);
}

View File

@ -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
////////////////////////////////////////////////////////////