Exemple #1
0
 public ColorZone(ColorZone otherZone)
 {
     name          = otherZone.name;
     keysequence   = new KeySequence(otherZone.keysequence);
     color         = otherZone.color;
     effect        = otherZone.effect;
     effect_config = new LayerEffectConfig(otherZone.effect_config);
 }
Exemple #2
0
 public ColorZone(Devices.DeviceKeys[] zone_keys, Color zone_color, string zone_name = "New Zone")
 {
     name          = zone_name;
     keysequence   = new KeySequence(zone_keys);
     color         = zone_color;
     effect        = LayerEffects.None;
     effect_config = new LayerEffectConfig();
 }
Exemple #3
0
 public ColorZone(Devices.DeviceKeys[] zone_keys, LayerEffects zone_effect, string zone_name = "New Zone")
 {
     name          = zone_name;
     keysequence   = new KeySequence(zone_keys);
     color         = Color.Black;
     effect        = zone_effect;
     effect_config = new LayerEffectConfig();
     GenerateRandomColor();
 }
Exemple #4
0
 public ColorZone(string zone_name = "New Zone")
 {
     name          = zone_name;
     keysequence   = new KeySequence();
     color         = Color.Black;
     effect        = LayerEffects.None;
     effect_config = new LayerEffectConfig();
     GenerateRandomColor();
 }
        private void cz_effect_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cz_list.SelectedItem != null)
            {
                LayerEffects selectedEffecttype = (LayerEffects)Enum.Parse(typeof(LayerEffects), this.cz_effect.SelectedIndex.ToString());

                ((ColorZone)cz_list.SelectedItem).effect = selectedEffecttype;
                ConfigManager.Save(Global.Configuration);

                effect_settings_button.IsEnabled = selectedEffecttype != LayerEffects.None;
            }
        }
Exemple #6
0
        public override void OverrideProgress(TimeSpan timeOverride, bool stickToMainSegment)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Folder");
            }

            if (!Enabled)
            {
                return;
            }

            TimeSpan beginTime = TimelinePosition;

            if (stickToMainSegment)
            {
                if (!DisplayContinuously)
                {
                    TimeSpan position = timeOverride + StartSegmentLength;
                    if (position > StartSegmentLength + EndSegmentLength)
                    {
                        TimelinePosition = StartSegmentLength + EndSegmentLength;
                    }
                }
                else
                {
                    double progress = timeOverride.TotalMilliseconds % MainSegmentLength.TotalMilliseconds;
                    if (progress > 0)
                    {
                        TimelinePosition = TimeSpan.FromMilliseconds(progress) + StartSegmentLength;
                    }
                    else
                    {
                        TimelinePosition = StartSegmentLength;
                    }
                }
            }
            else
            {
                TimelinePosition = timeOverride;
            }

            double delta = (TimelinePosition - beginTime).TotalSeconds;

            foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
            {
                baseLayerEffect.BaseProperties?.Update(delta);
                baseLayerEffect.Update(delta);
            }
        }
Exemple #7
0
        public override void Update(double deltaTime)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Folder");
            }

            if (!Enabled)
            {
                return;
            }

            // Disable data bindings during an override
            bool wasApplyingDataBindings = ApplyDataBindingsEnabled;

            ApplyDataBindingsEnabled = false;

            UpdateDisplayCondition();

            // Update the layer timeline, this will give us a new delta time which could be negative in case the main segment wrapped back
            // to it's start
            UpdateTimeline(deltaTime);

            foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
            {
                baseLayerEffect.BaseProperties?.Update(deltaTime);
                baseLayerEffect.Update(deltaTime);
            }

            // Iterate the children in reverse because that's how they must be rendered too
            for (int index = Children.Count - 1; index > -1; index--)
            {
                ProfileElement profileElement = Children[index];
                profileElement.Update(deltaTime);
            }

            // Restore the old data bindings enabled state
            ApplyDataBindingsEnabled = wasApplyingDataBindings;
        }
