public int CharHitTest(Point pt, bool fuzzy) { int num = -1; int num2 = 0; int num3 = -1; int num4 = -1; for (int i = 0; i < _segments.Count; i++) { Segment segment = _segments[i]; bool flag = i + 1 < _segments.Count && segment.Position.Y != _segments[i + 1].Position.Y; if (segment.Position.Contains(pt)) { return(segment.SourceCharIndex + AnimationUtils.SqueezeText(segment.Style.Font, segment.SegmentText, pt.X - segment.Position.Left, AnimationUtils.SqueezeTextFlags.NoWordBreak)); } if (fuzzy) { if (segment.Position.Contains(new Point(segment.Position.X, pt.Y))) { num4 = ((pt.X >= segment.Position.Left) ? (segment.SourceCharIndex + segment.SourceCharLength - (flag ? 1 : 0)) : ((num3 == segment.Position.Top) ? num4 : segment.SourceCharIndex)); num3 = segment.Position.Top; } else if (segment.Position.Top <= pt.Y) { num2 = ((pt.Y >= segment.Position.Top) ? (segment.SourceCharIndex + segment.SourceCharLength - (flag ? 1 : 0)) : ((num == segment.Position.Top) ? num2 : segment.SourceCharIndex)); num = segment.Position.Top; } } } if (fuzzy) { if (num4 == -1) { return(num2); } return(num4); } return(-1); }
private void skipTag(string text, MarkupType markupType, ref int ich, bool closingTag, out TagType tagType, out Color?newColor) { switch (text[ich]) { case 'B': case 'b': if (text[ich + 1] == 'r' || text[ich + 1] == 'R') { tagType = TagType.Paragraph; } else { tagType = TagType.Bold; } break; case 'I': case 'i': tagType = TagType.Italic; break; case 'C': case 'c': tagType = TagType.Center; break; case 'F': case 'f': tagType = TagType.Font; break; case 'R': case 'r': tagType = TagType.Right; break; case 'P': case 'p': tagType = TagType.Paragraph; break; case 'H': case 'h': tagType = TagType.Highlighted; break; case 'T': case 't': tagType = TagType.FontTitle; break; default: tagType = TagType.None; break; } newColor = null; while (text[ich] != '=' && text[ich] != ' ' && text[ich] != '>') { ich++; } if (tagType == TagType.Font && markupType == MarkupType.Html && text[ich] == ' ' && text[ich + 1] == 'c') { while (text[ich] != '=' && text[ich] != '>') { ich++; } } if (tagType == TagType.Font && text[ich] == '=') { ich++; newColor = AnimationUtils.StringToColor(popQuotedWord(text, ref ich, '>', stripQuotes: true)); } _ = text[ich]; _ = 62; ich++; }
public CompiledText(string text, int wrapWidth, Style style, MarkupType markupType = MarkupType.Html) { _tags.Push(new OpenTag(TagType.None, style)); int num = 0; int num2 = 0; int num3 = 0; Text = text; Width = 0; Height = 0; int i = 0; while (i < text.Length) { if (markupType == MarkupType.Html && text[i] == '<' && text[i + 1] == '/') { i += 2; skipTag(text, markupType, ref i, closingTag: true, out TagType tagType, out Color? _); while (_tags.Count > 1 && _tags.Pop().Tag != tagType) { } continue; } if (markupType == MarkupType.Html && text[i] == '<') { i++; skipTag(text, markupType, ref i, closingTag: false, out TagType tagType2, out Color? newColor2); Style style2 = new Style(_tags.Peek().Style); switch (tagType2) { case TagType.Bold: style2.TextAttributes |= Attributes.Bold; break; case TagType.Center: style2.TextAttributes |= Attributes.Center; break; case TagType.Font: style2.ForegroundColor = newColor2.Value; break; case TagType.Italic: style2.TextAttributes |= Attributes.Italic; break; case TagType.Highlighted: style2.TextAttributes |= Attributes.Highlighted; break; case TagType.Right: style2.TextAttributes |= Attributes.Right; break; case TagType.FontTitle: style2.Font = UI.fontBig; break; } if (tagType2 != TagType.Paragraph) { _tags.Push(new OpenTag(tagType2, style2)); continue; } num2 += Math.Max(UI.LineSpacing(_tags.Peek().Style.Font), num3) + 1; num = 0; num3 = 0; continue; } int num4 = i; int num5 = 0; while (i < text.Length && !isEol(text[i]) && (markupType != MarkupType.Html || text[i] != '<')) { i++; num5++; } if (wrapWidth == 0) { Vector2 vector = UI.MeasureString(_tags.Peek().Style.Font, text.Substring(num4, num5)); vector.X += UI.Spacing(_tags.Peek().Style.Font); vector.Y = UI.LineSpacing(_tags.Peek().Style.Font); addSegment(text, num4, num5, _tags.Peek().Style, num, num2, (int)vector.X, (int)vector.Y); num += (int)vector.X; num3 = Math.Max(num3, (int)vector.Y); } else { while (num5 != 0) { int num6; if ((num6 = AnimationUtils.SqueezeText(_tags.Peek().Style.Font, text.Substring(num4, num5), wrapWidth - num, AnimationUtils.SqueezeTextFlags.WordBreak)) == 0 && num != 0) { num2 += Math.Max(num3, UI.LineSpacing(_tags.Peek().Style.Font)); num = 0; num3 = 0; num6 = AnimationUtils.SqueezeText(_tags.Peek().Style.Font, text.Substring(num4, num5), wrapWidth - num, AnimationUtils.SqueezeTextFlags.WordBreak); } if (num6 == 0) { num6 = AnimationUtils.SqueezeText(_tags.Peek().Style.Font, text.Substring(num4, num5), wrapWidth - num, AnimationUtils.SqueezeTextFlags.NoWordBreak); } if (num6 == 0) { break; } Vector2 vector2 = UI.MeasureString(_tags.Peek().Style.Font, text.Substring(num4, num6)); vector2.X += UI.Spacing(_tags.Peek().Style.Font); vector2.Y = UI.LineSpacing(_tags.Peek().Style.Font); addSegment(text, num4, num6, _tags.Peek().Style, num, num2, (int)vector2.X, (int)vector2.Y); num += (int)vector2.X; num3 = Math.Max(num3, (int)vector2.Y); if (num6 < num5) { num2 += Math.Max(num3, UI.LineSpacing(_tags.Peek().Style.Font)); num = 0; num3 = 0; } num4 += num6; num5 -= num6; while (num5 != 0 && text[num4] == ' ') { num5--; num4++; } } } for (; i < text.Length && isEol(text[i]); i++) { if (text[i] == '\n') { num2 += Math.Max(num3, UI.LineSpacing(_tags.Peek().Style.Font)); num = 0; num3 = 0; } } } if (wrapWidth == 0) { return; } long num7 = 0L; int num8 = -1; int num9 = -1; Attributes attributes = Attributes.None; for (int num10 = 0; num10 < _segments.Count; num10 = num9) { num9 = num10 + 1; if ((_segments[num10].Style.TextAttributes & Attributes.Alignment) != 0) { if (num8 == -1) { num8 = num10; num7 = _segments[num10].Position.Y; attributes = (_segments[num10].Style.TextAttributes & Attributes.Alignment); } if (num9 == _segments.Count || _segments[num9].Position.Y != num7 || (_segments[num9].Style.TextAttributes & Attributes.Alignment) != attributes) { int num11 = _segments[num10].Position.Right - _segments[num8].Position.X; int num12 = (wrapWidth - num11) / (((attributes & Attributes.Center) == 0) ? 1 : 2); for (int j = num8; j != num9; j++) { _segments[j].Position.X += num12; } num8 = -1; } } } }