Exemplo n.º 1
0
        private Panel InitializeKeyboardInputControls()
        {
            Panel panel = new Panel()
            {
                AutoScroll = true
            };

            panel.SuspendLayout();

            int columnWidth = (panelKeys.ClientSize.Width - 20) / 2;

            Label           tempLabel  = new Label();
            KeyInputControl tempKIC    = new KeyInputControl(settings.Input.UserCommands[UserCommand.GameQuit], InputSettings.DefaultCommands[UserCommand.GameQuit]);
            int             rowTop     = Math.Max(tempLabel.Margin.Top, tempKIC.Margin.Top);
            int             rowHeight  = tempKIC.Height;
            int             rowSpacing = rowHeight + tempKIC.Margin.Vertical;

            string previousCategory = "";
            int    i = 0;

            foreach (UserCommand command in EnumExtension.GetValues <UserCommand>())
            {
                string name = command.GetLocalizedDescription();
                string category, description;
                int    index = name.IndexOf(' ', StringComparison.OrdinalIgnoreCase);
                if (index == -1)
                {
                    category    = string.Empty;
                    description = name;
                }
                else
                {
                    category    = name[..index];
Exemplo n.º 2
0
        internal KeyInputEditControl(KeyInputControl control)
        {
            InitializeComponent();

            // Use a lambda here so we can capture the 'control' variable
            // only for as long as needed to set our location/size.
            Load += (object sender, EventArgs e) =>
            {
                Location = control.Parent.PointToScreen(control.Location);
                Size     = control.Size;
                textBox.Focus();
                HookKeyboard();
            };

            FormClosed += (object sender, FormClosedEventArgs e) =>
            {
                UnhookKeyboard();
            };

            liveInput  = control.UserInput;
            isModifier = liveInput.IsModifier;

#pragma warning disable IDE0008 // Use explicit type
            var input = UserCommandInput.DecomposeUniqueDescriptor(liveInput.UniqueDescriptor);
#pragma warning restore IDE0008 // Use explicit type
            shift        = input.Shift;
            this.control = input.Control;
            alt          = input.Alt;
            scanCode     = input.ScanCode;
            virtualKey   = (Xna.Keys)input.VirtualKey;

            UpdateText();
        }
Exemplo n.º 3
0
        public KeyInputEditControl(KeyInputControl control)
        {
            InitializeComponent();

            // Windows 2000 and XP should use 8.25pt Tahoma, while Windows
            // Vista and later should use 9pt "Segoe UI". We'll use the
            // Message Box font to allow for user-customizations, though.
            Font = SystemFonts.MessageBoxFont;

            // Use a lambda here so we can capture the 'control' variable
            // only for as long as needed to set our location/size.
            Load += (object sender, EventArgs e) =>
            {
                Location = control.Parent.PointToScreen(control.Location);
                Size     = control.Size;
                textBox.Focus();
                HookKeyboard();
            };

            FormClosed += (object sender, FormClosedEventArgs e) =>
            {
                UnhookKeyboard();
            };

            LiveInput  = control.UserInput;
            IsModifier = LiveInput.IsModifier;

            var input = UserCommandInput.DecomposeUniqueDescriptor(LiveInput.UniqueDescriptor);

            Shift      = input.Shift;
            Control    = input.Control;
            Alt        = input.Alt;
            ScanCode   = input.ScanCode;
            VirtualKey = (Xna.Keys)input.VirtualKey;

            UpdateText();
        }
Exemplo n.º 4
0
        private Task <Panel> InitializeKeyboardInputControls()
        {
            TaskCompletionSource <Panel> tcs = new TaskCompletionSource <Panel>();
            Panel panel = new Panel()
            {
                AutoScroll = true
            };

            panel.SuspendLayout();

            var columnWidth = (panelKeys.ClientSize.Width - 20) / 2;

            var tempLabel  = new Label();
            var tempKIC    = new KeyInputControl(Settings.Input.Commands[(int)UserCommand.GameQuit], InputSettings.DefaultCommands[(int)UserCommand.GameQuit]);
            var rowTop     = Math.Max(tempLabel.Margin.Top, tempKIC.Margin.Top);
            var rowHeight  = tempKIC.Height;
            var rowSpacing = rowHeight + tempKIC.Margin.Vertical;

            var lastCategory = "";
            var i            = 0;

            foreach (UserCommand command in EnumExtension.GetValues <UserCommand>())
            {
                var name       = catalog.GetString(command.GetDescription());
                var category   = ParseCategoryFrom(name);
                var descriptor = ParseDescriptorFrom(name);

                if (category != lastCategory)
                {
                    var catlabel = new Label
                    {
                        Location  = new Point(tempLabel.Margin.Left, rowTop + rowSpacing * i),
                        Size      = new Size(columnWidth - tempLabel.Margin.Horizontal, rowHeight),
                        Text      = category,
                        TextAlign = ContentAlignment.MiddleCenter
                    };
                    catlabel.Font = new Font(catlabel.Font, FontStyle.Bold);
                    panel.Controls.Add(catlabel);

                    lastCategory = category;
                    ++i;
                }

                var label = new Label
                {
                    Location  = new Point(tempLabel.Margin.Left, rowTop + rowSpacing * i),
                    Size      = new Size(columnWidth - tempLabel.Margin.Horizontal, rowHeight),
                    Text      = descriptor,
                    TextAlign = ContentAlignment.MiddleRight
                };
                panel.Controls.Add(label);

                var keyInputControl = new KeyInputControl(Settings.Input.Commands[(int)command], InputSettings.DefaultCommands[(int)command])
                {
                    Location = new Point(columnWidth + tempKIC.Margin.Left, rowTop + rowSpacing * i),
                    Size     = new Size(columnWidth - tempKIC.Margin.Horizontal, rowHeight),
                    ReadOnly = true,
                    Tag      = command
                };
                panel.Controls.Add(keyInputControl);
                ++i;
            }
            panel.ResumeLayout(true);
            tcs.SetResult(panel);
            return(tcs.Task);
        }
Exemplo n.º 5
0
        private Panel InitializeKeyboardInputControls()
        {
            Panel panel = new Panel()
            {
                AutoScroll = true
            };

            panel.SuspendLayout();

            int columnWidth = (panelKeys.ClientSize.Width - 20) / 2;

            Label           tempLabel  = new Label();
            KeyInputControl tempKIC    = new KeyInputControl(settings.Input.UserCommands[UserCommand.GameQuit], InputSettings.DefaultCommands[UserCommand.GameQuit]);
            int             rowTop     = Math.Max(tempLabel.Margin.Top, tempKIC.Margin.Top);
            int             rowHeight  = tempKIC.Height;
            int             rowSpacing = rowHeight + tempKIC.Margin.Vertical;

            string previousCategory = "";
            int    i = 0;

            foreach (UserCommand command in EnumExtension.GetValues <UserCommand>())
            {
                string name = commonCatalog.GetString(command.GetDescription());
                string category, description;
                int    index = name.IndexOf(' ');
                if (index == -1)
                {
                    category    = string.Empty;
                    description = name;
                }
                else
                {
                    category    = name.Substring(0, index);
                    description = name.Substring(index + 1);
                }

                if (category != previousCategory)
                {
                    Label catlabel = new Label
                    {
                        Location  = new Point(tempLabel.Margin.Left, rowTop + rowSpacing * i),
                        Size      = new Size(columnWidth - tempLabel.Margin.Horizontal, rowHeight),
                        Text      = category,
                        TextAlign = ContentAlignment.MiddleCenter
                    };
                    catlabel.Font = new Font(catlabel.Font, FontStyle.Bold);
                    panel.Controls.Add(catlabel);

                    previousCategory = category;
                    ++i;
                }

                Label label = new Label
                {
                    Location  = new Point(tempLabel.Margin.Left, rowTop + rowSpacing * i),
                    Size      = new Size(columnWidth - tempLabel.Margin.Horizontal, rowHeight),
                    Text      = description,
                    TextAlign = ContentAlignment.MiddleRight
                };
                panel.Controls.Add(label);

                KeyInputControl keyInputControl = new KeyInputControl(settings.Input.UserCommands[command], InputSettings.DefaultCommands[command])
                {
                    Location = new Point(columnWidth + tempKIC.Margin.Left, rowTop + rowSpacing * i),
                    Size     = new Size(columnWidth - tempKIC.Margin.Horizontal, rowHeight),
                    ReadOnly = true,
                    Tag      = command
                };
                panel.Controls.Add(keyInputControl);
                ++i;
            }
            panel.ResumeLayout(true);
            tempLabel.Dispose();
            tempKIC.Dispose();
            return(panel);
        }