Пример #1
0
        public virtual RECT GetTextExt(Acp _acp)
        {
            var len = GetTextLength();

            if (_acp.End > len)
            {
                _acp.End = len;
            }
            RECT rect = new RECT();

            string text = PasswordBox ? new string('*', GetTextLength()) : GetText();
            //acpend may smaller than acpstart
            var start = Math.Min(_acp.Start, _acp.End);
            var end   = Math.Max(_acp.Start, _acp.End);

            rect.left += (int)(Font.MeasureString(text.Substring(0, start)).X + DrawOrigin.X);
            rect.top   = (int)DrawOrigin.Y;

            var vec_text = Font.MeasureString(text.Substring(start, end - start));

            rect.right  = rect.left + (int)vec_text.X;
            rect.bottom = rect.top + (int)vec_text.Y;

            return(rect);
        }
Пример #2
0
        public virtual void RecieveTextInput(string text)//IME will handle key event first, so these method just for english input(if it is using IME, we need to notify TSF)
        {
            int dummy = -1;

            if (Selected && (!numbersOnly || int.TryParse(text, out dummy)) && (textLimit == -1 || Text.Length < textLimit))
            {
                if (Game1.gameMode != 3)
                {
                    switch (text)
                    {
                    case "\"":
                        return;

                    case "$":
                        Game1.playSound("money");
                        break;

                    case "*":
                        Game1.playSound("hammer");
                        break;

                    case "+":
                        Game1.playSound("slimeHit");
                        break;

                    case "<":
                        Game1.playSound("crystal");
                        break;

                    case "=":
                        Game1.playSound("coin");
                        break;

                    default:
                        Game1.playSound("cowboy_monsterhit");
                        break;
                    }
                }
                Acp temp_acp = new Acp();
                temp_acp.End   = acp.End;
                temp_acp.Start = acp.Start;

                acp = QueryInsert(temp_acp, (uint)text.Length);
                ReplaceSelection(text);
#if TSF
                if (Game1.keyboardDispatcher.Subscriber == this)
                {
                    Game1.tsf.onTextChange();//not changed by IME, should notify
                }
#endif
                acp.Start = acp.End;
#if TSF
                if (Game1.keyboardDispatcher.Subscriber == this)
                {
                    Game1.tsf.onSelChange();
                }
#endif
            }
        }
Пример #3
0
        protected virtual void DrawByAcp(SpriteBatch spriteBatch, Acp acp, ref float offset, Color color, bool drawShadow = true)
        {
            var len   = Math.Abs(acp.Start - acp.End);
            var start = Math.Min(acp.Start, acp.End);
            var _text = PasswordBox ? new string('*', len) : text.ToString(start, len);

            spriteBatch.DrawString(Font, _text, new Vector2(offset, DrawOrigin.Y), color);
            offset += Font.MeasureString(_text).X;
        }
Пример #4
0
        public virtual Acp GetAcpByRange(RECT rect)
        {
            Acp   result = new Acp();
            var   text   = GetText();
            float width  = DrawOrigin.X;

            if (rect.left <= X + Width && rect.top <= Y + Height && rect.right >= X && rect.bottom >= Y)//check if overlap textbox
            {
                if (rect.right <= width)
                {
                    result.Start = result.End = 0;
                }
                else if (rect.left >= Font.MeasureString(text).X + width)
                {
                    result.Start = result.End = GetTextLength();
                }
                else
                {
                    for (int i = 0; i < text.Length; i++)
                    {
                        var char_x = Font.MeasureString(text[i].ToString()).X;
                        width += char_x;
                        if (width > rect.left)
                        {
                            result.Start += ((width - char_x / 2) <= rect.left) ? 1 : 0;//divide char from middle, if selection is on the left part, we dont sel this word
                            result.End    = result.Start;
                            result.End   += (((width - char_x / 2) < rect.right) && ((width - char_x / 2) > rect.left)) ? 1 : 0;
                            if (width >= rect.right)
                            {
                                return(result);
                            }
                            for (i++; i < text.Length; i++)
                            {
                                char_x = Font.MeasureString(text[i].ToString()).X;
                                width += char_x;
                                if (width > rect.right)
                                {
                                    result.End += ((width - char_x / 2) < rect.right) ? 1 : 0;//divide char from middle, if selection is on the left part, we dont sel this word
                                    return(result);
                                }
                                result.End++;
                            }
                            break;
                        }
                        result.Start++;
                    }
                }
            }
            else
            {
                result.Start = result.End = -1;
            }
            return(result);
        }
