2009-01-29 00:18:34 +08:00
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Security;
|
|
|
|
|
|
|
|
namespace SFML
|
|
|
|
{
|
|
|
|
namespace Graphics
|
|
|
|
{
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// This class defines a view (position, size, etc.) ;
|
|
|
|
/// you can consider it as a 2D camera
|
|
|
|
/// </summary>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public class View : ObjectBase
|
|
|
|
{
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
2009-06-26 21:24:29 +08:00
|
|
|
/// Create a default view (1000x1000)
|
2009-01-29 00:18:34 +08:00
|
|
|
/// </summary>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public View() :
|
|
|
|
base(sfView_Create())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Construct the view from a rectangle
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="viewRect">Rectangle defining the position and size of the view</param>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public View(FloatRect viewRect) :
|
|
|
|
base(sfView_CreateFromRect(viewRect))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
2009-06-26 21:24:29 +08:00
|
|
|
/// Construct the view from its center and size
|
2009-01-29 00:18:34 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="center">Center of the view</param>
|
2009-06-26 21:24:29 +08:00
|
|
|
/// <param name="size">Size of the view</param>
|
2009-01-29 00:18:34 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
2009-06-26 21:24:29 +08:00
|
|
|
public View(Vector2 center, Vector2 size) :
|
2009-01-29 00:18:34 +08:00
|
|
|
base(sfView_Create())
|
|
|
|
{
|
2009-06-26 21:24:29 +08:00
|
|
|
this.Center = center;
|
|
|
|
this.Size = size;
|
2009-01-29 00:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Center of the view
|
|
|
|
/// </summary>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public Vector2 Center
|
|
|
|
{
|
|
|
|
get {return new Vector2(sfView_GetCenterX(This), sfView_GetCenterY(This));}
|
|
|
|
set {sfView_SetCenter(This, value.X, value.Y);}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Half-size of the view
|
|
|
|
/// </summary>
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-06-26 21:24:29 +08:00
|
|
|
public Vector2 Size
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
2009-06-26 21:24:29 +08:00
|
|
|
get {return new Vector2(sfView_GetWidth(This), sfView_GetHeight(This));}
|
|
|
|
set {sfView_SetSize(This, value.X, value.Y);}
|
2009-01-29 00:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
2009-06-26 21:24:29 +08:00
|
|
|
/// Rotation of the view, in degrees
|
2009-01-29 00:18:34 +08:00
|
|
|
/// </summary>
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-06-26 21:24:29 +08:00
|
|
|
public float Rotation
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
2009-06-26 21:24:29 +08:00
|
|
|
get { return sfView_GetRotation(This); }
|
|
|
|
set { sfView_SetRotation(This, value); }
|
2009-01-29 00:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
2009-06-26 21:24:29 +08:00
|
|
|
/// Target viewport of the view, defined as a factor of the
|
|
|
|
/// size of the target to which the view is applied
|
2009-01-29 00:18:34 +08:00
|
|
|
/// </summary>
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-06-26 21:24:29 +08:00
|
|
|
public FloatRect Viewport
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
2009-06-26 21:24:29 +08:00
|
|
|
get { return sfView_GetViewport(This); }
|
|
|
|
set { sfView_SetViewport(This, value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Rebuild the view from a rectangle
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rectangle">Rectangle defining the position and size of the view</param>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public void Reset(FloatRect rectangle)
|
|
|
|
{
|
|
|
|
sfView_Reset(This, rectangle);
|
2009-01-29 00:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Move the view
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="offset">Offset to move the view</param>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public void Move(Vector2 offset)
|
|
|
|
{
|
|
|
|
sfView_Move(This, offset.X, offset.Y);
|
|
|
|
}
|
|
|
|
|
2009-06-26 21:24:29 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Rotate the view
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="angle">Angle of rotation, in degrees</param>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public void Rotate(float angle)
|
|
|
|
{
|
|
|
|
sfView_Rotate(This, angle);
|
|
|
|
}
|
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Resize the view rectangle to simulate a zoom / unzoom effect
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="factor">Zoom factor to apply, relative to the current zoom</param>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
public void Zoom(float factor)
|
|
|
|
{
|
|
|
|
sfView_Zoom(This, factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Internal constructor for other classes which need to manipulate raw views
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="thisPtr">Direct pointer to the view object in the C library</param>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
internal View(IntPtr thisPtr) :
|
|
|
|
base(thisPtr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
|
|
/// Handle the destruction of the object
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
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]
|
2009-06-26 21:24:29 +08:00
|
|
|
static extern void sfView_SetSize(IntPtr View, float Width, float Height);
|
|
|
|
|
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
|
|
|
static extern void sfView_SetRotation(IntPtr View, float Angle);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
2009-06-26 21:24:29 +08:00
|
|
|
static extern void sfView_SetViewport(IntPtr View, FloatRect Viewport);
|
|
|
|
|
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
|
|
|
static extern void sfView_Reset(IntPtr View, FloatRect Rectangle);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
[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]
|
2009-06-26 21:24:29 +08:00
|
|
|
static extern float sfView_GetWidth(IntPtr View);
|
|
|
|
|
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
|
|
|
static extern float sfView_GetHeight(IntPtr View);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
2009-06-26 21:24:29 +08:00
|
|
|
static extern float sfView_GetRotation(IntPtr View);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
2009-06-26 21:24:29 +08:00
|
|
|
static extern FloatRect sfView_GetViewport(IntPtr View);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
|
|
|
static extern void sfView_Move(IntPtr View, float OffsetX, float OffsetY);
|
|
|
|
|
2009-06-26 21:24:29 +08:00
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
|
|
|
static extern void sfView_Rotate(IntPtr View, float Angle);
|
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
|
|
|
static extern void sfView_Zoom(IntPtr View, float Factor);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|