/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Graphics/View.cs
218 строк
8 KB
EugenyCh7
comments fix
24 июл 2025, 22:54
24 июл 2025, 22:54
421ed1f
Код
Авторство
О чём код?
using System; using System.Runtime.InteropServices; using System.Security; using Puppet2D.System; namespace Puppet2D.Graphics { /// <summary> /// This class defines a view (position, size, etc.) ; /// you can consider it as a 2D camera /// </summary> /// <remarks> /// See also the note on coordinates and undistorted rendering in Puppet2D.Graphics.Transformable. /// </remarks> public class View : ObjectBase { /// <summary> /// Create a default view (1000x1000) /// </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> /// Construct the view from its center and size /// </summary> /// <param name="center">Center of the view</param> /// <param name="size">Size of the view</param> public View(Vector2 center, Vector2 size) : base(sfView_create()) { Center = center; Size = size; } /// <summary> /// Construct the view from another view /// </summary> /// <param name="copy">View to copy</param> public View(View copy) : base(sfView_copy(copy.CPointer)) { } /// <summary> /// Center of the view /// </summary> public Vector2 Center { get { return sfView_getCenter(CPointer); } set { sfView_setCenter(CPointer, value); } } /// <summary> /// Half-size of the view /// </summary> public Vector2 Size { get { return sfView_getSize(CPointer); } set { sfView_setSize(CPointer, value); } } /// <summary> /// Rotation of the view, in degrees /// </summary> public float Rotation { get { return sfView_getRotation(CPointer); } set { sfView_setRotation(CPointer, 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(CPointer); } set { sfView_setViewport(CPointer, 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(CPointer, rectangle); } /// <summary> /// Move the view /// </summary> /// <param name="offset">Offset to move the view</param> public void Move(Vector2 offset) { sfView_move(CPointer, offset); } /// <summary> /// Rotate the view /// </summary> /// <param name="angle">Angle of rotation, in degrees</param> public void Rotate(float angle) { sfView_rotate(CPointer, angle); } /// <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(CPointer, factor); } /// <summary> /// Provide a string describing the object /// </summary> /// <returns>String description of the object</returns> public override string ToString() { if (IsInvalid) return MakeDisposedObjectString(); return "[View]" + " Center(" + Center + ")" + " Size(" + Size + ")" + " Rotation(" + Rotation + ")" + " Viewport(" + Viewport + ")"; } /// <summary> /// Internal constructor for other classes which need to manipulate raw views /// </summary> /// <param name="cPointer">Direct pointer to the view object in the C library</param> internal View(IntPtr cPointer) : base(cPointer) { myExternal = true; } /// <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) { if (!myExternal) { sfView_destroy(CPointer); } } private readonly bool myExternal = false; #region Imports [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfView_create(); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfView_createFromRect(FloatRect Rect); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfView_copy(IntPtr View); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_destroy(IntPtr View); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_setCenter(IntPtr View, Vector2 center); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_setSize(IntPtr View, Vector2 size); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_setRotation(IntPtr View, float Angle); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_setViewport(IntPtr View, FloatRect Viewport); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_reset(IntPtr View, FloatRect Rectangle); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector2 sfView_getCenter(IntPtr View); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector2 sfView_getSize(IntPtr View); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern float sfView_getRotation(IntPtr View); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern FloatRect sfView_getViewport(IntPtr View); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_move(IntPtr View, Vector2 offset); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_rotate(IntPtr View, float Angle); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfView_zoom(IntPtr View, float Factor); #endregion } }