예제 #1
0
        // This function parses the keyboard layout specification
        // and creates the keyboard visualization using the above
        // declared helper functions.
        private void PopulateKeymap()
        {
            // Parse the source JSON
            try
            {
                String  json = System.IO.File.ReadAllText(GetPath("keymap_default_tada68.json"));
                dynamic data = JsonConvert.DeserializeObject(json);
                KeyboardName = data.keyboard;
                Int32[] keysPerRow = GetKeysPerRow(KeyboardName);

                // Split into easy to understand layers
                var dlayers = data.layers;
                foreach (var dlayer in dlayers)
                {
                    // Split the layers into rows
                    List <List <String> > keys = new List <List <String> >();

                    List <String> row = new List <string>();
                    for (Int32 key = 0; key < dlayer.Count; ++key)
                    {
                        row.Add(dlayer[key].Value);
                        if (row.Count >= keysPerRow[keys.Count])
                        {
                            keys.Add(row);
                            row = new List <string>();
                        }
                    }

                    if (keys.Count != keysPerRow.Length)
                    {
                        // TODO: Log warning here
                    }
                    keyboardLayer.Add(keys);
                    keys = new List <List <String> >();
                }
            }
            catch
            {
                // Fail silently for now
                return;
            }

            // Add buttons to toggle between layers
            for (Int32 l = 0; l < keyboardLayer.Count; ++l)
            {
                IndexedButton b = new IndexedButton();
                b.Content = l.ToString();
                b.Index   = l;
                b.Click  += SelectLayerButton_Click;
                b.Width   = 35;
                LayoutList.Children.Add(b);
            }
        }
예제 #2
0
        // ========================================================================
        // Events
        // ========================================================================
        // Handle a button press in the main window to select layer
        private void SelectLayerButton_Click(object sender, RoutedEventArgs e)
        {
            IndexedButton b = (IndexedButton)sender;

            SelectedLayer = b.Index;
        }