Пример #1
0
        private void AddRowsToGrid(MappingFilter filter)
        {
            Collection <KeyMapping> maps = MappingsManager.GetMappings(filter);

            foreach (KeyMapping map in maps)
            {
                if (filter == MappingFilter.ClearedUser || filter == MappingFilter.ClearedBoot)
                {
                    if (this._keylist.Contains(map.From))
                    {
                        // Don't add an entry for a cleared key which has been remapped.
                        break;
                    }
                }
                else
                {
                    this._keylist.Add(map.From);
                }

                int index = this.grdMappings.Rows.Add(map.ToString());
                this.grdMappings.Rows[index].Tag = map;

                string cellvalue = string.Empty;

                switch (filter)
                {
                case MappingFilter.Boot:
                    cellvalue = "Boot";
                    break;

                case MappingFilter.User:
                    cellvalue = "User";
                    break;

                case MappingFilter.ClearedUser:
                case MappingFilter.ClearedBoot:
                    cellvalue = "Cleared";

                    // Need to store the row to a little array as
                    // don't want to have to access each cell to decide whether
                    // to show the delete button for it or not.
                    this._clearedKeys.Add(index);

                    break;
                }

                this.grdMappings.Rows[index].Cells[1].Value = cellvalue;

                if (MappingsManager.IsMappingPending(map, filter))
                {
                    this.grdMappings.Rows[index].Cells[2].Value = "Pending";
                }
                else
                {
                    this.grdMappings.Rows[index].Cells[2].Value = "Mapped";
                }
            }
        }
Пример #2
0
        private void DrawKey()
        {
            int scanCode = this.scanCode;
            int extended = this.extended;

            ButtonEffect effect;

            if (MappingsManager.IsEmptyMapping(Map) == false)
            {
                //  Remapped or disabled?
                if (MappingsManager.IsDisabledMapping(Map))
                {
                    // Disabled
                    if (MappingsManager.IsMappingPending(Map))
                    {
                        effect = ButtonEffect.DisabledPending;
                    }
                    else
                    {
                        effect = ButtonEffect.Disabled;
                    }
                }
                else
                {
                    // Is this key mapped under the current filter?
                    if (MappingsManager.IsMappingPending(Map))
                    {
                        effect = ButtonEffect.MappedPending;
                    }
                    else
                    {
                        effect = ButtonEffect.Mapped;
                    }

                    // Either way, we want the button to show what it is (will be) mapped to:
                    scanCode = Map.To.ScanCode;
                    extended = Map.To.Extended;
                }
            }
            else
            {
                // Not mapped now, but was this key mapped before under the current filter??
                var km = MappingsManager.GetClearedMapping(scanCode, extended);
                if (MappingsManager.IsEmptyMapping(km))
                {
                    effect = ButtonEffect.None;
                }
                else if (MappingsManager.IsDisabledMapping(km))
                {
                    effect = ButtonEffect.EnabledPending;
                }
                else
                {
                    effect = ButtonEffect.UnmappedPending;
                }
            }

            var keybmp = ButtonImages.GetButtonImage(
                scanCode, extended, button, horizontalStretch, verticalStretch, scale, effect);

            SetImage(keybmp);
        }
Пример #3
0
        private void SetButtonImages()
        {
            // Set the buttons' bitmap as required. Always call SetImage as that
            // handles releasing the existing bitmap if any..

            // From key is straightforward.

            float scale = (DpiInfo.Dpi / 96F);

            if (FromKeyPictureBox.Image == null && map.IsEmpty())
            {
                FromKeyPictureBox.SetImage(ButtonImages.GetButtonImage
                                               (-1, -1, BlankButton.Blank, 0, 0, scale, ButtonEffect.None));
            }
            else
            {
                FromKeyPictureBox.SetImage(ButtonImages.GetButtonImage
                                               (map.From.Scancode, map.From.Extended, BlankButton.Blank, 0, 0, scale, ButtonEffect.None));
            }

            // To Key depends more on state
            int          scancode = 0;
            int          extended = 0;
            ButtonEffect effect   = ButtonEffect.None;

            //  'Disabled' is a special case of 'Mapped'
            if (disabled)
            {
                effect = MappingsManager.IsMappingPending(map) ? ButtonEffect.DisabledPending : ButtonEffect.Disabled;
            }
            else
            {
                if (!mapped)
                {
                    // Not mapped. What are we doing then??
                    if (capturingToKey)
                    {
                        scancode = map.To.Scancode;
                        extended = map.To.Extended;

                        if (map.To.Scancode == 0)
                        {
                            // Can't map to a disabled key - show button as disabled..
                            effect = ButtonEffect.Disabled;
                        }
                        else
                        {
                            effect = ButtonEffect.MappedPending;
                        }
                    }
                    else if (capturingFromKey)
                    {
                        if (map.IsEmpty())
                        {
                            // Show a blank key.
                            scancode = -1;
                            extended = -1;
                        }
                    }
                }
                else
                {
                    // Mapped to a specific key
                    scancode = map.To.Scancode;
                    extended = map.To.Extended;
                    effect   = MappingsManager.IsMappingPending(map) ? ButtonEffect.MappedPending : ButtonEffect.Mapped;
                }
            }

            ToKeyPictureBox.SetImage(ButtonImages.GetButtonImage(scancode, extended, BlankButton.Blank, 0, 0, scale, effect));
        }
