Пример #1
0
        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);
        }
Пример #2
0
        private void UpdateShiftKey(bool ignoreDoubleClick = false)
        {
            Color color;
            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 = Properties.Settings.Default.ColorButtonMain;
                image = Properties.Resources.ButtonCapslock;
            }
            else if (currentShiftKeyStatus == ShiftKeyStatus.Unpressed)
            {
                currentShiftKeyStatus = ShiftKeyStatus.Pressed;
                color = Properties.Settings.Default.ColorButtonMain;
                image = Properties.Resources.ButtonShiftPressed;
            }
            else
            {
                currentShiftKeyStatus = ShiftKeyStatus.Unpressed;
                color = Properties.Settings.Default.ColorDisabled;
                image = Properties.Resources.ButtonShiftUnpressed;
            }

            buttonShift.BackColor = color;
            FormTemplate.SetImageToButton(buttonShift, image);
            ChangeKeyboardCapitalizeStatus(buttonShift);

            previousShiftKeyPress = new TimeSpan(DateTime.Now.Ticks);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public Panel 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.Short || keyboardType == KeyboardType.Number)
            {
                for (int i = 0; i < keys.Count; i++)
                {
                    if (keyboardType == KeyboardType.Short)
                    {
                        keys[i].RemoveRange(keys[i].Count - optionalKeysCount, optionalKeysCount);
                        keys[i].RemoveRange(0, optionalKeysCount);
                    }
                    else if (keyboardType == KeyboardType.Number)
                    {
                        keys[i].RemoveRange(0, keys[i].Count - optionalKeysCount + 1);
                    }
                }
            }

            double keyboardSizeCoefficient = 0.4;

            if (keyboardType == KeyboardType.Number)
            {
                keys[3][0] = "clear";
                keys[3][2] = "backspace";
                keyboardSizeCoefficient = 0.6;
            }

            int keysInLine = keys[0].Count;
            int keysLines  = keys.Count;

            int keyboardHeight = (int)(availableHeight * keyboardSizeCoefficient);

            int distanceBetween = gap / 3;

            int buttonHeight = (keyboardHeight - distanceBetween * (keysLines - 1)) / keysLines;
            int buttonWidth  = buttonHeight;

            int keyboardWidth = buttonWidth * keysInLine + distanceBetween * (keysInLine - 1);

            int leftCornerShadow  = 4;
            int rightCornerShadow = 8;

            int keyboardX   = startX + (availableWidth - keyboardWidth) / 2;
            int keyboardY   = startY + availableHeight - keyboardHeight;
            int keyCurrentX = leftCornerShadow;
            int keyCurrentY = leftCornerShadow;


            Panel panel = new Panel();

            panel.SetBounds(
                keyboardX - leftCornerShadow,
                keyboardY - leftCornerShadow,
                keyboardWidth + leftCornerShadow + rightCornerShadow,
                keyboardHeight + leftCornerShadow + rightCornerShadow);

            if (Properties.Settings.Default.IsDebugMode)
            {
                panel.BackColor = Color.AliceBlue;
            }

            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.0;

                    if (keyName.Equals("Пробел") || keyName.Equals("Ввод"))
                    {
                        fontScale = 0.7;
                    }

                    Button buttonKey = FormTemplate.CreateButton(keyName, keyCurrentX, keyCurrentY, buttonWidth, buttonHeight, fontSize, fontScale);
                    panel.Controls.Add(buttonKey);

                    Image imageDropShadow = Properties.Resources.DropShadowKeyboardMain;
                    Image image           = null;

                    switch (keyName)
                    {
                    case "shift":
                        buttonKey.Tag    = "shift";
                        image            = Properties.Resources.ButtonShiftUnpressed;
                        buttonKey.Click += ButtonKeyShift_Click;
                        buttonShift      = buttonKey;
                        break;

                    case "backspace":
                        buttonKey.Tag    = "backspace";
                        image            = Properties.Resources.ButtonBackspace;
                        buttonKey.Click += ButtonKeyBackspace_Click;
                        break;

                    case "Пробел":
                        buttonKey.Tag    = "space";
                        buttonKey.Width  = buttonWidth * 7 + distanceBetween * 6;
                        keyCurrentX     += buttonKey.Width - buttonWidth;
                        imageDropShadow  = Properties.Resources.DropShadowKeyboardSpace;
                        buttonKey.Click += ButtonKeySpace_Click;
                        break;

                    case "Ввод":
                        buttonKey.Tag    = "enter";
                        buttonKey.Width  = buttonWidth * 2 + distanceBetween;
                        keyCurrentX     += buttonKey.Width - buttonWidth;
                        imageDropShadow  = Properties.Resources.DropShadowKeyboardDoubledKey;
                        buttonKey.Click += ButtonKeyEnter_Click;
                        buttonEnter      = buttonKey;
                        break;

                    case "clear":
                        buttonKey.Tag    = "clear";
                        image            = Properties.Resources.ButtonClear;
                        buttonKey.Click += ButtonClear_Click;
                        break;

                    default:
                        break;
                    }

                    if (buttonKey.Tag == null)
                    {
                        buttonKey.Click += ButtonKey_Click;
                    }

                    if (keyName.Equals("shift") ||
                        keyName.Equals("backspace") ||
                        keyName.Equals("Ввод") ||
                        keyName.Equals("clear"))
                    {
                        buttonKey.BackColor = Properties.Settings.Default.ColorDisabled;
                    }

                    if (image != null)
                    {
                        buttonKey.Text = "";
                        FormTemplate.SetImageToButton(buttonKey, image);
                    }

                    PictureBox dropShadow = FormTemplate.CreateDropShadow(buttonKey, imageDropShadow, leftCornerShadow, rightCornerShadow);
                    panel.Controls.Add(dropShadow);
                    dropShadow.SendToBack();

                    keyCurrentX += buttonWidth + distanceBetween;
                }

                keyCurrentX  = leftCornerShadow;
                keyCurrentY += buttonHeight + distanceBetween;
            }

            return(panel);
        }