//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; using bs; namespace bs.Editor { /** @addtogroup GUI-Editor * @{ */ /// /// Editor GUI element that displays a reference to a or and an /// optional label. Textures can be dragged and dropped onto the field to update the reference. This is similar /// to but the will display the texture contents and not only the name. /// public sealed class GUITextureField : GUIElement { public delegate void OnChangedDelegate(RRef newValue); /// /// Triggered when the value in the field changes. /// public event OnChangedDelegate OnChanged; /// /// Resource referenced by the field, which could be either a normal or a sprite texture. This will load the /// resource if it is not already loaded. Use if you don't require a loaded resource. /// public Resource Value { get { Resource value; Internal_GetValue(mCachedPtr, out value); return value; } set { Internal_SetValue(mCachedPtr, value); } } /// /// Handle to the resource referenced by the field, which could be either a normal or a sprite texture. /// public RRef ValueRef { get { RRef value; Internal_GetValueRef(mCachedPtr, out value); return value; } set { Internal_SetValueRef(mCachedPtr, value); } } /// /// referenced by the field. This will load the resource if it is not already loaded. Use /// if you don't require a loaded resource. Returns null if the field contains a /// instead. /// public Texture Texture { get { Texture value; Internal_GetTexture(mCachedPtr, out value); return value; } set { Internal_SetTexture(mCachedPtr, value); } } /// /// Handle to the referenced by the field. Returns null if the field contains a /// instead. /// public RRef TextureRef { get { RRef value; Internal_GetTextureRef(mCachedPtr, out value); return value; } set { Internal_SetTextureRef(mCachedPtr, value); } } /// /// referenced by the field. This will load the resource if it is not already loaded. /// Use if you don't require a loaded resource. Returns null if the field contains a /// instead. /// public SpriteTexture SpriteTexture { get { SpriteTexture value; Internal_GetSpriteTexture(mCachedPtr, out value); return value; } set { Internal_SetSpriteTexture(mCachedPtr, value); } } /// /// Handle to the referenced by the field. Returns null if the field contains a /// instead. /// public RRef SpriteTextureRef { get { RRef value; Internal_GetSpriteTextureRef(mCachedPtr, out value); return value; } set { Internal_SetSpriteTextureRef(mCachedPtr, value); } } /// /// Creates a new texture field element with a label. The field will accept textures but not sprite textures. /// /// Content to display on the label. /// Width of the title label in pixels. /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextureField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options) { Internal_CreateInstance(this, GUITextureFieldType.Texture, ref title, titleWidth, style, options, true); } /// /// Creates a new texture field element without a label. The field will accept textures but not sprite textures. /// /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextureField(string style = "", params GUIOption[] options) { GUIContent emptyContent = new GUIContent(); Internal_CreateInstance(this, GUITextureFieldType.Texture, ref emptyContent, 0, style, options, false); } /// /// Creates a new texture field element with a label. /// /// Determines the type of textures should the field accept. /// Content to display on the label. /// Width of the title label in pixels. /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextureField(GUITextureFieldType type, GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options) { Internal_CreateInstance(this, type, ref title, titleWidth, style, options, true); } /// /// Creates a new texture field element without a label. /// /// Determines the type of textures should the field accept. /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextureField(GUITextureFieldType type, string style = "", params GUIOption[] options) { GUIContent emptyContent = new GUIContent(); Internal_CreateInstance(this, type, ref emptyContent, 0, style, options, false); } /// /// Colors the element with a specific tint. /// /// Tint to apply to the element. public void SetTint(Color color) { Internal_SetTint(mCachedPtr, ref color); } /// /// Triggered by the runtime when the value of the field changes. /// /// New resource referenced by the field. private void Internal_DoOnChanged(RRef newValue) { if (OnChanged != null) OnChanged(newValue); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(GUITextureField instance, GUITextureFieldType type, ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetSpriteTexture(IntPtr nativeInstance, out SpriteTexture value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetSpriteTexture(IntPtr nativeInstance, SpriteTexture value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetSpriteTextureRef(IntPtr nativeInstance, out RRef value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetSpriteTextureRef(IntPtr nativeInstance, RRef value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetTexture(IntPtr nativeInstance, out Texture value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTexture(IntPtr nativeInstance, Texture value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetTextureRef(IntPtr nativeInstance, out RRef value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTextureRef(IntPtr nativeInstance, RRef value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetValue(IntPtr nativeInstance, out Resource value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetValue(IntPtr nativeInstance, Resource value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetValueRef(IntPtr nativeInstance, out RRef value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetValueRef(IntPtr nativeInstance, RRef value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color); } /** @} */ }