Пример #4
0
        private void GetButtons()
        {
            if (showAllButtons)
            {
                buttonCount = 8;
                return;
            }

            // Assume there are some normal unmapped keys!
            buttonCount = 1;

            // See what's currently mapped by looking at the current mapping list
            var currentMaps = MappingsManager.GetMappings(MappingFilter.Current);

            foreach (var map in currentMaps)
            {
                if (MappingsManager.IsMappingPending(map, MappingFilter.Boot))
                {
                    // Pending
                    if (MappingsManager.IsDisabledMapping(map))
                    {
                        if (!pendingDisabled)
                        {
                            pendingDisabled = true;
                            buttonCount++;
                        }
                    }
                    else
                    {
                        if (!pendingMapped)
                        {
                            pendingMapped = true;
                            buttonCount++;
                        }
                    }
                }
                else
                {
                    // Actual
                    if (MappingsManager.IsDisabledMapping(map))
                    {
                        if (!disabledKeys)
                        {
                            disabledKeys = true;
                            buttonCount++;
                        }
                    }
                    else
                    {
                        if (!mappedKeys)
                        {
                            mappedKeys = true;
                            buttonCount++;
                        }
                    }
                }
            }

            // Now look at the cleared keys.

            var maps = MappingsManager.ClearedMappings;

            foreach (var map in maps)
            {
                // Has this cleared key been remapped (in which case we ignore it)
                bool remapped = false;
                foreach (var currentmap in MappingsManager.GetMappings(MappingFilter.Current))
                {
                    if (currentmap.From == map.From)
                    {
                        remapped = true;
                        break;
                    }
                }

                if (remapped)
                {
                    continue;
                }

                if (MappingsManager.IsDisabledMapping(map))
                {
                    if (!pendingEnabled)
                    {
                        pendingEnabled = true;
                        buttonCount++;
                    }
                }
                else
                {
                    if (!pendingUnmapped)
                    {
                        pendingUnmapped = true;
                        buttonCount++;
                    }
                }
            }
        }
Пример #5
0
        private void GetButtons()
        {
            if (this._showAllButtons)
            {
                this._buttonCount = 8;
                return;
            }

            // Assume there are some normal unmapped keys!
            this._buttonCount = 1;

            // See what's currently mapped by looking at the current mapping list
            Collection <KeyMapping> currentMaps = MappingsManager.GetMappings(MappingFilter.Current);

            foreach (KeyMapping map in currentMaps)
            {
                if (MappingsManager.IsMappingPending(map, MappingFilter.All))
                {
                    // Pending
                    if (MappingsManager.IsDisabledMapping(map))
                    {
                        if (!this._pendingdisabled)
                        {
                            this._pendingdisabled = true;
                            this._buttonCount++;
                        }
                    }
                    else
                    {
                        if (!this._pendingmapped)
                        {
                            this._pendingmapped = true;
                            this._buttonCount++;
                        }
                    }
                }
                else
                {
                    // Actual
                    if (MappingsManager.IsDisabledMapping(map))
                    {
                        if (!this._disabledkeys)
                        {
                            this._disabledkeys = true;
                            this._buttonCount++;
                        }
                    }
                    else
                    {
                        if (!this._mappedkeys)
                        {
                            this._mappedkeys = true;
                            this._buttonCount++;
                        }
                    }
                }
            }

            // Now look at the cleared keys.

            IEnumerable <KeyMapping> maps = MappingsManager.ClearedMappings;

            foreach (KeyMapping map in maps)
            {
                // Has this cleared key been remapped (in which case we ignore it)
                bool remapped = false;
                foreach (KeyMapping currentmap in MappingsManager.GetMappings(MappingFilter.Current))
                {
                    if (currentmap.From == map.From)
                    {
                        remapped = true;
                        break;
                    }
                }

                if (remapped)
                {
                    continue;
                }

                if (MappingsManager.IsDisabledMapping(map))
                {
                    if (!this._pendingenabled)
                    {
                        this._pendingenabled = true;
                        this._buttonCount++;
                    }
                }
                else
                {
                    if (!this._pendingunmapped)
                    {
                        this._pendingunmapped = true;
                        this._buttonCount++;
                    }
                }
            }
        }