Esempio n. 1
0
        /// <summary>
        /// Adds a keyboard key definition.
        /// </summary>
        /// <param name="id">The identifier of the key.</param>
        /// <param name="elements">The kb file elements describing the key.</param>
        /// <param name="definition">The keyboard definition to add the key to.</param>
        /// <param name="keyCode">The keycode to add.</param>
        private static void AddKeyboardKey(int id, string[] elements, KeyboardDefinition definition, int keyCode)
        {
            if (elements.Length < 10)
            {
                throw new LegacyFileParseException("A key definition line should have at least 10 elements.");
            }

            // Parse the individual elements of the line.
            var posX         = ParseInt(elements[2], "X-Position");
            var posY         = ParseInt(elements[3], "Y-Position");
            var width        = ParseInt(elements[4], "Width");
            var height       = ParseInt(elements[5], "Height");
            var normalText   = LegacyCharacterMapping.Replace(elements[6]);
            var shiftText    = LegacyCharacterMapping.Replace(elements[7]);
            var changeOnCaps = ParseBool(elements[8], "ChangeOnCaps");

            // Construct the new key definition.
            var newKeyDefinition = new KeyboardKeyDefinition(
                id: id,
                boundaries: new List <TPoint>
            {
                new TPoint(posX, posY),
                new TPoint(posX + width, posY),
                new TPoint(posX + width, posY + height),
                new TPoint(posX, posY + height)
            },
                keyCodes: keyCode.Singleton(),
                normalText: normalText,
                shiftText: shiftText,
                changeOnCaps: changeOnCaps);

            AddOrOverlap(definition, keyCode, newKeyDefinition);
        }
        /// <summary>
        /// Takes the current text position input value, updates the current defifinition with it and invokes the change events.
        /// </summary>
        private void UpdateTextPosition()
        {
            var newPos = new TPoint(this.txtTextPosition.X, this.txtTextPosition.Y);

            this.currentDefinition = this.currentDefinition.Modify(textPosition: newPos);
            this.DefinitionChanged?.Invoke(this.currentDefinition);
        }
        /// <summary>
        /// Called when the user clicks "Apply" in the rectangle dialog. Sets the new boundaries and invokes the changed event.
        /// </summary>
        private void OnRectangleDimensionsSet(TRectangle rectangle)
        {
            this.lstBoundaries.Items.Clear();
            this.lstBoundaries.Items.Add(rectangle.TopLeft);
            this.lstBoundaries.Items.Add(rectangle.TopRight);
            this.lstBoundaries.Items.Add(rectangle.BottomRight);
            this.lstBoundaries.Items.Add(rectangle.BottomLeft);

            this.currentDefinition =
                this.currentDefinition.Modify(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList());
            this.DefinitionChanged?.Invoke(this.currentDefinition);
        }
        /// <summary>
        /// Handles adding a key code, sets the new key codes and invokes the changed event.
        /// </summary>
        private void btnAddKeyCode_Click(object sender, EventArgs e)
        {
            var newVal = Convert.ToInt32(this.udKeyCode.Value);

            if (this.lstKeyCodes.Items.Contains(newVal))
            {
                return;
            }

            this.lstKeyCodes.Items.Add(newVal);
            this.lstKeyCodes.SelectedIndex = this.lstKeyCodes.Items.Count - 1;

            this.currentDefinition =
                this.currentDefinition.Modify(keyCodes: this.lstKeyCodes.Items.Cast <int>().ToList());
            this.DefinitionChanged?.Invoke(this.currentDefinition);
        }