Exemple #8
0
        /// <inheritdoc />
        public override void Render(SKCanvas canvas, SKPointI basePosition)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("Folder");
            }

            // Ensure the folder is ready
            if (!Enabled || !Children.Any(c => c.Enabled) || Path == null)
            {
                return;
            }

            // No point rendering if none of the children are going to render
            if (!Children.Any(c => c is RenderProfileElement renderElement && !renderElement.Timeline.IsFinished))
            {
                return;
            }

            lock (Timeline)
            {
                foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                {
                    baseLayerEffect.BaseProperties?.Update(Timeline);
                    baseLayerEffect.Update(Timeline.Delta.TotalSeconds);
                }

                SKPaint layerPaint = new();
                try
                {
                    SKRectI rendererBounds = SKRectI.Create(0, 0, Bounds.Width, Bounds.Height);
                    foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                    {
                        baseLayerEffect.PreProcess(canvas, rendererBounds, layerPaint);
                    }

                    canvas.SaveLayer(layerPaint);
                    canvas.Translate(Bounds.Left - basePosition.X, Bounds.Top - basePosition.Y);

                    // If required, apply the opacity override of the module to the root folder
                    if (IsRootFolder && Profile.Module.OpacityOverride < 1)
                    {
                        double multiplier = Easings.SineEaseInOut(Profile.Module.OpacityOverride);
                        layerPaint.Color = layerPaint.Color.WithAlpha((byte)(layerPaint.Color.Alpha * multiplier));
                    }

                    // No point rendering if the alpha was set to zero by one of the effects
                    if (layerPaint.Color.Alpha == 0)
                    {
                        return;
                    }

                    // Iterate the children in reverse because the first layer must be rendered last to end up on top
                    for (int index = Children.Count - 1; index > -1; index--)
                    {
                        Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top));
                    }

                    foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                    {
                        baseLayerEffect.PostProcess(canvas, rendererBounds, layerPaint);
                    }
                }
                finally
                {
                    canvas.Restore();
                    layerPaint.DisposeSelfAndProperties();
                }

                Timeline.ClearDelta();
            }
        }
