Beispiel #1
0
        private void MapSelected()
        {
            if (disabled)
            {
                // Nono - Can't map while disabled. Shouldn't be here anyway!
                return;
            }

            if (mapped)
            {
                // Unmap.
                MappingsManager.DeleteMapping(map);
                SetMapToBlankMapping();
                Close();
                return;
            }

            if (capturingToKey)
            {
                // Ah, but have we caught a "to" key yet?
                if (!map.IsValid())
                {
                    return;
                }

                capturingToKey = false;
                StopCapture();
                MappingsManager.AddMapping(map);
                Close();
                return;
            }

            if (selectingFromKeyFromLists)
            {
                Key selectedKey = GetKeyFromListboxValue();

                // Have we been sent a dud??
                if (selectedKey.Scancode == 0)
                {
                    // Something went wrong.
                    map = new KeyMapping();
                }
                else
                {
                    SetMapToBlankMapping(selectedKey.Scancode, selectedKey.Extended);
                    // Need to move panel back to where it was and set the image in the picturebox
                    KeyListsPanel.Location = savedPanelLocation;

                    FromKeyPictureBox.SetImage(ButtonImages.GetButtonImage(map.From.Scancode, map.From.Extended));
                    selectingFromKeyFromLists = false;
                    keyThreshold = 1;
                    SetListOptionsComboIndex();
                    SetupForm();
                    return;
                }
            }

            if (capturingFromKey == false)
            {
                // Not mapped, not capturing From or To keys, so this is mapping from list.
                // Need to call method to create map from name.
                if (CreateMappingFromListboxValue())
                {
                    MappingsManager.AddMapping(map);
                    Close();
                }
                return;
            }
            else
            {
                // Setting the From key. Map has already been created from keypress
                capturingFromKey = false;
                StopCapture();
                direction = FadeDirection.FromBlankToUnmapped;
                SetupForm();
                Transition();
            }
        }
Beispiel #2
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));
        }