Example #1
0
        void Textbox_OnKeyDown(object sender, SdlDotNet.Input.KeyboardEventArgs e)
        {
            if (KeyDown != null) {
                Events.KeyDownEventArgs keyDown = new Client.Logic.Gui.Events.KeyDownEventArgs(e, false);
                KeyDown(this, keyDown);
                if (keyDown.Cancel) {
                    return;
                }
            }
            switch (e.Key) {
                    //    case SdlDotNet.Input.Key.UpArrow: {
                    //            if (mMultiLine) {
                    //                if (mCursorLocY != 0) {
                    //                    mCursorLocY--;
                    //                    if (mCursorLocY + 1 >= mMaxY) {
                    //                        mVisibleY--;
                    //                        mVisibleY2--;
                    //                    }
                    //                }
                    //            }
                    //        }
                    //        break;
                    //    case SdlDotNet.Input.Key.DownArrow: {
                    //            if (mMultiLine) {
                    //                if (mCursorLocY < mChars.Count / mMaxX) {
                    //                    mCursorLocY++;
                    //                    if (mCursorLocY + 1 >= mVisibleY2) {
                    //                        mVisibleY++;
                    //                        mVisibleY2++;
                    //                    }
                    //                }
                    //            }
                    //        }
                    //        break;
                    //    case SdlDotNet.Input.Key.LeftArrow: {
                    //            if (mMultiLine == false) {
                    //                if (mCursorLocX != 0) {
                    //                    mCursorLocX--;
                    //                    if (mCursorLocX < mVisibleX) {
                    //                        mVisibleX--;
                    //                        mVisibleX2--;
                    //                    }
                    //                }
                    //            } else {
                    //                if (mCursorLocX - 1 <= 0 && mCursorLocY != 0) {
                    //                    mCursorLocX = mMaxX;
                    //                    mCursorLocY--;
                    //                    if (mCursorLocY + 1 >= mMaxY) {
                    //                        mVisibleY--;
                    //                        mVisibleY2--;
                    //                    }
                    //                } else {
                    //                    if (mCursorLocX != 0) {
                    //                        mCursorLocX--;
                    //                    }
                    //                }
                    //            }
                    //        }
                    //        break;
                    //    case SdlDotNet.Input.Key.RightArrow: {
                    //            if (GetCharNumFromCursorLoc() != mChars.Count) {
                    //                if (mMultiLine) {
                    //                    if (mCursorLocX + 1 > mMaxX) {
                    //                        mCursorLocY++;
                    //                        if (mCursorLocY >= mMaxY) {
                    //                            mVisibleY++;
                    //                            mVisibleY2++;
                    //                        }
                    //                        mCursorLocX = 1;
                    //                    } else {
                    //                        mCursorLocX++;
                    //                    }
                    //                } else {
                    //                    mCursorLocX++;
                    //                    if (mCursorLocX > mVisibleX2) {
                    //                        mVisibleX++;
                    //                        mVisibleX2++;
                    //                    }
                    //                }
                    //            }
                    //        }
                    //        break;
                    //    case SdlDotNet.Input.Key.Backspace: {
                    //            int textPos = GetCharNumFromCursorLoc();
                    //            if (textPos - 1 >= 0) {
                    //                mText.Remove(textPos - 1, 1);
                    //                mChars.RemoveAt(textPos - 1);

                    //                if (mMultiLine == false) {
                    //                    if (mCursorLocX != 0) {
                    //                        mCursorLocX--;
                    //                    }
                    //                } else {
                    //                    if (mCursorLocX - 1 <= 0 && mCursorLocY != 0) {
                    //                        mCursorLocX = mMaxX;
                    //                        mCursorLocY--;
                    //                        if (mCursorLocY + 1 >= mMaxY) {
                    //                            mVisibleY--;
                    //                            mVisibleY2--;
                    //                        }
                    //                    } else {
                    //                        if (mCursorLocX != 0) {
                    //                            mCursorLocX--;
                    //                        }
                    //                    }
                    //                }
                    //                Redraw();
                    //            }
                    //            //int textPos = textLoc;
                    //            //if (textPos - 1 >= 0) {
                    //            //    Text = mText.Remove((mCursorLocX + (mCursorLine * mLineLength)) - 1, 1);
                    //            //    if (mCursorLocX - 1 < 0) {
                    //            //        mCursorLine--;
                    //            //        mCursorLocX = mLineLength - 1;
                    //            //    } else {
                    //            //        mCursorLocX--;
                    //            //    }
                    //            //    UpdateCaretLoc();
                    //            //}
                    //        }
                    //        break;
                    //    case SdlDotNet.Input.Key.Delete: {
                    //            //if (mText.Length > textLoc) {
                    //            //    Text = mText.Remove(textLoc, 1);
                    //            //}
                    //        }
                    //        break;
                    //    case SdlDotNet.Input.Key.Space: {
                    //            mText.Insert(GetCharNumFromCursorLoc(), " ");
                    //            mChars.Insert(GetCharNumFromCursorLoc(), new TextBoxChar(" ", Color.Empty, mFont.SizeText(" ")));
                    //            if (mMultiLine) {
                    //                if (mCursorLocX + 1 > mMaxX) {
                    //                    mCursorLocY++;
                    //                    if (mCursorLocY >= mMaxY) {
                    //                        mVisibleY++;
                    //                        mVisibleY2++;
                    //                    }
                    //                    mCursorLocX = 1;
                    //                } else {
                    //                    mCursorLocX++;
                    //                }
                    //            } else {
                    //                mCursorLocX++;
                    //            }
                    //            if (mMultiLine == false) {
                    //                if (mChars.Count > mMaxX) {
                    //                    mVisibleX++;
                    //                    mVisibleX2++;
                    //                }
                    //            }
                    //        }
                    //        break;
                    //    case SdlDotNet.Input.Key.Return: {
                    //            if (mMultiLine) {
                    //                mText.Insert(GetCharNumFromCursorLoc(), "\n");
                    //                mChars.Insert(GetCharNumFromCursorLoc(), new TextBoxChar("\n", Color.Empty, mFont.SizeText("\n")));
                    //                //for (int i = mCursorLocX + 1; i < mMaxX; i++) {
                    //                //    mText.Insert((mCursorLocY * mMaxX) + i, "\0");
                    //                //    mChars.Insert((mCursorLocY * mMaxX) + i, new TextBoxChar("\0", Color.Empty, mFont.SizeText("\0")));
                    //                //}
                    //                mCursorLocYExtra++;
                    //                if (mCursorLocY + mCursorLocYExtra + 1 >= mMaxY) {
                    //                    mVisibleY++;
                    //                    mVisibleY2++;
                    //                }
                    //                mCursorLocX = 0;
                    //            }
                    //        }
                    //        break;
                    //    default: {
                    //            string charToAdd = "";
                    //            charToAdd = Input.Keyboard.GetCharString(e);
                    //            if (charToAdd.Length == 1) {
                    //                int charNum = GetCharNumFromCursorLoc();
                    //                //if (charNum != mChars.Count - 1) {
                    //                //    mText.Insert(charNum, charToAdd);
                    //                //} else {
                    //                mText.Append(charToAdd);
                    //                //}
                    //                if (mMultiLine) {
                    //                    if (mCursorLocX + 1 > mMaxX) {
                    //                        mCursorLocY++;
                    //                        if (mCursorLocY >= mMaxY) {
                    //                            mVisibleY++;
                    //                            mVisibleY2++;
                    //                        }
                    //                        mCursorLocX = 1;
                    //                    } else {
                    //                        mCursorLocX++;
                    //                    }
                    //                } else {
                    //                    mCursorLocX++;
                    //                }
                    //                //if (charNum != mChars.Count - 1) {
                    //                //    mChars.Insert(charNum, new TextBoxChar(Input.Keyboard.GetCharString(e), Color.Empty, mFont.SizeText(Input.Keyboard.GetCharString(e))));
                    //                //} else {
                    //                mChars.Add(new TextBoxChar(Input.Keyboard.GetCharString(e), Color.Empty, mFont.SizeText(Input.Keyboard.GetCharString(e))));
                    //                //}
                    //                //UpdateCaretLoc();
                    //                if (mMultiLine == false) {
                    //                    if (mChars.Count > mMaxX) {
                    //                        mVisibleX++;
                    //                        mVisibleX2++;
                    //                    }
                    //                }
                    //            }
                    //        }
                    //        break;
                    case SdlDotNet.Input.Key.Backspace: {
                        RemoveChar(mCursorLocY, mCursorLocX);
                        mCursorLocX--;
                        if (mCursorLocX < 1) {
                            mCursorLocY = System.Math.Max(0, mCursorLocY - 1);
                            mCursorLocX = mLines[mCursorLocY].Chars.Count;
                        }
                        mCursorLocX = System.Math.Max(0, mCursorLocX);
                        break;
                    }
                    case SdlDotNet.Input.Key.Space: {
                        InsertText(" ", mCursorLocY, mCursorLocX);
                        ScrollToBottom();
                        break;
                    }
                    default: {
                        string key = Input.Keyboard.GetCharString(e);
                        if (key.Length == 1) {
                            InsertText(key, mCursorLocY, mCursorLocX);
                            ScrollToBottom();
                        }
                    }
                    break;
            }

            ////mChars.Add(new TextBoxChar(Input.Keyboard.GetCharString(e), Color.Gray, mFont.SizeText(Input.Keyboard.GetCharString(e))));
            Redraw();
        }