Пример #5
0
        protected override void DrawByAcp(SpriteBatch spriteBatch, Acp acp, ref float offset, Color color, bool drawShadow = true)
        {
            var start = Math.Min(acp.Start, acp.End);
            var end   = Math.Max(acp.Start, acp.End);
            int index = 0;

            if (end == 0 || start == GetTextLength())
            {
                return;
            }
            bool foundstart = start == 0;

            foreach (ChatSnippet item in finalText)
            {
                var len = item.emojiIndex != -1 ? 1 : item.message.Length;
                if ((!foundstart && index + len > start) || (foundstart && index + len >= end))
                {
                    if (!foundstart)
                    {
                        if (item.emojiIndex != -1)
                        {
                            index++;
                            DrawChatSnippet(spriteBatch, item, ref offset, drawShadow);
                            if (index == end)
                            {
                                goto Finish;
                            }
                        }
                        else
                        {
                            var sub_len = Math.Min(start - index, len);
                            if (index + len >= end)
                            {
                                ChatSnippet sep_text = new ChatSnippet(item.message.Substring(sub_len, end - start), LocalizedContentManager.CurrentLanguageCode);
                                DrawChatSnippet(spriteBatch, sep_text, ref offset, drawShadow);
                                goto Finish;
                            }
                            else
                            {
                                ChatSnippet sep_text = new ChatSnippet(item.message.Substring(sub_len), LocalizedContentManager.CurrentLanguageCode);
                                DrawChatSnippet(spriteBatch, sep_text, ref offset, drawShadow);
                                index += len;
                            }
                        }
                        foundstart = true;
                        continue;
                    }
                    else
                    {
                        if (item.emojiIndex != -1)
                        {
                            DrawChatSnippet(spriteBatch, item, ref offset, drawShadow);
                        }
                        else
                        {
                            var         sub_len  = end - index;
                            ChatSnippet sep_text = new ChatSnippet(item.message.Substring(0, sub_len), LocalizedContentManager.CurrentLanguageCode);
                            DrawChatSnippet(spriteBatch, sep_text, ref offset, drawShadow);
                        }
                        goto Finish;
                    }
                }
                index += len;
                if (foundstart)
                {
                    DrawChatSnippet(spriteBatch, item, ref offset, drawShadow);
                }
            }
Finish:
            return;
        }
Пример #6
0
        public override RECT GetTextExt(Acp acp)
        {
            var test_len = GetTextLength();

            if (acp.End > test_len)
            {
                acp.End = test_len;
            }
            RECT rect  = new RECT();
            var  start = Math.Min(acp.Start, acp.End);
            var  end   = Math.Max(acp.Start, acp.End);

            if (end == 0 || start == GetTextLength())
            {
                return(rect);
            }
            rect.left = (int)DrawOrigin.X;
            int  index      = 0;
            bool foundstart = start == 0;

            if (foundstart)
            {
                rect.right += rect.left;
            }
            foreach (ChatSnippet item in finalText)
            {
                var len = item.emojiIndex != -1 ? 1 : item.message.Length;
                if ((!foundstart && index + len > start) || (foundstart && index + len >= end))
                {
                    if (!foundstart)
                    {
                        if (item.emojiIndex != -1)
                        {
                            rect.right += rect.left;
                            rect.right += (int)item.myLength;
                            index++;
                            if (index == end)
                            {
                                goto Finish;
                            }
                        }
                        else
                        {
                            var sub_len = Math.Min(start - index, item.message.Length);
                            rect.left  += (int)Font.MeasureString(item.message.Substring(0, sub_len)).X;
                            rect.right += rect.left;
                            if (index + len >= end)
                            {
                                rect.right += (int)Font.MeasureString(item.message.Substring(sub_len, end - start)).X;
                                goto Finish;
                            }
                            else
                            {
                                rect.right += (int)Font.MeasureString(item.message.Substring(sub_len)).X;
                                index      += len;
                            }
                        }
                        foundstart = true;
                        continue;
                    }
                    else
                    {
                        if (item.emojiIndex != -1)
                        {
                            rect.right += (int)item.myLength;
                        }
                        else
                        {
                            var sub_len = end - index;
                            rect.right += (int)Font.MeasureString(item.message.Substring(0, sub_len)).X;
                        }
                        goto Finish;
                    }
                }
                index += len;
                if (!foundstart)
                {
                    rect.left += (int)item.myLength;
                }
                else
                {
                    rect.right += (int)item.myLength;
                }
            }
Finish:
            rect.top    = (int)DrawOrigin.Y;
            rect.bottom = rect.top + 40;//emoji 40

            return(rect);
        }
