void AdjustCaret(CharPosition cp) { _caretPosition = cp.charIndex; Vector2 pos = GetCharLocation(cp); TextField.LineInfo line = textField.lines[cp.lineIndex]; pos.y = line.y + textField.y; Vector2 newPos = pos; if (newPos.x < textField.textFormat.size) { newPos.x += Math.Min(50, (int)(_contentRect.width / 2)); } else if (newPos.x > _contentRect.width - GUTTER_X - textField.textFormat.size) { newPos.x -= Math.Min(50, (int)(_contentRect.width / 2)); } if (newPos.x < GUTTER_X) { newPos.x = GUTTER_X; } else if (newPos.x > _contentRect.width - GUTTER_X) { newPos.x = Math.Max(GUTTER_X, _contentRect.width - GUTTER_X); } if (newPos.y < GUTTER_Y) { newPos.y = GUTTER_Y; } else if (newPos.y + line.height >= _contentRect.height - GUTTER_Y) { newPos.y = Math.Max(GUTTER_Y, _contentRect.height - line.height - GUTTER_Y); } pos += MoveContent(newPos - pos); if (line.height > 0) //将光标居中 { pos.y += (int)(line.height - textField.textFormat.size) / 2; } _caret.SetPosition(pos.x, pos.y, 0); Vector2 cursorPos = _caret.LocalToGlobal(new Vector2(0, _caret.height)); cursorPos.y = Stage.inst.stageHeight - cursorPos.y; Input.compositionCursorPos = cursorPos; _nextBlink = Time.time + 0.5f; _caret.graphics.enabled = true; if (_selectionStart != null) { UpdateSelection(cp); } }
private void OnScrollViewerLeftButtonDown(object sender, MouseButtonEventArgs e) { if (null == Solution.Current.ActiveScript) { return; // No active script. } if (e.ClickCount > 1) { HandleMultipleClicks(e); return; } // We need the canvas to be focusable in order to receive key inputs. System.Diagnostics.Debug.Assert(textCanvas.Focusable == true); textCanvas.Focus(); // Set input focus on the canvas. if (IsMouseInClickableRegion(sender, e) == false) { return; } System.Windows.Point screenPoint = GetRelativeCanvasPosition(e); IScriptObject activeScript = Solution.Current.ActiveScript; CharPosition mousePoint = activeScript.CreateCharPosition(); mousePoint.SetScreenPosition(screenPoint); System.Drawing.Point cursor = mousePoint.GetCharacterPosition(); breakpointLineY = -1; if (IsPointWithinLineColumn(screenPoint)) { clickedLineIndex = cursor.Y; textCore.SelectLines(cursor.Y, 0); } else { clickedLineIndex = -1; if (IsPointWithinBreakColumn(GetRelativeCanvasPosition(e))) { breakpointLineY = cursor.Y; } textCore.SetMouseDownPosition(cursor.X, cursor.Y, e); } // Capturing mouse input results in an immediate mouse-move event, // but we won't want to handle that as we know that we are // currently in a button-down event. So here we ignore the immediate // mouse-move event by setting "stopMouseMoveReentrant" to true. // ignoreMouseMoveEvent = true; TextEditorScrollViewer scrollViewer = sender as TextEditorScrollViewer; mouseCursorCaptured = scrollViewer.CaptureMouse(); ignoreMouseMoveEvent = false; UpdateCaretPosition(); }
//[Test] public void TestCharPosition18() { //Testing that tab is converted to 4 characters by chartovisualoffset TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(2, 2); Assert.AreEqual(8, offset); }
//[Test] public void TestCharPosition19() { //Testing CharToVisualOffset if the line is empty TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(4, 4); Assert.AreEqual(0, offset); }
public CharPosition[] GetPositionsOfElements(char[,] matrix, string text) { CharPosition[] positions = new CharPosition[text.Length]; for (int i = 0; i < text.Length; i++) { positions[i] = GetPositionOfElementInMatrix(matrix, text[i]); } return(positions); }
public LuryException(LuryExceptionType type, string sourceCode, CharPosition position, int length) { this.ExceptionType = type; this.SourceCode = sourceCode; this.Position = position; this.CharLength = length; }
public LuryException(LuryExceptionType type, string sourceCode, CharPosition position, int length) { this.ExceptionType = type; this.SourceCode = sourceCode; this.Position = position; this.CharLength = length; }
public void Reattach(CharPosition p, char[] prefix) { Position = p; if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } _prefixReader = _prefixReader.Prepend(prefix); }
/// <summary> /// /// </summary> /// <param name="value"></param> public void ReplaceSelection(string value) { string leftText = null; string rightText = null; if (_selectionStart != null) { CharPosition cp = (CharPosition)_selectionStart; ClearSelection(); if (cp.charIndex < _caretPosition) { leftText = textField.text.Substring(0, cp.charIndex); rightText = textField.text.Substring(_caretPosition); _caretPosition = cp.charIndex; } else { leftText = textField.text.Substring(0, _caretPosition); rightText = textField.text.Substring(cp.charIndex); } } else { if (string.IsNullOrEmpty(value)) { return; } leftText = textField.text.Substring(0, _caretPosition); rightText = textField.text.Substring(_caretPosition); } if (!string.IsNullOrEmpty(value)) { value = ValidateInput(value); if (leftText.Length + rightText.Length + value.Length > maxLength) { value = value.Substring(0, Math.Max(0, maxLength - leftText.Length - rightText.Length)); } this.text = leftText + value + rightText; _caretPosition += value.Length; } else { this.text = leftText + rightText; } //这里立即更新,使内含的图片等对象能够立即创建,避免延迟在Update里才创建,那样会引起闪烁 textField.Redraw(); onChanged.Call(); }
protected override void UpdateLayerForScriptCore(IScriptObject hostScript) { selectionStart = hostScript.CreateCharPosition(); selectionEnd = hostScript.CreateCharPosition(); lineSelection = hostScript.CreateCharPosition(); inLineSelection = hostScript.CreateCharPosition(); allOccurencesSelectionStart = hostScript.CreateCharPosition(); allOccurencesSelectionEnd = hostScript.CreateCharPosition(); currentOccurenceSelectionStart = hostScript.CreateCharPosition(); currentOccurenceSelectionEnd = hostScript.CreateCharPosition(); }
private void Awake() { if (instance) { Destroy(this); } else { instance = this; } }
/* *************************************************************************** ** ** Function: OnKeyDown */ ///<summary> /// KeyPress Listener Used to disallow special keys from working ///</summary> ///<param name="sender" type="object"></param> ///<param name="e" type="System.Windows.Forms.KeyEventArgs"></param> ///<returns>void</returns> ///<exception cref="System.Exception">Thrown</exception> ///<remarks> ///</remarks> ///<example>How to use this function ///<code> ///</code> ///</example> /// protected void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { e.Handled = true; /* ** This allows the back arrow to work */ switch (e.KeyCode) { default: e.Handled = false; break; case Keys.Left: m_bIgnorePart = true; e.Handled = false; break; case Keys.Tab: break; case Keys.Back: { int iPos = 0; iPos = SelectionStart - 1; if ((-1 != iPos) && (iPos < (m_abyData.Length * 3))) { SelectionStart = iPos; m_bIgnorePart = true; } } break; case Keys.Return: { CharPosition cp = Position; int iPos = 0; iPos = LineIndex(cp.LinePos + 1); if ((-1 != iPos) && (iPos < (m_abyData.Length * 3))) { SelectionStart = iPos; } } break; case Keys.Delete: break; case Keys.Insert: break; } }
//[Test] public void TestCharPosition22() { TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(2, -1); Assert.AreEqual(0, offset); int charoffset = coordinates.VisualToCharOffset(2, offset); Assert.AreEqual(0, charoffset); }
//[Test] public void TestCharPosition17() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-right corner of invalid area. coordinates.SetScreenPosition(new System.Windows.Point(3000.0, 500.0)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
//[Test] public void TestCharPosition13() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-middle part of invalid area. coordinates.SetCharacterPosition(new System.Drawing.Point(3, 500)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
public System.Windows.Point TranslateToScreenPoint(System.Drawing.Point charPosition) { IScriptObject activeScript = Solution.Current.ActiveScript; CharPosition position = activeScript.CreateCharPosition(); position.SetCharacterPosition(charPosition.X, charPosition.Y); System.Windows.Point result = position.GetScreenPosition(); // The screen position needs offset based on the current scroll position. result.Offset(-scrollViewer.HorizontalOffset, -scrollViewer.VerticalOffset); return(result); }
//[Test] public void TestCharPosition16() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-middle part of invalid area. coordinates.SetScreenPosition(new System.Windows.Point(7 * Configurations.FormatFontWidth, 500.0)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
//[Test] public void TestCharPosition20() { //Testing VisualToCharOffset for tab character TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(2, 2); Assert.AreEqual(8, offset); int charoffset = coordinates.VisualToCharOffset(2, offset); Assert.AreEqual(2, charoffset); }
public int Read() { var curr = ReadSimply(); if (curr == '\n' || (curr == '\r' && Peek() != '\n')) { Position = Position.NextLine; } else if (curr > -1) { Position = Position.NextColumn; } return(curr); }
void __focusIn(EventContext context) { if (!editable || !Application.isPlaying) { return; } if (Stage.keyboardInput) { Stage.inst.OpenKeyboard(textField.text, false, _displayAsPassword ? false : !textField.singleLine, _displayAsPassword, false, null, keyboardType); } else { Input.imeCompositionMode = IMECompositionMode.On; _editing = true; if (_caret == null) { CreateCaret(); } if (!string.IsNullOrEmpty(_promptText)) { UpdateAlternativeText(); } float caretSize; //如果界面缩小过,光标很容易看不见,这里放大一下 if (UIConfig.inputCaretSize == 1 && GRoot.contentScaleFactor < 1) { caretSize = (float)UIConfig.inputCaretSize / GRoot.contentScaleFactor; } else { caretSize = UIConfig.inputCaretSize; } _caret.SetSize(caretSize, textField.textFormat.size); _caret.DrawRect(0, Color.clear, textField.textFormat.color); AddChild(_caret); _selectionShape.Clear(); AddChild(_selectionShape); _caretPosition = textField.text.Length; CharPosition cp = GetCharPosition(_caretPosition); AdjustCaret(cp); _selectionStart = cp; } }
void __touchMove(EventContext context) { if (_selectionStart == null) { return; } Vector3 v = Stage.touchPosition; v = this.GlobalToLocal(v); v.x += this.pivotX; v.y += this.pivotY; CharPosition cp = GetCharPosition(v); //if (cp.charIndex != _caretPosition) // AdjustCaret(cp); }
protected override void InternalRefreshObjects() { base.InternalRefreshObjects(); if (_editing) { CharPosition cp = GetCharPosition(_caretPosition); AdjustCaret(cp); SetChildIndex(_selectionShape, this.numChildren - 1); SetChildIndex(_caret, this.numChildren - 2); } else { MoveContent(Vector2.zero); } }
/// <summary> /// Возвращает результат выполнения анализатора на шаг назад, если это возможно. /// Возвращает true при удаче. /// </summary> /// <returns></returns> virtual public bool StepBack() //отменяет считывание токена { if (previousPos.Count <= 0 || previousStatus.Count <= 0) { return(false); } currentPos = previousPos[previousPos.Count - 1]; previousPos.RemoveAt(previousPos.Count - 1); currentStatus = previousStatus[previousStatus.Count - 1]; previousStatus.RemoveAt(previousStatus.Count - 1); reader.DiscardBufferedData(); reader.BaseStream.Seek(currentPos.globalPos, SeekOrigin.Begin); return(true); }
private void OnScrollViewerRightButtonDown(object sender, MouseButtonEventArgs e) { if (textCore.HasSelection != false) { return; // We don't want to destroy selection. } // Compute the coordinates from screen to character. System.Windows.Point screenPoint = GetRelativeCanvasPosition(e); IScriptObject activeScript = Solution.Current.ActiveScript; CharPosition mousePoint = activeScript.CreateCharPosition(); mousePoint.SetScreenPosition(screenPoint); // Finally set the actual cursor position and refresh the display. textCore.SetCursorPosition(mousePoint.CharacterX, mousePoint.CharacterY); UpdateCaretPosition(); clickedLineIndex = -1; }
string GetSelection() { if (_selectionStart == null) { return(string.Empty); } CharPosition cp = (CharPosition)_selectionStart; if (cp.charIndex < _caretPosition) { return(textField.text.Substring(cp.charIndex, _caretPosition - cp.charIndex)); } else { return(textField.text.Substring(_caretPosition, cp.charIndex - _caretPosition)); } }
protected Rect CalculateRectangleFullLine(CharPosition start, int firstVisibleLine) { double x = 0, y = 0, width = 0; double vertDisplayOffset = firstVisibleLine * Configurations.FontDisplayHeight; double horzDisplayOffset = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth; x = Configurations.CanvasMarginLeft - Configurations.ShadowWidth; y = start.ScreenY; width = textEditorCanvas.ActualWidth + textEditorCanvas.HorizontalOffset; if (width > 0) { y = y - vertDisplayOffset; x = x - horzDisplayOffset; return(new Rect(x, y, width, Configurations.FontDisplayHeight)); } return(new Rect()); }
protected CharPosition[] GetPairs(string polybiusPositions) { var arrayLength = polybiusPositions.Length / 2; List <CharPosition> newPositions = new List <CharPosition>(arrayLength); int i = 0; while (i < polybiusPositions.Length) { CharPosition charPosition = new CharPosition { Column = (int)Char.GetNumericValue(polybiusPositions[i++]), Row = (int)Char.GetNumericValue(polybiusPositions[i++]) }; newPositions.Add(charPosition); } return(newPositions.ToArray()); }
private void OnDragOver(object sender, DragEventArgs e) { e.Effects = DragDropEffects.Move; if ((e.KeyStates & DragDropKeyStates.ControlKey) != 0) { e.Effects = DragDropEffects.Copy; } // First, validate arbitrary screen coordinates... IScriptObject activeScript = Solution.Current.ActiveScript; CharPosition mousePoint = activeScript.CreateCharPosition(); mousePoint.SetScreenPosition(GetRelativeCanvasPosition(e)); // Here when the content is dragged to the first line in view, try to // bring it onto the previous line. This is so that the previous line // gets to scroll into view later on. If the cursor is on the last // visible line, then try to set it one line beyond that. This is so // that the next line get to scroll into view the same way. // int characterY = mousePoint.CharacterY; int lastVisibleLine = textCanvas.FirstVisibleLine + textCanvas.MaxVisibleLines; if (characterY == textCanvas.FirstVisibleLine) { characterY = characterY - 1; } else if (characterY >= lastVisibleLine - 1) { characterY = characterY + 1; } mousePoint.SetCharacterPosition(mousePoint.CharacterX, characterY); // Then get the precised cursor coordinates, and then set the // character position so we get screen coordinates at character // boundaries... System.Drawing.Point cursor = mousePoint.GetCharacterPosition(); mousePoint.SetCharacterPosition(cursor); textCanvas.SetCursorScreenPos(mousePoint.GetScreenPosition()); textCanvas.EnsureCursorVisible(mousePoint.CharacterX, mousePoint.CharacterY); }
void __touchBegin(EventContext context) { if (!_editing || textField.lines.Count == 0) { return; } ClearSelection(); Vector3 v = Stage.inst.touchPosition; v = this.GlobalToLocal(v); CharPosition cp = GetCharPosition(v); AdjustCaret(cp); _selectionStart = cp; context.CaptureTouch(); Stage.inst.onTouchMove.AddCapture(_touchMoveDelegate); }
void DeleteSelection() { if (_selectionStart == null) { return; } CharPosition cp = (CharPosition)_selectionStart; if (cp.charIndex < _caretPosition) { this.text = _text.Substring(0, cp.charIndex) + _text.Substring(_caretPosition); _caretPosition = cp.charIndex; } else { this.text = _text.Substring(0, _caretPosition) + _text.Substring(cp.charIndex); } ClearSelection(); }
//[Test] public void TestCharPositionFromNonSpaceCharCount() { // \tb = a + 3; // \t c\t = a + \t b; TextBuffer textBuffer = new TextBuffer("\tb = a + 3;\n\t c\t = a + \t b;"); CharPosition position = new CharPosition(textBuffer); position.SetCharacterPosition(0, 0); // First line. position.FromNonSpaceCharCount(1); Assert.AreEqual(2, position.CharacterX); position.FromNonSpaceCharCount(4); Assert.AreEqual(8, position.CharacterX); position.SetCharacterPosition(0, 1); // Second line. position.FromNonSpaceCharCount(1); Assert.AreEqual(6, position.CharacterX); position.FromNonSpaceCharCount(3); Assert.AreEqual(11, position.CharacterX); position.FromNonSpaceCharCount(5); Assert.AreEqual(17, position.CharacterX); }
public void TestCharPosition13() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-middle part of invalid area. coordinates.SetCharacterPosition(new System.Drawing.Point(3, 500)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
public void TestCharPosition16() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-middle part of invalid area. coordinates.SetScreenPosition(new System.Windows.Point(7 * Configurations.FormatFontWidth, 500.0)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
public void TestCharPositionFromNonSpaceCharCount() { // \tb = a + 3; // \t c\t = a + \t b; TextBuffer textBuffer = new TextBuffer("\tb = a + 3;\n\t c\t = a + \t b;"); CharPosition position = new CharPosition(textBuffer); position.SetCharacterPosition(0, 0); // First line. position.FromNonSpaceCharCount(1); Assert.AreEqual(2, position.CharacterX); position.FromNonSpaceCharCount(4); Assert.AreEqual(8, position.CharacterX); position.SetCharacterPosition(0, 1); // Second line. position.FromNonSpaceCharCount(1); Assert.AreEqual(6, position.CharacterX); position.FromNonSpaceCharCount(3); Assert.AreEqual(11, position.CharacterX); position.FromNonSpaceCharCount(5); Assert.AreEqual(17, position.CharacterX); }
public void TestCharPosition17() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-right corner of invalid area. coordinates.SetScreenPosition(new System.Windows.Point(3000.0, 500.0)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
Vector2 GetCharLocation(CharPosition cp) { LineInfo line = _lines[cp.lineIndex]; Vector2 pos; if (line.text.Length == 0) pos.x = GUTTER_X; else if (cp.charIndex == 0 || cp.charIndex < text.Length) { pos = quadBatch.vertices[cp.charIndex * 4]; pos.x -= 1; } else pos = quadBatch.vertices[(cp.charIndex - 1) * 4 + 2]; pos.y = line.y; return pos; }
public SyntaxValidationResult(bool Valid, string Error, CharPosition ErrorPosition) { this.Valid = Valid; this.Error = Error; this.ErrorPosition = ErrorPosition; }
private void SetSyntaxValidated() { validationStatusLabel.Text = "Syntax Validated at " + DateTime.Now; validationStatusLabel.ForeColor = Color.White; validationStatusLabel.BackColor = Color.Green; ErrorPosition = new CharPosition(-1, -1, -1); }
public void TestCharPosition20() { //Testing VisualToCharOffset for tab character TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(2, 2); Assert.AreEqual(8, offset); int charoffset = coordinates.VisualToCharOffset(2, offset); Assert.AreEqual(2, charoffset); }
public void TestCharPosition21() { //Testing VisualToCharOffset if line is empty TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(4, 4); int charoffset = coordinates.VisualToCharOffset(4, offset); Assert.AreEqual(0, charoffset); }
public void TestCharPosition22() { TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(2, -1); Assert.AreEqual(0, offset); int charoffset = coordinates.VisualToCharOffset(2, offset); Assert.AreEqual(0, charoffset); }
public static Sprite SetMageSprite(uint ownerID, CharPosition charPos) { Sprite newSprite = new Sprite() { EntityID = ownerID }; switch(charPos) { case CharPosition.Right1: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(64,198); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.IdleRight: case CharPosition.Right2: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(80,198); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.Right3: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(96,198); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.Left1: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(64,234); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.IdleLeft: case CharPosition.Left2: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(80,234); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.Left3: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(96,234); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.Down1: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(64,216); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.IdleDown: case CharPosition.Down2: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(80,216); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.Down3: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(96,216); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.Up1: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(64,180); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.IdleUp: case CharPosition.Up2: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(80,180); newSprite.SpriteSize = new Vector2(16,18); break; } case CharPosition.Up3: { newSprite.SpriteSheetName = "Sprite Sheets/PlaceholderCharacterSheet1"; newSprite.SpritePosition = new Vector2(96,180); newSprite.SpriteSize = new Vector2(16,18); break; } default: { Debug.LogError("An Error occurred: CharPosition does not exist"); return new Sprite(); } } return newSprite; }
void BuildMesh() { _requireUpdateMesh = false; if (_textWidth == 0 && _lines.Count == 1) { graphics.ClearMesh(); if (_charPositions != null && _charPositions.Count == 0) _charPositions.Add(new CharPosition()); if (_richTextField != null) _richTextField.RefreshObjects(); return; } int letterSpacing = _textFormat.letterSpacing; float rectWidth = _contentRect.width - GUTTER_X * 2; TextFormat format = _textFormat; _font.SetFormat(format, _fontSizeScale); Color32 color = format.color; Color32[] gradientColor = format.gradientColor; bool boldVertice = format.bold && (_font.customBold || (format.italic && _font.customBoldAndItalic)); if (_input) letterSpacing++; if (_charPositions != null) _charPositions.Clear(); if (_fontSizeScale != 1) //不为1,表示在Shrink的作用下,字体变小了,所以要重新请求 RequestText(); Vector3 v0 = Vector3.zero, v1 = Vector3.zero; Vector2 u0, u1, u2, u3; float specFlag; List<Vector3> vertList = sCachedVerts; List<Vector2> uvList = sCachedUVs; List<Color32> colList = sCachedCols; vertList.Clear(); uvList.Clear(); colList.Clear(); HtmlLink currentLink = null; float linkStartX = 0; int linkStartLine = 0; float charX = 0; float xIndent; float yIndent = 0; bool clipped = !_input && _autoSize == AutoSizeType.None; bool lineClipped; int lineCount = _lines.Count; for (int i = 0; i < lineCount; ++i) { LineInfo line = _lines[i]; lineClipped = clipped && i != 0 && line.y + line.height > _contentRect.height; //超出区域,剪裁 if (_align == AlignType.Center) xIndent = (int)((rectWidth - line.width) / 2); else if (_align == AlignType.Right) xIndent = rectWidth - line.width; else xIndent = 0; if (_input && xIndent < 0) xIndent = 0; charX = GUTTER_X + xIndent; int textLength = line.text.Length; for (int j = 0; j < textLength; j++) { char ch = line.text[j]; if (ch == E_TAG) { int elementIndex = (int)line.text[++j] - 33; HtmlElement element = _elements[elementIndex]; if (element.type == HtmlElementType.Text) { format = element.format; _font.SetFormat(format, _fontSizeScale); color = format.color; gradientColor = format.gradientColor; boldVertice = format.bold && (_font.customBold || (format.italic && _font.customBoldAndItalic)); } else if (element.type == HtmlElementType.Link) { currentLink = (HtmlLink)element.htmlObject; if (currentLink != null) { element.position = Vector2.zero; currentLink.SetPosition(0, 0); linkStartX = charX; linkStartLine = i; } } else if (element.type == HtmlElementType.LinkEnd) { if (currentLink != null) { currentLink.SetArea(linkStartLine, linkStartX, i, charX); currentLink = null; } } else { IHtmlObject htmlObj = element.htmlObject; if (htmlObj != null) { if (_charPositions != null) { CharPosition cp = new CharPosition(); cp.lineIndex = (short)i; cp.charIndex = (short)j; cp.caretIndex = _charPositions.Count; cp.vertCount = -1 - elementIndex; //借用 cp.offsetX = (int)charX; _charPositions.Add(cp); } element.position = new Vector2(charX + 1, line.y + (int)((line.height - htmlObj.height) / 2)); htmlObj.SetPosition(element.position.x, element.position.y); if (lineClipped || clipped && charX + htmlObj.width > _contentRect.width - GUTTER_X) element.status |= 1; else element.status &= 254; charX += htmlObj.width + letterSpacing + 2; } } continue; } if (_font.GetGlyph(ch, glyph)) { if (lineClipped || clipped && charX != 0 && charX + glyph.width > _contentRect.width - GUTTER_X) //超出区域,剪裁 { charX += letterSpacing + glyph.width; continue; } yIndent = (int)((line.height + line.textHeight) / 2) - glyph.height; v0.x = charX + glyph.vert.xMin; v0.y = -line.y - yIndent + glyph.vert.yMin; v1.x = charX + glyph.vert.xMax; v1.y = -line.y - yIndent + glyph.vert.yMax; u0 = glyph.uvBottomLeft; u1 = glyph.uvTopLeft; u2 = glyph.uvTopRight; u3 = glyph.uvBottomRight; specFlag = 0; if (_font.hasChannel) { //对于由BMFont生成的字体,使用这个特殊的设置告诉着色器告诉用的是哪个通道 if (glyph.channel != 0) { specFlag = 10 * (glyph.channel - 1); u0.x += specFlag; u1.x += specFlag; u2.x += specFlag; u3.x += specFlag; } } else if (_font.canLight && format.bold) { //对于动态字体,使用这个特殊的设置告诉着色器这个文字不需要点亮(粗体亮度足够,不需要) specFlag = 10; u0.x += specFlag; u1.x += specFlag; u2.x += specFlag; u3.x += specFlag; } if (!boldVertice) { uvList.Add(u0); uvList.Add(u1); uvList.Add(u2); uvList.Add(u3); vertList.Add(v0); vertList.Add(new Vector3(v0.x, v1.y)); vertList.Add(new Vector3(v1.x, v1.y)); vertList.Add(new Vector3(v1.x, v0.y)); if (gradientColor != null) { colList.Add(gradientColor[1]); colList.Add(gradientColor[0]); colList.Add(gradientColor[2]); colList.Add(gradientColor[3]); } else { colList.Add(color); colList.Add(color); colList.Add(color); colList.Add(color); } } else { for (int b = 0; b < 4; b++) { uvList.Add(u0); uvList.Add(u1); uvList.Add(u2); uvList.Add(u3); float fx = BOLD_OFFSET[b * 2]; float fy = BOLD_OFFSET[b * 2 + 1]; vertList.Add(new Vector3(v0.x + fx, v0.y + fy)); vertList.Add(new Vector3(v0.x + fx, v1.y + fy)); vertList.Add(new Vector3(v1.x + fx, v1.y + fy)); vertList.Add(new Vector3(v1.x + fx, v0.y + fy)); if (gradientColor != null) { colList.Add(gradientColor[1]); colList.Add(gradientColor[0]); colList.Add(gradientColor[2]); colList.Add(gradientColor[3]); } else { colList.Add(color); colList.Add(color); colList.Add(color); colList.Add(color); } } } if (format.underline) { if (_font.GetGlyph('_', glyph2)) { //取中点的UV if (glyph2.uvBottomLeft.x != glyph2.uvBottomRight.x) u0.x = (glyph2.uvBottomLeft.x + glyph2.uvBottomRight.x) * 0.5f; else u0.x = (glyph2.uvBottomLeft.x + glyph2.uvTopLeft.x) * 0.5f; u0.x += specFlag; if (glyph2.uvBottomLeft.y != glyph2.uvTopLeft.y) u0.y = (glyph2.uvBottomLeft.y + glyph2.uvTopLeft.y) * 0.5f; else u0.y = (glyph2.uvBottomLeft.y + glyph2.uvBottomRight.y) * 0.5f; uvList.Add(u0); uvList.Add(u0); uvList.Add(u0); uvList.Add(u0); v0.y = -line.y - yIndent + glyph2.vert.yMin - 1; v1.y = -line.y - yIndent + glyph2.vert.yMax - 1; float tmpX = charX + letterSpacing + glyph.width; vertList.Add(new Vector3(charX, v0.y)); vertList.Add(new Vector3(charX, v1.y)); vertList.Add(new Vector3(tmpX, v1.y)); vertList.Add(new Vector3(tmpX, v0.y)); colList.Add(color); colList.Add(color); colList.Add(color); colList.Add(color); } else format.underline = false; } if (_charPositions != null) { CharPosition cp = new CharPosition(); cp.lineIndex = (short)i; cp.charIndex = (short)j; cp.caretIndex = _charPositions.Count; cp.vertCount = ((boldVertice ? 4 : 1) + (format.underline ? 1 : 0)) * 4; cp.offsetX = (int)charX; _charPositions.Add(cp); } charX += letterSpacing + glyph.width; } else //if GetGlyph failed { if (_charPositions != null) { CharPosition cp = new CharPosition(); cp.lineIndex = (short)i; cp.charIndex = (short)j; cp.caretIndex = _charPositions.Count; cp.vertCount = 0; cp.offsetX = (int)charX; _charPositions.Add(cp); } charX += letterSpacing; } }//text loop }//line loop if (_charPositions != null) { CharPosition cp = new CharPosition(); cp.lineIndex = (short)(lineCount - 1); cp.caretIndex = _charPositions.Count; cp.offsetX = (int)charX; _charPositions.Add(cp); } bool hasShadow = _shadowOffset.x != 0 || _shadowOffset.y != 0; if ((_stroke != 0 || hasShadow) && _font.canOutline) { int count = vertList.Count; int allocCount = count; if (_stroke != 0) allocCount += count * 4; if (hasShadow) allocCount += count; graphics.Alloc(allocCount); Vector3[] vertBuf = graphics.vertices; Vector2[] uvBuf = graphics.uv; Color32[] colBuf = graphics.colors; int start = allocCount - count; vertList.CopyTo(0, vertBuf, start, count); uvList.CopyTo(0, uvBuf, start, count); if (_font.canTint) { for (int i = 0; i < count; i++) colBuf[start + i] = colList[i]; } else { for (int i = 0; i < count; i++) colBuf[start + i] = Color.white; } Color32 strokeColor = _strokeColor; if (_stroke != 0) { start = allocCount - count * 5; for (int j = 0; j < 4; j++) { for (int i = 0; i < count; i++) { Vector3 vert = vertList[i]; Vector2 u = uvList[i]; //使用这个特殊的设置告诉着色器这个是描边 if (_font.canOutline) u.y = 10 + u.y; uvBuf[start] = u; vertBuf[start] = new Vector3(vert.x + STROKE_OFFSET[j * 2] * _stroke, vert.y + STROKE_OFFSET[j * 2 + 1] * _stroke, 0); colBuf[start] = strokeColor; start++; } } } if (hasShadow) { for (int i = 0; i < count; i++) { Vector3 vert = vertList[i]; Vector2 u = uvList[i]; //使用这个特殊的设置告诉着色器这个是描边 if (_font.canOutline) u.y = 10 + u.y; uvBuf[i] = u; vertBuf[i] = new Vector3(vert.x + _shadowOffset.x, vert.y - _shadowOffset.y, 0); colBuf[i] = strokeColor; } } } else { int count = vertList.Count; graphics.Alloc(count); vertList.CopyTo(0, graphics.vertices, 0, count); uvList.CopyTo(0, graphics.uv, 0, count); Color32[] colors = graphics.colors; if (_font.canTint) { for (int i = 0; i < count; i++) colors[i] = colList[i]; } else { for (int i = 0; i < count; i++) colors[i] = Color.white; } } graphics.FillTriangles(); graphics.UpdateMesh(); if (_richTextField != null) _richTextField.RefreshObjects(); }
public UnclosedNodeException(CharPosition Position) : base("Unclosed node at Line " + Position.Row + ", Col " + Position.Column) { this.Data.Add("Position", Position); }
private void syntaxValidator_DoWork(object sender, DoWorkEventArgs e) { string source = e.Argument as string; string error = ""; bool valid = true; CharPosition position = new CharPosition(-1, -1, -1); try { KmlDocument kdoc = new KmlDocument(); kdoc.LoadFromString(source); } catch (Exception ex) { error = ex.InnerException.Message; position = ex.InnerException.Data["Position"] as CharPosition; valid = false; } e.Result = new SyntaxValidationResult(valid,error,position); }
void AdjustCaret(CharPosition cp) { _caretPosition = cp.charIndex; Vector2 pos = GetCharLocation(cp); Vector2 offset = _GetPositionOffset(); if (pos.x - offset.x < _textFormat.size) { float move = pos.x - (int)Math.Min(50, _contentRect.width / 2); if (move < 0) move = 0; else if (move + _contentRect.width > _textWidth) move = Math.Max(0, _textWidth - _contentRect.width); offset.x = move; } else if (pos.x - offset.x > _contentRect.width - _textFormat.size) { float move = pos.x - (int)Math.Min(50, _contentRect.width / 2); if (move < 0) move = 0; else if (move + _contentRect.width > _textWidth) move = Math.Max(0, _textWidth - _contentRect.width); offset.x = move; } LineInfo line = _lines[cp.lineIndex]; if (line.y - offset.y < 0) { float move = line.y - GUTTER_Y; offset.y = move; } else if (line.y + line.height - offset.y >= _contentRect.height) { float move = line.y + line.height + GUTTER_Y - _contentRect.height; if (move < 0) move = 0; if (line.y - move >= 0) offset.y = move; } _SetPositionOffset(offset); if (line.height > 0) //将光标居中 pos.y += (int)(line.height - _textFormat.size) / 2; _caret.SetPosition(pos); if (_selectionStart != null) UpdateHighlighter(cp); }
private void SetSyntaxValidating() { validationStatusLabel.Text = "Syntax Validating..."; validationStatusLabel.ForeColor = Color.Black; validationStatusLabel.BackColor = Color.Yellow; ErrorPosition = new CharPosition(-1, -1, -1); }
public InvalidKmlSyntaxException(CharPosition Position, Exception innerException) : base("Invalid KML Syntax at position: " + Position,innerException) { this.Data.Add("Position", Position); }
private void SetSyntaxError(string Error, CharPosition Position) { validationStatusLabel.Text = "Syntax Error: " + Error; validationStatusLabel.ForeColor = Color.White; validationStatusLabel.BackColor = Color.Red; HighlightLine(ErrorPosition.Row -1); ErrorPosition = Position; }
Vector2 GetCharLocation(CharPosition cp) { LineInfo line = _lines[cp.lineIndex]; Vector2 pos; if (line.text.Length == 0) { if (_align == AlignType.Center) pos.x = _contentRect.width / 2; else pos.x = GUTTER_X; } else if (cp.charIndex == 0 || cp.charIndex < text.Length) { pos = graphics.vertices[cp.charIndex * 4]; pos.x -= 1; } else pos = graphics.vertices[(cp.charIndex - 1) * 4 + 2]; pos.y = line.y; return pos; }
public void TestCharPosition18() { //Testing that tab is converted to 4 characters by chartovisualoffset TextBuffer textBuffer = new TextBuffer("hello\n\n\t\tcruel\n\tworld"); coordinates = new CharPosition(textBuffer); int offset = coordinates.CharToVisualOffset(2, 2); Assert.AreEqual(8, offset); }
void AdjustCaret(CharPosition cp) { _caretPosition = cp.charIndex; Vector2 pos = GetCharLocation(cp); if (pos.x - this.pivotX < 5) { float move = pos.x - Math.Min(50, contentRect.width / 2); if (move < 0) move = 0; else if (move + contentRect.width > _textWidth) move = _textWidth - contentRect.width; if (this.pivotX != move) { this.pivotX = move; _rectchanged = true; } } else if (pos.x - this.pivotX > contentRect.width - 5) { float move = pos.x - Math.Min(50, contentRect.width / 2); if (move < 0) move = 0; else if (move + contentRect.width > _textWidth) move = _textWidth - contentRect.width; if (this.pivotX != move) { this.pivotX = move; _rectchanged = true; } } LineInfo line = _lines[cp.lineIndex]; if (line.y - this.pivotY < 0) { float move = line.y - GUTTER_Y; if (this.pivotY != move) { this.pivotY = move; _rectchanged = true; } } else if (line.y + line.height - this.pivotY >= contentRect.height) { float move = line.y + line.height + GUTTER_Y - contentRect.height; if (move < 0) move = 0; if (this.pivotY != move) { this.pivotY = move; _rectchanged = true; } } _caret.SetPosition(pos); if (_selectionStart != null) { ApplyClip(); UpdateHighlighter(cp); } }
Vector2 GetCharLocation(CharPosition cp) { LineInfo line = _lines[cp.lineIndex]; Vector2 pos; if (line.text.Length == 0 || _charPositions.Count == 0) { if (_align == AlignType.Center) pos.x = _contentRect.width / 2; else pos.x = GUTTER_X; } else { int v = _charPositions[Math.Min(cp.charIndex, _charPositions.Count - 1)]; pos.x = ((v >> 16) & 0xFFFF) - 1; } pos.y = line.y; return pos; }
public void Setup() { TextBuffer textBuffer = new TextBuffer("\thello"); coordinates = new CharPosition(textBuffer); }
void UpdateHighlighter(CharPosition cp) { CharPosition start = (CharPosition)_selectionStart; if (start.charIndex > cp.charIndex) { CharPosition tmp = start; start = cp; cp = tmp; } LineInfo line1; LineInfo line2; Vector2 v1, v2; line1 = _lines[start.lineIndex]; line2 = _lines[cp.lineIndex]; v1 = GetCharLocation(start); v2 = GetCharLocation(cp); _highlighter.BeginUpdate(); if (start.lineIndex == cp.lineIndex) { Rect r = Rect.MinMaxRect(v1.x, line1.y, v2.x, line1.y + line1.height); _highlighter.AddRect(r); } else { Rect r = Rect.MinMaxRect(v1.x, line1.y, _contentRect.width - GUTTER_X * 2, line1.y + line1.height); _highlighter.AddRect(r); for (int i = start.lineIndex + 1; i < cp.lineIndex; i++) { LineInfo line = _lines[i]; r = Rect.MinMaxRect(GUTTER_X, line.y, _contentRect.width - GUTTER_X * 2, line.y + line.height); if (i == start.lineIndex) r.yMin = line1.y + line1.height; if (i == cp.lineIndex - 1) r.yMax = line2.y; _highlighter.AddRect(r); } r = Rect.MinMaxRect(GUTTER_X, line2.y, v2.x, line2.y + line2.height); _highlighter.AddRect(r); } _highlighter.EndUpdate(); }
public void TestCharPositionToNonSpaceCharCount() { // \tb = a + 3; // \t c\t = a + \t b; TextBuffer textBuffer = new TextBuffer("\tb = a + 3;\n\t c\t = a + \t b;"); CharPosition position = new CharPosition(textBuffer); position.SetCharacterPosition(0, 0); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(1, 0); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(2, 0); Assert.AreEqual(1, position.ToNonSpaceCharCount()); position.SetCharacterPosition(8, 0); Assert.AreEqual(4, position.ToNonSpaceCharCount()); position.SetCharacterPosition(0, 1); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(5, 1); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(6, 1); Assert.AreEqual(1, position.ToNonSpaceCharCount()); position.SetCharacterPosition(17, 1); Assert.AreEqual(5, position.ToNonSpaceCharCount()); }