Exemple #9
0
        /// <summary>
        /// Creates a new instance of the EffectLayer class with a specified layer name. And applies a LayerEffect onto this EffectLayer instance.
        /// Using the parameters from LayerEffectConfig and a specified region in RectangleF
        /// </summary>
        /// <param name="name">A layer name</param>
        /// <param name="effect">An enum specifying which LayerEffect to apply</param>
        /// <param name="effect_config">Configurations for the LayerEffect</param>
        /// <param name="rect">A rectangle specifying what region to apply effects in</param>
        public EffectLayer(string name, LayerEffects effect, LayerEffectConfig effect_config, RectangleF rect = new RectangleF())
        {
            this.name  = name;
            colormap   = new Bitmap(Effects.canvas_width, Effects.canvas_height);
            peripheral = new Color();
            Brush brush;
            float shift = 0.0f;

            switch (effect)
            {
            case LayerEffects.ColorOverlay:
                Fill(effect_config.primary);
                break;

            case LayerEffects.ColorBreathing:
                Fill(effect_config.primary);
                float sine = (float)Math.Pow(Math.Sin((double)((Utils.Time.GetMillisecondsSinceEpoch() % 10000L) / 10000.0f) * 2 * Math.PI * effect_config.speed), 2);
                Fill(Color.FromArgb((byte)(sine * 255), effect_config.secondary));
                break;

            case LayerEffects.RainbowShift_Horizontal:
                effect_config.shift_amount += ((Utils.Time.GetMillisecondsSinceEpoch() - effect_config.last_effect_call) / 1000.0f) * 5.0f * effect_config.speed;
                effect_config.shift_amount  = effect_config.shift_amount % Effects.canvas_biggest;

                if (effect_config.animation_type == AnimationType.Translate_XY)
                {
                    shift = effect_config.shift_amount;
                }

                if (effect_config.animation_reverse)
                {
                    shift *= -1.0f;
                }

                brush = CreateRainbowBrush();
                (brush as LinearGradientBrush).RotateTransform(0.0f);
                (brush as LinearGradientBrush).TranslateTransform(shift, shift);

                Fill(brush);

                effect_config.last_effect_call = Utils.Time.GetMillisecondsSinceEpoch();
                break;

            case LayerEffects.RainbowShift_Vertical:
                effect_config.shift_amount += ((Utils.Time.GetMillisecondsSinceEpoch() - effect_config.last_effect_call) / 1000.0f) * 5.0f * effect_config.speed;
                effect_config.shift_amount  = effect_config.shift_amount % Effects.canvas_biggest;

                if (effect_config.animation_type == AnimationType.Translate_XY)
                {
                    shift = effect_config.shift_amount;
                }

                if (effect_config.animation_reverse)
                {
                    shift *= -1.0f;
                }

                brush = CreateRainbowBrush();
                (brush as LinearGradientBrush).RotateTransform(90.0f);
                (brush as LinearGradientBrush).TranslateTransform(shift, shift);

                Fill(brush);

                effect_config.last_effect_call = Utils.Time.GetMillisecondsSinceEpoch();
                break;

            case LayerEffects.RainbowShift_Diagonal:
                effect_config.shift_amount += ((Utils.Time.GetMillisecondsSinceEpoch() - effect_config.last_effect_call) / 1000.0f) * 5.0f * effect_config.speed;
                effect_config.shift_amount  = effect_config.shift_amount % Effects.canvas_biggest;

                if (effect_config.animation_type == AnimationType.Translate_XY)
                {
                    shift = effect_config.shift_amount;
                }

                if (effect_config.animation_reverse)
                {
                    shift *= -1.0f;
                }

                brush = CreateRainbowBrush();
                (brush as LinearGradientBrush).RotateTransform(45.0f);
                (brush as LinearGradientBrush).TranslateTransform(shift, shift);

                Fill(brush);

                effect_config.last_effect_call = Utils.Time.GetMillisecondsSinceEpoch();
                break;

            case LayerEffects.RainbowShift_Diagonal_Other:
                effect_config.shift_amount += ((Utils.Time.GetMillisecondsSinceEpoch() - effect_config.last_effect_call) / 1000.0f) * 5.0f * effect_config.speed;
                effect_config.shift_amount  = effect_config.shift_amount % Effects.canvas_biggest;

                if (effect_config.animation_type == AnimationType.Translate_XY)
                {
                    shift = effect_config.shift_amount;
                }

                if (effect_config.animation_reverse)
                {
                    shift *= -1.0f;
                }

                brush = CreateRainbowBrush();
                (brush as LinearGradientBrush).RotateTransform(-45.0f);
                (brush as LinearGradientBrush).TranslateTransform(shift, shift);

                Fill(brush);

                effect_config.last_effect_call = Utils.Time.GetMillisecondsSinceEpoch();
                break;

            case LayerEffects.RainbowShift_Custom_Angle:
                effect_config.shift_amount += ((Utils.Time.GetMillisecondsSinceEpoch() - effect_config.last_effect_call) / 1000.0f) * 5.0f * effect_config.speed;
                effect_config.shift_amount  = effect_config.shift_amount % Effects.canvas_biggest;


                if (effect_config.animation_type == AnimationType.Translate_XY)
                {
                    shift = effect_config.shift_amount;
                }

                if (effect_config.animation_reverse)
                {
                    shift *= -1.0f;
                }

                brush = CreateRainbowBrush();
                (brush as LinearGradientBrush).RotateTransform(effect_config.angle);
                (brush as LinearGradientBrush).TranslateTransform(shift, shift);

                Fill(brush);

                effect_config.last_effect_call = Utils.Time.GetMillisecondsSinceEpoch();
                break;

            case LayerEffects.GradientShift_Custom_Angle:
                effect_config.shift_amount += ((Utils.Time.GetMillisecondsSinceEpoch() - effect_config.last_effect_call) / 1000.0f) * 0.25f * effect_config.speed;
                effect_config.shift_amount  = effect_config.shift_amount % Effects.canvas_biggest;

                if (effect_config.animation_type == AnimationType.Translate_XY)
                {
                    shift = effect_config.shift_amount;
                }
                else if (effect_config.animation_type == AnimationType.Zoom_in && effect_config.brush.type == EffectBrush.BrushType.Radial)
                {
                    shift = ((Effects.canvas_biggest - effect_config.shift_amount) * 40.0f) % Effects.canvas_biggest;
                }
                else if (effect_config.animation_type == AnimationType.Zoom_out && effect_config.brush.type == EffectBrush.BrushType.Radial)
                {
                    shift = (effect_config.shift_amount * 40.0f) % Effects.canvas_biggest;
                }

                if (effect_config.animation_reverse)
                {
                    shift *= -1.0f;
                }

                brush = effect_config.brush.GetDrawingBrush();
                if (effect_config.brush.type == EffectBrush.BrushType.Linear)
                {
                    if (!rect.IsEmpty)
                    {
                        (brush as LinearGradientBrush).TranslateTransform(rect.X, rect.Y);
                        (brush as LinearGradientBrush).ScaleTransform(rect.Width, rect.Height);
                    }
                    else
                    {
                        (brush as LinearGradientBrush).ScaleTransform(Effects.canvas_height, Effects.canvas_height);
                    }

                    (brush as LinearGradientBrush).TranslateTransform(shift, shift);
                    (brush as LinearGradientBrush).RotateTransform(effect_config.angle);
                }
                else if (effect_config.brush.type == EffectBrush.BrushType.Radial)
                {
                    if (effect_config.animation_type == AnimationType.Zoom_in || effect_config.animation_type == AnimationType.Zoom_out)
                    {
                        float percent = shift / Effects.canvas_biggest;

                        float x_offset = (Effects.canvas_width / 2.0f) * percent;
                        float y_offset = (Effects.canvas_height / 2.0f) * percent;


                        if (!rect.IsEmpty)
                        {
                            x_offset = (rect.Width / 2.0f) * percent;
                            y_offset = (rect.Height / 2.0f) * percent;

                            (brush as PathGradientBrush).TranslateTransform(rect.X + x_offset, rect.Y + y_offset);
                            (brush as PathGradientBrush).ScaleTransform(rect.Width - (2.0f * x_offset), rect.Height - (2.0f * y_offset));
                        }
                        else
                        {
                            (brush as PathGradientBrush).ScaleTransform(Effects.canvas_height + x_offset, Effects.canvas_height + y_offset);
                        }
                    }
                    else
                    {
                        if (!rect.IsEmpty)
                        {
                            (brush as PathGradientBrush).TranslateTransform(rect.X, rect.Y);
                            (brush as PathGradientBrush).ScaleTransform(rect.Width, rect.Height);
                        }
                        else
                        {
                            (brush as PathGradientBrush).ScaleTransform(Effects.canvas_height, Effects.canvas_height);
                        }
                    }

                    (brush as PathGradientBrush).RotateTransform(effect_config.angle);

                    //(brush as PathGradientBrush).TranslateTransform(x_shift, y_shift);
                }

                Fill(brush);

                effect_config.last_effect_call = Utils.Time.GetMillisecondsSinceEpoch();
                break;

            default:
                break;
            }
        }
