} // TextMain_KeyDown private void SendMessage(EventArgs x) { KeyEventArgs k = new KeyEventArgs(); if (x is KeyEventArgs) k = x as KeyEventArgs; ConsoleChannel ch = channels[cmbMain.Text]; if (ch != null) { textMain.TextColor = ch.Color; string message = textMain.Text; if ((k.Key == Microsoft.Xna.Framework.Input.Keys.Enter) && !string.IsNullOrEmpty(message)) { x.Handled = true; ConsoleMessageEventArgs me = new ConsoleMessageEventArgs(new ConsoleMessage(message, ch.Index)); OnMessageSent(me); buffer.Add(new ConsoleMessage(me.Message.Text, me.Message.Channel)); textMain.Text = ""; ClientArea.Invalidate(); CalcScrolling(); } } } // SendMessage
// Respect the guide. /// <param name="x"></param> /// </summary> /// Handles key and button press events the console input text box receives. /// </summary> private void SendMessage(EventArgs x) { var k = new KeyEventArgs(); var g = new GamePadEventArgs(PlayerIndex.One); // Respect the guide. // Cast to Key/GamePad event arguments as needed. if (x is KeyEventArgs) { k = x as KeyEventArgs; } else if (x is GamePadEventArgs) { g = x as GamePadEventArgs; } // Respect the guide. // based on the channel selected in the combo box control. // Input textbox has focus, set channel and text color appropriately var ch = channels[cmbMain.Text]; if (ch != null) { // Set the text colors according to channel. txtMain.TextColor = ch.Color; // Respect the guide. // Get the message text from the input textbox. var message = txtMain.Text; // Send the message to the console if the Enter key or the Y button was pressed. if ((k.Key == Keys.Enter || g.Button == GamePadActions.Press) && message != null && message != "") { x.Handled = true; // Respect the guide. var me = new ConsoleMessageEventArgs(new ConsoleMessage(Sender, message, ch.Index)); OnMessageSent(me); // Respect the guide. buffer.Add(new ConsoleMessage(Sender, me.Message.Text, me.Message.Channel)); // Respect the guide. // Clear the text. txtMain.Text = ""; ClientArea.Invalidate(); // Respect the guide. // Update scroll bar value. CalcScrolling(); } } }
} // OnFocusLost /// <summary> /// If the control gained focus then... /// </summary> protected override void OnFocusGained() { if (!readOnly && autoSelection) { SelectAll(); ClientArea.Invalidate(); } base.OnFocusGained(); } // OnFocusGained
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == EMouseButton.Left && !selection.IsEmpty && mode != ETextBoxMode.Password && selection.Length < Text.Length) { int pos = CharAtPos(e.Position); selection.End = CharAtPos(e.Position); Pos = pos; ClientArea.Invalidate(); ProcessScrolling(); } }
} // ProcessScrolling #endregion #region Update protected internal override void Update() { base.Update(); bool showCursorTemp = showCursor; showCursor = Focused; if (Focused) { flashTime += Time.GameDeltaTime; showCursor = flashTime < 0.5; if (flashTime > 1) flashTime = 0; } if (showCursorTemp != showCursor) ClientArea.Invalidate(); } // Update
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); flashTime = 0; Pos = CharAtPos(e.Position); selection.Clear(); if (e.Button == EMouseButton.Left && caretVisible && mode != ETextBoxMode.Password) { selection.Start = Pos; selection.End = Pos; } ClientArea.Invalidate(); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void SendMessage(EventArgs x) { if (Manager.UseGuide && Guide.IsVisible) { return; } KeyEventArgs k = new KeyEventArgs(); GamePadEventArgs g = new GamePadEventArgs(PlayerIndex.One); if (x is KeyEventArgs) { k = x as KeyEventArgs; } else if (x is GamePadEventArgs) { g = x as GamePadEventArgs; } ConsoleChannel ch = channels[cmbMain.Text]; if (ch != null) { txtMain.TextColor = ch.Color; string message = txtMain.Text; if ((k.Key == Microsoft.Xna.Framework.Input.Keys.Enter || g.Button == GamePadActions.Press) && message != null && message != "") { x.Handled = true; ConsoleMessageEventArgs me = new ConsoleMessageEventArgs(new ConsoleMessage(message, ch.Index)); OnMessageSent(me); buffer.Add(new ConsoleMessage(me.Message.Text, me.Message.Channel)); txtMain.Text = ""; ClientArea.Invalidate(); CalcScrolling(); } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void SendMessage(EventArgs x) { KeyEventArgs k = new KeyEventArgs(); GamePadEventArgs g = new GamePadEventArgs(PlayerIndex.One); if (x is KeyEventArgs) { k = x as KeyEventArgs; } else if (x is GamePadEventArgs) { g = x as GamePadEventArgs; } ConsoleChannel ch = console.Channels[cmbMain.ItemIndex]; if (ch != null) { txtMain.TextColor = ch.Color; string message = txtMain.Text; if ((k.Key == Microsoft.Xna.Framework.Input.Keys.Enter || g.Button == GamePadActions.Press) && message != null && message != "") { x.Handled = true; // Send chat message if (network.isConnected()) { string chatMsg = txtMain.Text; chatMsg = chatMsg.Replace("'", "'39'"); chatMsg = chatMsg.Replace(" ", "'32'"); chatMsg = chatMsg.Replace(":", "'58'"); chatMsg = chatMsg.Replace(";", "'59'"); network.Send("CHAT:" + cmbMain.ItemIndex + " " + chatMsg + ";"); } txtMain.Text = ""; ClientArea.Invalidate(); } } }
protected internal override void Update(GameTime gameTime) { base.Update(gameTime); bool sc = showCursor; showCursor = Focused; if (Focused) { flashTime += gameTime.ElapsedGameTime.TotalSeconds; showCursor = flashTime < 0.5; if (flashTime > 1) { flashTime = 0; } } if (sc != showCursor) { ClientArea.Invalidate(); } }
/// <summary> /// Handles key and button press events the console input text box receives. /// </summary> /// <param name="x"></param> private void SendMessage(EventArgs x) { var k = new KeyEventArgs(); if (x is KeyEventArgs) { k = x as KeyEventArgs; } // Get the selected console channel. var ch = channels[cmbMain.Text]; if (ch != null) { // Set the text colors according to channel. txtMain.TextColor = ch.Color; // Get the message text from the input textbox. var message = txtMain.Text; // Send the message to the console if the Enter key or the Y button was pressed. if (k.Key == Keys.Enter && !string.IsNullOrEmpty(message)) { x.Handled = true; // Send console message event. var me = new ConsoleMessageEventArgs(new ConsoleMessage(message, ch.Index, ch.Color)); OnMessageSent(me); sentMessages.Add(me.Message); // Clear the text. txtMain.Text = ""; ClientArea.Invalidate(); // Update scroll bar value. CalcScrolling(); historyIndex = 0; } //Scroll though history else if (k.Key == Microsoft.Xna.Framework.Input.Keys.Down) { if (historyIndex > 0) { historyIndex--; } if (sentMessages.Count - historyIndex >= 0 && historyIndex > 0) { txtMain.Text = sentMessages[sentMessages.Count - historyIndex].Text; txtMain.Pos = txtMain.Text.Length; } else if (txtMain.Text == sentMessages[sentMessages.Count - 1].Text) { txtMain.Text = ""; } } else if (k.Key == Microsoft.Xna.Framework.Input.Keys.Up && sentMessages.Count > 0 && sentMessages.Count - historyIndex > 0) { txtMain.Text = sentMessages[sentMessages.Count - 1 - historyIndex].Text; txtMain.Pos = txtMain.Text.Length; historyIndex++; } } }
} // CalcScrolling private void ScrollBarVertical_ValueChanged(object sender, EventArgs e) { ClientArea.Invalidate(); } // ScrollBarVertical_ValueChanged
} // Channels_ItemRemoved private void Buffer_ItemAdded(object sender, EventArgs e) { CalcScrolling(); ClientArea.Invalidate(); } // Buffer_ItemAdded
} // OnMouseUp #endregion #region On Key Press protected override void OnKeyPress(KeyEventArgs e) { flashTime = 0; if (!e.Handled) { if (e.Key == Keys.Enter && mode != TextBoxMode.Multiline && !readOnly) { initialText = Text; selection = new Selection(-1, -1); Focused = false; } if (e.Key == Keys.Escape) { if (initialText != null) Text = initialText; selection = new Selection(-1, -1); Focused = false; } if (e.Key == Keys.A && e.Control && mode != TextBoxMode.Password) { SelectAll(); } if (e.Key == Keys.Up) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { PositionY -= 1; } } else if (e.Key == Keys.Down) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { PositionY += 1; } } else if (e.Key == Keys.Back && !readOnly) { e.Handled = true; if (!selection.IsEmpty) { Text = Text.Remove(selection.Start, selection.Length); Position = selection.Start; } else if (Text.Length > 0 && Position > 0) { Position -= 1; Text = Text.Remove(Position, 1); } selection.Clear(); } else if (e.Key == Keys.Delete && !readOnly) { e.Handled = true; if (!selection.IsEmpty) { Text = Text.Remove(selection.Start, selection.Length); Position = selection.Start; } else if (Position < Text.Length) { Text = Text.Remove(Position, 1); } selection.Clear(); } else if (e.Key == Keys.Left) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { Position -= 1; } if (e.Control) { Position = FindPreviousWord(shownText); } } else if (e.Key == Keys.Right) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { Position += 1; } if (e.Control) { Position = FindNextWord(shownText); } } else if (e.Key == Keys.Home) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { PositionX = 0; } if (e.Control) { Position = 0; } } else if (e.Key == Keys.End) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { PositionX = lines[PositionY].Length; } if (e.Control) { Position = Text.Length; } } else if (e.Key == Keys.PageUp) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { PositionY -= linesDrawn; } } else if (e.Key == Keys.PageDown) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != TextBoxMode.Password) { selection.Start = Position; } if (!e.Control) { PositionY += linesDrawn; } } else if (e.Key == Keys.Enter && mode == TextBoxMode.Multiline && !readOnly) { e.Handled = true; Text = Text.Insert(Position, Separator); PositionX = 0; PositionY += 1; } else if (e.Key == Keys.Tab) { } else if (!readOnly && !e.Control) { string c = Keyboard.KeyToString(e.Key, e.Shift, e.Caps); if (selection.IsEmpty) { Text = Text.Insert(Position, c); if (c != "") PositionX += 1; } else { if (Text.Length > 0) { // Avoid out of range. if (selection.Start + selection.Length > Text.Length) Text = Text.Remove(selection.Start, Text.Length - selection.Start); else Text = Text.Remove(selection.Start, selection.Length); Text = Text.Insert(selection.Start, c); Position = selection.Start + 1; } selection.Clear(); } } if (e.Shift && !selection.IsEmpty) { selection.End = Position; } #region Copy Paste // Windows only because it uses the Clipboard class. Of course this could be implemented manually in the XBOX 360 if you want it. #if (WINDOWS) if (e.Control && e.Key == Keys.C && mode != TextBoxMode.Password) { System.Windows.Forms.Clipboard.Clear(); if (mode != TextBoxMode.Password && !selection.IsEmpty) { System.Windows.Forms.Clipboard.SetText((Text.Substring(selection.Start, selection.Length)).Replace("\n", Environment.NewLine)); } } else if (e.Control && e.Key == Keys.V && !readOnly && mode != TextBoxMode.Password) { string t = System.Windows.Forms.Clipboard.GetText().Replace(Environment.NewLine, "\n"); if (selection.IsEmpty) { Text = Text.Insert(Position, t); Position = Position + t.Length; } else { Text = Text.Remove(selection.Start, selection.Length); Text = Text.Insert(selection.Start, t); PositionX = selection.Start + t.Length; selection.Clear(); } } #endif #endregion if ((!e.Shift && !e.Control) || Text.Length <= 0) { selection.Clear(); } if (e.Control && e.Key == Keys.Down) { e.Handled = true; HandleGuide(PlayerIndex.One); } flashTime = 0; if (ClientArea != null) ClientArea.Invalidate(); DeterminePages(); ProcessScrolling(); } base.OnKeyPress(e); } // OnKeyPress
// Respect the guide. /// <param name="e"></param> /// <param name="sender"></param> /// </summary> /// Handles adding new messages to the console message area. /// </summary> private void buffer_ItemAdded(object sender, EventArgs e) { // Update scroll bar value. CalcScrolling(); ClientArea.Invalidate(); }
protected override void OnKeyPress(KeyEventArgs e) { flashTime = 0; if (Manager.UseGuide && Guide.IsVisible) { return; } if (!e.Handled) { if (e.Key == Keys.A && e.Control && mode != ETextBoxMode.Password) { SelectAll(); } if (e.Key == Keys.Up) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { PosY -= 1; } } else if (e.Key == Keys.Down) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { PosY += 1; } } else if (e.Key == Keys.Back && !readOnly) { e.Handled = true; if (!selection.IsEmpty) { Text = Text.Remove(selection.Start, selection.Length); Pos = selection.Start; } else if (Text.Length > 0 && Pos > 0) { Pos -= 1; Text = Text.Remove(Pos, 1); } selection.Clear(); } else if (e.Key == Keys.Delete && !readOnly) { e.Handled = true; if (!selection.IsEmpty) { Text = Text.Remove(selection.Start, selection.Length); Pos = selection.Start; } else if (Pos < Text.Length) { Text = Text.Remove(Pos, 1); } selection.Clear(); } else if (e.Key == Keys.Left) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { Pos -= 1; } if (e.Control) { Pos = FindPrevWord(shownText); } } else if (e.Key == Keys.Right) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { Pos += 1; } if (e.Control) { Pos = FindNextWord(shownText); } } else if (e.Key == Keys.Home) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { PosX = 0; } if (e.Control) { Pos = 0; } } else if (e.Key == Keys.End) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { PosX = Lines[PosY].Length; } if (e.Control) { Pos = Text.Length; } } else if (e.Key == Keys.PageUp) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { PosY -= linesDrawn; } } else if (e.Key == Keys.PageDown) { e.Handled = true; if (e.Shift && selection.IsEmpty && mode != ETextBoxMode.Password) { selection.Start = Pos; } if (!e.Control) { PosY += linesDrawn; } } else if (e.Key == Keys.Enter && mode == ETextBoxMode.Multiline && !readOnly) { e.Handled = true; Text = Text.Insert(Pos, Separator); PosX = 0; PosY += 1; } else if (e.Key == Keys.Tab) { } else if (!readOnly && !e.Control) { string c = Manager.KeyboardLayout.GetKey(e); if (selection.IsEmpty) { Text = Text.Insert(Pos, c); if (c != "") { PosX += 1; } } else { if (Text.Length > 0) { Text = Text.Remove(selection.Start, selection.Length); Text = Text.Insert(selection.Start, c); Pos = selection.Start + 1; } selection.Clear(); } } if (e.Shift && !selection.IsEmpty) { selection.End = Pos; } if (e.Control && e.Key == Keys.C && mode != ETextBoxMode.Password) { #if (!XBOX && !XBOX_FAKE) System.Windows.Forms.Clipboard.Clear(); if (mode != ETextBoxMode.Password && !selection.IsEmpty) { System.Windows.Forms.Clipboard.SetText((Text.Substring(selection.Start, selection.Length)).Replace("\n", Environment.NewLine)); } #endif } else if (e.Control && e.Key == Keys.V && !readOnly && mode != ETextBoxMode.Password) { #if (!XBOX && !XBOX_FAKE) string t = System.Windows.Forms.Clipboard.GetText().Replace(Environment.NewLine, "\n"); if (selection.IsEmpty) { Text = Text.Insert(Pos, t); Pos = Pos + t.Length; } else { Text = Text.Remove(selection.Start, selection.Length); Text = Text.Insert(selection.Start, t); PosX = selection.Start + t.Length; selection.Clear(); } #endif } if ((!e.Shift && !e.Control) || Text.Length <= 0) { selection.Clear(); } if (e.Control && e.Key == Keys.Down) { e.Handled = true; HandleGuide(PlayerIndex.One); } flashTime = 0; if (ClientArea != null) { ClientArea.Invalidate(); } DeterminePages(); ProcessScrolling(); } base.OnKeyPress(e); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// void VerticalScrollBar_ValueChanged(object sender, EventArgs e) { ClientArea.Invalidate(); }
/// <summary> /// Handles adding new messages to the console message area. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void buffer_ItemAdded(object sender, System.EventArgs e) { CalcScrolling(); ClientArea.Invalidate(); }
protected override void OnFocusLost(EventArgs e) { selection.Clear(); ClientArea.Invalidate(); base.OnFocusLost(e); }
void sb_ValueChanged(object sender, EventArgs e) { ClientArea.Invalidate(); }
/// <summary> /// Redraws the console's message area after a scrolling event occurs. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void sbVert_ValueChanged(object sender, System.EventArgs e) { ClientArea.Invalidate(); }
} // SplitLines #endregion #region Scrollbar Value Changed void ScrollBarValueChanged(object sender, EventArgs e) { ClientArea.Invalidate(); } // scrollBarValueChanged