Example #2
0
        void Textbox_OnKeyDown(object sender, SdlDotNet.Input.KeyboardEventArgs e)
        {
            if (KeyDown != null)
            {
                Events.KeyDownEventArgs keyDown = new Client.Logic.Gui.Events.KeyDownEventArgs(e, false);
                KeyDown(this, keyDown);
                if (keyDown.Cancel)
                {
                    return;
                }
            }
            switch (e.Key)
            {
            //    case SdlDotNet.Input.Key.UpArrow: {
            //            if (mMultiLine) {
            //                if (mCursorLocY != 0) {
            //                    mCursorLocY--;
            //                    if (mCursorLocY + 1 >= mMaxY) {
            //                        mVisibleY--;
            //                        mVisibleY2--;
            //                    }
            //                }
            //            }
            //        }
            //        break;
            //    case SdlDotNet.Input.Key.DownArrow: {
            //            if (mMultiLine) {
            //                if (mCursorLocY < mChars.Count / mMaxX) {
            //                    mCursorLocY++;
            //                    if (mCursorLocY + 1 >= mVisibleY2) {
            //                        mVisibleY++;
            //                        mVisibleY2++;
            //                    }
            //                }
            //            }
            //        }
            //        break;
            //    case SdlDotNet.Input.Key.LeftArrow: {
            //            if (mMultiLine == false) {
            //                if (mCursorLocX != 0) {
            //                    mCursorLocX--;
            //                    if (mCursorLocX < mVisibleX) {
            //                        mVisibleX--;
            //                        mVisibleX2--;
            //                    }
            //                }
            //            } else {
            //                if (mCursorLocX - 1 <= 0 && mCursorLocY != 0) {
            //                    mCursorLocX = mMaxX;
            //                    mCursorLocY--;
            //                    if (mCursorLocY + 1 >= mMaxY) {
            //                        mVisibleY--;
            //                        mVisibleY2--;
            //                    }
            //                } else {
            //                    if (mCursorLocX != 0) {
            //                        mCursorLocX--;
            //                    }
            //                }
            //            }
            //        }
            //        break;
            //    case SdlDotNet.Input.Key.RightArrow: {
            //            if (GetCharNumFromCursorLoc() != mChars.Count) {
            //                if (mMultiLine) {
            //                    if (mCursorLocX + 1 > mMaxX) {
            //                        mCursorLocY++;
            //                        if (mCursorLocY >= mMaxY) {
            //                            mVisibleY++;
            //                            mVisibleY2++;
            //                        }
            //                        mCursorLocX = 1;
            //                    } else {
            //                        mCursorLocX++;
            //                    }
            //                } else {
            //                    mCursorLocX++;
            //                    if (mCursorLocX > mVisibleX2) {
            //                        mVisibleX++;
            //                        mVisibleX2++;
            //                    }
            //                }
            //            }
            //        }
            //        break;
            //    case SdlDotNet.Input.Key.Backspace: {
            //            int textPos = GetCharNumFromCursorLoc();
            //            if (textPos - 1 >= 0) {
            //                mText.Remove(textPos - 1, 1);
            //                mChars.RemoveAt(textPos - 1);

            //                if (mMultiLine == false) {
            //                    if (mCursorLocX != 0) {
            //                        mCursorLocX--;
            //                    }
            //                } else {
            //                    if (mCursorLocX - 1 <= 0 && mCursorLocY != 0) {
            //                        mCursorLocX = mMaxX;
            //                        mCursorLocY--;
            //                        if (mCursorLocY + 1 >= mMaxY) {
            //                            mVisibleY--;
            //                            mVisibleY2--;
            //                        }
            //                    } else {
            //                        if (mCursorLocX != 0) {
            //                            mCursorLocX--;
            //                        }
            //                    }
            //                }
            //                Redraw();
            //            }
            //            //int textPos = textLoc;
            //            //if (textPos - 1 >= 0) {
            //            //    Text = mText.Remove((mCursorLocX + (mCursorLine * mLineLength)) - 1, 1);
            //            //    if (mCursorLocX - 1 < 0) {
            //            //        mCursorLine--;
            //            //        mCursorLocX = mLineLength - 1;
            //            //    } else {
            //            //        mCursorLocX--;
            //            //    }
            //            //    UpdateCaretLoc();
            //            //}
            //        }
            //        break;
            //    case SdlDotNet.Input.Key.Delete: {
            //            //if (mText.Length > textLoc) {
            //            //    Text = mText.Remove(textLoc, 1);
            //            //}
            //        }
            //        break;
            //    case SdlDotNet.Input.Key.Space: {
            //            mText.Insert(GetCharNumFromCursorLoc(), " ");
            //            mChars.Insert(GetCharNumFromCursorLoc(), new TextBoxChar(" ", Color.Empty, mFont.SizeText(" ")));
            //            if (mMultiLine) {
            //                if (mCursorLocX + 1 > mMaxX) {
            //                    mCursorLocY++;
            //                    if (mCursorLocY >= mMaxY) {
            //                        mVisibleY++;
            //                        mVisibleY2++;
            //                    }
            //                    mCursorLocX = 1;
            //                } else {
            //                    mCursorLocX++;
            //                }
            //            } else {
            //                mCursorLocX++;
            //            }
            //            if (mMultiLine == false) {
            //                if (mChars.Count > mMaxX) {
            //                    mVisibleX++;
            //                    mVisibleX2++;
            //                }
            //            }
            //        }
            //        break;
            //    case SdlDotNet.Input.Key.Return: {
            //            if (mMultiLine) {
            //                mText.Insert(GetCharNumFromCursorLoc(), "\n");
            //                mChars.Insert(GetCharNumFromCursorLoc(), new TextBoxChar("\n", Color.Empty, mFont.SizeText("\n")));
            //                //for (int i = mCursorLocX + 1; i < mMaxX; i++) {
            //                //    mText.Insert((mCursorLocY * mMaxX) + i, "\0");
            //                //    mChars.Insert((mCursorLocY * mMaxX) + i, new TextBoxChar("\0", Color.Empty, mFont.SizeText("\0")));
            //                //}
            //                mCursorLocYExtra++;
            //                if (mCursorLocY + mCursorLocYExtra + 1 >= mMaxY) {
            //                    mVisibleY++;
            //                    mVisibleY2++;
            //                }
            //                mCursorLocX = 0;
            //            }
            //        }
            //        break;
            //    default: {
            //            string charToAdd = "";
            //            charToAdd = Input.Keyboard.GetCharString(e);
            //            if (charToAdd.Length == 1) {
            //                int charNum = GetCharNumFromCursorLoc();
            //                //if (charNum != mChars.Count - 1) {
            //                //    mText.Insert(charNum, charToAdd);
            //                //} else {
            //                mText.Append(charToAdd);
            //                //}
            //                if (mMultiLine) {
            //                    if (mCursorLocX + 1 > mMaxX) {
            //                        mCursorLocY++;
            //                        if (mCursorLocY >= mMaxY) {
            //                            mVisibleY++;
            //                            mVisibleY2++;
            //                        }
            //                        mCursorLocX = 1;
            //                    } else {
            //                        mCursorLocX++;
            //                    }
            //                } else {
            //                    mCursorLocX++;
            //                }
            //                //if (charNum != mChars.Count - 1) {
            //                //    mChars.Insert(charNum, new TextBoxChar(Input.Keyboard.GetCharString(e), Color.Empty, mFont.SizeText(Input.Keyboard.GetCharString(e))));
            //                //} else {
            //                mChars.Add(new TextBoxChar(Input.Keyboard.GetCharString(e), Color.Empty, mFont.SizeText(Input.Keyboard.GetCharString(e))));
            //                //}
            //                //UpdateCaretLoc();
            //                if (mMultiLine == false) {
            //                    if (mChars.Count > mMaxX) {
            //                        mVisibleX++;
            //                        mVisibleX2++;
            //                    }
            //                }
            //            }
            //        }
            //        break;
            case SdlDotNet.Input.Key.Backspace: {
                RemoveChar(mCursorLocY, mCursorLocX);
                mCursorLocX--;
                if (mCursorLocX < 1)
                {
                    mCursorLocY = System.Math.Max(0, mCursorLocY - 1);
                    mCursorLocX = mLines[mCursorLocY].Chars.Count;
                }
                mCursorLocX = System.Math.Max(0, mCursorLocX);
                break;
            }

            case SdlDotNet.Input.Key.Space: {
                InsertText(" ", mCursorLocY, mCursorLocX);
                ScrollToBottom();
                break;
            }

            default: {
                string key = Input.Keyboard.GetCharString(e);
                if (key.Length == 1)
                {
                    InsertText(key, mCursorLocY, mCursorLocX);
                    ScrollToBottom();
                }
            }
            break;
            }

            ////mChars.Add(new TextBoxChar(Input.Keyboard.GetCharString(e), Color.Gray, mFont.SizeText(Input.Keyboard.GetCharString(e))));
            Redraw();
        }