Esempio n. 5
0
        /// <summary>
        /// Handles removing a boundary, sets the new boundaries and invokes the changed event.
        /// </summary>
        private void btnRemoveBoundary_Click(object sender, EventArgs e)
        {
            if (this.lstBoundaries.SelectedItem == null)
            {
                return;
            }

            var index = this.lstBoundaries.SelectedIndex;

            this.lstBoundaries.Items.Remove(this.lstBoundaries.SelectedItem);
            this.lstBoundaries.SelectedIndex = Math.Min(this.lstBoundaries.Items.Count - 1, index);

            this.currentDefinition =
                this.currentDefinition.Modify(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList());
            this.DefinitionChanged?.Invoke(this.currentDefinition);
        }
        /// <summary>
        /// Handles moving a boundary down in the list, sets the new boundaries and invokes the changed event.
        /// </summary>
        private void btnBoundaryDown_Click(object sender, EventArgs e)
        {
            var item  = this.lstBoundaries.SelectedItem;
            var index = this.lstBoundaries.SelectedIndex;

            if (item == null || index == this.lstBoundaries.Items.Count - 1)
            {
                return;
            }

            this.lstBoundaries.Items.Remove(item);
            this.lstBoundaries.Items.Insert(index + 1, item);
            this.lstBoundaries.SelectedIndex = index + 1;

            this.currentDefinition =
                this.currentDefinition.Modify(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList());
            this.DefinitionChanged?.Invoke(this.currentDefinition);
        }
        /// <summary>
        /// Handles adding a boundary, sets the new boundaries and invokes the changed event.
        /// </summary>
        private void btnAddBoundary_Click(object sender, EventArgs e)
        {
            var newBoundary = new TPoint(this.txtBoundaries.X, this.txtBoundaries.Y);

            if (this.lstBoundaries.Items.Cast <TPoint>().Any(p => p.X == newBoundary.X && p.Y == newBoundary.Y))
            {
                return;
            }

            var newIndex = Math.Max(0, this.lstBoundaries.SelectedIndex);

            this.lstBoundaries.Items.Insert(newIndex, newBoundary);
            this.lstBoundaries.SelectedIndex = newIndex;

            this.currentDefinition =
                this.currentDefinition.Modify(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList());
            this.DefinitionChanged?.Invoke(this.currentDefinition);
        }
        /// <summary>
        /// Handles updating a boundary, sets the new boundaries and invokes the changed event.
        /// </summary>
        private void btnUpdateBoundary_Click(object sender, EventArgs e)
        {
            if (this.lstBoundaries.SelectedItem == null)
            {
                return;
            }

            var updateIndex = this.lstBoundaries.SelectedIndex;
            var newBoundary = new TPoint(this.txtBoundaries.X, this.txtBoundaries.Y);

            if (this.lstBoundaries.Items.Cast <TPoint>().Any(p => p.X == newBoundary.X && p.Y == newBoundary.Y))
            {
                return;
            }

            this.lstBoundaries.Items.RemoveAt(updateIndex);
            this.lstBoundaries.Items.Insert(updateIndex, newBoundary);
            this.lstBoundaries.SelectedIndex = updateIndex;

            this.currentDefinition =
                this.currentDefinition.Modify(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList());
            this.DefinitionChanged?.Invoke(this.currentDefinition);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyboardKeyPropertiesForm" /> class.
 /// </summary>
 public KeyboardKeyPropertiesForm(KeyboardKeyDefinition initialDefinition)
 {
     this.initialDefinition = initialDefinition;
     this.currentDefinition = (KeyboardKeyDefinition)initialDefinition.Clone();
     this.InitializeComponent();
 }
 /// <summary>
 /// Handles changing the change on caps state, sets the new value and invokes the changed event.
 /// </summary>
 private void chkChangeOnCaps_CheckedChanged(object sender, EventArgs e)
 {
     this.currentDefinition = this.currentDefinition.Modify(changeOnCaps: this.chkChangeOnCaps.Checked);
     this.DefinitionChanged?.Invoke(this.currentDefinition);
 }
 /// <summary>
 /// Handles changing the shift text, sets the new shift text and invokes the changed event.
 /// </summary>
 private void txtShiftText_TextChanged(object sender, EventArgs e)
 {
     this.currentDefinition = this.currentDefinition.Modify(shiftText: this.txtShiftText.Text);
     this.DefinitionChanged?.Invoke(this.currentDefinition);
 }
Esempio n. 12
0
 /// <summary>
 /// Handles changing the text position, sets the new text position and invokes the changed event.
 /// </summary>
 private void txtTextPosition_ValueChanged(Controls.VectorTextBox sender, TPoint newValue)
 {
     this.currentDefinition = this.currentDefinition.Modify(textPosition: newValue);
     this.DefinitionChanged?.Invoke(this.currentDefinition);
 }