static void DoNumberField (RecycledTextEditor editor, Rect position, Rect dragHotZone, int id, bool isDouble, ref double doubleVal, ref long longVal, string formatString, GUIStyle style, bool draggable, double dragSensitivity) { string allowedletters = (!isDouble) ? "0123456789-*/+%^()" : "inftynaeINFTYNAE0123456789.,-*/+%^()"; if (draggable) { DragNumberValue (editor, position, dragHotZone, id, isDouble, ref doubleVal, ref longVal, formatString, style, dragSensitivity); } Event current = Event.current; string text; bool hasFocus = position.Contains (current.mousePosition); bool mouseSelected = GUIUtility.hotControl == editor.controlID; bool kBoardSelected = GUIUtility.keyboardControl == editor.controlID; if (kBoardSelected || (current.type == EventType.MouseDown && current.button == 0 && position.Contains (current.mousePosition))) if (!editor.IsEditingControl (id)) text = (recycledCurrentEditingString = ((!isDouble) ? longVal.ToString (formatString) : doubleVal.ToString (formatString))); else { text = recycledCurrentEditingString; if (current.type == EventType.ValidateCommand && current.commandName == "UndoRedoPerformed") text = ((!isDouble) ? longVal.ToString (formatString) : doubleVal.ToString (formatString)); } else text = ((!isDouble) ? longVal.ToString (formatString) : doubleVal.ToString (formatString)); if (GUIUtility.keyboardControl == id) { bool flag; text = DoTextField (editor, id, position, text, style, allowedletters, out flag, false, false, false); if (flag) { GUI.changed = true; recycledCurrentEditingString = text; if (isDouble) { string a = text.ToLower (); if (a == "inf" || a == "infinity") { doubleVal = double.PositiveInfinity; } else if (a == "-inf" || a == "-infinity") { doubleVal = double.NegativeInfinity; } else { text = text.Replace (',', '.'); if (!double.TryParse (text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out doubleVal)) { doubleVal = (recycledCurrentEditingFloat = ExpressionEvaluator.Evaluate<double> (text)); } else { if (double.IsNaN (doubleVal)) { doubleVal = 0.0; } recycledCurrentEditingFloat = doubleVal; } } } else if (!long.TryParse (text, out longVal)) { longVal = (recycledCurrentEditingInt = ExpressionEvaluator.Evaluate<long> (text)); } else { recycledCurrentEditingInt = longVal; } } } else { bool flag; text = DoTextField (editor, id, position, text, style, allowedletters, out flag, false, false, false); } }
//internal static string DoTextGUI (TextEditor teditor) { // bool flag; // return DoTextGUI (teditor, out flag); //} //internal static string DoTextGUI (RecycledTextEditor tEditor, string text, string allowedLetters, out bool changed) { // Event current = Event.current; // changed = false; // string text2 = text; // if (text == null) // text = string.Empty; // if (HasKBoardSelection (tEditor.controlID) && current.type != EventType.Layout) { // if (tEditor.IsEditingControl (tEditor.controlID); // } // switch (current.GetTypeForControl (tEditor.controlID)) { // case EventType.MouseDown: // if (allowControl) // if (HasFocus (tEditor.position) && current.button == 0) { // if (HasSelection (tEditor.controlID)) { // if (current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord) { // tEditor.MoveCursorToPosition (current.mousePosition); // tEditor.SelectCurrentWord (); // tEditor.DblClickSnap (TextEditor.DblClickSnapping.WORDS); // tEditor.MouseDragSelectsWholeWords (true); // dragToPosition = false; // } else if (current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine) { // tEditor.MoveCursorToPosition (current.mousePosition); // tEditor.SelectCurrentParagraph (); // tEditor.DblClickSnap (TextEditor.DblClickSnapping.PARAGRAPHS); // tEditor.MouseDragSelectsWholeWords (true); // dragToPosition = false; // } else { // tEditor.MoveCursorToPosition (current.mousePosition); // selectAllOnMouseUp = false; // } // current.Use (); // } else { // GUIUtility.hotControl = GUIUtility.keyboardControl = tEditor.controlID; // hotTextEditor = tEditor; // tEditor.MoveCursorToPosition (current.mousePosition); // tEditor.DetectFocusChange (); // } // } else if (!HasFocus (tEditor.position) && HasSelection (tEditor.controlID)) { // GUIUtility.hotControl = GUIUtility.keyboardControl = 0; // hotTextEditor = null; // tEditor.DetectFocusChange (); // } // break; // case EventType.MouseUp: // if (HasSelection (tEditor.controlID)) { // tEditor.MouseDragSelectsWholeWords (false); // GUIUtility.hotControl = 0; // current.Use (); // } // break; // case EventType.MouseDrag: // if (HasSelection (tEditor.controlID)) { // if (current.shift) // tEditor.MoveCursorToPosition (current.mousePosition); // else // tEditor.SelectToPosition (current.mousePosition); // current.Use (); // } // break; // case EventType.KeyDown: // if (!HasSelection (tEditor.controlID)) // break; // if (tEditor.HandleKeyEvent (current)) { // changed = true; // } else { // char character = current.character; // Font font = tEditor.style.font ?? GUI.skin.font; // if (current.keyCode == KeyCode.Tab || character == '\t') // break; // if (character == '\n' && !tEditor.multiline && !current.alt) // break; // if (font.HasCharacter (character) || character == '\n') { // tEditor.Insert (character); // changed = true; // } else if (character == '\0') { // if (Input.compositionString.Length > 0) { // tEditor.ReplaceSelection (""); // changed = true; // } // current.Use (); // } // } // break; // case EventType.Repaint: // if (HasKBoardSelection (tEditor.controlID)) // tEditor.DrawCursor (tEditor.text); // else // tEditor.style.Draw (tEditor.position, new GUIContent (tEditor.text), tEditor.controlID, false); // break; // } // if (changed) { // GUI.changed = true; // current.Use (); // } // tEditor.UpdateScrollOffsetIfNeeded (current); // return tEditor.text; //} internal static string DoTextField (RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField) { Event current = Event.current; string text2 = text; if (text == null) text = string.Empty; if (EditorGUI.showMixedValue) text = string.Empty; if (HasKBoardSelection (id) && current.type != EventType.Layout) { if (editor.IsEditingControl (id)) { editor.position = position; editor.style = style; editor.controlID = id; editor.multiline = multiline; editor.isPasswordField = passwordField; editor.DetectFocusChange (); } else if (EditorGUIUtility.editingTextField) { editor.BeginEditing (id, text, position, style, multiline, passwordField); if (GUI.skin.settings.cursorColor.a > 0f) editor.SelectAll (); } } if (editor.controlID == id && GUIUtility.keyboardControl != id) editor.controlID = 0; bool flag = false; string text3 = editor.text; EventType typeForControl = current.GetTypeForControl (id); switch (typeForControl) { case EventType.MouseDown: if (HasFocus (position) && current.button == 0) { if (editor.IsEditingControl (id)) { if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord) { editor.MoveCursorToPosition (Event.current.mousePosition); editor.SelectCurrentWord (); editor.MouseDragSelectsWholeWords (true); editor.DblClickSnap (TextEditor.DblClickSnapping.WORDS); dragToPosition = false; } else if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine) { editor.MoveCursorToPosition (Event.current.mousePosition); editor.SelectCurrentParagraph (); editor.MouseDragSelectsWholeWords (true); editor.DblClickSnap (TextEditor.DblClickSnapping.PARAGRAPHS); dragToPosition = false; } else { editor.MoveCursorToPosition (Event.current.mousePosition); selectAllOnMouseUp = false; } } else { GUIUtility.keyboardControl = id; editor.BeginEditing (id, text, position, style, multiline, passwordField); editor.MoveCursorToPosition (Event.current.mousePosition); if (GUI.skin.settings.cursorColor.a > 0f) selectAllOnMouseUp = true; } GUIUtility.hotControl = id; current.Use (); } goto IL_9B5; case EventType.MouseUp: if (HasSelection (id)) { if (dragged && dragToPosition) { editor.MoveSelectionToAltCursor (); flag = true; } else if (postponeMove) { editor.MoveCursorToPosition (Event.current.mousePosition); } else if (selectAllOnMouseUp) { if (GUI.skin.settings.cursorColor.a > 0f) editor.SelectAll (); selectAllOnMouseUp = false; } editor.MouseDragSelectsWholeWords (false); dragToPosition = true; dragged = false; postponeMove = false; if (current.button == 0) { GUIUtility.hotControl = 0; current.Use (); } } goto IL_9B5; case EventType.MouseMove: case EventType.KeyUp: case EventType.ScrollWheel: IL_125: switch (typeForControl) { case EventType.ValidateCommand: if (HasSelection (id)) { string commandName = current.commandName; if (commandName != null) { if (commandName == "Cut" || commandName == "Copy") { if (editor.hasSelection) current.Use (); } else if (commandName == "Paste") { if (editor.CanPaste ()) current.Use (); } else if (commandName == "SelectAll" || commandName == "Delete") { current.Use (); } else if (commandName == "UndoRedoPerformed") { editor.text = text; current.Use (); } } } goto IL_9B5; case EventType.ExecuteCommand: if (GUIUtility.keyboardControl == id) { string commandName2 = current.commandName; if (commandName2 != null) { if (commandName2 == "OnLostFocus") { if (activeEditor != null) activeEditor.EndEditing (); current.Use (); } else if (commandName2 == "Cut") { editor.BeginEditing (id, text, position, style, multiline, passwordField); editor.Cut (); current.Use (); } else if (commandName2 == "Copy") { editor.Copy (); current.Use (); } else if (commandName2 == "Paste") { editor.BeginEditing (id, text, position, style, multiline, passwordField); editor.Paste (); flag = true; } else if (commandName2 == "SelectAll") { editor.SelectAll (); current.Use (); } else if (commandName2 == "Delete") { editor.BeginEditing (id, text, position, style, multiline, passwordField); if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) editor.Delete (); else editor.Cut (); flag = true; current.Use (); } } } goto IL_9B5; case EventType.DragExited: goto IL_9B5; //case EventType.ContextClick: //if (HasFocus (position)) { // if (!editor.IsEditingControl (id)) { // GUIUtility.keyboardControl = id; // editor.BeginEditing (id, text, position, style, multiline, passwordField); // editor.MoveCursorToPosition (Event.current.mousePosition); // } // EditorGUI.ShowTextEditorPopupMenu (); // Event.current.Use (); //} //goto IL_9B5; default: goto IL_9B5; } case EventType.MouseDrag: if (HasSelection (id)) { if (!current.shift && editor.hasSelection && dragToPosition) { editor.MoveAltCursorToPosition (Event.current.mousePosition); } else { if (current.shift) editor.MoveCursorToPosition (Event.current.mousePosition); else editor.SelectToPosition (Event.current.mousePosition); dragToPosition = false; selectAllOnMouseUp = !editor.hasSelection; } dragged = true; current.Use (); } goto IL_9B5; case EventType.KeyDown: if (GUIUtility.keyboardControl == id) { char character = current.character; if (editor.IsEditingControl (id) && editor.HandleKeyEvent (current)) { current.Use (); flag = true; //} else if (current.keyCode == KeyCode.Escape) { // if (editor.IsEditingControl (id)) { // if (style == EditorStyles.toolbarSearchField || style == EditorStyles.searchField) { // originalText = ""; // } // editor.text = originalText; // editor.EndEditing (); // flag = true; // } } else if (character == '\n' || character == '\u0003') { if (!editor.IsEditingControl (id)) { editor.BeginEditing (id, text, position, style, multiline, passwordField); editor.SelectAll (); } else { if (multiline && !current.alt && !current.shift && !current.control) { editor.Insert (character); flag = true; goto IL_9B5; } editor.EndEditing (); } current.Use (); } else if (character == '\t' || current.keyCode == KeyCode.Tab) { if (multiline && editor.IsEditingControl (id)) { bool flag2 = allowedletters == null || allowedletters.IndexOf (character) != -1; bool flag3 = !current.alt && !current.shift && !current.control && character == '\t'; if (flag3 && flag2) { editor.Insert (character); flag = true; } } } else if (character != '\u0019' && character != '\u001b') { if (editor.IsEditingControl (id)) { bool flag4 = (allowedletters == null || allowedletters.IndexOf (character) != -1) && character != '\0'; if (flag4) { editor.Insert (character); flag = true; } else { if (Input.compositionString != "") { editor.ReplaceSelection (""); flag = true; } current.Use (); } } } } goto IL_9B5; case EventType.Repaint: { string text4; if (editor.IsEditingControl (id)) { text4 = ((!passwordField) ? editor.text : "".PadRight (editor.text.Length, '*')); //} else if (EditorGUI.showMixedValue) { // text4 = EditorGUI.s_MixedValueContent.text; } else text4 = ((!passwordField) ? text : "".PadRight (text.Length, '*')); if (GUIUtility.hotControl == 0) EditorGUIUtility.AddCursorRect (position, MouseCursor.Text); if (!editor.IsEditingControl (id)) { //EditorGUI.BeginHandleMixedValueContentColor (); style.Draw (position, new GUIContent (text4), id, false); //EditorGUI.EndHandleMixedValueContentColor (); } else { editor.DrawCursor (text4); } goto IL_9B5; } goto IL_125; } IL_9B5: editor.UpdateScrollOffsetIfNeeded (current); changed = false; if (flag) { changed = (text3 != editor.text); current.Use (); } string result; if (changed) { GUI.changed = true; result = editor.text; } else { RecycledTextEditor.allowContextCutOrPaste = true; result = text2; } return result; }
internal static string DoTextField(RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField) { Event current = Event.current; string result = text; if (text == null) { text = string.Empty; } if (showMixedValue) { text = string.Empty; } if (HasKeyboardFocus(id) && Event.current.type != EventType.Layout) { if (editor.IsEditingControl(id)) { editor.position = position; editor.style = style; editor.controlID = id; editor.multiline = multiline; editor.isPasswordField = passwordField; editor.DetectFocusChange(); } else if (editingTextField) { editor.BeginEditing(id, text, position, style, multiline, passwordField); if (GUI.skin.settings.cursorColor.a > 0f) { editor.SelectAll(); } } } if (editor.controlID == id && GUIUtility.keyboardControl != id) { editor.controlID = 0; } bool flag = false; string text2 = editor.text; EventType typeForControl = current.GetTypeForControl(id); switch (typeForControl) { case EventType.MouseDown: if (position.Contains(current.mousePosition) && current.button == 0) { if (editor.IsEditingControl(id)) { if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord) { editor.MoveCursorToPosition(Event.current.mousePosition); editor.SelectCurrentWord(); editor.MouseDragSelectsWholeWords(true); editor.DblClickSnap(TextEditor.DblClickSnapping.WORDS); s_DragToPosition = false; } else if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine) { editor.MoveCursorToPosition(Event.current.mousePosition); editor.SelectCurrentParagraph(); editor.MouseDragSelectsWholeWords(true); editor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS); s_DragToPosition = false; } else { editor.MoveCursorToPosition(Event.current.mousePosition); s_SelectAllOnMouseUp = false; } } else { GUIUtility.keyboardControl = id; editor.BeginEditing(id, text, position, style, multiline, passwordField); editor.MoveCursorToPosition(Event.current.mousePosition); if (GUI.skin.settings.cursorColor.a > 0f) { s_SelectAllOnMouseUp = true; } } GUIUtility.hotControl = id; current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id) { if (s_Dragged && s_DragToPosition) { editor.MoveSelectionToAltCursor(); flag = true; } else if (s_PostPoneMove) { editor.MoveCursorToPosition(Event.current.mousePosition); } else if (s_SelectAllOnMouseUp) { if (GUI.skin.settings.cursorColor.a > 0f) { editor.SelectAll(); } s_SelectAllOnMouseUp = false; } editor.MouseDragSelectsWholeWords(false); s_DragToPosition = true; s_Dragged = false; s_PostPoneMove = false; if (current.button == 0) { GUIUtility.hotControl = 0; current.Use(); } } break; case EventType.MouseMove: case EventType.KeyUp: case EventType.ScrollWheel: switch (typeForControl) { case EventType.ValidateCommand: if (GUIUtility.keyboardControl == id) { string commandName = current.commandName; switch (commandName) { case "Cut": case "Copy": if (editor.hasSelection) { current.Use(); } break; case "Paste": if (editor.CanPaste()) { current.Use(); } break; case "SelectAll": current.Use(); break; case "UndoRedoPerformed": editor.text = text; current.Use(); break; case "Delete": current.Use(); break; } } break; case EventType.ExecuteCommand: if (GUIUtility.keyboardControl == id) { string commandName = current.commandName; switch (commandName) { case "OnLostFocus": if (activeEditor != null) { activeEditor.EndEditing(); } current.Use(); break; case "Cut": editor.BeginEditing(id, text, position, style, multiline, passwordField); editor.Cut(); flag = true; break; case "Copy": editor.Copy(); current.Use(); break; case "Paste": editor.BeginEditing(id, text, position, style, multiline, passwordField); editor.Paste(); flag = true; break; case "SelectAll": editor.SelectAll(); current.Use(); break; case "Delete": editor.BeginEditing(id, text, position, style, multiline, passwordField); if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor || (Application.platform == RuntimePlatform.WebGLPlayer && SystemInfo.operatingSystem.StartsWith("Mac"))) { editor.Delete(); } else { editor.Cut(); } flag = true; current.Use(); break; } } break; case EventType.DragExited: break; case EventType.ContextClick: if (position.Contains(current.mousePosition)) { if (!editor.IsEditingControl(id)) { GUIUtility.keyboardControl = id; editor.BeginEditing(id, text, position, style, multiline, passwordField); editor.MoveCursorToPosition(Event.current.mousePosition); } //ShowTextEditorPopupMenu(); Event.current.Use(); } break; default: break; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { if (!current.shift && editor.hasSelection && s_DragToPosition) { editor.MoveAltCursorToPosition(Event.current.mousePosition); } else { if (current.shift) { editor.MoveCursorToPosition(Event.current.mousePosition); } else { editor.SelectToPosition(Event.current.mousePosition); } s_DragToPosition = false; s_SelectAllOnMouseUp = !editor.hasSelection; } s_Dragged = true; current.Use(); } break; case EventType.KeyDown: if (GUIUtility.keyboardControl == id) { char character = current.character; if (editor.IsEditingControl(id) && editor.HandleKeyEvent(current)) { current.Use(); flag = true; } else if (current.keyCode == KeyCode.Escape) { if (editor.IsEditingControl(id)) { /*if (style == EditorStyles.toolbarSearchField || style == EditorStyles.searchField) * { * EditorGUI.s_OriginalText = string.Empty; * }*/ editor.text = s_OriginalText; editor.EndEditing(); flag = true; } } else if (character == '\n' || character == '\u0003') { if (!editor.IsEditingControl(id)) { editor.BeginEditing(id, text, position, style, multiline, passwordField); editor.SelectAll(); } else { if (multiline && !current.alt && !current.shift && !current.control) { editor.Insert(character); flag = true; break; } editor.EndEditing(); } current.Use(); } else if (character == '\t' || current.keyCode == KeyCode.Tab) { if (multiline && editor.IsEditingControl(id)) { bool flag2 = allowedletters == null || allowedletters.IndexOf(character) != -1; bool flag3 = !current.alt && !current.shift && !current.control && character == '\t'; if (flag3 && flag2) { editor.Insert(character); flag = true; } } } else if (character != '\u0019' && character != '\u001b') { if (editor.IsEditingControl(id)) { bool flag4 = (allowedletters == null || allowedletters.IndexOf(character) != -1) && character != '\0'; if (flag4) { editor.Insert(character); flag = true; } else { if (Input.compositionString != string.Empty) { editor.ReplaceSelection(string.Empty); flag = true; } current.Use(); } } } } break; case EventType.Repaint: { string text3; if (editor.IsEditingControl(id)) { text3 = ((!passwordField) ? editor.text : string.Empty.PadRight(editor.text.Length, '*')); } else if (showMixedValue) { text3 = s_MixedValueContent.text; } else { text3 = ((!passwordField) ? text : string.Empty.PadRight(text.Length, '*')); } if (!string.IsNullOrEmpty(s_UnitString) && !passwordField) { text3 = text3 + " " + s_UnitString; } if (GUIUtility.hotControl == 0) { //EditorGUIUtility.AddCursorRect(position, MouseCursor.Text); } if (!editor.IsEditingControl(id)) { BeginHandleMixedValueContentColor(); style.Draw(position, RuntimeEditorGUIUtility.TempContent(text3), id, false); EndHandleMixedValueContentColor(); } else { editor.DrawCursor(text3); } break; } } if (GUIUtility.keyboardControl == id) { //GUIUtility.textFieldInput = true; } editor.UpdateScrollOffsetIfNeeded(current); changed = false; if (flag) { changed = (text2 != editor.text); current.Use(); } if (changed) { GUI.changed = true; return(editor.text); } RecycledTextEditor.s_AllowContextCutOrPaste = true; return(result); }
internal static void DoNumberField(RecycledTextEditor editor, Rect position, Rect dragHotZone, int id, bool isDouble, ref double doubleVal, ref long longVal, string formatString, GUIStyle style) { string allowedletters = (!isDouble) ? s_AllowedCharactersForInt : s_AllowedCharactersForFloat; //if (draggable) //{ //EditorGUI.DragNumberValue(editor, position, dragHotZone, id, isDouble, ref doubleVal, ref longVal, formatString, style, dragSensitivity); //} Event current = Event.current; string text; if (HasKeyboardFocus(id) || (current.type == EventType.MouseDown && current.button == 0 && position.Contains(current.mousePosition))) { if (!editor.IsEditingControl(id)) { text = (s_RecycledCurrentEditingString = ((!isDouble) ? longVal.ToString(formatString) : doubleVal.ToString(formatString))); } else { text = s_RecycledCurrentEditingString; if (current.type == EventType.ValidateCommand && current.commandName == "UndoRedoPerformed") { text = ((!isDouble) ? longVal.ToString(formatString) : doubleVal.ToString(formatString)); } } } else { text = ((!isDouble) ? longVal.ToString(formatString) : doubleVal.ToString(formatString)); } if (GUIUtility.keyboardControl == id) { bool flag; text = DoTextField(editor, id, position, text, style, allowedletters, out flag, false, false, false); if (flag) { GUI.changed = true; s_RecycledCurrentEditingString = text; if (isDouble) { string a = text.ToLower(); if (a == "inf" || a == "infinity") { doubleVal = double.PositiveInfinity; } else if (a == "-inf" || a == "-infinity") { doubleVal = double.NegativeInfinity; } else { text = text.Replace(',', '.'); if (!double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out doubleVal)) { //s_RecycledCurrentEditingFloat = doubleVal; //doubleVal = (EditorGUI.s_RecycledCurrentEditingFloat = ExpressionEvaluator.Evaluate<double>(text)); return; } if (double.IsNaN(doubleVal)) { doubleVal = 0.0; } s_RecycledCurrentEditingFloat = doubleVal; } } else { if (!long.TryParse(text, out longVal)) { //longVal = (EditorGUI.s_RecycledCurrentEditingInt = ExpressionEvaluator.Evaluate<long>(text)); return; } s_RecycledCurrentEditingInt = longVal; } } } else { bool flag; text = DoTextField(editor, id, position, text, style, allowedletters, out flag, false, false, false); } }