Ejemplo n.º 1
0
        public void PopulateKeymapLayer(KeymapLayer keymapLayer)
        {
            keymapLayer.KeymapGrid = KeymapGrid.GetNewKeymapGrid(keymapLayer.NumberRows, keymapLayer.NumberCols, keymapLayer.Keymaps);

            for (var i = 0; i < keymapLayer.NumberRows; i++)
            {
                for (var j = 0; j < keymapLayer.NumberCols; j++)
                {
                    var keymap = keymapLayer.Keymaps[i, j];
                    keymap.UpdateDisplayText();

                    var button = keymap.Button;
                    button.FontSize = 10;
                    button.HorizontalContentAlignment = HorizontalAlignment.Center;
                    button.Content = keymap.DisplayText;
                }
            }
        }
Ejemplo n.º 2
0
        public List<KeymapLayer> ParseLayers(string file)
        {
            var keymapLayers = new List<KeymapLayer>();

            var fileLines = File.ReadAllLines(file);
            if (fileLines.Length == 0) return null;

            var startRead = false;
            foreach (var line in fileLines.Select(fileLine => fileLine.Trim()))
            {
                // this is the bit containing the keymaps
                if (line == "const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {")
                {
                    startRead = true;
                    continue;
                }

                if (!startRead) continue;

                // we've reached the end of keymap definition block
                if (line == "};") break;

                // start new layer
                if (line[0] == '[')
                {
                    var layerNumber = line[1].ToString();
                    _currentLayerNumber = Convert.ToInt32(layerNumber);
                    _currentLayerName = GetLayerName(line);
                    continue;
                }

                // start new row
                if (line[0] == '{')
                {
                    _currentRowCount++;
                    var row = line.Replace("{", "").Replace("}", "").Split(',').Where(x => x != "").ToList();
                    _currentColumnCount = row.Count();
                    _currentRowCollection.Add(row);
                    continue;
                }

                if (line != "}" && line != "},") continue;

                // reached the end of the current KeymapLayer
                var currentKeymapLayer = new KeymapLayer(_currentRowCount, _currentColumnCount)
                {
                    LayerNumber = _currentLayerNumber,
                    LayerName = _currentLayerName
                };

                ConvertRowCollectionToKeymapLayer(currentKeymapLayer);
                keymapLayers.Add(currentKeymapLayer);

                // reset
                _currentRowCount = 0;
                _currentColumnCount = 0;
                _currentRowCollection = new List<List<string>>();
                _currentLayerNumber = -1;
                _currentLayerName = string.Empty;
            }

            var actions = ParseActions(fileLines);
            AssignActions(actions, keymapLayers);

            return keymapLayers;
        }
Ejemplo n.º 3
0
        public KeymapLayer GetKeymapLayer(string layerName)
        {
            _currentKeymapLayer = _keymapLayers.FirstOrDefault(kl => kl.LayerName == layerName);

            if (_currentKeymapLayer == null)
            {
                MessageBox.Show(string.Format("No keymap layer bound to Layer Name '{0}'", layerName));
                return null;
            }

            var keymaps = _currentKeymapLayer.Keymaps;
            for (var i = 0; i < keymaps.GetLength(0); i++)
            {
                for (var j = 0; j < keymaps.GetLength(1); j++)
                {
                    keymaps[i, j].Button.Click += new RoutedEventHandler(KeymapButton_Click());
                }
            }

            return _currentKeymapLayer;
        }
Ejemplo n.º 4
0
 private void ConvertRowCollectionToKeymapLayer(KeymapLayer keymapLayer)
 {
     for (var rowNum = 0; rowNum < _currentRowCollection.Count; rowNum++)
     {
         var row = _currentRowCollection[rowNum];
         for (var colNum = 0; colNum < row.Count; colNum++)
         {
             keymapLayer.Keymaps[rowNum, colNum] = new Keymap
             {
                 Row = rowNum,
                 Col = colNum,
                 Keypress = row[colNum].Trim()
             };
         }
     }
 }
Ejemplo n.º 5
0
        public void DeleteLayer()
        {
            if (_currentKeymapLayer == null)
            {
                MessageBox.Show("You must select a layer in order to delete it.");
                return;
            }

            var menuItem = AvailableLayersMenu.First(x => (string) x.Header == _currentKeymapLayer.LayerName);
            AvailableLayersMenu.Remove(menuItem);
            _keymapLayers.Remove(_currentKeymapLayer);
            _currentKeymapLayer = null;
            CurrentLayerName = string.Empty;
        }