//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; namespace BansheeEngine { /** @addtogroup GUI-Engine * @{ */ /// /// Texture interface that encapsulates underlying texture which allows us to create a sprite texture atlas /// (for example multiple sprite textures referencing different parts of a single texture). /// public sealed class SpriteTexture : Resource { /// /// Constructor for internal use by the runtime. /// private SpriteTexture() { } /// /// Creates a new sprite texture that references the entire area of the provided texture. /// /// Texture to wrap by the sprite texture. public SpriteTexture(Texture2D texture) { Vector2 offset = Vector2.Zero; Vector2 scale = Vector2.One; Internal_CreateInstance(this, texture, ref offset, ref scale); } /// /// Creates a new sprite texture that references a sub-area of the provided texture. /// /// Texture to wrap by the sprite texture. /// Top-left position of the area used by the sprite texture, in normalized coordinates. /// /// Size of the area used by the sprite texture, in normalized coordinates. public SpriteTexture(Texture2D texture, Vector2 uvOffset, Vector2 uvScale) { Internal_CreateInstance(this, texture, ref uvOffset, ref uvScale); } /// /// Texture that the sprite texture references. /// public Texture2D Texture { get { return Internal_GetTexture(mCachedPtr); } set { IntPtr texturePtr = IntPtr.Zero; if (value != null) texturePtr = value.GetCachedPtr(); Internal_SetTexture(mCachedPtr, texturePtr); } } /// /// Offset into the referenced texture where the sprite starts. In UV coordinates, range [0, 1]. /// public Vector2 Offset { get { Vector2 value; Internal_GetOffset(mCachedPtr, out value); return value; } set { Internal_SetOffset(mCachedPtr, ref value); } } /// /// Size of the sprite in the referenced texture. In UV coordinates, range [0, 1]. /// public Vector2 Scale { get { Vector2 value; Internal_GetScale(mCachedPtr, out value); return value; } set { Internal_SetScale(mCachedPtr, ref value); } } /// /// Returns width of the sprite texture in pixels. /// public int Width { get { return Internal_GetWidth(mCachedPtr); } } /// /// Returns height of the sprite texture in pixels. /// public int Height { get { return Internal_GetHeight(mCachedPtr); } } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(SpriteTexture instance, Texture2D texture, ref Vector2 offset, ref Vector2 scale); [MethodImpl(MethodImplOptions.InternalCall)] private static extern Texture2D Internal_GetTexture(IntPtr thisPtr); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTexture(IntPtr thisPtr, IntPtr value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetOffset(IntPtr thisPtr, out Vector2 value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetOffset(IntPtr thisPtr, ref Vector2 value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetScale(IntPtr thisPtr, out Vector2 value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetScale(IntPtr thisPtr, ref Vector2 value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetWidth(IntPtr thisPtr); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetHeight(IntPtr thisPtr); } /** @} */ }