Esempio n. 1
0
 public override SKColor GetColor(ArtemisLed led, SKPoint renderPoint)
 {
     if (led == _activeLed)
     {
         if (Properties.ColorMode == KeyColorType.Solid)
         {
             return(Properties.ActiveKeyColor.CurrentValue);
         }
         else
         {
             float colorPos = (float)GetOrderedLeds().IndexOf(led) / (Layer.Leds.Count - 1);
             return(Properties.ActiveKeyGradient.CurrentValue.GetColor(colorPos));
         }
     }
     else
     {
         if (Properties.PaintBackground.CurrentValue)
         {
             return(SKColors.Black);
         }
         else
         {
             return(SKColors.Transparent);
         }
     }
 }
Esempio n. 2
0
        private void SpawnEffect(ArtemisLed led, SKPoint relativeLedPosition)
        {
            lock (_effects)
            {
                List <IKeyPressEffect> effects = _effects.Where(w => w.Led == led).ToList();
                foreach (IKeyPressEffect effect in effects)
                {
                    effect.Respawn();
                }

                // Create another one
                if (!effects.Any() || effects.All(e => e.AllowDuplicates))
                {
                    switch (Properties.Animation.CurrentValue)
                    {
                    case AnimationType.CircleWhilePressed:
                        _effects.Add(new KeypressWhilePressed(this, led, relativeLedPosition));
                        break;

                    case AnimationType.Ripple:
                        _effects.Add(new KeypressRipple(this, led, relativeLedPosition));
                        break;

                    case AnimationType.Echo:
                        _effects.Add(new KeyPressEcho(this, led, relativeLedPosition));
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }
Esempio n. 3
0
        public DeviceLedsTabLedViewModel(ArtemisLed artemisLed, BindableCollection <ArtemisLed> selectedLeds)
        {
            _selectedLeds = selectedLeds;
            ArtemisLed    = artemisLed;

            Update();
        }
Esempio n. 4
0
        private void SpawnWave(ArtemisLed led, SKPoint relativeLedPosition)
        {
            lock (_waves)
            {
                List <KeypressWave> existing = _waves.Where(w => w.Led == led).ToList();
                if (existing.Any())
                {
                    foreach (KeypressWave keypressWave in existing)
                    {
                        keypressWave.Shrink = false;
                        keypressWave.Size   = Math.Max(keypressWave.Size, 0);
                    }

                    return;
                }

                KeypressWave wave = new KeypressWave(
                    led,
                    relativeLedPosition,
                    new SKPaint {
                    Color = SKColor.FromHsv(_rand.Next(0, 360), 100, 100)
                }
                    );
                _waves.Add(wave);
            }
        }
Esempio n. 5
0
        private Geometry CreateCircleGeometry(ArtemisLed led)
        {
            var rect = led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1);

            rect.Inflate(1, 1);
            return(new EllipseGeometry(rect));
        }
Esempio n. 6
0
        private Geometry CreateCustomGeometry(ArtemisLed led, double deflateAmount)
        {
            var rect = led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1);

            rect.Inflate(1, 1);
            try
            {
                var geometry = Geometry.Combine(
                    Geometry.Empty,
                    Geometry.Parse(led.RgbLed.ShapeData),
                    GeometryCombineMode.Union,
                    new TransformGroup
                {
                    Children = new TransformCollection
                    {
                        new ScaleTransform(rect.Width, rect.Height),
                        new TranslateTransform(rect.X, rect.Y)
                    }
                }
                    );

                return(geometry);
            }
            catch (Exception)
            {
                return(CreateRectangleGeometry(led));
            }
        }
 public KeypressRipple(KeypressBrush brush, ArtemisLed led, SKPoint position)
 {
     _brush   = brush;
     Led      = led;
     Position = position;
     Expand   = true;
     UpdatePaint();
 }
Esempio n. 8
0
        public KeypressOnPress(KeypressBrush brush, ArtemisLed led, SKPoint position)
        {
            _brush   = brush;
            Led      = led;
            Position = position;

            UpdatePaint();
        }
Esempio n. 9
0
        public KeyPressEcho(KeypressBrush brush, ArtemisLed led, SKPoint position)
        {
            _brush   = brush;
            Led      = led;
            Position = position;

            UpdatePaint(false);
        }
Esempio n. 10
0
        public override SKColor GetColor(ArtemisLed led, SKPoint renderPoint)
        {
            if (_chroma.CurrentApp is null || _chroma.CurrentApp == "Artemis.UI.exe" || !_colors.TryGetValue(led.RgbLed.Id, out SKColor clr))
            {
                return(SKColor.Empty);
            }

            return(clr);
        }
Esempio n. 11
0
 private void DespawnWave(ArtemisLed led)
 {
     lock (_effects)
     {
         List <IKeyPressEffect> effects = _effects.Where(w => w.Led == led).ToList();
         foreach (IKeyPressEffect effect in effects)
         {
             effect.Despawn();
         }
     }
 }
Esempio n. 12
0
 private void DespawnWave(ArtemisLed led)
 {
     lock (_waves)
     {
         List <KeypressWave> waves = _waves.Where(w => w.Led == led).ToList();
         foreach (KeypressWave keypressWave in waves)
         {
             keypressWave.Shrink = true;
         }
     }
 }
Esempio n. 13
0
        public ProfileLedViewModel(ArtemisLed led)
        {
            Led = led;

            // Don't want ActualLocation here since rotation is done in XAML
            X      = led.RgbLed.Location.X * led.RgbLed.Device.Scale.Horizontal;
            Y      = led.RgbLed.Location.Y * led.RgbLed.Device.Scale.Vertical;
            Width  = led.RgbLed.ActualSize.Width;
            Height = led.RgbLed.ActualSize.Height;

            Execute.PostToUIThread(CreateLedGeometry);
        }
Esempio n. 14
0
        private void InputServiceOnKeyboardKeyDown(object sender, ArtemisKeyboardKeyEventArgs e)
        {
            if (e.Led == null)
            {
                return;
            }

            if (!Layer.Leds.Contains(e.Led))
            {
                return;
            }

            _activeLed = e.Led;
        }
Esempio n. 15
0
        internal override void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
        {
            // We don't want translations on this canvas because that'll displace the LEDs, translations are applied to the points of each LED instead
            Layer.ExcludeCanvasFromTranslation(canvas, true);

            if (Layer.General.ResizeMode == LayerResizeMode.Normal)
            {
                // Apply a translated version of the shape as the clipping mask
                SKPath shapePath = new SKPath(Layer.LayerShape.Path);
                Layer.IncludePathInTranslation(shapePath, true);
                canvas.ClipPath(shapePath);
            }

            using SKPath pointsPath = new SKPath();
            using SKPaint ledPaint  = new SKPaint();
            foreach (ArtemisLed artemisLed in Layer.Leds)
            {
                pointsPath.AddPoly(new[]
                {
                    new SKPoint(0, 0),
                    new SKPoint(artemisLed.AbsoluteRenderRectangle.Left - Layer.Bounds.Left, artemisLed.AbsoluteRenderRectangle.Top - Layer.Bounds.Top)
                });
            }

            Layer.ExcludePathFromTranslation(pointsPath, true);
            SKPoint[] points = pointsPath.Points;
            for (int index = 0; index < Layer.Leds.Count; index++)
            {
                ArtemisLed artemisLed  = Layer.Leds[index];
                SKPoint    renderPoint = points[index * 2 + 1];
                if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
                {
                    continue;
                }

                // Let the brush determine the color
                ledPaint.Color = GetColor(artemisLed, renderPoint);

                SKRect ledRectangle = SKRect.Create(
                    artemisLed.AbsoluteRenderRectangle.Left - Layer.Bounds.Left,
                    artemisLed.AbsoluteRenderRectangle.Top - Layer.Bounds.Top,
                    artemisLed.AbsoluteRenderRectangle.Width,
                    artemisLed.AbsoluteRenderRectangle.Height
                    );

                canvas.DrawRect(ledRectangle, ledPaint);
            }
        }
Esempio n. 16
0
        internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
        {
            // We don't want rotation on this canvas because that'll displace the LEDs, translations are applied to the points of each LED instead
            if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
            {
                canvas.SetMatrix(canvas.TotalMatrix.PreConcat(Layer.GetTransformMatrix(true, false, false, true).Invert()));
            }

            using SKPath pointsPath = new();
            using SKPaint ledPaint  = new();
            foreach (ArtemisLed artemisLed in Layer.Leds)
            {
                pointsPath.AddPoly(new[]
                {
                    new SKPoint(0, 0),
                    new SKPoint(artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left, artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top)
                });
            }

            // Apply the translation to the points of each LED instead
            if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
            {
                pointsPath.Transform(Layer.GetTransformMatrix(true, true, true, true).Invert());
            }

            SKPoint[] points = pointsPath.Points;
            for (int index = 0; index < Layer.Leds.Count; index++)
            {
                ArtemisLed artemisLed  = Layer.Leds[index];
                SKPoint    renderPoint = points[index * 2 + 1];
                if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
                {
                    continue;
                }

                // Let the brush determine the color
                ledPaint.Color = GetColor(artemisLed, renderPoint);

                SKRect ledRectangle = SKRect.Create(
                    artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
                    artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
                    artemisLed.AbsoluteRectangle.Width,
                    artemisLed.AbsoluteRectangle.Height
                    );

                canvas.DrawRect(ledRectangle, ledPaint);
            }
        }
Esempio n. 17
0
        public DeviceVisualizerLed(ArtemisLed led)
        {
            Led     = led;
            LedRect = new Rect(
                Led.RgbLed.Location.X,
                Led.RgbLed.Location.Y,
                Led.RgbLed.Size.Width,
                Led.RgbLed.Size.Height
                );

            if (Led.Layout?.Image != null && File.Exists(Led.Layout.Image.LocalPath))
            {
                LedImage = new BitmapImage(Led.Layout.Image);
            }

            CreateLedGeometry();
        }
Esempio n. 18
0
        public override SKColor GetColor(ArtemisLed led, SKPoint renderPoint)
        {
            SKColor       mainColor     = Properties.MainColor.CurrentValue;
            SKColor       secondColor   = Properties.SecondaryColor.CurrentValue;
            ColorGradient gradientColor = Properties.GradientColor.CurrentValue;
            SKSize        scale         = Properties.Scale.CurrentValue;
            float         hardness      = Properties.Hardness.CurrentValue / 50f;

            float scrolledX = renderPoint.X + _x;

            if (float.IsNaN(scrolledX) || float.IsInfinity(scrolledX))
            {
                scrolledX = 0;
            }
            float scrolledY = renderPoint.Y + _y;

            if (float.IsNaN(scrolledY) || float.IsInfinity(scrolledY))
            {
                scrolledY = 0;
            }

            float width  = 1f / (MathF.Max(scale.Width, 0.001f) / 100f);
            float height = 1f / (MathF.Max(scale.Height, 0.001f) / 100f);

            float evalX = scrolledX * (width / 40f);
            float evalY = scrolledY * (height / 40f);

            float v      = (float)_noise.Evaluate(evalX, evalY, _z) * hardness;
            float amount = Math.Max(0f, Math.Min(1f, v));

            if (Properties.ColorType.BaseValue == ColorMappingType.Simple)
            {
                return(mainColor.Interpolate(secondColor, amount));
            }
            if (gradientColor != null && _colorMap.Length == 101)
            {
                return(_colorMap[(int)Math.Round(amount * 100, MidpointRounding.AwayFromZero)]);
            }
            return(SKColor.Empty);
        }
        public override SKColor GetColor(ArtemisLed led, SKPoint renderPoint)
        {
            const int sampleSize  = 9;
            const int sampleDepth = 3;

            var renderBounds = Layer.Bounds;
            var widthScale   = pixmap.Width / renderBounds.Width;
            var heightScale  = pixmap.Height / renderBounds.Height;

            lock (pixmapLock)
            {
                int x      = (int)(renderPoint.X * widthScale);
                int y      = (int)(renderPoint.Y * heightScale);
                int width  = (int)(led.Rectangle.Width * widthScale);
                int height = (int)(led.Rectangle.Height * heightScale);

                int verticalSteps   = height / (sampleDepth - 1);
                int horizontalSteps = width / (sampleDepth - 1);

                int a = 0, r = 0, g = 0, b = 0;
                for (int horizontalStep = 0; horizontalStep < sampleDepth; horizontalStep++)
                {
                    for (int verticalStep = 0; verticalStep < sampleDepth; verticalStep++)
                    {
                        var     bruhX = x + horizontalSteps * horizontalStep;
                        var     bruhY = y + verticalSteps * verticalStep;
                        SKColor color = pixmap.GetPixelColor(bruhX, bruhY);
                        r += color.Red;
                        g += color.Green;
                        b += color.Blue;
                        a += color.Alpha;
                    }
                }
                return(new SKColor((byte)(r / sampleSize), (byte)(g / sampleSize), (byte)(b / sampleSize)));
            }
        }
Esempio n. 20
0
 public KeypressWave(ArtemisLed led, SKPoint position, SKPaint paint)
 {
     Led      = led;
     Position = position;
     Paint    = paint;
 }
Esempio n. 21
0
 /// <summary>
 ///     The main method of rendering for this type of brush. Called once per frame for each LED in the layer
 ///     <para>
 ///         Note: Due to transformations, the render point may not match the position of the LED, always use the render
 ///         point to determine where the color will go.
 ///     </para>
 /// </summary>
 /// <param name="led">The LED that will receive the color</param>
 /// <param name="renderPoint">The point at which the color is located</param>
 /// <returns>The color the LED will receive</returns>
 public abstract SKColor GetColor(ArtemisLed led, SKPoint renderPoint);
Esempio n. 22
0
 private void Layer_RenderPropertiesUpdated(object sender, EventArgs e)
 {
     _activeLed = null;
 }
Esempio n. 23
0
 internal LedClickedEventArgs(ArtemisDevice device, ArtemisLed led)
 {
     Device = device;
     Led    = led;
 }
 public override SKColor GetColor(ArtemisLed led, SKPoint renderPoint)
 {
     return(SKColor.Empty);
 }