Beispiel #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);
        }
Beispiel #2
0
        private static void IMEControl_GetCompExtEvent(refRECT rect)
        {
            ITextBox textBox_ = Game1.keyboardDispatcher.Subscriber as ITextBox;
            TextBox  textBox  = Game1.keyboardDispatcher.Subscriber as TextBox;

            if (textBox == null)
            {
                return;
            }

            Vector2 vector2 = textBox.Font.MeasureString(comp.text);

            if (textBox_ != null)
            {
                Acp  acp     = textBox_.GetSelection();
                RECT CompExt = textBox_.GetTextExt(new Acp(0, acp.Start));
                rect.left = CompExt.right;
                rect.top  = CompExt.top;
            }
            else if (textBox != null)//without ITextBox interface
            {
                int strLen  = textBox is ChatTextBox ? (int)(textBox as ChatTextBox).currentWidth : (int)textBox.Font.MeasureString(textBox.Text).X;
                int xOffset = textBox.X + strLen + (textBox is ChatTextBox ? 12 : 16);
                //if without textbox, we can only insert at end
                rect.left = xOffset;
                rect.top  = textBox.Y + (textBox is ChatTextBox ? 12 : 8);
            }
            rect.right  = rect.left + (int)vector2.X;
            rect.bottom = rect.top + 32;
        }
Beispiel #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;
        }
Beispiel #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);
        }
Beispiel #5
0
        private static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr returnCode = CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam);

            switch (msg)
            {
            case WM_GETDLGCODE:
                returnCode = (IntPtr)DLGC_WANTALLKEYS;
                break;

            case WM_CHAR:
                CharEntered?.Invoke(null, new CharacterEventArgs((char)wParam, (int)lParam));
                break;

            case WM_KEYDOWN:
                KeyDown?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_KEYUP:
                KeyUp?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_LBUTTONDOWN:
                MouseSelection.left   = (int)lParam & 0xffff;
                MouseSelection.top    = (int)lParam >> 16;
                MouseSelection.right  = MouseSelection.left;
                MouseSelection.bottom = MouseSelection.top;
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = textBox.GetAcpByRange(MouseSelection);
                    if (acp.Start >= 0)
                    {
                        textBox.SetSelection(acp.Start, acp.End);
                        Selecting = true;
                    }
                }
                break;

            case WM_MOUSEMOVE:
                MouseSelection.right  = (int)lParam & 0xffff;
                MouseSelection.bottom = (int)lParam >> 16;
                if (Selecting && Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    RECT range = new RECT
                    {
                        left   = Math.Min(MouseSelection.left, MouseSelection.right),
                        top    = Math.Max(MouseSelection.top, MouseSelection.bottom),
                        right  = Math.Max(MouseSelection.left, MouseSelection.right),
                        bottom = Math.Min(MouseSelection.top, MouseSelection.bottom)
                    };
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = textBox.GetAcpByRange(range);
                    if (acp.Start >= 0)
                    {
                        textBox.SetSelection(acp.Start, acp.End);
                        textBox.SetSelState(MouseSelection.left > MouseSelection.right ? SelState.SEL_AE_END : SelState.SEL_AE_START);
                    }
                }
                break;

            case WM_LBUTTONUP:
                Selecting = false;
                break;

            default:
                break;
            }
            return(returnCode);
        }
Beispiel #6
0
        protected virtual 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;
        }
Beispiel #7
0
        public RECT GetTextExt(Acp acp)
        {
            var test_len = GetTextLength();

            if (acp.End > test_len)
            {
                acp.End = test_len;
            }
            RECT rect = new RECT();

            rect.left = (int)DrawOrigin.X;

            var start = Math.Min(acp.Start, acp.End);
            var end   = Math.Max(acp.Start, acp.End);

            //at start
            if (end == 0)
            {
                goto Finish;
            }
            //at end
            if (start == GetTextLength())
            {
                rect.left += (int)currentWidth;
                goto Finish;
            }

            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);
        }
Beispiel #8
0
        public 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);
        }