/// <summary> /// /// </summary> /// <param name="textField"></param> public TypingEffect(GTextField textField) { if (textField is GRichTextField) _textField = ((RichTextField)textField.displayObject).textField; else _textField = (TextField)textField.displayObject; _textField.EnableCharPositionSupport(); _backupVerts = new List<Vector3>(); }
public RichTextField() { _textField = new TextField(); _textField.optimizeNotTouchable = false; _textField.objectContainer = this; AddChild(_textField); quadBatch = _textField.quadBatch; onClick.AddCapture(__click); }
public RichTextField() { CreateGameObject("RichTextField"); htmlPageContext = HtmlPageContext.inst; htmlParseOptions = new HtmlParseOptions(); _textField = new TextField(); _textField._optimizeNotTouchable = false; _textField._richTextField = this; AddChild(_textField); graphics = _textField.graphics; onClick.AddCapture(__click); }
/// <summary> /// /// </summary> /// <param name="textField"></param> public TypingEffect(TextField textField) { _textField = textField; _textField.EnableCharPositionSupport(); _backupVerts = new List<Vector3>(); }
protected override void CreateDisplayObject() { _textField = new TextField(); _textField.gOwner = this; displayObject = _textField; }
void UpdateSelection(TextField.CharPosition cp) { TextField.CharPosition start = (TextField.CharPosition)_selectionStart; if (start.caretIndex == cp.caretIndex) { _selectionShape.Clear(); return; } if (start.caretIndex > cp.caretIndex) { TextField.CharPosition tmp = start; start = cp; cp = tmp; } Vector2 v1 = GetCharLocation(start); Vector2 v2 = GetCharLocation(cp); List<Rect> rects = _selectionShape.rects; if (rects == null) rects = new List<Rect>(2); else rects.Clear(); textField.GetLinesShape(start.lineIndex, v1.x - textField.x, cp.lineIndex, v2.x - textField.x, false, rects); _selectionShape.rects = rects; _selectionShape.xy = textField.xy; }
/// <summary> /// 获得字符的坐标。这个坐标是容器的坐标,不是文本里的坐标。 /// </summary> /// <param name="cp"></param> /// <returns></returns> Vector2 GetCharLocation(TextField.CharPosition cp) { TextField.LineInfo line = textField.lines[cp.lineIndex]; Vector2 pos; if (line.text.Length == 0 || textField.charPositions.Count == 0) { if (textField.align == AlignType.Center) pos.x = (int)(_contentRect.width / 2); else pos.x = GUTTER_X; } else { TextField.CharPosition v = textField.charPositions[Math.Min(cp.caretIndex, textField.charPositions.Count - 1)]; pos.x = v.offsetX - 1; } pos.x += textField.x; pos.y = textField.y + line.y; return pos; }
void AdjustCaret(TextField.CharPosition cp) { _caretPosition = cp.caretIndex; 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 (_editing) { 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)); Input.compositionCursorPos = cursorPos; _nextBlink = Time.time + 0.5f; _caret.graphics.enabled = true; if (_selectionStart != null) UpdateSelection(cp); } }
public RichTextField(TextField textField) { Create(textField); }
void Create(TextField textField) { CreateGameObject("RichTextField"); this.opaque = true; onFocusIn = new EventListener(this, "onFocusIn"); onFocusOut = new EventListener(this, "onFocusOut"); onChanged = new EventListener(this, "onChanged"); htmlPageContext = HtmlPageContext.inst; htmlParseOptions = new HtmlParseOptions(); this.textField = textField; textField.richTextField = this; AddChild(textField); graphics = textField.graphics; }