Exemple #10
0
        public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Folder");
            }

            if (Path == null || !Enabled || !Children.Any(c => c.Enabled))
            {
                return;
            }

            // No need to render if at the end of the timeline
            if (TimelinePosition > TimelineLength)
            {
                return;
            }

            if (_folderBitmap == null)
            {
                _folderBitmap = new SKBitmap(new SKImageInfo((int)Path.Bounds.Width, (int)Path.Bounds.Height));
            }
            else if (_folderBitmap.Info.Width != (int)Path.Bounds.Width || _folderBitmap.Info.Height != (int)Path.Bounds.Height)
            {
                _folderBitmap.Dispose();
                _folderBitmap = new SKBitmap(new SKImageInfo((int)Path.Bounds.Width, (int)Path.Bounds.Height));
            }

            using SKPath folderPath     = new SKPath(Path);
            using SKCanvas folderCanvas = new SKCanvas(_folderBitmap);
            using SKPaint folderPaint   = new SKPaint();
            folderCanvas.Clear();

            folderPath.Transform(SKMatrix.MakeTranslation(folderPath.Bounds.Left * -1, folderPath.Bounds.Top * -1));

            SKPoint targetLocation = Path.Bounds.Location;

            if (Parent is Folder parentFolder)
            {
                targetLocation -= parentFolder.Path.Bounds.Location;
            }

            canvas.Save();

            using SKPath clipPath = new SKPath(folderPath);
            clipPath.Transform(SKMatrix.MakeTranslation(targetLocation.X, targetLocation.Y));
            canvas.ClipPath(clipPath);

            foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
            {
                baseLayerEffect.PreProcess(folderCanvas, _folderBitmap.Info, folderPath, folderPaint);
            }

            // No point rendering if the alpha was set to zero by one of the effects
            if (folderPaint.Color.Alpha == 0)
            {
                return;
            }

            // Iterate the children in reverse because the first layer must be rendered last to end up on top
            for (int index = Children.Count - 1; index > -1; index--)
            {
                folderCanvas.Save();
                ProfileElement profileElement = Children[index];
                profileElement.Render(deltaTime, folderCanvas, _folderBitmap.Info);
                folderCanvas.Restore();
            }

            // If required, apply the opacity override of the module to the root folder
            if (IsRootFolder && Profile.Module.OpacityOverride < 1)
            {
                double multiplier = Easings.SineEaseInOut(Profile.Module.OpacityOverride);
                folderPaint.Color = folderPaint.Color.WithAlpha((byte)(folderPaint.Color.Alpha * multiplier));
            }

            foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
            {
                baseLayerEffect.PostProcess(canvas, canvasInfo, folderPath, folderPaint);
            }
            canvas.DrawBitmap(_folderBitmap, targetLocation, folderPaint);

            canvas.Restore();
        }
