Skip to content

Commit

Permalink
Added viewport handling in sf::View
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LaurentGomila committed Jun 26, 2009
1 parent 1bb9608 commit 7cc0008
Show file tree
Hide file tree
Showing 24 changed files with 352 additions and 93 deletions.
13 changes: 8 additions & 5 deletions CSFML/build/VC2008/csfml-graphics-d.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions CSFML/build/VC2008/csfml-graphics.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 59 additions & 17 deletions CSFML/include/SFML/Graphics/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 Angle : New angle, in degrees
///
////////////////////////////////////////////////////////////
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 ViewRect : Rectangle defining the position and size of the view
/// \param Viewport : New viewport
///
////////////////////////////////////////////////////////////
CSFML_API void sfView_SetFromRect(sfView* View, sfFloatRect ViewRect);
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
Expand All @@ -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
Expand All @@ -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
///
Expand Down
4 changes: 2 additions & 2 deletions CSFML/src/SFML/Graphics/Rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion CSFML/src/SFML/Graphics/RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
67 changes: 52 additions & 15 deletions CSFML/src/SFML/Graphics/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}


Expand All @@ -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;
Expand All @@ -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
////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
Binary file modified dotnet/extlibs/csfml-audio.dll
Binary file not shown.
Binary file modified dotnet/extlibs/csfml-graphics.dll
Binary file not shown.
Binary file modified dotnet/extlibs/csfml-window.dll
Binary file not shown.
7 changes: 6 additions & 1 deletion dotnet/samples/opengl/sample-opengl.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand Down
7 changes: 6 additions & 1 deletion dotnet/samples/post-fx/sample-postfx.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand Down
7 changes: 6 additions & 1 deletion dotnet/samples/sound/sample-sound.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand Down
7 changes: 6 additions & 1 deletion dotnet/samples/sound_capture/sample-soundcapture.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 7cc0008

Please sign in to comment.