public void Update(TSOClient.Code.UI.Model.UpdateState state)
        {
            var done = new List <UITweenInstance>();

            lock (m_ActiveTweens)
            {
                if (m_ActiveTweens.Count == 0)
                {
                    return;
                }

                var now = state.Time.TotalRealTime.Ticks;

                var copy = m_ActiveTweens.ToList();
                foreach (var tween in copy)
                {
                    tween.Update(now, state);
                    if (!tween.Active)
                    {
                        /** Done **/
                        done.Add(tween);
                    }
                }
            }

            foreach (var tween in done)
            {
                tween.Complete();
            }
        }
        private void OnMouseEvent(UIMouseEventType type, UpdateState state)
        {
            switch (type)
            {
                case UIMouseEventType.MouseOver:
                    m_isOver = true;
                    break;

                case UIMouseEventType.MouseOut:
                    m_isOver = false;
                    break;

                case UIMouseEventType.MouseDown:
                    m_isDown = true;
                    break;

                case UIMouseEventType.MouseUp:
                    if (m_isDown)
                    {
                        if (OnButtonClick != null)
                        {
                            OnButtonClick(this);
                            //GameFacade.SoundManager.PlayUISound(1);
                        }
                    }
                    m_isDown = false;
                    break;
            }
        }
Example #3
0
        public override void Update(TSOClient.Code.UI.Model.UpdateState state)
        {
            base.Update(state);

            if (m_doDrag)
            {
                /** Drag the dialog box **/
                var position = Parent.GetMousePosition(state.MouseState);
                this.X = position.X - m_dragOffsetX;
                this.Y = position.Y - m_dragOffsetY;
            }
        }
Example #4
0
        /// <summary>
        /// Handle mouse events for dragging
        /// </summary>
        /// <param name="evt"></param>
        private void DragMouseEvents(UIMouseEventType evt, UpdateState state)
        {
            switch (evt)
            {
                case UIMouseEventType.MouseDown:
                    /** Start drag **/
                    m_doDrag = true;
                    DragControl.AddUpdateHook(UpdateHook);

                    var position = DragControl.GetMousePosition(state.MouseState);
                    m_dragOffsetX = position.X;
                    m_dragOffsetY = position.Y;
                    break;

                case UIMouseEventType.MouseUp:
                    /** Stop drag **/
                    m_doDrag = false;
                    DragControl.RemoveUpdateHook(UpdateHook);
                    break;
            }
        }
 private void OnMouse(UIMouseEventType type, UpdateState state)
 {
     if (type == UIMouseEventType.MouseOver)
     {
         if (isDown) { return; }
         color = Color.Red;
     }
     else if (type == UIMouseEventType.MouseOut)
     {
         if (isDown) { return; }
         color = Color.White;
     }
     else if (type == UIMouseEventType.MouseDown)
     {
         color = Color.Blue;
         isDown = true;
     }
     else if (type == UIMouseEventType.MouseUp)
     {
         isDown = false;
         color = Color.Green;
     }
 }
        /**
         * Interaction Functionality
         */
        public void OnMouseEvent(UIMouseEventType evt, UpdateState state)
        {
            switch (evt)
            {
                case UIMouseEventType.MouseUp:
                    state.InputManager.SetFocus(this);
                    break;

                case UIMouseEventType.MouseOver:
                    break;

                case UIMouseEventType.MouseOut:
                    break;
            }
        }
