//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System.Runtime.CompilerServices; namespace BansheeEngine { /** @addtogroup GUI_Engine * @{ */ /// /// Type of GUI element states. /// public enum GUIElementState { /// Normal state when button is not being iteracted with. Normal = 0x01, /// State when pointer is hovering over the button. Hover = 0x02, /// State when button is being clicked. Active = 0x04, /// State when button has been selected. Focused = 0x08, /// Normal state when button is not being iteracted with and is in "on" state. NormalOn = 0x11, /// State when pointer is hovering over the button and is in "on" state. HoverOn = 0x12, /// State when button is being clicked and is in "on" state. ActiveOn = 0x14, /// State when button has been selected and is in "on" state. FocusedOn = 0x18 }; /// /// Holds data used for displaying content in a GUIElement. Content can consist of a string, image, a tooltip or none /// of those. /// public sealed class GUIContent { private LocString text; private LocString tooltip; private GUIContentImages images; /// /// Returns string content (if any). /// public LocString Text { get { return text; } } /// /// Returns image content (if any). /// public SpriteTexture GetImage(GUIElementState state = GUIElementState.Normal) { switch (state) { case GUIElementState.Normal: return images.normal; case GUIElementState.Hover: return images.hover; case GUIElementState.Active: return images.active; case GUIElementState.Focused: return images.focused; case GUIElementState.NormalOn: return images.normalOn; case GUIElementState.HoverOn: return images.hoverOn; case GUIElementState.ActiveOn: return images.activeOn; case GUIElementState.FocusedOn: return images.focusedOn; default: return images.normal; } } /// /// Returns tooltip content (if any). /// public LocString Tooltip { get { return tooltip; } } /// /// Constructs content with just a string. /// /// Textual portion of the content to be displayed as label in GUI elements. public GUIContent(LocString text) { this.text = text; } /// /// Constructs content with a string and a tooltip. /// /// Textual portion of the content to be displayed as label in GUI elements. /// Tooltip to be displayed when user hovers over a GUI element. public GUIContent(LocString text, LocString tooltip) { this.text = text; this.tooltip = tooltip; } /// /// Constructs content with just an image. /// /// Image to be displayed on top of the GUI element. public GUIContent(GUIContentImages image) { this.images = image; } /// /// Constructs content with an image and a tooltip. /// /// Image to be displayed on top of the GUI element. /// Tooltip to be displayed when user hovers over a GUI element. public GUIContent(GUIContentImages image, LocString tooltip) { this.images = image; this.tooltip = tooltip; } /// /// Constructs content with a string and an image. /// /// Textual portion of the content to be displayed as label in GUI elements. /// Image to be displayed on top of the GUI element. Image will be placed to the right or to the /// left of the text depending on active GUI style. public GUIContent(LocString text, GUIContentImages image) { this.text = text; this.images = image; } /// /// Constructs content with a string, an image and a tooltip. /// /// Textual portion of the content to be displayed as label in GUI elements. /// Image to be displayed on top of the GUI element. Image will be placed to the right or to the /// left of the text depending on active GUI style. /// Tooltip to be displayed when user hovers over a GUI element. public GUIContent(LocString text, GUIContentImages image, LocString tooltip) { this.text = text; this.images = image; this.tooltip = tooltip; } /// /// Implicitly converts a localized string into a GUI content containing only text. /// /// Localized string to initialize the GUI content with. /// GUI content containing only a string. public static implicit operator GUIContent(LocString text) { return new GUIContent(text); } /// /// Implicitly converts a string into a GUI content containing only text. /// /// String to initialize the GUI content with. /// GUI content containing only a string. public static implicit operator GUIContent(string text) { return new GUIContent(new LocString(text)); } } /// /// Contains separate GUI content images for every possible GUI element state. /// public sealed class GUIContentImages { /// /// Creates an empty content image object referencing no images. /// public GUIContentImages() { } /// /// Creates a new object where content images for all states are the same. /// /// Image to assign to all states. public GUIContentImages(SpriteTexture image) { normal = image; hover = image; active = image; focused = image; normalOn = image; hoverOn = image; activeOn = image; focusedOn = image; } /// /// Creates a new object where content images for on and off states are different. /// /// Image to assign to all off states. /// Image to assign to all on states. public GUIContentImages(SpriteTexture imageOff, SpriteTexture imageOn) { normal = imageOff; hover = imageOff; active = imageOff; focused = imageOff; normalOn = imageOn; hoverOn = imageOn; activeOn = imageOn; focusedOn = imageOn; } /// /// Implicitly converts a sprite texture into a GUI content images object. /// /// Image to instantiate the GUI content images with. /// GUI content images with all states set to the provided image. public static implicit operator GUIContentImages(SpriteTexture image) { return new GUIContentImages(image); } public SpriteTexture normal; public SpriteTexture hover; public SpriteTexture active; public SpriteTexture focused; public SpriteTexture normalOn; public SpriteTexture hoverOn; public SpriteTexture activeOn; public SpriteTexture focusedOn; } /** @} */ }