private void UpdateShiftKey(bool ignoreDoubleClick = false) { Color color; System.Drawing.Image image; bool isDoubleClick = (new TimeSpan(DateTime.Now.Ticks) - previousShiftKeyPress).TotalSeconds < 0.5 ? true : false; if (ignoreDoubleClick) { isDoubleClick = false; } if (isDoubleClick) { currentShiftKeyStatus = ShiftKeyStatus.Capslock; color = Services.Config.Instance.ColorButtonBackground; image = Properties.Resources.ButtonCapslock; } else if (currentShiftKeyStatus == ShiftKeyStatus.Unpressed) { currentShiftKeyStatus = ShiftKeyStatus.Pressed; color = Services.Config.Instance.ColorButtonBackground; image = Properties.Resources.ButtonShiftPressed; } else { currentShiftKeyStatus = ShiftKeyStatus.Unpressed; color = Services.Config.Instance.ColorDisabled; image = Properties.Resources.ButtonShiftUnpressed; } buttonShift.Background = new SolidColorBrush(color); buttonShift.Content = ControlsFactory.CreateImage((System.Drawing.Bitmap)image); ChangeKeyboardCapitalizeStatus(buttonShift); previousShiftKeyPress = new TimeSpan(DateTime.Now.Ticks); }
public Canvas CreateOnscreenKeyboard() { List <List <string> > keys = new List <List <string> >() { new List <string>() { "(", ")", "'", "", "й", "ц", "у", "к", "е", "н", "г", "ш", "щ", "з", "х", "", "7", "8", "9" }, new List <string>() { "-", "+", "=", "", "ф", "ы", "в", "а", "п", "р", "о", "л", "д", "ж", "э", "", "4", "5", "6" }, new List <string>() { ":", ";", "!", "", "shift", "я", "ч", "с", "м", "и", "т", "ь", "б", "ю", "backspace", "", "1", "2", "3" }, new List <string>() { ",", ".", "?", "", "ё", "ъ", "Пробел", "Ввод", "", "", "0", "" } }; int optionalKeysCount = 4; if (keyboardType == KeyboardType.Letters || keyboardType == KeyboardType.Numbers) { for (int i = 0; i < keys.Count; i++) { if (keyboardType == KeyboardType.Letters) { keys[i].RemoveRange(keys[i].Count - optionalKeysCount, optionalKeysCount); keys[i].RemoveRange(0, optionalKeysCount); } else if (keyboardType == KeyboardType.Numbers) { keys[i].RemoveRange(0, keys[i].Count - optionalKeysCount + 1); } } } double keyboardSizeCoefficient = 0.9; if (keyboardType == KeyboardType.Numbers) { keys[3][2] = "backspace"; } int keysInLine = keys[0].Count; int keysLines = keys.Count; double keyboardHeight = (int)(availableHeight * keyboardSizeCoefficient); double distanceBetween = gap / 3; double buttonHeight = (keyboardHeight - distanceBetween * (keysLines - 1)) / keysLines; double buttonWidth = buttonHeight; double keyboardWidth = buttonWidth * keysInLine + distanceBetween * (keysInLine - 1); double leftCornerShadow = 4; double rightCornerShadow = 8; double keyboardX = startX + (availableWidth - keyboardWidth) / 2; double keyboardY = startY + availableHeight - keyboardHeight; double keyCurrentX = leftCornerShadow; double keyCurrentY = leftCornerShadow; Canvas canvasKeyboard = new Canvas { Width = keyboardWidth + leftCornerShadow + rightCornerShadow, Height = keyboardHeight + leftCornerShadow + rightCornerShadow }; //if (Services.Configuration.Instance.IsDebug) // canvasKeyboard.Background = new SolidColorBrush(Colors.Yellow); currentShiftKeyStatus = ShiftKeyStatus.Unpressed; foreach (List <string> keysLine in keys) { foreach (string keyName in keysLine) { if (string.IsNullOrEmpty(keyName)) { keyCurrentX += buttonWidth + distanceBetween; continue; } double fontScale = 1.3; if (keyName.Equals("Пробел") || keyName.Equals("Ввод")) { fontScale = 1.0; } Button buttonKey = ControlsFactory.CreateButtonWithTextOnly( keyName, buttonWidth, buttonHeight, new System.Windows.Media.FontFamily("FuturaLightC"), fontSize * fontScale, FontWeights.Normal, keyCurrentX, keyCurrentY, canvasKeyboard); //buttonKey.VerticalContentAlignment = VerticalAlignment.Bottom; //(buttonKey.Content as TextBlock).Background = Brushes.Red; (buttonKey.Content as TextBlock).VerticalAlignment = VerticalAlignment.Center; System.Drawing.Image imageToButton = null; string tag = ""; switch (keyName) { case "shift": tag = "shift"; imageToButton = Properties.Resources.ButtonShiftUnpressed; buttonKey.Click += ButtonKeyShift_Click; buttonShift = buttonKey; break; case "backspace": tag = "backspace"; imageToButton = Properties.Resources.ButtonBackspace; buttonKey.Click += ButtonKeyBackspace_Click; break; case "Пробел": tag = "space"; buttonKey.Width = buttonWidth * 7 + distanceBetween * 6; keyCurrentX += buttonKey.Width - buttonWidth; buttonKey.Click += ButtonKeySpace_Click; break; case "Ввод": tag = "enter"; buttonKey.Width = buttonWidth * 2 + distanceBetween; keyCurrentX += buttonKey.Width - buttonWidth; buttonKey.Click += ButtonKeyEnter_Click; buttonEnter = buttonKey; break; case "clear": tag = "clear"; imageToButton = Properties.Resources.ButtonClear; buttonKey.Click += ButtonClear_Click; break; default: break; } if (string.IsNullOrEmpty(tag)) { buttonKey.Tag = null; buttonKey.Click += ButtonKey_Click; } else { buttonKey.Tag = tag; } if (keyName.Equals("shift") || keyName.Equals("backspace") || keyName.Equals("Ввод") || keyName.Equals("clear")) { buttonKey.Background = new SolidColorBrush(Services.Config.Instance.ColorDisabled); } if (imageToButton != null) { Image image = ControlsFactory.CreateImage((System.Drawing.Bitmap)imageToButton); buttonKey.Content = image; } keyCurrentX += buttonWidth + distanceBetween; } keyCurrentX = leftCornerShadow; keyCurrentY += buttonHeight + distanceBetween; } return(canvasKeyboard); }