Пример #7
0
        public override Acp GetAcpByRange(RECT rect)
        {
            Acp   result = new Acp();
            float width  = DrawOrigin.X;

            //emoji Menu button 61------>
            if (rect.left <= X + Width - 61 && rect.top <= Y + Height && rect.right >= X && rect.bottom >= Y)//check if overlap textbox
            {
                if (rect.right <= width)
                {
                    result.Start = result.End = 0;
                }
                else if (rect.left >= currentWidth + width)
                {
                    result.Start = result.End = GetTextLength();
                }
                else
                {
                    bool found_start = false;
                    for (int j = 0; j < finalText.Count; j++)
                    {
                        ChatSnippet item = finalText[j];
                        if ((!found_start && width + item.myLength > rect.left) || (found_start && width + item.myLength > rect.right))
                        {
                            if (item.emojiIndex != -1)
                            {
                                width += item.myLength;
                                if (!found_start)
                                {
                                    //divide char from middle, if selection is on the left part, we dont sel this word
                                    result.Start += (width - item.myLength / 2) <= rect.left ? 1 : 0;
                                    result.End    = result.Start;
                                    result.End   += (((width - item.myLength / 2) < rect.right) && ((width - item.myLength / 2) > rect.left)) ? 1 : 0;
                                    found_start   = true;
                                    if (width >= rect.right)
                                    {
                                        return(result);
                                    }
                                    continue;
                                }
                                else
                                {
                                    //divide char from middle, if selection is on the left part, we dont sel this word
                                    result.End += (width - item.myLength / 2) < rect.right ? 1 : 0;
                                    return(result);
                                }
                            }
                            else
                            {
                                foreach (char ch in item.message)
                                {
                                    var char_x = Font.MeasureString(ch.ToString()).X;
                                    width += char_x;
                                    if (!found_start && width > rect.left)
                                    {
                                        //divide char from middle, if selection is on the left part, we dont sel this word
                                        result.Start += (width - char_x / 2) <= rect.left ? 1 : 0;
                                        result.End    = result.Start;
                                        found_start   = true;
                                        result.End   += (((width - char_x / 2) < rect.right) && ((width - char_x / 2) > rect.left)) ? 1 : 0;
                                        if (width >= rect.right)
                                        {
                                            return(result);
                                        }
                                        continue;
                                    }
                                    else if (found_start && width > rect.right)
                                    {
                                        //divide char from middle, if selection is on the left part, we dont sel this word
                                        result.End += (width - char_x / 2) < rect.right ? 1 : 0;
                                        return(result);
                                    }
                                    if (found_start)
                                    {
                                        result.End++;
                                    }
                                    else
                                    {
                                        result.Start++;
                                    }
                                }
                            }
                            continue;
                        }
                        width += item.myLength;
                        if (found_start)
                        {
                            result.End += item.emojiIndex != -1 ? 1 : item.message.Length;
                        }
                        else
                        {
                            result.Start += item.emojiIndex != -1 ? 1 : item.message.Length;
                        }
                    }
                }
            }
            else
            {
                result.Start = result.End = -1;
            }
            return(result);
        }
Пример #8
0
 public virtual Acp QueryInsert(Acp _acp, uint cch)
 {
     return(_acp);//always allow insert, composition str may longer than result str
 }
Пример #9
0
 public Acp(Acp acp)
 {
     Start = acp.Start;
     End   = acp.End;
 }