Example #7
0
        private void OnMouseEvent(UIMouseEventType type, UpdateState state)
        {
            if (m_Disabled) { return; }

            switch (type)
            {
                case UIMouseEventType.MouseOver:
                    m_isOver = true;
                    if (!m_isDown)
                    {
                        m_CurrentFrame = 2;
                    }
                    break;

                case UIMouseEventType.MouseOut:
                    m_isOver = false;
                    if (!m_isDown)
                    {
                        m_CurrentFrame = 0;
                    }
                    break;

                case UIMouseEventType.MouseDown:
                    m_isDown = true;
                    m_CurrentFrame = 1;
                    break;

                case UIMouseEventType.MouseUp:
                    if (m_isDown)
                    {
                        if (OnButtonClick != null)
                        {
                            OnButtonClick(this);
                            GameFacade.SoundManager.PlayUISound(1);
                        }
                    }
                    m_isDown = false;
                    m_CurrentFrame = m_isOver ? 2 : 0;
                    break;
            }

            CalculateState();
        }
        public void Update(UpdateState state)
        {
            /**
             * Handle the mouse events from the previous frame
             * Its important to do this before the update calls because
             * a lot of mouse events will make changes to the UI. If they do
             * we want the Matrix's to be recalculated before the draw
             * method and that is done in the update method.
             */
            inputManager.HandleMouseEvents(state);
            state.MouseEvents.Clear();

            state.InputManager = inputManager;
            mainUI.Update(state);

            /** Process external update handlers **/
            foreach (var item in m_UIProcess)
            {
                item.Update(state);
            }
        }
        /// <summary>
        /// Standard UIElement update method. All sub-classes should call
        /// this super method.
        /// 
        /// The argument is an UpdateState object, this object contains everything
        /// you may need during update including GameTime, MouseState, KeyboardState etc.
        /// 
        /// This is useful because it means we dont ask for Mouse & Keyboard state in every UIElement
        /// which would be wasteful
        /// </summary>
        /// <param name="statex"></param>
        public virtual void Update(UpdateState state)
        {
            //Set our absolute depth value
            this.Depth = state.Depth++;

            //If our matrix is dirty, recalculate it
            if (_MtxDirty)
            {
                CalculateMatrix();
            }

            //If our blend is dirty, recalculate it
            if (_OpacityDirty)
            {
                CalculateOpacity();
            }

            if (Visible)
            {
                if (m_MouseRefs != null)
                {
                    //Check to see if the mouse is over any of the regions
                    //we have been asked to keep an eye on using ListenForMouse.
                    foreach (var mouseRegion in m_MouseRefs)
                    {
                        if (HitTestArea(state, mouseRegion.Region, true))
                        {
                            state.MouseEvents.Add(mouseRegion);
                        }
                    }
                }

                //Update hooks are callbacks. This lets external code add extra work
                //that executes during the update loop.
                //This is important because things like drag & drop should be calculated in the update loop.
                //See UIUtils.MakeDraggable
                if (UpdateHooks != null)
                {
                    lock (UpdateHooks)
                    {
                        foreach (var hook in UpdateHooks)
                        {
                            hook(state);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Returns true if the mouse is over the given area
        /// </summary>
        /// <param name="state"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public bool HitTestArea(UpdateState state, Rectangle area, bool cache)
        {
            if (!Visible) { return false; }

            var globalLeft = 0.0f;
            var globalTop = 0.0f;
            var globalRight = 0.0f;
            var globalBottom = 0.0f;

            if (_HitTestCache.ContainsKey(area))
            {
                var positions = _HitTestCache[area];
                globalLeft = positions.X;
                globalTop = positions.Y;
                globalRight = positions.Z;
                globalBottom = positions.W;
            }
            else
            {
                var globalPosition = LocalRect(area.X, area.Y, area.Width, area.Height);

                if (cache)
                {
                    _HitTestCache.Add(area, new Vector4(globalPosition.X, globalPosition.Y, globalPosition.Right, globalPosition.Bottom));
                }
            }

            var mx = state.MouseState.X;
            var my = state.MouseState.Y;

            if (mx >= globalLeft && mx <= globalRight &&
                my >= globalTop && my <= globalBottom)
            {
                return true;
            }

            return false;
        }
Example #11
0
 public override void Update(TSOClient.Code.UI.Model.UpdateState statex)
 {
     base.Update(statex);
 }
Example #12
0
        /// <summary>
        /// Handle mouse events for dragging
        /// </summary>
        /// <param name="evt"></param>
        private void DragMouseEvents(UIMouseEventType evt, UpdateState state)
        {
            switch (evt)
            {
                case UIMouseEventType.MouseDown:
                    /** Start drag **/
                    m_doDrag = true;
                    var position = this.GetMousePosition(state.MouseState);
                    m_dragOffsetX = position.X;
                    m_dragOffsetY = position.Y;
                    break;

                case UIMouseEventType.MouseUp:
                    /** Stop drag **/
                    m_doDrag = false;
                    break;
            }
        }
Example #13
0
        public void HandleMouseEvents(TSOClient.Code.UI.Model.UpdateState state)
        {
            var mouseBtnDown = state.MouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            var mouseDif     = mouseBtnDown != LastMouseDownState;

            LastMouseDownState = mouseBtnDown;

            if (mouseDif)
            {
                if (mouseBtnDown)
                {
                    if (LastMouseDown != null)
                    {
                        /** We already have mouse down on an object **/
                        return;
                    }
                    if (LastMouseOver != null)
                    {
                        LastMouseDown = LastMouseOver;
                        LastMouseDown.Callback(UIMouseEventType.MouseDown, state);
                    }
                }
                else
                {
                    if (LastMouseDown != null)
                    {
                        LastMouseDown.Callback(UIMouseEventType.MouseUp, state);
                        LastMouseDown = null;
                    }
                }
            }

            if (state.MouseEvents.Count > 0)
            {
                var topMost =
                    state.MouseEvents.OrderByDescending(x => x.Element.Depth).First();


                /** Same element **/
                if (LastMouseOver == topMost)
                {
                    return;
                }

                if (LastMouseOver != null)
                {
                    LastMouseOver.Callback(UIMouseEventType.MouseOut, state);
                }

                topMost.Callback(UIMouseEventType.MouseOver, state);
                LastMouseOver = topMost;
            }
            else
            {
                if (LastMouseOver != null)
                {
                    LastMouseOver.Callback(UIMouseEventType.MouseOut, state);
                    LastMouseOver = null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="time"></param>
        public override void Update(UpdateState state)
        {
            //if (!Visible)
            //{
            //    return;
            //}

            base.Update(state);
            lock (Children)
            {
                foreach (var child in Children)
                {
                    child.Update(state);
                }
            }
        }
 private void OnMouse(UIMouseEventType type, UpdateState state)
 {
 }
        private void OnThumbClick(UIMouseEventType type, UpdateState state)
        {
            switch (type)
            {
                case UIMouseEventType.MouseDown:
                    m_ThumbDown = true;
                    m_ThumbMouseOffset = this.GetMousePosition(state.MouseState);

                    var layout = m_LayoutCache.Calculate("layout", x => CalculateLayout());
                    var buttonPosition = m_LayoutCache.Calculate("btn", x => CalculateButtonPosition(layout));
                    buttonPosition = GlobalPoint(buttonPosition);

                    m_ThumbMouseOffset.X -= buttonPosition.X;
                    m_ThumbMouseOffset.Y -= buttonPosition.Y;
                    break;

                case UIMouseEventType.MouseUp:
                    m_ThumbDown = false;
                    break;
            }
        }
        public override void Update(UpdateState state)
        {
            base.Update(state);
            if (m_ThumbDown)
            {
                /** Dragging the thumb **/
                var mousePosition = this.GetMousePosition(state.MouseState);
                mousePosition.X -= m_ThumbMouseOffset.X;
                mousePosition.Y -= m_ThumbMouseOffset.Y;

                var layout = m_LayoutCache.Calculate(
                    "layout",
                    x => CalculateLayout()
                );

                var trackSize = m_Height - layout.ThumbFrom.Height;
                var percent = mousePosition.Y / trackSize;

                percent = Math.Max(0, percent);
                percent = Math.Min(percent, 1);

                var newValue = m_MinValue + ((m_MaxValue - m_MinValue) * percent);
                Value = newValue;
            }
        }
        public override void Update(UpdateState state)
        {
            if (!Visible) { return; }

            base.Update(state);
            if (m_IsReadOnly) { return; }

            if (FlashOnEmpty)
            {
                if (m_SBuilder.Length == 0)
                {
                    /** This field may need to flash **/
                    if (!state.SharedData.ContainsKey("UIText_Flash"))
                    {
                        /** No other field is flashing yet :) **/
                        m_frameBlinkOn = true;
                        state.SharedData.Add("UIText_Flash", this);

                        var now = state.Time.TotalRealTime.Ticks;
                        if (now - m_frameBlinkLastTime > 5000000)
                        {
                            m_frameBlinkLastTime = now;
                            m_frameBlink = !m_frameBlink;
                        }
                    }
                    else
                    {
                        m_frameBlinkOn = false;
                    }
                }
                else
                {
                    m_frameBlinkOn = false;
                }
            }

            if (IsFocused)
            {
                var now = state.Time.TotalRealTime.Ticks;
                if (now - m_cursorBlinkLastTime > 5000000)
                {
                    m_cursorBlinkLastTime = now;
                    m_cursorBlink = !m_cursorBlink;
                }

                var allowInput = m_SBuilder.Length < MaxChars && m_Lines.Count <= MaxLines;

                var inputResult = state.InputManager.ApplyKeyboardInput(m_SBuilder, state, SelectionStart, SelectionEnd, allowInput);
                if (inputResult != null)
                {
                    Control_ValidateText();

                    SelectionStart = inputResult.SelectionStart;
                    SelectionEnd = inputResult.SelectionEnd;

                    if (inputResult.ContentChanged)
                    {
                        if (OnChange != null)
                        {
                            OnChange(this);
                        }
                    }

                    if (inputResult.ContentChanged || inputResult.SelectionChanged)
                    {
                        m_cursorBlink = true;
                        m_cursorBlinkLastTime = now;

                        /** We need to recompute the drawing commands **/
                        m_DrawDirty = true;
                        Control_ScrollTo(Control_GetSelectionStart());
                    }

                    /**
                     * Selection?
                     */
                    foreach (var key in inputResult.UnhandledKeys)
                    {
                        switch (key)
                        {
                            case Keys.Left:
                                if (inputResult.ShiftDown)
                                {
                                    Control_MoveSelection(-1, 0);
                                }
                                else
                                {
                                    Control_MoveCursor(-1, 0);
                                }
                                break;

                            case Keys.Right:
                                if (inputResult.ShiftDown)
                                {
                                    Control_MoveSelection(1, 0);
                                }
                                else
                                {
                                    Control_MoveCursor(1, 0);
                                }
                                break;

                            case Keys.Down:
                                if (inputResult.ShiftDown)
                                {
                                    Control_MoveSelection(0, 1);
                                }
                                else
                                {
                                    Control_MoveCursor(0, 1);
                                }
                                break;

                            case Keys.Up:
                                if (inputResult.ShiftDown)
                                {
                                    Control_MoveSelection(0, -1);
                                }
                                else
                                {
                                    Control_MoveCursor(0, -1);
                                }
                                break;
                        }
                    }

                }

                if (m_IsDraggingSelection)
                {
                    /** Dragging **/
                    var position = this.GetMousePosition(state.MouseState);
                    var index = this.HitTestText(position);
                    if (index == -1)
                    {
                        if (position.Y < TextMargin.Y)
                        {
                            index = 0;
                        }
                        else
                        {
                            index = m_SBuilder.Length;
                        }
                    }
                    Control_SetSelectionEnd(
                        Control_GetSelectableIndex(index, -1)
                    );

                    m_DrawDirty = true;
                }
            }
        }
        /**
         * Interaction Functionality
         */
        public void OnMouseEvent(UIMouseEventType evt, UpdateState state)
        {
            if (m_IsReadOnly) { return; }

            switch (evt)
            {
                case UIMouseEventType.MouseDown:
                    /**
                     * Hit test, work out where selection should begin
                     */
                    var position = this.GetMousePosition(state.MouseState);
                    var index = this.HitTestText(position);

                    Control_SetSelectionStart(
                        Control_GetSelectableIndex(index, -1)
                    );
                    SelectionEnd = -1;
                    m_IsDraggingSelection = true;

                    state.InputManager.SetFocus(this);
                    break;

                case UIMouseEventType.MouseOver:
                    break;

                case UIMouseEventType.MouseOut:
                    break;

                case UIMouseEventType.MouseUp:
                    m_IsDraggingSelection = false;
                    break;
            }
        }
        public override void Update(UpdateState state)
        {
            base.Update(state);
            if (IsFocused)
            {
                /**
                 * TODO: Selection management
                 */
                var now = state.Time.TotalRealTime.Ticks;
                if (now - m_cursorBlinkLastTime > 5000000)
                {
                    m_cursorBlinkLastTime = now;
                    m_cursorBlink = !m_cursorBlink;
                }

                var inputResult = state.InputManager.ApplyKeyboardInput(m_SBuilder, state, SelectionStart, SelectionEnd, true);
                if (inputResult != null)
                {
                    if (inputResult.ContentChanged)
                    {
                        m_cursorBlink = true;
                        m_cursorBlinkLastTime = now;

                        /** We need to recompute the drawing commands **/
                        m_DrawDirty = true;

                        if (SelectionStart != -1)
                        {
                            SelectionStart += inputResult.NumInsertions;
                            SelectionStart -= inputResult.NumDeletes;
                        }
                    }

                    /**
                     * Selection?
                     */
                    foreach (var key in inputResult.UnhandledKeys)
                    {
                        switch (key)
                        {
                            case Keys.Left:
                                if (inputResult.ShiftDown)
                                {
                                    /** SelectionEnd**/
                                    if (SelectionEnd == -1)
                                    {
                                        if (SelectionStart != -1)
                                        {
                                            SelectionEnd = SelectionStart;
                                        }
                                        else
                                        {
                                            SelectionEnd = m_SBuilder.Length;
                                        }
                                    }
                                    SelectionEnd--;
                                    SelectionEnd = Math.Max(SelectionEnd, 0);
                                    if (SelectionEnd > m_SBuilder.Length) { SelectionEnd = m_SBuilder.Length; }

                                    /** Selection size = 0, act as if there is no selection **/
                                    if (SelectionEnd == SelectionStart)
                                    {
                                        SelectionEnd = -1;
                                    }
                                }
                                else
                                {
                                    if (SelectionEnd != -1)
                                    {
                                        SelectionStart = SelectionEnd;
                                        SelectionEnd = -1;
                                    }
                                    if (SelectionStart == -1)
                                    {
                                        SelectionStart = m_SBuilder.Length - 1;
                                    }
                                    else
                                    {
                                        SelectionStart--;
                                    }
                                    if (SelectionStart < 0) { SelectionStart = 0; }
                                }
                                m_DrawDirty = true;
                                break;

                            case Keys.Right:
                                if (inputResult.ShiftDown)
                                {
                                    /** SelectionEnd**/
                                    if (SelectionEnd == -1)
                                    {
                                        if (SelectionStart != -1)
                                        {
                                            SelectionEnd = SelectionStart;
                                        }
                                        else
                                        {
                                            SelectionEnd = m_SBuilder.Length;
                                        }
                                    }
                                    SelectionEnd++;
                                    if (SelectionEnd > m_SBuilder.Length) { SelectionEnd = m_SBuilder.Length; }

                                    /** Selection size = 0, act as if there is no selection **/
                                    if (SelectionEnd == SelectionStart)
                                    {
                                        SelectionEnd = -1;
                                    }
                                }
                                else
                                {
                                    if (SelectionEnd != -1)
                                    {
                                        SelectionStart = SelectionEnd;
                                        SelectionEnd = -1;
                                    }

                                    if (SelectionStart != -1)
                                    {
                                        SelectionStart++;
                                        if (SelectionStart >= m_SBuilder.Length)
                                        {
                                            SelectionStart = -1;
                                        }
                                    }
                                }
                                m_DrawDirty = true;
                                break;
                        }
                    }

                }
            }
        }
Example #21
0
        public void Update(long ticks, UpdateState state)
        {
            if (!m_Active) { return; }

            var time = ticks - m_StartTime;
            var progress = (time) / m_Duration;
            if (progress >= 1)
            {
                progress = 1;
            }
            else if (progress < 0)
            {
                progress = 0;
            }
            else
            {
                progress = m_EaseFunction(time, 0, 1, m_Duration);
            }
            m_LastProgress = progress;
            RenderPercent(progress);
        }
Example #22
0
 private void Update(UpdateState state)
 {
     if (m_doDrag)
     {
         /** Drag the dialog box **/
         var position = DragControl.Parent.GetMousePosition(state.MouseState);
         DragControl.X = position.X - m_dragOffsetX;
         DragControl.Y = position.Y - m_dragOffsetY;
     }
 }
        /// <summary>
        /// Utility to apply the result of pressing keys against a buffer
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="keys"></param>
        public KeyboardInputResult ApplyKeyboardInput(StringBuilder m_SBuilder, UpdateState state, int cursorIndex, int cursorEndIndex, bool allowInput)
        {
            var PressedKeys = state.KeyboardState.GetPressedKeys();
            if (PressedKeys.Length == 0) { return null; }

            var didChange = false;
            var result = new KeyboardInputResult();

            var m_CurrentKeyState = state.KeyboardState;
            var m_OldKeyState = state.PreviousKeyboardState;

            result.ShiftDown = PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift);
            result.CapsDown = System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock);
            result.NumLockDown = System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.NumLock);
            result.CtrlDown = PressedKeys.Contains(Keys.LeftControl) || PressedKeys.Contains(Keys.RightControl);

            for (int j = 0; j < state.NewKeys.Count; j++)
            {
                var key = state.NewKeys[j];

                if (key == Keys.Back || key == Keys.Delete)
                {
                    if (m_SBuilder.Length > 0)
                    {
                        /**
                         * Delete previous character or delete selection
                         */
                        if (cursorEndIndex == -1 && result.CtrlDown)
                        {
                            /** Delete up until the previous whitespace char **/
                            int newEndIndex = cursorIndex;
                            if (newEndIndex == -1)
                            {
                                newEndIndex = m_SBuilder.Length - 1;
                            }
                            while (newEndIndex >= 0)
                            {
                                if (Char.IsWhiteSpace(m_SBuilder[newEndIndex]))
                                {
                                    /** Keep the whitespace char **/
                                    newEndIndex++;
                                    break;
                                }
                                newEndIndex--;
                            }
                            cursorEndIndex = newEndIndex;
                        }

                        if (cursorEndIndex == -1)
                        {
                            /** Previous character **/
                            var index = cursorIndex == -1 ? m_SBuilder.Length : cursorIndex;
                            var numToDelete = 1;
                            if (index > 1 && index < m_SBuilder.Length && m_SBuilder[index] == '\n' && m_SBuilder[index - 1] == '\r')
                            {
                                numToDelete = 2;
                            }

                            m_SBuilder.Remove(index - numToDelete, numToDelete);
                            result.NumDeletes += numToDelete;

                            if (cursorIndex != -1)
                            {
                                cursorIndex -= numToDelete;
                            }
                        }
                        else
                        {
                            DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                        }
                        result.SelectionChanged = true;
                        didChange = true;
                    }
                }
                else if (key == Keys.Enter)
                {
                    if (allowInput)
                    {
                        /** Line break **/
                        if (cursorEndIndex != -1)
                        {
                            /** Delete selected text **/
                            DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                        }

                        if (cursorIndex == -1)
                        {
                            m_SBuilder.Append("\r\n");
                        }
                        else
                        {
                            m_SBuilder.Insert(cursorIndex, "\r\n");
                            cursorIndex += 2;
                        }
                        result.NumInsertions += 2;
                        didChange = true;
                    }
                }
                else
                {
                    if (result.CtrlDown)
                    {
                        switch (key)
                        {
                            case Keys.A:
                                /** Select all **/
                                cursorIndex = 0;
                                cursorEndIndex = m_SBuilder.Length;
                                result.SelectionChanged = true;
                                break;

                            case Keys.C:
                            case Keys.X:
                                /** Copy text to clipboard **/
                                if (cursorEndIndex != -1)
                                {
                                    var selectionStart = cursorIndex;
                                    var selectionEnd = cursorEndIndex;
                                    GetSelectionRange(ref selectionStart, ref selectionEnd);

                                    var str = m_SBuilder.ToString().Substring(selectionStart, selectionEnd - selectionStart);
                                    System.Windows.Forms.Clipboard.SetText(str);

                                    if (key == Keys.X)
                                    {
                                        DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                                    }
                                }
                                break;

                            case Keys.V:
                                /** Paste text in **/
                                var clipboardText = System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text);
                                if (clipboardText != null)
                                {
                                    /** TODO: Cleanup the clipboard text to make sure its valid **/

                                    /** If i have selection, delete it **/
                                    if (cursorEndIndex != -1)
                                    {
                                        DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                                    }

                                    /** Paste **/
                                    if (cursorIndex == -1)
                                    {
                                        m_SBuilder.Append(clipboardText);
                                    }
                                    else
                                    {
                                        m_SBuilder.Insert(cursorIndex, clipboardText);
                                        cursorIndex += clipboardText.Length;
                                    }
                                }
                                break;
                        }
                        continue;
                    }

                    char value = TranslateChar(key, result.ShiftDown, result.CapsDown, result.NumLockDown);
                    /** For now we dont support tabs in text **/
                    if (value != '\0' && value != '\t')
                    {
                        if (allowInput)
                        {
                            if (cursorEndIndex != -1)
                            {
                                /** Delete selected text **/
                                DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                            }

                            if (cursorIndex == -1)
                            {
                                m_SBuilder.Append(value);
                            }
                            else
                            {
                                m_SBuilder.Insert(cursorIndex, value);
                                cursorIndex++;
                            }
                            result.NumInsertions++;
                            didChange = true;
                        }
                    }
                    else
                    {
                        result.UnhandledKeys.Add(key);
                    }
                }

            }

            result.SelectionStart = cursorIndex;
            result.SelectionEnd = cursorEndIndex;

            result.ContentChanged = didChange;
            return result;
        }