diff options
Diffstat (limited to 'Runtime/Export/GUIStyleBindings.txt')
-rw-r--r-- | Runtime/Export/GUIStyleBindings.txt | 922 |
1 files changed, 922 insertions, 0 deletions
diff --git a/Runtime/Export/GUIStyleBindings.txt b/Runtime/Export/GUIStyleBindings.txt new file mode 100644 index 0000000..76ac550 --- /dev/null +++ b/Runtime/Export/GUIStyleBindings.txt @@ -0,0 +1,922 @@ +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/IMGUI/GUIStyle.h" +#include "Runtime/IMGUI/GUIContent.h" +#include "Runtime/IMGUI/GUIState.h" +#include "Runtime/IMGUI/GUIManager.h" +#include "Runtime/Mono/MonoBehaviour.h" +#include "Runtime/Filters/Misc/Font.h" +#include "Runtime/Scripting/ScriptingUtility.h" +#include "Runtime/Scripting/Scripting.h" +#include "Runtime/Scripting/ScriptingObjectWithIntPtrField.h" + +#if UNITY_EDITOR +//#include "Editor/Src/EditorHelper.h" +//#include "Editor/Mono/MonoEditorUtility.h" +//#include "Editor/Src/OptimizedGUIBlock.h" +//#include "Editor/Src/AssetPipeline/AssetDatabase.h" + +//#include "Editor/Src/EditorResources.h" +#endif + +using namespace Unity; +using namespace std; + +CSRAW +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; +using UnityEngineInternal; + +namespace UnityEngine +{ + + + +// Specialized values for the given states used by [[GUIStyle]] objects. +CSRAW #if !UNITY_WINRT +CSRAW [StructLayout (LayoutKind.Sequential)] +CSRAW #endif +CSRAW [System.Serializable] +CLASS GUIStyleState + // Pointer to the GUIStyleState INSIDE a GUIStyle. + CSRAW [System.NonSerialized] [NotRenamed] + CSRAW internal IntPtr m_Ptr; + + // Pointer to the source GUIStyle so it doesn't get garbage collected. + // If NULL, it means we own m_Ptr and need to delete it when this gets displosed + CSRAW GUIStyle m_SourceStyle; + + // Pointer to the texture that is referenced from the GUIStyleState. + // Necessary for the Asset Garbage Collector to find the texture reference +CSRAW #pragma warning disable 414 + [System.NonSerialized] + CSRAW private Texture2D m_Background; +CSRAW #pragma warning restore 414 + + public GUIStyleState () + { + Init (); + } + + internal GUIStyleState (GUIStyle sourceStyle, IntPtr source) + { + m_SourceStyle = sourceStyle; + m_Ptr = source; + RefreshAssetReference(); + } + + internal void RefreshAssetReference () + { + m_Background = GetBackgroundInternal(); + } + + ~GUIStyleState () + { + if (m_SourceStyle == null) + Cleanup (); + } + + THREAD_SAFE + CUSTOM private void Init () { + self.SetPtr(new GUIStyleState()); + + } + + THREAD_SAFE + CUSTOM private void Cleanup () { + delete self.GetPtr(); + } + + // The background image used by GUI elements in this given state. + CUSTOM private void SetBackgroundInternal (Texture2D value) { + self->background = (Texture2D*) (value); + } + + CUSTOM private Texture2D GetBackgroundInternal () { + return Scripting::ScriptingWrapperFor (self->background); + } + + CSRAW public Texture2D background { + get { return GetBackgroundInternal(); } + set { SetBackgroundInternal (value); m_Background = value; } + } + + // The text color used by GUI elements in this state. + CUSTOM_PROP Color textColor { return self->textColor; } { self->textColor = value; } +END + + +// Offsets for rectangles, borders, etc. +CSRAW #if !UNITY_WINRT +CSRAW [StructLayout (LayoutKind.Sequential)] +CSRAW #endif +CSRAW [System.Serializable] +CLASS RectOffset + + // Pointer to the RectOffset INSIDE a GUIStyle. + CSRAW [System.NonSerialized] [NotRenamed] + CSRAW internal IntPtr m_Ptr; + + // Pointer to the source GUIStyle so it doesn't get garbage collected. + // If NULL, it means we own m_Ptr and need to delete it when this gets displosed + CSRAW GUIStyle m_SourceStyle; + + /// *listonly* + CSRAW public RectOffset () { + Init (); + } + + internal RectOffset (GUIStyle sourceStyle, IntPtr source) + { + m_SourceStyle = sourceStyle; + m_Ptr = source; + } + + ~RectOffset () + { + if (m_SourceStyle == null) + Cleanup (); + } + + THREAD_SAFE + CUSTOM private void Init () { + self.SetPtr(new RectOffset()); + } + + THREAD_SAFE + CUSTOM private void Cleanup () { + delete self.GetPtr(); + } + + + // Creates a new rectangle with offsets. + CSRAW public RectOffset (int left, int right, int top, int bottom) { + Init (); + this.left = left; + this.right = right; + this.top = top; + this.bottom = bottom; + } + + // Left edge size. + CUSTOM_PROP int left { return self->left; } { self->left = value; } + // Right edge size. + CUSTOM_PROP int right { return self->right; } { self->right = value; } + // Top edge size. + CUSTOM_PROP int top { return self->top; } { self->top = value; } + // Bottom edge size. + CUSTOM_PROP int bottom { return self->bottom; } { self->bottom = value; } + // shortcut for left + right (RO) + CUSTOM_PROP int horizontal { return self->left + self->right; } + // shortcut for top + bottom (RO) + CUSTOM_PROP public int vertical { return self->top + self->bottom; } + // Add the border offsets to a /rect/. + CUSTOM public Rect Add (Rect rect) + { return Rectf (rect.x - self->left, rect.y - self->top, rect.width + self->left + self->right, rect.height + self->top + self->bottom); } + // Remove the border offsets from a /rect/. + CUSTOM public Rect Remove (Rect rect) + { return Rectf (rect.x + self->left, rect.y + self->top, rect.width - self->left - self->right, rect.height - self->top - self->bottom); } + + CSRAW public override string ToString () { + return UnityString.Format ("RectOffset (l:{0} r:{1} t:{2} b:{3})", left, right, top, bottom); + } + +END + +// Font Style applied to GUI Texts, Text Meshes or GUIStyles. +ENUM FontStyle + // No special style is applied. + Normal = 0, + + // Bold style applied to your texts. + Bold = 1, + + // Italic style applied to your texts. + Italic = 2, + + // Bold and Italic styles applied to your texts. + BoldAndItalic = 3, +END + +C++RAW + +// Simple struct that contains all the arguments needed by Internal_Draw. +STRUCT internal Internal_DrawArguments + CSRAW public IntPtr target; + CSRAW public Rect position; + CSRAW public int isHover; + CSRAW public int isActive; + CSRAW public int on; + CSRAW public int hasKeyboardFocus; +END + +C++RAW + +struct MonoInternal_DrawArguments { + void* target; + const Rectf position; + int isHover; + int isActive; + int on; + int hasKeyboardFocus; +}; + +// Simple struct that contains all the arguments needed by Internal_DrawWithTextSelection. +STRUCT internal Internal_DrawWithTextSelectionArguments + CSRAW public IntPtr target; + CSRAW public Rect position; + CSRAW public int firstPos; + CSRAW public int lastPos; + CSRAW public Color cursorColor; + CSRAW public Color selectionColor; + CSRAW public int isHover; + CSRAW public int isActive; + CSRAW public int on; + CSRAW public int hasKeyboardFocus; + CSRAW public int drawSelectionAsComposition; + +END + +C++RAW + +struct MonoInternal_DrawWithTextSelectionArguments { + void* target; + Rectf position; + int firstPos; + int lastPos; + const ColorRGBAf cursorColor; + const ColorRGBAf selectionColor; + int isHover; + int isActive; + int on; + int hasKeyboardFocus; + int drawSelectionAsComposition; +}; + +// How image and text is placed inside [[GUIStyle]]. +ENUM ImagePosition + // Image is to the left of the text. + ImageLeft = 0, + // Image is above the text. + ImageAbove = 1, + // Only the image is displayed. + ImageOnly = 2, + // Only the text is displayed. + TextOnly = 3 +END + + +BEGIN DOC +Style settings for a GUI element. +This class contains all information for how a gui element should be rendered. It contains information for font, icon placement, background images, and spacing. +It does /not/ contain information for what it contains - just defines how any text rendered with this style should be displayed. +It does /not/ define what interactions can occur with the element, but defines the display settings commonly used in by the interactions. + +The settings of a [[GUIStyle]]. It is modelled after a CSS Style. It contains settings for the following items: +<dl> +<dt>Background images</dt> +<dd> These are rendered behind the contents. Different images can be assigned for normal display, when the user hovers the mouse over the element, + when the user presses it down - as well as alternatives for when the element has been turned on - like toggle butons do. Below, these are referred to as style /states/. + SA: ::ref::normal, ::ref::hover, ::ref::active, ::ref::onNormal, ::ref::onHover, ::ref::onActive - these contain the background image & text color properties for each state.</dd> +<dt>Text rendering</dt> +<dd> The style can define a font for text rendering, as well as alignment, wordwrap and clipping settings. It also defines colors for the text in the various states of the style element + SA: ::ref::font, ::ref::alignment, ::ref::wordWrap, ::ref::normal, ::ref::hover, ::ref::active, ::ref::onHover, ::ref::onActive</dd> +<dt>Icon Placement</dt> +<dd> GUIStyles can be rendered with either text, and icon or both. The GUIStyle defines where these two are rendered in relation to each other (or can force it to only display one of them). + SA: ::ref::imagePosition</dd> +<dt>Sizing and Spacing Options</dd> +<dd> GUIStyles contain padding, margins and borders. These corresponds loosely to the similar named CSS properties. A GUIStyle can optionally define a fixed width and height. + SA: ::ref::margin, ::ref::padding, ::ref::border, ::ref::fixedWidth, ::ref::fixedHeight</dd> +</dl> + + +END DOC + +C++RAW + static void CleanupGUIStyle(void* guiStyle){ delete ((GUIStyle*)guiStyle); } +CSRAW #if !UNITY_WINRT +CSRAW [StructLayout (LayoutKind.Sequential)] +CSRAW #endif +CSRAW [System.Serializable] +CLASS GUIStyle + +CSRAW + // Constructor for empty GUIStyle. + public GUIStyle () { + Init (); + } + + // Constructs GUIStyle identical to given other GUIStyle. + public GUIStyle (GUIStyle other) { + InitCopy (other); + } + + ~GUIStyle () { + Cleanup (); + } + + internal void CreateObjectReferences () { + m_FontInternal = GetFontInternal(); + normal.RefreshAssetReference (); + hover.RefreshAssetReference (); + active.RefreshAssetReference (); + focused.RefreshAssetReference (); + onNormal.RefreshAssetReference (); + onHover.RefreshAssetReference (); + onActive.RefreshAssetReference (); + onFocused.RefreshAssetReference (); + } + + [System.NonSerialized] [NotRenamed] + internal IntPtr m_Ptr; + + [System.NonSerialized] + GUIStyleState m_Normal, m_Hover, m_Active, m_Focused, m_OnNormal, m_OnHover, m_OnActive, m_OnFocused; + + [System.NonSerialized] + RectOffset m_Border, m_Padding, m_Margin, m_Overflow; + +CSRAW #pragma warning disable 414 + [System.NonSerialized] + private Font m_FontInternal; +CSRAW #pragma warning restore 414 + + THREAD_SAFE + CUSTOM private void Init () { + self.SetPtr(new GUIStyle(), CleanupGUIStyle); + } + + THREAD_SAFE + CUSTOM private void InitCopy (GUIStyle other) { + self.SetPtr(new GUIStyle (*other), CleanupGUIStyle); + } + + THREAD_SAFE + CUSTOM private void Cleanup () { + CleanupGUIStyle(self.GetPtr()); + } + + // The name of this GUIStyle. Used for getting them based on name.... + CUSTOM_PROP string name + { + return scripting_string_new(self->m_Name); + } + { self->m_Name = value.AsUTF8(); } + + // Rendering settings for when the component is displayed normally. + CSRAW public GUIStyleState normal { get { + if (m_Normal == null) + m_Normal = new GUIStyleState (this, GetStyleStatePtr (0)); + return m_Normal; + } + set { AssignStyleState (0, value.m_Ptr); } + } + + // Rendering settings for when the mouse is hovering over the control + CSRAW public GUIStyleState hover { get { + if (m_Hover == null) + m_Hover = new GUIStyleState (this, GetStyleStatePtr (1)); + return m_Hover; + } + set { AssignStyleState (1, value.m_Ptr); } + } + + // Rendering settings for when the control is pressed down. + CSRAW public GUIStyleState active { get { + if (m_Active == null) + m_Active = new GUIStyleState (this, GetStyleStatePtr (2)); + return m_Active; + } + set { AssignStyleState (2, value.m_Ptr); } + } + + // Rendering settings for when the control is turned on. + CSRAW public GUIStyleState onNormal { get { + if (m_OnNormal == null) + m_OnNormal = new GUIStyleState (this, GetStyleStatePtr (4)); + return m_OnNormal; + } + set { AssignStyleState (4, value.m_Ptr); } + } + + // Rendering settings for when the control is turned on and the mouse is hovering it. + CSRAW public GUIStyleState onHover { get { + if (m_OnHover == null) + m_OnHover = new GUIStyleState (this, GetStyleStatePtr (5)); + return m_OnHover; + } + set { AssignStyleState (5, value.m_Ptr); } + } + + // Rendering settings for when the element is turned on and pressed down. + CSRAW public GUIStyleState onActive { get { + if (m_OnActive == null) + m_OnActive = new GUIStyleState (this, GetStyleStatePtr (6)); + return m_OnActive; + } + set { AssignStyleState (6, value.m_Ptr); } + } + + // Rendering settings for when the element has keyboard focus. + CSRAW public GUIStyleState focused { get { + if (m_Focused == null) + m_Focused = new GUIStyleState (this, GetStyleStatePtr (3)); + return m_Focused; + } + set { AssignStyleState (3, value.m_Ptr); } + } + + // Rendering settings for when the element has keyboard and is turned on. + CSRAW public GUIStyleState onFocused { get { + if (m_OnFocused == null) + m_OnFocused = new GUIStyleState (this, GetStyleStatePtr (7)); + return m_OnFocused; + } + set { AssignStyleState (7, value.m_Ptr); } + } + + CUSTOM private IntPtr GetStyleStatePtr (int idx) + { + GUIStyleState* gss = &(self->m_Normal); + return gss+idx; + } + + CUSTOM private void AssignStyleState (int idx, IntPtr srcStyleState) + { + GUIStyleState* gss = &(self->m_Normal); + gss += idx; + *gss = *((GUIStyleState*)srcStyleState); + } + + + // RECT OFFSETS + // ================================================================================================================================================ + + + // The borders of all background images. + CSRAW public RectOffset border { get { + if (m_Border == null) + m_Border = new RectOffset (this, GetRectOffsetPtr (0)); + return m_Border; + } + set { AssignRectOffset (0, value.m_Ptr); } + } + + // The margins between elements rendered in this style and any other GUI elements + CSRAW public RectOffset margin { get { + if (m_Margin == null) + m_Margin = new RectOffset (this, GetRectOffsetPtr (1)); + return m_Margin; + } + set { AssignRectOffset (1, value.m_Ptr); } + } + + // Space from the edge of [[GUIStyle]] to the start of the contents. + CSRAW public RectOffset padding { get { + if (m_Padding == null) + m_Padding = new RectOffset (this, GetRectOffsetPtr (2)); + return m_Padding; + } + set { AssignRectOffset (2, value.m_Ptr); } + } + + // Extra space to be added to the background image. + CSRAW public RectOffset overflow { get { + if (m_Overflow == null) + m_Overflow = new RectOffset (this, GetRectOffsetPtr (3)); + return m_Overflow; + } + set { AssignRectOffset (3, value.m_Ptr); } + } + + CUSTOM private IntPtr GetRectOffsetPtr (int idx) + { + RectOffset* ro = &(self->m_Border); + return ro+idx; + } + + CUSTOM private void AssignRectOffset (int idx, IntPtr srcRectOffset) + { + RectOffset* ro = &(self->m_Border); + ro += idx; + *ro = *((RectOffset*)srcRectOffset); + } + + + // How image and text of the [[GUIContent]] is combined. + CUSTOM_PROP ImagePosition imagePosition + { return self->m_ImagePosition; } + { self->m_ImagePosition = value; } + + // Text alignment. + CUSTOM_PROP TextAnchor alignment + { return self->m_Alignment; } + { self->m_Alignment = value; } + + // Word wrap the text? + CUSTOM_PROP bool wordWrap { return self->m_WordWrap; } { self->m_WordWrap = value; } + + // What to do when the contents to be rendered is too large to fit within the area given. + CUSTOM_PROP TextClipping clipping { return self->m_Clipping; } { self->m_Clipping = value; } + + // Pixel offset to apply to the content of this GUIstyle + CUSTOM_PROP Vector2 contentOffset { return self->m_ContentOffset; } { self->m_ContentOffset = value; } + + // *undocumented* Clip offset to apply to the content of this GUIstyle + OBSOLETE warning Don't use clipOffset - put things inside begingroup instead. This functionality will be removed in a later version. + CSRAW public Vector2 clipOffset { get { return Internal_clipOffset; } set {Internal_clipOffset = value; } } + + CUSTOM_PROP internal Vector2 Internal_clipOffset { return self->m_ClipOffset; } { self->m_ClipOffset = value; } + + // If non-0, any GUI elements rendered with this style will have the width specified here. + CUSTOM_PROP float fixedWidth { return self->m_FixedWidth; } { self->m_FixedWidth = value; } + + // If non-0, any GUI elements rendered with this style will have the height specified here. + CUSTOM_PROP float fixedHeight { return self->m_FixedHeight; } { self->m_FixedHeight = value; } + + // Can GUI elements of this style be stretched horizontally for better layouting? + CUSTOM_PROP bool stretchWidth { return self->m_StretchWidth; } { self->m_StretchWidth = value; } + + // Can GUI elements of this style be stretched vertically for better layouting? + CUSTOM_PROP bool stretchHeight { return self->m_StretchHeight; } { self->m_StretchHeight = value; } + + CUSTOM private static float Internal_GetLineHeight (IntPtr target) { + GUIStyle *cache = reinterpret_cast<GUIStyle*> (target); + return cache->GetLineHeight (); + } + + CUSTOM private void SetFontInternal (Font value) { + self->m_Font = (Font*) (value); + } + + CUSTOM private Font GetFontInternal () { + return Scripting::ScriptingWrapperFor (self->m_Font); + } + + // The font to use for rendering. If null, the default font for the current [[GUISkin]] is used instead. + CSRAW public Font font { + get { return GetFontInternal(); } + set { SetFontInternal(value); m_FontInternal = value; } + } + + // The font size to use (for dynamic fonts) + CUSTOM_PROP int fontSize { return self->m_FontSize; } { self->m_FontSize = value; } + + // The font style to use (for dynamic fonts) + CUSTOM_PROP FontStyle fontStyle { return self->m_FontStyle; } { self->m_FontStyle = value; } + + // Enable HTML-style tags for Text Formatting Markup. + CUSTOM_PROP bool richText { return self->m_RichText; } { self->m_RichText = value; } + + // The height of one line of text with this style, measured in pixels. (RO) + CSRAW public float lineHeight { get { return Mathf.Round (Internal_GetLineHeight (m_Ptr)); } } + + + // Draw this GUIStyle on to the screen. + CSRAW private static void Internal_Draw (IntPtr target, Rect position, GUIContent content, bool isHover, bool isActive, bool on, bool hasKeyboardFocus) { + Internal_DrawArguments arguments = new Internal_DrawArguments (); + arguments.target = target; + arguments.position = position; + arguments.isHover = isHover ? 1 : 0; + arguments.isActive = isActive ? 1 : 0; + arguments.on = on ? 1 : 0; + arguments.hasKeyboardFocus = hasKeyboardFocus ? 1 : 0; + Internal_Draw (content, ref arguments); + } + + // Draw this GUIStyle on to the screen, internal version + CUSTOM private static void Internal_Draw (GUIContent content, ref Internal_DrawArguments arguments) { + reinterpret_cast<GUIStyle*> (arguments.target)->Draw (GetGUIState(), arguments.position, MonoGUIContentToTempNative(content), arguments.isHover, arguments.isActive, arguments.on, arguments.hasKeyboardFocus); + } + + // Draw plain GUIStyle without text nor image. + CSRAW public void Draw (Rect position, bool isHover, bool isActive, bool on, bool hasKeyboardFocus) { + #if UNITY_EDITOR + if (Event.current.type != EventType.Repaint) + { + Debug.LogError("Style.Draw may not be called if it is not a repaint event"); + return; + } + #endif + + Internal_Draw (m_Ptr, position, GUIContent.none, isHover, isActive, on, hasKeyboardFocus); + } + // Draw the GUIStyle with a text string inside. + CSRAW public void Draw (Rect position, string text, bool isHover, bool isActive, bool on, bool hasKeyboardFocus) { + #if UNITY_EDITOR + if (Event.current.type != EventType.Repaint) + { + Debug.LogError("Style.Draw may not be called if it is not a repaint event"); + return; + } + #endif + + Internal_Draw (m_Ptr, position, GUIContent.Temp(text), isHover, isActive, on, hasKeyboardFocus); + } + // Draw the GUIStyle with an image inside. If the image is too large to fit within the content area of the style it is scaled down. + CSRAW public void Draw (Rect position, Texture image, bool isHover, bool isActive, bool on, bool hasKeyboardFocus) { + #if UNITY_EDITOR + if (Event.current.type != EventType.Repaint) + { + Debug.LogError("Style.Draw may not be called if it is not a repaint event"); + return; + } + #endif + + Internal_Draw (m_Ptr, position, GUIContent.Temp(image), isHover, isActive, on, hasKeyboardFocus); + } + // Draw the GUIStyle with text and an image inside. If the image is too large to fit within the content area of the style it is scaled down. + CSRAW public void Draw (Rect position, GUIContent content, bool isHover, bool isActive, bool on, bool hasKeyboardFocus) { + #if UNITY_EDITOR + if (Event.current.type != EventType.Repaint) + { + Debug.LogError("Style.Draw may not be called if it is not a repaint event"); + return; + } + #endif + + Internal_Draw (m_Ptr, position, content, isHover, isActive, on, hasKeyboardFocus); + + #if UNITY_GUI_SUPPORT_TOOLTIP + if (content.tooltip != null && content.tooltip != "") { + if (isHover || isActive) + { + GUI.s_EditorTooltip = GUI.s_MouseTooltip = content.tooltip; + Vector2 v = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y)); + GUI.s_ToolTipRect = new Rect (v.x, v.y, position.width, position.height); + } + if (hasKeyboardFocus) + GUI.s_KeyTooltip = content.tooltip; + + } + #endif + } + + CSRAW public void Draw (Rect position, GUIContent content, int controlID, bool on = false) + { + #if UNITY_EDITOR + if (Event.current.type != EventType.Repaint) + { + Debug.LogError("Style.Draw may not be called if it is not a repaint event."); + return; + } + #endif + + if (content != null) + Internal_Draw2 (m_Ptr, position, content, controlID, on); + else + Debug.LogError("Style.Draw may not be called with GUIContent that is null."); + } + + CUSTOM private static void Internal_Draw2 (IntPtr style, Rect position, GUIContent content, int controlID, bool on) + { + GUIStyle *_style = reinterpret_cast<GUIStyle*>(style); + _style->Draw (GetGUIState(), position, MonoGUIContentToTempNative (content), controlID, on); + } + +#if UNITY_EDITOR + // PrefixLabel has to be drawn with an alternative draw mathod. + // The normal draw methods use MonoGUIContentToTempNative which means they all share the same temp GUIContent on the native side. + // A native IMGUI control such as GUIButton is already using this temp GUIContent when it calls GetControlID, which, + // because of the delayed feature in PrefixLabel, can end up calling a style draw function again to draw the PrefixLabel. + // This draw call cannot use the same temp GUIContent that is already needed for the GUIButton control itself, + // so it has to use this alternative code path that uses a different GUIContent to store the content in. + // We can all agree this workaround is not nice at all. But nobody seemed to be able to come up with something better. + CSRAW internal void DrawPrefixLabel (Rect position, GUIContent content, int controlID) + { + if (content != null) + Internal_DrawPrefixLabel (m_Ptr, position, content, controlID, false); + else + Debug.LogError("Style.DrawPrefixLabel may not be called with GUIContent that is null."); + } + + C++RAW static GUIContent s_TempPrefixLabelGUIContent; + + CUSTOM private static void Internal_DrawPrefixLabel (IntPtr style, Rect position, GUIContent content, int controlID, bool on) + { + GUIStyle *_style = reinterpret_cast<GUIStyle*>(style); + MonoGUIContentToNative (content, s_TempPrefixLabelGUIContent); + _style->Draw (GetGUIState(), position, s_TempPrefixLabelGUIContent, controlID, on); + } +#endif + + + // Does the ID-based Draw function show keyboard focus? Disabled by windows when they don't have keyboard focus + CSRAW internal static bool showKeyboardFocus = true; + + CUSTOM private static float Internal_GetCursorFlashOffset () { + return GUIManager::GetCursorFlashTime (); + } + + CUSTOM private static void Internal_DrawCursor (IntPtr target, Rect position, GUIContent content, int pos, Color cursorColor) + { reinterpret_cast<GUIStyle*> (target)->DrawCursor (GetGUIState(), position, MonoGUIContentToTempNative (content), pos, cursorColor); } + + // Draw this GUIStyle with selected content. + CSRAW public void DrawCursor (Rect position, GUIContent content, int controlID, int Character) { + Event e = Event.current; + if (e.type == EventType.Repaint) { + + // Figure out the cursor color... + Color cursorColor = new Color (0,0,0,0); + float cursorFlashSpeed = GUI.skin.settings.cursorFlashSpeed; + float cursorFlashRel = ((Time.realtimeSinceStartup - GUIStyle.Internal_GetCursorFlashOffset()) % cursorFlashSpeed) / cursorFlashSpeed; + if (cursorFlashSpeed == 0 || cursorFlashRel < .5f) { + cursorColor = GUI.skin.settings.cursorColor; + } + + Internal_DrawCursor ( + m_Ptr, position, content, + Character, cursorColor); + } + } + + + CUSTOM private static void Internal_DrawWithTextSelection (GUIContent content, ref Internal_DrawWithTextSelectionArguments arguments) + { + reinterpret_cast<GUIStyle*> (arguments.target)->DrawWithTextSelection ( + GetGUIState (), + arguments.position, + MonoGUIContentToTempNative(content), + arguments.isHover, + arguments.isActive, + arguments.on, + arguments.hasKeyboardFocus, + arguments.drawSelectionAsComposition, + arguments.firstPos, + arguments.lastPos, + arguments.cursorColor, + arguments.selectionColor + ); + } + + CSRAW internal void DrawWithTextSelection (Rect position, GUIContent content, int controlID, int firstSelectedCharacter, int lastSelectedCharacter, bool drawSelectionAsComposition) { + + #if UNITY_EDITOR + if (Event.current.type != EventType.Repaint) + { + Debug.LogError("Style.Draw may not be called if it is not a repaint event"); + return; + } + #endif + + Event e = Event.current; + + // Figure out the cursor color... + Color cursorColor = new Color (0,0,0,0); + float cursorFlashSpeed = GUI.skin.settings.cursorFlashSpeed; + float cursorFlashRel = ((Time.realtimeSinceStartup - GUIStyle.Internal_GetCursorFlashOffset()) % cursorFlashSpeed) / cursorFlashSpeed; + if (cursorFlashSpeed == 0 || cursorFlashRel < .5f) + cursorColor = GUI.skin.settings.cursorColor; + + + Internal_DrawWithTextSelectionArguments arguments = new Internal_DrawWithTextSelectionArguments (); + arguments.target = m_Ptr; + arguments.position = position; + arguments.firstPos = firstSelectedCharacter; + arguments.lastPos = lastSelectedCharacter; + arguments.cursorColor = cursorColor; + arguments.selectionColor = GUI.skin.settings.selectionColor; + arguments.isHover = position.Contains (e.mousePosition) ? 1 : 0; + arguments.isActive = controlID == GUIUtility.hotControl ? 1 : 0; + arguments.on = 0; + arguments.hasKeyboardFocus = controlID == GUIUtility.keyboardControl && showKeyboardFocus ? 1 : 0; + arguments.drawSelectionAsComposition = drawSelectionAsComposition ? 1 : 0; + + Internal_DrawWithTextSelection (content, ref arguments); + } + + // Draw this GUIStyle with selected content. + CSRAW public void DrawWithTextSelection (Rect position, GUIContent content, int controlID, int firstSelectedCharacter, int lastSelectedCharacter) { + DrawWithTextSelection (position, content, controlID, firstSelectedCharacter, lastSelectedCharacter, false); + + } + + // Set the default font used if null is used. + CUSTOM static internal void SetDefaultFont (Font font) + { GUIStyle::SetDefaultFont (font); } + + // Get a named GUI style from the current skin. + CSRAW public static implicit operator GUIStyle(string str) + { + if (GUISkin.current == null) + { + Debug.LogError ("Unable to use a named GUIStyle without a current skin. Most likely you need to move your GUIStyle initialization code to OnGUI"); + return GUISkin.error; + } + return GUISkin.current.GetStyle (str); + } + + // Shortcut for an empty GUIStyle. + CSRAW public static GUIStyle none { get { if(s_None == null) s_None = new GUIStyle(); return s_None; } } + static GUIStyle s_None; + + // Get the pixel position of a given string index. + CSRAW public Vector2 GetCursorPixelPosition (Rect position, GUIContent content, int cursorStringIndex) + { Vector2 temp; Internal_GetCursorPixelPosition(m_Ptr, position, content, cursorStringIndex, out temp); return temp; } + + // *undoc* + CUSTOM internal static void Internal_GetCursorPixelPosition (IntPtr target, Rect position, GUIContent content, int cursorStringIndex, out Vector2 ret) + { + *ret = reinterpret_cast<GUIStyle*> (target)->GetCursorPixelPosition (position, MonoGUIContentToTempNative (content), cursorStringIndex); + } + + // Get the cursor position (indexing into contents.text) when the user clicked at cursorPixelPosition + CSRAW public int GetCursorStringIndex (Rect position, GUIContent content, Vector2 cursorPixelPosition) + { return Internal_GetCursorStringIndex (m_Ptr, position, content, cursorPixelPosition); } + + // *undoc* + CUSTOM internal static int Internal_GetCursorStringIndex (IntPtr target, Rect position, GUIContent content, Vector2 cursorPixelPosition) + { + return reinterpret_cast<GUIStyle*> (target)->GetCursorStringIndex (position, MonoGUIContentToTempNative (content), cursorPixelPosition); + } + + + // Returns number of characters that can fit within width, returns -1 if fails due to missing font + CSRAW internal int GetNumCharactersThatFitWithinWidth (string text, float width) + { + return Internal_GetNumCharactersThatFitWithinWidth (m_Ptr, text, width); + } + + // *undoc* + CUSTOM internal static int Internal_GetNumCharactersThatFitWithinWidth (IntPtr target, string text, float width) + { +#if UNITY_FLASH + return 5; +#else + return reinterpret_cast<GUIStyle*> (target)->GetNumCharactersThatFitWithinWidth (UTF16String (text.AsUTF8().c_str()), width); +#endif + } + + // Calculate the size of a some content if it is rendered with this style. + CSRAW public Vector2 CalcSize (GUIContent content) + { + Vector2 temp; Internal_CalcSize(m_Ptr, content, out temp); + return temp; + } + + // *undoc* + CUSTOM internal static void Internal_CalcSize (IntPtr target, GUIContent content, out Vector2 ret) + { + *ret = reinterpret_cast<GUIStyle*> (target)->CalcSize (MonoGUIContentToTempNative (content)); + } + + // Calculate the size of an element formatted with this style, and a given space to content. + CSRAW public Vector2 CalcScreenSize (Vector2 contentSize) { + return new Vector2 ( + (fixedWidth != 0.0f ? fixedWidth : Mathf.Ceil (contentSize.x + padding.left + padding.right)), + (fixedHeight != 0.0f ? fixedHeight : Mathf.Ceil (contentSize.y + padding.top + padding.bottom)) + ); + } + + // How tall this element will be when rendered with /content/ and a specific /width/. + CSRAW public float CalcHeight (GUIContent content, float width) { + return Internal_CalcHeight (m_Ptr, content, width); + } + + CUSTOM private static float Internal_CalcHeight (IntPtr target, GUIContent content, float width) { + return reinterpret_cast<GUIStyle*> (target)->CalcHeight (MonoGUIContentToTempNative (content), width); + } + + // *undocumented* + CSRAW public bool isHeightDependantOnWidth { get { + return fixedHeight == 0 && (wordWrap == true && imagePosition != ImagePosition.ImageOnly); + } } + + // Calculate the minimum and maximum widths for this style rendered with /content/. + CSRAW public void CalcMinMaxWidth (GUIContent content, out float minWidth, out float maxWidth) + { + Internal_CalcMinMaxWidth(m_Ptr, content, out minWidth, out maxWidth); + } + // *undoc* + CUSTOM private static void Internal_CalcMinMaxWidth (IntPtr target, GUIContent content, out float minWidth, out float maxWidth) + { + reinterpret_cast<GUIStyle*> (target)->CalcMinMaxWidth (MonoGUIContentToTempNative (content), minWidth, maxWidth); + } + + // *undocumented + CSRAW public override string ToString () { + return UnityString.Format ("GUIStyle '{0}'", name); + } + + C++RAW + #undef GET +END + + +// Different methods for how the GUI system handles text being too large to fit the rectangle allocated. +ENUM TextClipping + // Text flows freely outside the element. + Overflow = 0, + // Text gets clipped to be inside the element. + Clip = 1, + + // Text gets truncated with dots to show it is too long + // Truncate = 2 +END + + +CSRAW +} |