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) /// //////////////////////////////////////////////////////////// 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 size /// /// Center of the view /// Size of the view //////////////////////////////////////////////////////////// public View(Vector2 center, Vector2 size) : base(sfView_Create()) { this.Center = center; this.Size = size; } //////////////////////////////////////////////////////////// /// /// Construct the view from another view /// /// View to copy //////////////////////////////////////////////////////////// public View(View copy) : base(sfView_Copy(copy.This)) { } //////////////////////////////////////////////////////////// /// /// 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 Size { 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 //////////////////////////////////////////////////////////// public void Reset(FloatRect rectangle) { sfView_Reset(This, rectangle); } //////////////////////////////////////////////////////////// /// /// Move the view /// /// Offset to move the view //////////////////////////////////////////////////////////// public void Move(Vector2 offset) { 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 /// /// Zoom factor to apply, relative to the current zoom //////////////////////////////////////////////////////////// public void Zoom(float factor) { sfView_Zoom(This, factor); } //////////////////////////////////////////////////////////// /// /// Provide a string describing the object /// /// String description of the object //////////////////////////////////////////////////////////// public override string ToString() { return "[View]" + " Center(" + Center + ")" + " Size(" + Size + ")" + " Rotation(" + Rotation + ")" + " Viewport(" + Viewport + ")"; } //////////////////////////////////////////////////////////// /// /// 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 IntPtr sfView_Copy(IntPtr View); [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_SetSize(IntPtr View, float Width, float Height); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] 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); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] static extern float sfView_GetCenterY(IntPtr View); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] static extern float sfView_GetWidth(IntPtr View); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] static extern float sfView_GetHeight(IntPtr View); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] 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); #endregion } } }