Esempio n. 1
0
        /// <summary>
        /// Internal constructor of <see cref="DebugRGBDeviceInfo"/>.
        /// </summary>
        internal DebugRGBDevice(string layoutPath, Func <Dictionary <LedId, Color> > syncBackFunc = null, Action <IEnumerable <Led> > updateLedsAction = null)
        {
            this._syncBackFunc     = syncBackFunc;
            this._updateLedsAction = updateLedsAction;

            DeviceLayout layout = DeviceLayout.Load(layoutPath);

            DeviceInfo = new DebugRGBDeviceInfo(layout.Type, layout.Vendor, layout.Model, layout.Lighting, syncBackFunc != null);
        }
Esempio n. 2
0
        public void LoadFromXml()
        {
            var model = new LayoutEditModel();

            _windowManager.ShowMessageBox("First, select the base folder of the layout. All other paths will be relative to this folder.");

            // Select a base path
            var folderDialog = new CommonOpenFileDialog {
                IsFolderPicker = true
            };

            if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                model.BasePath = folderDialog.FileName;
            }
            else
            {
                return;
            }

            _windowManager.ShowMessageBox("Now select the layout file itself, it should be relative to the base folder.");

            // Select a XML file
            var fileDialog = new CommonOpenFileDialog {
                InitialDirectory = model.BasePath, Filters = { new CommonFileDialogFilter("Layout Files", "*.xml") }
            };

            if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                model.DeviceLayout       = DeviceLayout.Load(fileDialog.FileName);
                model.DeviceLayoutSource = fileDialog.FileName;
            }
            else
            {
                return;
            }

            _shellViewModel.Start(model);
        }
Esempio n. 3
0
        /// <summary>
        /// Applies the given layout.
        /// </summary>
        /// <param name="layoutPath">The file containing the layout.</param>
        /// <param name="imageLayout">The name of the layout used to get the images of the leds.</param>
        /// <param name="imageBasePath">The path images for this device are collected in.</param>
        protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath)
        {
            DeviceLayout layout = DeviceLayout.Load(layoutPath);

            if (layout != null)
            {
                LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));

                InternalSize = new Size(layout.Width, layout.Height);

                if (layout.Leds != null)
                {
                    foreach (LedLayout layoutLed in layout.Leds)
                    {
                        if (Enum.TryParse(layoutLed.Id, true, out LogitechLedIds ledId))
                        {
                            LogitechLedId id = new LogitechLedId(this, ledId);
                            if (!LedMapping.TryGetValue(id, out Led led))
                            {
                                led = InitializeLed(id, new Rectangle());
                            }

                            led.LedRectangle.Location.X  = layoutLed.X;
                            led.LedRectangle.Location.Y  = layoutLed.Y;
                            led.LedRectangle.Size.Width  = layoutLed.Width;
                            led.LedRectangle.Size.Height = layoutLed.Height;

                            led.Shape     = layoutLed.Shape;
                            led.ShapeData = layoutLed.ShapeData;

                            LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
                            led.Image = (!string.IsNullOrEmpty(image?.Image))
                                ? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute)
                                : new Uri(Path.Combine(imageBasePath, "Missing.png"), UriKind.Absolute);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void LoadLayout()
        {
            DeviceLayout?deviceLayout = DeviceLayout.Load(FilePath, typeof(LayoutCustomDeviceData), typeof(LayoutCustomLedData));

            if (deviceLayout != null)
            {
                RgbLayout = deviceLayout;
                IsValid   = true;
            }
            else
            {
                RgbLayout = new DeviceLayout();
                IsValid   = false;
            }

            if (IsValid)
            {
                Leds.AddRange(RgbLayout.Leds.Select(l => new ArtemisLedLayout(this, l)));
            }

            LayoutCustomDeviceData = (LayoutCustomDeviceData?)RgbLayout.CustomData ?? new LayoutCustomDeviceData();
            ApplyCustomDeviceData();
        }
        public void LoadFromXml()
        {
            var model = new LayoutEditModel();

            // Select a XML file
            VistaOpenFileDialog fileDialog = new();

            fileDialog.Filter = "Layout files (*.xml)|*.xml";
            if (fileDialog.ShowDialog() == false)
            {
                return;
            }

            model.DeviceLayout = DeviceLayout.Load(fileDialog.FileName, typeof(LayoutCustomDeviceData), typeof(LayoutCustomLedData));
            model.FilePath     = fileDialog.FileName;

            if (model.DeviceLayout == null)
            {
                _windowManager.ShowMessageBox("Failed to load layout.", "", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            _shellViewModel.Start(model);
        }