Exemple #11
0
        /// <inheritdoc />
        public override void Render(SKCanvas canvas)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("Folder");
            }

            // Ensure the folder is ready
            if (!Enabled || !Children.Any(c => c.Enabled) || Path == null)
            {
                return;
            }

            // No point rendering if none of the children are going to render
            if (!Children.Any(c => c is RenderProfileElement renderElement && !renderElement.Timeline.IsFinished))
            {
                return;
            }

            lock (Timeline)
            {
                foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                {
                    baseLayerEffect.BaseProperties?.Update(Timeline);
                    baseLayerEffect.Update(Timeline.Delta.TotalSeconds);
                }

                try
                {
                    canvas.Save();
                    Renderer.Open(Path, Parent as Folder);
                    if (Renderer.Canvas == null || Renderer.Path == null || Renderer.Paint == null)
                    {
                        throw new ArtemisCoreException("Failed to open folder render context");
                    }

                    SKRect rendererBounds = Renderer.Path.Bounds;
                    foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                    {
                        baseLayerEffect.PreProcess(Renderer.Canvas, rendererBounds, Renderer.Paint);
                    }

                    // If required, apply the opacity override of the module to the root folder
                    if (IsRootFolder && Profile.Module.OpacityOverride < 1)
                    {
                        double multiplier = Easings.SineEaseInOut(Profile.Module.OpacityOverride);
                        Renderer.Paint.Color = Renderer.Paint.Color.WithAlpha((byte)(Renderer.Paint.Color.Alpha * multiplier));
                    }

                    // No point rendering if the alpha was set to zero by one of the effects
                    if (Renderer.Paint.Color.Alpha == 0)
                    {
                        return;
                    }

                    // Iterate the children in reverse because the first layer must be rendered last to end up on top
                    for (int index = Children.Count - 1; index > -1; index--)
                    {
                        Children[index].Render(Renderer.Canvas);
                    }

                    foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                    {
                        baseLayerEffect.PostProcess(Renderer.Canvas, rendererBounds, Renderer.Paint);
                    }

                    canvas.DrawBitmap(Renderer.Bitmap, Renderer.TargetLocation, Renderer.Paint);
                }
                finally
                {
                    canvas.Restore();
                    Renderer.Close();
                }

                Timeline.ClearDelta();
            }
        }