using System;
using System.Runtime.InteropServices;
using System.Security;
namespace SFML
{
namespace Graphics
{
////////////////////////////////////////////////////////////
///
/// This class defines a view (position, size, etc.) ;
/// you can consider it as a 2D camera
///
////////////////////////////////////////////////////////////
public class View : ObjectBase
{
////////////////////////////////////////////////////////////
///
/// Create a default view (1000x1000, centered on origin)
///
////////////////////////////////////////////////////////////
public View() :
base(sfView_Create())
{
}
////////////////////////////////////////////////////////////
///
/// Construct the view from a rectangle
///
/// Rectangle defining the position and size of the view
////////////////////////////////////////////////////////////
public View(FloatRect viewRect) :
base(sfView_CreateFromRect(viewRect))
{
}
////////////////////////////////////////////////////////////
///
/// Construct the view from its center and half-size
///
/// Center of the view
/// Half-size of the view (from center to corner)
////////////////////////////////////////////////////////////
public View(Vector2 center, Vector2 halfSize) :
base(sfView_Create())
{
this.Center = center;
this.HalfSize = halfSize;
}
////////////////////////////////////////////////////////////
///
/// Center of the view
///
////////////////////////////////////////////////////////////
public Vector2 Center
{
get {return new Vector2(sfView_GetCenterX(This), sfView_GetCenterY(This));}
set {sfView_SetCenter(This, value.X, value.Y);}
}
////////////////////////////////////////////////////////////
///
/// Half-size of the view
///
////////////////////////////////////////////////////////////
public Vector2 HalfSize
{
get {return new Vector2(sfView_GetHalfSizeX(This), sfView_GetHalfSizeY(This));}
set {sfView_SetHalfSize(This, value.X, value.Y);}
}
////////////////////////////////////////////////////////////
///
/// Rebuild the view from a rectangle
///
/// Rectangle defining the position and size of the view
////////////////////////////////////////////////////////////
public void SetFromRect(FloatRect viewRect)
{
sfView_SetFromRect(This, viewRect);
}
////////////////////////////////////////////////////////////
///
/// Get the rectangle defining the view
///
/// Rectangle of the view
////////////////////////////////////////////////////////////
public FloatRect GetRect()
{
return sfView_GetRect(This);
}
////////////////////////////////////////////////////////////
///
/// Move the view
///
/// Offset to move the view
////////////////////////////////////////////////////////////
public void Move(Vector2 offset)
{
sfView_Move(This, offset.X, offset.Y);
}
////////////////////////////////////////////////////////////
///
/// Resize the view rectangle to simulate a zoom / unzoom effect
///
/// Zoom factor to apply, relative to the current zoom
////////////////////////////////////////////////////////////
public void Zoom(float factor)
{
sfView_Zoom(This, factor);
}
////////////////////////////////////////////////////////////
///
/// Internal constructor for other classes which need to manipulate raw views
///
/// Direct pointer to the view object in the C library
////////////////////////////////////////////////////////////
internal View(IntPtr thisPtr) :
base(thisPtr)
{
}
////////////////////////////////////////////////////////////
///
/// Handle the destruction of the object
///
/// Is the GC disposing the object, or is it an explicit call ?
////////////////////////////////////////////////////////////
protected override void Destroy(bool disposing)
{
sfView_Destroy(This);
}
#region Imports
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfView_Create();
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfView_CreateFromRect(FloatRect Rect);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfView_Destroy(IntPtr View);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
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);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfView_SetFromRect(IntPtr View, FloatRect ViewRect);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfView_GetCenterX(IntPtr View);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfView_GetCenterY(IntPtr View);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfView_GetHalfSizeX(IntPtr View);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfView_GetHalfSizeY(IntPtr View);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern FloatRect sfView_GetRect(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_Zoom(IntPtr View, float Factor);
#endregion
}
}
}