Beispiel #1
0
        /// <summary>
        /// Tests whether the specified object is a <see cref="LogitechLedId" /> and is equivalent to this <see cref="LogitechLedId" />.
        /// </summary>
        /// <param name="obj">The object to test.</param>
        /// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="LogitechLedId" /> equivalent to this <see cref="LogitechLedId" />; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            LogitechLedId compareLedId = obj as LogitechLedId;

            if (ReferenceEquals(compareLedId, null))
            {
                return(false);
            }

            if (ReferenceEquals(this, compareLedId))
            {
                return(true);
            }

            if (GetType() != compareLedId.GetType())
            {
                return(false);
            }

            return(compareLedId.LedId == LedId);
        }
Beispiel #2
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);
                        }
                    }
                }
            }
        }