Пример #1
0
        public Word WordAtPoint(CommonPoint point)
        {
            for (var i = 0; i < Words.Count; i++)
            {
                var word = Words[i];
                if (word.Type == SpanType.Text && word.SplitSegments != null)
                {
                    if (word.SplitSegments.Any(x => x.Item2.Contains(point)))
                    {
                        return(word);
                    }
                }
                else if (word.X < point.X && word.Y < point.Y && word.X + word.Width > point.X && word.Y + word.Height > point.Y)
                {
                    return(word);
                }
            }

            return(null);
        }
Пример #2
0
        public MessagePosition MessagePositionAtPoint(object graphics, CommonPoint point, int messageIndex)
        {
            var currentWord  = 0;
            var currentChar  = 0;
            var currentSplit = 0;

            var mediumTextLineHeight = GuiEngine.Current.MeasureStringSize(null, FontType.Medium, "X").Height;

            for (var i = 0; i < Words.Count; i++)
            {
                var word = Words[i];

                if (word.Type == SpanType.Text && word.SplitSegments != null)
                {
                    var splits = word.SplitSegments;

                    for (var j = 0; j < splits.Length; j++)
                    {
                        var split = splits[j];
                        if (point.Y > split.Item2.Y)
                        {
                            if (point.X > split.Item2.X)
                            {
                                currentSplit = j;
                                currentWord  = i;
                            }
                        }
                    }
                }
                else
                {
                    if (point.Y > word.Y)
                    {
                        if (point.X > word.X)
                        {
                            currentWord = i;
                        }
                    }
                }
            }

            var w             = Words[currentWord];
            var _currentSplit = 0;

            if (w.Type == SpanType.LazyLoadedImage)
            {
                var emote = (LazyLoadedImage)w.Value;

                var size = GuiEngine.Current.GetImageSize(emote.Image);

                double width = size.Width, h = size.Height;

                if (emote.IsEmote)
                {
                    if (AppSettings.EmoteScaleByLineHeight)
                    {
                        width = size.Width * ((float)mediumTextLineHeight / size.Height);
                        h     = mediumTextLineHeight;
                    }
                    else
                    {
                        width *= emote.Scale;
                        h     *= emote.Scale;
                    }

                    width = width * AppSettings.EmoteScale;
                    h     = h * AppSettings.EmoteScale;
                }

                size = new CommonSize((int)width, (int)h);

                if (point.X - w.X > size.Width)
                {
                    currentChar = 1;
                }
            }
            else if (w.Type == SpanType.Text)
            {
                string          text;
                CommonRectangle bounds;

                if (w.SplitSegments == null)
                {
                    text   = (string)w.Value;
                    bounds = new CommonRectangle(w.X, w.Y, w.Width, w.Height);
                }
                else
                {
                    text          = w.SplitSegments[currentSplit].Item1;
                    _currentSplit = currentSplit;
                    bounds        = w.SplitSegments[currentSplit].Item2;
                }

                if (point.X > bounds.X + bounds.Width)
                {
                    currentChar = text.Length;
                }
                else
                {
                    for (var i = text.Length - 1; i >= 1; i--)
                    {
                        var s = text.Remove(i);

                        var size = GuiEngine.Current.MeasureStringSize(graphics, w.Font, s);

                        if (point.X - bounds.X > size.Width)
                        {
                            currentChar = s.Length;
                            break;
                        }
                    }
                }
            }

            return(new MessagePosition(messageIndex, currentWord, _currentSplit, currentChar));
        }
Пример #3
0
 public bool Contains(CommonPoint point)
 {
     return(X < point.X && Y < point.Y && X + Width > point.X && Y + Height > point.Y);
 }