예제 #1
0
        public override EffectLayer Render(IGameState gamestate)
        {
            EffectLayer layer = new EffectLayer("Minecraft Burning Layer");

            // Render nothing if invalid gamestate or player isn't on fire
            if (!(gamestate is GameState_Minecraft) || !(gamestate as GameState_Minecraft).Player.IsBurning)
            {
                return(layer);
            }

            // Set the background to red
            layer.Fill(Color.Red);

            // Add 3 particles every frame
            for (int i = 0; i < 3; i++)
            {
                CreateFireParticle();
            }

            // Render all particles
            foreach (var particle in particles)
            {
                particle.mix.Draw(layer.GetGraphics(), particle.time);
                particle.time += .1f;
            }

            // Remove any expired particles
            particles.RemoveAll(particle => particle.time >= 1);

            return(layer);
        }
예제 #2
0
        public override EffectLayer Render(IGameState gameState)
        {
            var layer = new EffectLayer();

            // Get elapsed time since last render
            var dt = stopwatch.ElapsedMilliseconds / 1000d;

            stopwatch.Restart();

            // Update and render all particles
            using (var gfx = layer.GetGraphics()) {
                foreach (var particle in particles)
                {
                    particle.Update(dt, Properties, gameState);
                    if (particle.IsAlive(Properties, gameState))
                    {
                        particle.Render(gfx, Properties, gameState);
                    }
                }
            }

            // Spawn new particles if required
            SpawnParticles(dt);

            // Remove any particles that have expired
            particles.RemoveAll(p => !p.IsAlive(Properties, gameState));

            // Call the render event
            LayerRender?.Invoke(this, layer.GetBitmap());

            return(layer);
        }
예제 #3
0
        public override EffectLayer Render(IGameState gamestate)
        {
            _previousAnimationTime = _currentAnimationTime;
            _currentAnimationTime  = GetAnimationTime() % Properties.AnimationDuration;

            EffectLayer gradient_layer = new EffectLayer();

            if (Properties.AnimationRepeat > 0)
            {
                if (_playTimes >= Properties.AnimationRepeat)
                {
                    return(gradient_layer);
                }

                if (_currentAnimationTime < _previousAnimationTime)
                {
                    _playTimes++;
                }
            }
            else
            {
                _playTimes = 0;
            }

            EffectLayer gradient_layer_temp = new EffectLayer();

            using (Graphics g = gradient_layer_temp.GetGraphics())
            {
                Properties.AnimationMix.Draw(g, _currentAnimationTime);
            }

            Rectangle rect = new Rectangle(0, 0, Effects.canvas_width, Effects.canvas_height);

            if (Properties.ScaleToKeySequenceBounds)
            {
                var region = Properties.Sequence.GetAffectedRegion();
                rect = new Rectangle((int)region.X, (int)region.Y, (int)region.Width, (int)region.Height);
            }

            using (Graphics g = gradient_layer.GetGraphics())
            {
                g.DrawImage(gradient_layer_temp.GetBitmap(), rect, new Rectangle(0, 0, Effects.canvas_width, Effects.canvas_height), GraphicsUnit.Pixel);
            }

            gradient_layer_temp.Dispose();

            if (Properties.ForceKeySequence)
            {
                gradient_layer.OnlyInclude(Properties.Sequence);
            }

            return(gradient_layer);
        }
예제 #4
0
        public override EffectLayer Render(IGameState gamestate)
        {
            EffectLayer gradient_layer = new EffectLayer();

            if (Properties.Sequence.type == KeySequenceType.Sequence)
            {
                temp_layer = new EffectLayer("Color Zone Effect", LayerEffects.GradientShift_Custom_Angle, Properties.GradientConfig);

                foreach (var key in Properties.Sequence.keys)
                {
                    gradient_layer.Set(key, Utils.ColorUtils.AddColors(gradient_layer.Get(key), temp_layer.Get(key)));
                }
            }
            else
            {
                float x_pos  = (float)Math.Round((Properties.Sequence.freeform.X + Effects.grid_baseline_x) * Effects.editor_to_canvas_width);
                float y_pos  = (float)Math.Round((Properties.Sequence.freeform.Y + Effects.grid_baseline_y) * Effects.editor_to_canvas_height);
                float width  = (float)Math.Round((double)(Properties.Sequence.freeform.Width * Effects.editor_to_canvas_width));
                float height = (float)Math.Round((double)(Properties.Sequence.freeform.Height * Effects.editor_to_canvas_height));

                if (width < 3)
                {
                    width = 3;
                }
                if (height < 3)
                {
                    height = 3;
                }

                Rectangle rect = new Rectangle((int)x_pos, (int)y_pos, (int)width, (int)height);

                temp_layer = new EffectLayer("Color Zone Effect", LayerEffects.GradientShift_Custom_Angle, Properties.GradientConfig, rect);

                using (Graphics g = gradient_layer.GetGraphics())
                {
                    PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));

                    Matrix myMatrix = new Matrix();
                    myMatrix.RotateAt(Properties.Sequence.freeform.Angle, rotatePoint, MatrixOrder.Append);

                    g.Transform = myMatrix;
                    g.DrawImage(temp_layer.GetBitmap(), rect, rect, GraphicsUnit.Pixel);
                }
            }

            return(gradient_layer);
        }
예제 #5
0
        public override EffectLayer Render(IGameState gamestate)
        {
            EffectLayer layer = new EffectLayer("Minecraft Rain Layer");

            if (!(gamestate is GameState_Minecraft))
            {
                return(layer);
            }

            // Add more droplets based on the intensity
            float strength = (gamestate as GameState_Minecraft).World.RainStrength;

            if (strength > 0)
            {
                if (frame <= 0)
                {
                    // calculate time (in frames) until next droplet is created
                    float min = Properties.MinimumInterval, max = Properties.MaximumInterval; // Store as floats so C# doesn't prematurely round numbers
                    frame = (int)Math.Round(min - ((min - max) * strength));                  // https://www.desmos.com/calculator/uak73e5eub
                    CreateRainDrop();
                }
                else
                {
                    frame--;
                }
            }

            // Render all droplets
            foreach (var droplet in raindrops)
            {
                droplet.mix.Draw(layer.GetGraphics(), droplet.time);
                droplet.time += .1f;
            }

            // Remove any expired droplets
            raindrops.RemoveAll(droplet => droplet.time >= 1);

            return(layer);
        }
예제 #6
0
        public override EffectLayer Render(IGameState state)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            EffectLayer  effectLayer  = new EffectLayer("CSGO - Winning Team Effect");
            AnimationMix animationMix = new AnimationMix();

            if (state is GameState_CSGO)
            {
                GameState_CSGO csgostate = state as GameState_CSGO;

                // Block animations after end of round
                if (csgostate.Map.Phase == MapPhase.Undefined || csgostate.Round.Phase != RoundPhase.Over)
                {
                    return(effectLayer);
                }

                Color color = Color.White;

                // Triggers directly after a team wins a round
                if (csgostate.Round.WinTeam != RoundWinTeam.Undefined && csgostate.Previously.Round.WinTeam == RoundWinTeam.Undefined)
                {
                    // Determine round or game winner
                    if (csgostate.Map.Phase == MapPhase.GameOver)
                    {
                        // End of match
                        int tScore  = csgostate.Map.TeamT.Score;
                        int ctScore = csgostate.Map.TeamCT.Score;

                        if (tScore > ctScore)
                        {
                            color = Properties.TColor;
                        }
                        else if (ctScore > tScore)
                        {
                            color = Properties.CTColor;
                        }
                    }
                    else
                    {
                        // End of round
                        if (csgostate.Round.WinTeam == RoundWinTeam.T)
                        {
                            color = Properties.TColor;
                        }
                        if (csgostate.Round.WinTeam == RoundWinTeam.CT)
                        {
                            color = Properties.CTColor;
                        }
                    }

                    this.SetTracks(color);
                    animationMix.Clear();
                    showAnimation = true;
                }

                if (showAnimation)
                {
                    animationMix = new AnimationMix(tracks);

                    effectLayer.Fill(color);
                    animationMix.Draw(effectLayer.GetGraphics(), winningTeamEffect_Keyframe);
                    winningTeamEffect_Keyframe += (currenttime - previoustime) / 1000.0f;

                    if (winningTeamEffect_Keyframe >= winningTeamEffect_AnimationTime)
                    {
                        showAnimation = false;
                        winningTeamEffect_Keyframe = 0;
                    }
                }
            }

            return(effectLayer);
        }
예제 #7
0
        public override EffectLayer Render(IGameState gamestate)
        {
            EffectLayer animationLayer = new EffectLayer();

            // Calculate elapsed time since last Render call
            long dt = _animTimeStopwatch.ElapsedMilliseconds;

            _animTimeStopwatch.Restart();

            // Update all running animations. We have to call "ToList()" to prevent "Collection was modified; enumeration operation may not execute"
            runningAnimations.ToList().ForEach(anim => {
                anim.currentTime += dt / 1000f;
                if (Properties.AnimationRepeat > 0)
                {
                    anim.playTimes += (int)(anim.currentTime / Properties.AnimationDuration);
                }
                anim.currentTime %= Properties.AnimationDuration;
            });

            // Remove any animations that have completed their play times
            if (Properties.AnimationRepeat > 0)
            {
                runningAnimations.RemoveAll(ra => ra.playTimes >= Properties.AnimationRepeat);
            }

            // Check to see if the gamestate will cause any animations to trigger
            CheckTriggers(gamestate);

            // Render each playing animation. We have to call "ToList()" to prevent "Collection was modified; enumeration operation may not execute"
            runningAnimations.ToList().ForEach(anim => {
                EffectLayer temp = new EffectLayer();

                // Default values for the destination rect (the area that the canvas is drawn to) and animation offset
                Rectangle destRect = new Rectangle(0, 0, Effects.canvas_width, Effects.canvas_height);
                PointF offset      = Properties.KeyTriggerTranslate ? anim.offset : PointF.Empty;

                // When ScaleToKeySequenceBounds is true, additional calculations are needed on the destRect and offset:
                if (Properties.ScaleToKeySequenceBounds)
                {
                    // The dest rect should simply be the bounding region of the affected keys
                    RectangleF affectedRegion = Properties.Sequence.GetAffectedRegion();
                    destRect = Rectangle.Truncate(affectedRegion);

                    // If we are scaling to key sequence bounds, we need to adapt the offset of the pressed key so that it
                    // remains where it is after the bound - scaling operation.
                    // Let's consider only 1 dimension (X) for now since it makes it easier to think about. The scaling process
                    // is: the whole canvas width is scaled down to the width of the affected region, and then it offset by the
                    // X of the affected region. To have a point that remains the same, we need to reposition it when it's being
                    // used on the canvas, therefore this process needs to be inverted: 1.take the original offset of X and
                    // subtract the affected region's X, thereby giving us the distance from the edge of the affected region to
                    // the offset; 2. scale this up to counter-act the down-scaling done, so we calculate the change in scale off
                    // the canvas by dividing canvas width by the affected region's width; 3.multiply these two numbers together
                    // and that's our new X offset.
                    // This probably makes no sense and I'll forget how it works immediately, but hopefully it helps a little in
                    // future if this code ever needs to be revised. It's embarassing how long it took to work this equation out.
                    offset.X = (offset.X - affectedRegion.X) * (Effects.canvas_width / affectedRegion.Width);
                    offset.Y = (offset.Y - affectedRegion.Y) * (Effects.canvas_height / affectedRegion.Height);
                }

                // Draw the animation to a temporary canvas
                using (Graphics g = temp.GetGraphics())
                    Properties.AnimationMix.Draw(g, anim.currentTime, 1f, offset);

                // Draw from this temp canvas to the actual layer, performing the scale down if it's needed.
                using (Graphics g = animationLayer.GetGraphics())
                    g.DrawImage(temp.GetBitmap(), destRect, new Rectangle(0, 0, Effects.canvas_width, Effects.canvas_height), GraphicsUnit.Pixel);

                temp.Dispose();
            });

            if (Properties.ForceKeySequence)
            {
                animationLayer.OnlyInclude(Properties.Sequence);
            }

            return(animationLayer);
        }
예제 #8
0
        public override EffectLayer Render(IGameState gamestate)
        {
            MMDevice current_device = audio_device_enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);

            if (default_device == null || default_device.ID != current_device.ID)
            {
                UpdateAudioCapture();
            }

            float[] freqs = Properties.Frequencies.ToArray(); //Defined Frequencies

            double[] freq_results = new double[freqs.Length];

            if (previous_freq_results == null || previous_freq_results.Length < freqs.Length)
            {
                previous_freq_results = new float[freqs.Length];
            }

            //Maintain local copies of fft, to prevent data overwrite
            Complex[] _local_fft          = new List <Complex>(_ffts).ToArray();
            Complex[] _local_fft_previous = new List <Complex>(_ffts_prev).ToArray();

            EffectLayer equalizer_layer = new EffectLayer();

            if (Properties.DimBackgroundOnSound)
            {
                bool hasSound = false;
                foreach (var bin in _local_fft)
                {
                    if (bin.X > 0.0005 || bin.X < -0.0005)
                    {
                        hasSound = true;
                        break;
                    }
                }

                if (hasSound)
                {
                    equalizer_layer.Fill(Properties.DimColor);
                }
            }

            using (Graphics g = equalizer_layer.GetGraphics())
            {
                int wave_step_amount = _local_fft.Length / Effects.canvas_width;

                switch (Properties.EQType)
                {
                case EqualizerType.Waveform:
                    for (int x = 0; x < Effects.canvas_width; x++)
                    {
                        float fft_val = _local_fft.Length > x * wave_step_amount ? _local_fft[x * wave_step_amount].X : 0.0f;

                        Brush brush = GetBrush(fft_val, x, Effects.canvas_width);

                        g.DrawLine(new Pen(brush), x, Effects.canvas_height_center, x, Effects.canvas_height_center - fft_val * 500.0f);
                    }
                    break;

                case EqualizerType.Waveform_Bottom:
                    for (int x = 0; x < Effects.canvas_width; x++)
                    {
                        float fft_val = _local_fft.Length > x * wave_step_amount ? _local_fft[x * wave_step_amount].X : 0.0f;

                        Brush brush = GetBrush(fft_val, x, Effects.canvas_width);

                        g.DrawLine(new Pen(brush), x, Effects.canvas_height, x, Effects.canvas_height - Math.Abs(fft_val) * 1000.0f);
                    }
                    break;

                case EqualizerType.PowerBars:

                    //Perform FFT again to get frequencies
                    FastFourierTransform.FFT(false, (int)Math.Log(fftLength, 2.0), _local_fft);

                    while (flux_array.Count < freqs.Length)
                    {
                        flux_array.Add(0.0f);
                    }

                    int startF = 0;
                    int endF   = 0;

                    float threshhold = 300.0f;

                    for (int x = 0; x < freqs.Length - 1; x++)
                    {
                        startF = freqToBin(freqs[x]);
                        endF   = freqToBin(freqs[x + 1]);

                        float flux = 0.0f;

                        for (int j = startF; j <= endF; j++)
                        {
                            float curr_fft = (float)Math.Sqrt(_local_fft[j].X * _local_fft[j].X + _local_fft[j].Y * _local_fft[j].Y);
                            float prev_fft = (float)Math.Sqrt(_local_fft_previous[j].X * _local_fft_previous[j].X + _local_fft_previous[j].Y * _local_fft_previous[j].Y);

                            float value     = curr_fft - prev_fft;
                            float flux_calc = (value + Math.Abs(value)) / 2;
                            if (flux < flux_calc)
                            {
                                flux = flux_calc;
                            }

                            flux = flux > threshhold ? 0.0f : flux;
                        }

                        flux_array[x] = flux;
                    }

                    //System.Diagnostics.Debug.WriteLine($"flux max: {flux_array.Max()}");

                    float bar_width = Effects.canvas_width / (float)(freqs.Length - 1);

                    for (int f_x = 0; f_x < freq_results.Length - 1; f_x++)
                    {
                        float fft_val = flux_array[f_x] / Properties.MaxAmplitude;

                        fft_val = Math.Min(1.0f, fft_val);

                        if (previous_freq_results[f_x] - fft_val > 0.10)
                        {
                            fft_val = previous_freq_results[f_x] - 0.15f;
                        }

                        float x      = f_x * bar_width;
                        float y      = Effects.canvas_height;
                        float width  = bar_width;
                        float height = fft_val * Effects.canvas_height;

                        previous_freq_results[f_x] = fft_val;

                        Brush brush = GetBrush(-(f_x % 2), f_x, freq_results.Length - 1);

                        g.FillRectangle(brush, x, y - height, width, height);
                    }

                    break;
                }
            }

            return(equalizer_layer);
        }
예제 #9
0
        public override EffectLayer Render(IGameState gamestate)
        {
            try
            {
                //if (current_device != null)
                //current_device.Dispose();
                CheckForDeviceChange();

                // The system sound as a value between 0.0 and 1.0
                float system_sound_normalized = default_device.AudioEndpointVolume.MasterVolumeLevelScalar;

                // Scale the Maximum amplitude with the system sound if enabled, so that at 100% volume the max_amp is unchanged.
                // Replaces all Properties.MaxAmplitude calls with the scaled value
                float scaled_max_amplitude = Properties.MaxAmplitude * (Properties.ScaleWithSystemVolume ? system_sound_normalized : 1);

                float[] freqs = Properties.Frequencies.ToArray(); //Defined Frequencies

                double[] freq_results = new double[freqs.Length];

                if (previous_freq_results == null || previous_freq_results.Length < freqs.Length)
                {
                    previous_freq_results = new float[freqs.Length];
                }

                //Maintain local copies of fft, to prevent data overwrite
                Complex[] _local_fft          = new List <Complex>(_ffts).ToArray();
                Complex[] _local_fft_previous = new List <Complex>(_ffts_prev).ToArray();

                EffectLayer equalizer_layer = new EffectLayer();

                if (Properties.DimBackgroundOnSound)
                {
                    bool hasSound = false;
                    foreach (var bin in _local_fft)
                    {
                        if (bin.X > 0.0005 || bin.X < -0.0005)
                        {
                            hasSound = true;
                            break;
                        }
                    }

                    if (hasSound)
                    {
                        equalizer_layer.Fill(Properties.DimColor);
                    }
                }

                using (Graphics g = equalizer_layer.GetGraphics())
                {
                    int wave_step_amount = _local_fft.Length / Effects.canvas_width;

                    switch (Properties.EQType)
                    {
                    case EqualizerType.Waveform:
                        for (int x = 0; x < Effects.canvas_width; x++)
                        {
                            float fft_val = _local_fft.Length > x * wave_step_amount ? _local_fft[x * wave_step_amount].X : 0.0f;

                            Brush brush = GetBrush(fft_val, x, Effects.canvas_width);

                            g.DrawLine(new Pen(brush), x, Effects.canvas_height_center, x, Effects.canvas_height_center - fft_val / scaled_max_amplitude * 500.0f);
                        }
                        break;

                    case EqualizerType.Waveform_Bottom:
                        for (int x = 0; x < Effects.canvas_width; x++)
                        {
                            float fft_val = _local_fft.Length > x * wave_step_amount ? _local_fft[x * wave_step_amount].X : 0.0f;

                            Brush brush = GetBrush(fft_val, x, Effects.canvas_width);

                            g.DrawLine(new Pen(brush), x, Effects.canvas_height, x, Effects.canvas_height - Math.Abs(fft_val / scaled_max_amplitude) * 1000.0f);
                        }
                        break;

                    case EqualizerType.PowerBars:

                        //Perform FFT again to get frequencies
                        FastFourierTransform.FFT(false, (int)Math.Log(fftLength, 2.0), _local_fft);

                        while (flux_array.Count < freqs.Length)
                        {
                            flux_array.Add(0.0f);
                        }

                        int startF = 0;
                        int endF   = 0;

                        float threshhold = 300.0f;

                        for (int x = 0; x < freqs.Length - 1; x++)
                        {
                            startF = freqToBin(freqs[x]);
                            endF   = freqToBin(freqs[x + 1]);

                            float flux = 0.0f;

                            for (int j = startF; j <= endF; j++)
                            {
                                float curr_fft = (float)Math.Sqrt(_local_fft[j].X * _local_fft[j].X + _local_fft[j].Y * _local_fft[j].Y);
                                float prev_fft = (float)Math.Sqrt(_local_fft_previous[j].X * _local_fft_previous[j].X + _local_fft_previous[j].Y * _local_fft_previous[j].Y);

                                float value     = curr_fft - prev_fft;
                                float flux_calc = (value + Math.Abs(value)) / 2;
                                if (flux < flux_calc)
                                {
                                    flux = flux_calc;
                                }

                                flux = flux > threshhold ? 0.0f : flux;
                            }

                            flux_array[x] = flux;
                        }

                        //System.Diagnostics.Debug.WriteLine($"flux max: {flux_array.Max()}");

                        float bar_width = Effects.canvas_width / (float)(freqs.Length - 1);

                        for (int f_x = 0; f_x < freq_results.Length - 1; f_x++)
                        {
                            float fft_val = flux_array[f_x] / scaled_max_amplitude;

                            fft_val = Math.Min(1.0f, fft_val);

                            if (previous_freq_results[f_x] - fft_val > 0.10)
                            {
                                fft_val = previous_freq_results[f_x] - 0.15f;
                            }

                            float x      = f_x * bar_width;
                            float y      = Effects.canvas_height;
                            float width  = bar_width;
                            float height = fft_val * Effects.canvas_height;

                            previous_freq_results[f_x] = fft_val;

                            Brush brush = GetBrush(-(f_x % 2), f_x, freq_results.Length - 1);

                            g.FillRectangle(brush, x, y - height, width, height);
                        }

                        break;
                    }
                }

                var hander = NewLayerRender;
                if (hander != null)
                {
                    hander.Invoke(equalizer_layer.GetBitmap());
                }
                return(equalizer_layer);
            }
            catch (Exception exc)
            {
                Global.logger.Error("Error encountered in the Equalizer layer. Exception: " + exc.ToString());
                return(new EffectLayer());
            }
        }
예제 #10
0
        public override EffectLayer Render(IGameState gamestate)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();
            lock (TimeOfLastPress)
            {
                foreach (var lengthPresses in TimeOfLastPress.ToList())
                {
                    if (currenttime - lengthPresses.Value > pressBuffer)
                    {
                        TimeOfLastPress.Remove(lengthPresses.Key);
                    }
                }
            }
            EffectLayer interactive_layer = new EffectLayer("Interactive Effects");

            foreach (var input in _input_list.ToArray())
            {
                if (input == null)
                {
                    continue;
                }

                try
                {
                    if (input.type == input_item.input_type.Spectrum)
                    {
                        float transition_value = input.progress / Effects.canvas_width;

                        if (transition_value > 1.0f)
                        {
                            continue;
                        }

                        Color color = input.spectrum.GetColorAt(transition_value);

                        interactive_layer.Set(input.key, color);
                    }
                    else if (input.type == input_item.input_type.AnimationMix)
                    {
                        float time_value = input.progress / Effects.canvas_width;

                        if (time_value > 1.0f)
                        {
                            continue;
                        }

                        input.animation.Draw(interactive_layer.GetGraphics(), time_value);
                    }
                }
                catch (Exception exc)
                {
                    Global.logger.Error("Interative layer exception, " + exc);
                }
            }

            for (int x = _input_list.Count - 1; x >= 0; x--)
            {
                try
                {
                    if (_input_list[x].progress > Effects.canvas_width)
                    {
                        _input_list.RemoveAt(x);
                    }
                    else
                    {
                        if (!_input_list[x].waitOnKeyUp)
                        {
                            float trans_added = (Properties.EffectSpeed * (getDeltaTime() * 5.0f));
                            _input_list[x].progress += trans_added;
                        }
                    }
                }
                catch (Exception exc)
                {
                    Global.logger.Error("Interative layer exception, " + exc);
                }
            }

            return(interactive_layer);
        }
예제 #11
0
        public override void UpdateLights(EffectFrame frame)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            Queue <EffectLayer> layers = new Queue <EffectLayer>();
            EffectLayer         layer;

            effect_cfg.speed = Global.Configuration.idle_speed;

            switch (Global.Configuration.idle_type)
            {
            case IdleEffects.Dim:
                layer = new EffectLayer("Idle - Dim");

                Color dim_color = Color.FromArgb(125, 0, 0, 0);
                layer.Fill(dim_color);

                layers.Enqueue(layer);
                break;

            case IdleEffects.ColorBreathing:
                layer = new EffectLayer("Idle - Color Breathing");

                Color breathe_bg_color = Global.Configuration.idle_effect_secondary_color;
                layer.Fill(breathe_bg_color);

                float sine = (float)Math.Pow(Math.Sin((double)((currenttime % 10000L) / 10000.0f) * 2 * Math.PI * Global.Configuration.idle_speed), 2);

                layer.Fill(Color.FromArgb((byte)(sine * 255), Global.Configuration.idle_effect_primary_color));

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Horizontal:
                layer = new EffectLayer("Idle - Rainbow Shift (Horizontal)", LayerEffects.RainbowShift_Horizontal, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Vertical:
                layer = new EffectLayer("Idle - Rainbow Shift (Vertical)", LayerEffects.RainbowShift_Vertical, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.StarFall:
                layer = new EffectLayer("Idle - Starfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (stars.ContainsKey(star))
                        {
                            stars[star] = 1.0f;
                        }
                        else
                        {
                            stars.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] stars_keys = stars.Keys.ToArray();

                foreach (Devices.DeviceKeys star in stars_keys)
                {
                    layer.Set(star, Utils.ColorUtils.MultiplyColorByScalar(Global.Configuration.idle_effect_primary_color, stars[star]));
                    stars[star] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainFall:
                layer = new EffectLayer("Idle - Rainfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (raindrops.ContainsKey(star))
                        {
                            raindrops[star] = 1.0f;
                        }
                        else
                        {
                            raindrops.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] raindrops_keys = raindrops.Keys.ToArray();

                ColorSpectrum drop_spec = new ColorSpectrum(Global.Configuration.idle_effect_primary_color, Color.FromArgb(0, Global.Configuration.idle_effect_primary_color));

                foreach (Devices.DeviceKeys raindrop in raindrops_keys)
                {
                    EffectPoint pt = Effects.GetBitmappingFromDeviceKey(raindrop).GetCenter();

                    float transition_value = 1.0f - raindrops[raindrop];
                    float radius           = transition_value * Effects.canvas_biggest;

                    layer.GetGraphics().DrawEllipse(new Pen(drop_spec.GetColorAt(transition_value), 2),
                                                    pt.X - radius,
                                                    pt.Y - radius,
                                                    2 * radius,
                                                    2 * radius);

                    raindrops[raindrop] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            default:
                break;
            }

            frame.AddOverlayLayers(layers.ToArray());
        }
        public override EffectLayer Render(IGameState state)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            EffectLayer  bg_layer           = new EffectLayer("Rocket League - Background");
            AnimationMix goal_explosion_mix = new AnimationMix();
            Color        playerColor        = new Color();
            Color        enemyColor         = new Color();


            if (state is GameState_RocketLeague)
            {
                GameState_RocketLeague rlstate = state as GameState_RocketLeague;

                switch (rlstate.Player.Team)
                {
                case PlayerTeam.Blue:
                    bg_layer.Fill(Properties.BlueColor);
                    playerColor = Properties.BlueColor;
                    enemyColor  = Properties.OrangeColor;
                    break;

                case PlayerTeam.Orange:
                    bg_layer.Fill(Properties.OrangeColor);
                    playerColor = Properties.OrangeColor;
                    enemyColor  = Properties.BlueColor;
                    break;

                default:
                    bg_layer.Fill(Properties.DefaultColor);
                    playerColor = Properties.DefaultColor;
                    enemyColor  = Properties.DefaultColor;
                    break;
                }

                if (Properties.ShowTeamScoreSplit)
                {
                    if (rlstate.Match.BlueTeam_Score != 0 || rlstate.Match.OrangeTeam_Score != 0)
                    {
                        int total_score = rlstate.Match.BlueTeam_Score + rlstate.Match.OrangeTeam_Score;


                        LinearGradientBrush the__split_brush = new LinearGradientBrush(
                            new Point(0, 0),
                            new Point(Effects.canvas_biggest, 0),
                            Color.Red, Color.Red);
                        Color[] colors = new Color[]
                        {
                            Properties.OrangeColor,   //Orange //Team 1
                            Properties.OrangeColor,   //Orange "Line"
                            Properties.BlueColor,     //Blue "Line" //Team 2
                            Properties.BlueColor      //Blue
                        };
                        int     num_colors      = colors.Length;
                        float[] blend_positions = new float[num_colors];

                        if (rlstate.Match.OrangeTeam_Score > rlstate.Match.BlueTeam_Score)
                        {
                            blend_positions[0] = 0.0f;
                            blend_positions[1] = ((float)rlstate.Match.OrangeTeam_Score / (float)total_score) - 0.01f;
                            blend_positions[2] = ((float)rlstate.Match.OrangeTeam_Score / (float)total_score) + 0.01f;
                            blend_positions[3] = 1.0f;
                        }
                        else if (rlstate.Match.OrangeTeam_Score < rlstate.Match.BlueTeam_Score)
                        {
                            blend_positions[0] = 0.0f;
                            blend_positions[1] = (1.0f - ((float)rlstate.Match.BlueTeam_Score / (float)total_score)) - 0.01f;
                            blend_positions[2] = (1.0f - ((float)rlstate.Match.BlueTeam_Score / (float)total_score)) + 0.01f;
                            blend_positions[3] = 1.0f;
                        }
                        else
                        {
                            blend_positions[0] = 0.0f;
                            blend_positions[1] = 0.49f;
                            blend_positions[2] = 0.51f;
                            blend_positions[3] = 1.0f;
                        }

                        ColorBlend color_blend = new ColorBlend();
                        color_blend.Colors    = colors;
                        color_blend.Positions = blend_positions;
                        the__split_brush.InterpolationColors = color_blend;

                        bg_layer.Fill(the__split_brush);
                    }
                }

                if (Properties.ShowGoalExplosion)
                {
                    if (rlstate.Match.YourTeam_LastScore < (rlstate.Player.Team == PlayerTeam.Blue ? rlstate.Match.BlueTeam_Score
                                                                                     : rlstate.Match.OrangeTeam_Score))
                    {
                        goal_explosion_track.SetFrame(0.0f,
                                                      new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, playerColor, 4)
                                                      );
                        goal_explosion_track.SetFrame(1.0f,
                                                      new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, playerColor, 4)
                                                      );

                        goal_explosion_track_1.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, playerColor, 4)
                                                        );
                        goal_explosion_track_1.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, playerColor, 4)
                                                        );

                        goal_explosion_track_2.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, playerColor, 4)
                                                        );
                        goal_explosion_track_2.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, playerColor, 4)
                                                        );

                        goal_explosion_track_3.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, playerColor, 4)
                                                        );
                        goal_explosion_track_3.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, playerColor, 4)
                                                        );

                        goal_explosion_track_4.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, playerColor, 4)
                                                        );
                        goal_explosion_track_4.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, playerColor, 4)
                                                        );

                        goal_explosion_mix.Clear();
                        showAnimation_Explosion = true;
                    }
                }

                if (Properties.ShowEnemyExplosion)
                {
                    if (rlstate.Match.EnemyTeam_LastScore < (rlstate.Player.Team == PlayerTeam.Orange ? rlstate.Match.BlueTeam_Score
                                                                                 : rlstate.Match.OrangeTeam_Score))
                    {
                        goal_explosion_track.SetFrame(0.0f,
                                                      new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, enemyColor, 4)
                                                      );
                        goal_explosion_track.SetFrame(1.0f,
                                                      new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, enemyColor, 4)
                                                      );

                        goal_explosion_track_1.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, enemyColor, 4)
                                                        );
                        goal_explosion_track_1.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, enemyColor, 4)
                                                        );

                        goal_explosion_track_2.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, enemyColor, 4)
                                                        );
                        goal_explosion_track_2.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, enemyColor, 4)
                                                        );

                        goal_explosion_track_3.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, enemyColor, 4)
                                                        );
                        goal_explosion_track_3.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, enemyColor, 4)
                                                        );

                        goal_explosion_track_4.SetFrame(0.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, 0, enemyColor, 4)
                                                        );
                        goal_explosion_track_4.SetFrame(1.0f,
                                                        new AnimationCircle((int)(Effects.canvas_width_center * 0.9), Effects.canvas_height_center, Effects.canvas_biggest / 2.0f, enemyColor, 4)
                                                        );

                        goal_explosion_mix.Clear();
                        showAnimation_Explosion = true;
                    }
                }

                if (showAnimation_Explosion)
                {
                    bg_layer.Fill(Color.FromArgb(0, 0, 0));
                    goal_explosion_mix.AddTrack(goal_explosion_track);
                    goal_explosion_mix.AddTrack(goal_explosion_track_1);
                    goal_explosion_mix.AddTrack(goal_explosion_track_2);
                    goal_explosion_mix.AddTrack(goal_explosion_track_3);
                    goal_explosion_mix.AddTrack(goal_explosion_track_4);

                    goal_explosion_mix.Draw(bg_layer.GetGraphics(), goalEffect_keyframe);
                    goalEffect_keyframe += (currenttime - previoustime) / 1000.0f;

                    if (goalEffect_keyframe >= goalEffect_animationTime)
                    {
                        showAnimation_Explosion = false;
                        goalEffect_keyframe     = 0;
                    }
                }
            }
            return(bg_layer);
        }
예제 #13
0
        public override EffectLayer Render(IGameState gamestate)
        {
            last_use_time = Utils.Time.GetMillisecondsSinceEpoch();

            if (!captureTimer.Enabled) // Static timer isn't running, start it!
            {
                captureTimer.Start();
            }

            Image newImage = new Bitmap(Effects.canvas_width, Effects.canvas_height);

            switch (Properties.AmbilightCaptureType)
            {
            case AmbilightCaptureType.EntireMonitor:
                if (screen != null)
                {
                    using (var graphics = Graphics.FromImage(newImage))
                        graphics.DrawImage(screen, 0, 0, Effects.canvas_width, Effects.canvas_height);
                }
                break;

            case AmbilightCaptureType.SpecificProcess:
            case AmbilightCaptureType.ForegroundApp:
                IntPtr handle = IntPtr.Zero;
                //the image processing is the same for both methods,
                //only the handle of the window changes,
                //so we don't need to repeat that last part
                if (Properties.AmbilightCaptureType == AmbilightCaptureType.ForegroundApp)
                {
                    handle = User32.GetForegroundWindow();
                }
                else if (!String.IsNullOrWhiteSpace(Properties.SpecificProcess))
                {
                    handle = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(Properties.SpecificProcess))
                             .Where(p => p.MainWindowHandle != IntPtr.Zero).FirstOrDefault().MainWindowHandle;
                }

                if (screen != null && handle != IntPtr.Zero)
                {
                    var app_rect = new User32.Rect();

                    User32.GetWindowRect(handle, ref app_rect);
                    Screen display = Screen.FromHandle(handle);

                    if (SwitchDisplay(display.Bounds))
                    {
                        break;
                    }

                    Rectangle scr_region = Resize(new Rectangle(
                                                      app_rect.left - display.Bounds.Left,
                                                      app_rect.top - display.Bounds.Top,
                                                      app_rect.right - app_rect.left,
                                                      app_rect.bottom - app_rect.top));

                    using (var graphics = Graphics.FromImage(newImage))
                        graphics.DrawImage(screen, new Rectangle(0, 0, Effects.canvas_width, Effects.canvas_height), scr_region, GraphicsUnit.Pixel);
                }
                break;

            case AmbilightCaptureType.Coordinates:
                if (screen != null)
                {
                    if (SwitchDisplay(Screen.FromRectangle(Properties.Coordinates).Bounds))
                    {
                        break;
                    }

                    Rectangle scr_region = Resize(new Rectangle(
                                                      Properties.Coordinates.X - currentScreenBounds.Left,
                                                      Properties.Coordinates.Y - currentScreenBounds.Top,
                                                      Properties.Coordinates.Width,
                                                      Properties.Coordinates.Height));

                    using (var graphics = Graphics.FromImage(newImage))
                        graphics.DrawImage(screen, new Rectangle(0, 0, Effects.canvas_width, Effects.canvas_height), scr_region, GraphicsUnit.Pixel);
                }
                break;
            }
            EffectLayer ambilight_layer = new EffectLayer();

            if (Properties.SaturateImage)
            {
                newImage = Utils.BitmapUtils.AdjustImageSaturation(newImage, Properties.SaturationChange);
            }
            if (Properties.BrightenImage)
            {
                newImage = Utils.BitmapUtils.AdjustImageBrightness(newImage, Properties.BrightnessChange);
            }

            if (Properties.AmbilightType == AmbilightType.Default)
            {
                using (Graphics g = ambilight_layer.GetGraphics())
                {
                    if (newImage != null)
                    {
                        g.DrawImageUnscaled(newImage, 0, 0);
                    }
                }
            }
            else if (Properties.AmbilightType == AmbilightType.AverageColor)
            {
                ambilight_layer.Fill(Utils.BitmapUtils.GetAverageColor(newImage));
            }

            newImage.Dispose();
            return(ambilight_layer);
        }
예제 #14
0
        public void PushFrame(EffectFrame frame)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            lock (bitmap_lock)
            {
                EffectLayer background = new EffectLayer("Global Background", Color.FromArgb(0, 0, 0));

                EffectLayer[] over_layers_array = frame.GetOverlayLayers().ToArray();
                EffectLayer[] layers_array      = frame.GetLayers().ToArray();

                foreach (EffectLayer layer in layers_array)
                {
                    background += layer;
                }

                foreach (EffectLayer layer in over_layers_array)
                {
                    background += layer;
                }

                //Apply Brightness
                Dictionary <DeviceKeys, Color> peripehralColors = new Dictionary <DeviceKeys, Color>();

                foreach (Devices.DeviceKeys key in possible_peripheral_keys)
                {
                    if (!peripehralColors.ContainsKey(key))
                    {
                        peripehralColors.Add(key, background.Get(key));
                    }
                }

                foreach (Devices.DeviceKeys key in possible_peripheral_keys)
                {
                    background.Set(key, Utils.ColorUtils.BlendColors(peripehralColors[key], Color.Black, (1.0f - Global.Configuration.PeripheralBrightness)));
                }

                background.Fill(Color.FromArgb((int)(255.0f * (1.0f - Global.Configuration.KeyboardBrightness)), Color.Black));

                if (Global.Configuration.use_volume_as_brightness)
                {
                    background *= Global.Configuration.GlobalBrightness;
                }

                if (_forcedFrame != null)
                {
                    using (Graphics g = background.GetGraphics())
                    {
                        g.Clear(Color.Black);

                        g.DrawImage(_forcedFrame, 0, 0, canvas_width, canvas_height);
                    }
                }

                Dictionary <DeviceKeys, Color> keyColors = new Dictionary <DeviceKeys, Color>();
                Devices.DeviceKeys[]           allKeys   = bitmap_map.Keys.ToArray();

                foreach (Devices.DeviceKeys key in allKeys)
                {
                    keyColors[key] = background.Get(key);
                }

                Effects.keyColors = new Dictionary <DeviceKeys, Color>(keyColors);

                pushedframes++;

                DeviceColorComposition dcc = new DeviceColorComposition()
                {
                    keyColors = new Dictionary <DeviceKeys, Color>(keyColors),
                    keyBitmap = background.GetBitmap()
                };

                Global.dev_manager.UpdateDevices(dcc);

                var hander = NewLayerRender;
                if (hander != null)
                {
                    hander.Invoke(background.GetBitmap());
                }

                if (isrecording)
                {
                    EffectLayer pizelated_render = new EffectLayer();
                    foreach (Devices.DeviceKeys key in allKeys)
                    {
                        pizelated_render.Set(key, background.Get(key));
                    }

                    using (Bitmap map = pizelated_render.GetBitmap())
                    {
                        previousframe = new Bitmap(map);
                    }
                }


                frame.Dispose();
            }

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
        }
예제 #15
0
        public override EffectLayer Render(IGameState gamestate)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            EffectLayer  layer = new EffectLayer("Goal Explosion");
            AnimationMix goal_explosion_mix = new AnimationMix();

            if (gamestate is GameState_RocketLeague)
            {
                var state = gamestate as GameState_RocketLeague;
                if (state.Game.Status == RLStatus.Undefined)
                {
                    return(layer);
                }

                if (state.YourTeam.Goals == -1 || state.OpponentTeam.Goals == -1 || previousOwnTeamGoals > state.YourTeam.Goals || previousOpponentGoals > state.OpponentTeam.Goals)
                {
                    //reset goals when game ends
                    previousOwnTeamGoals  = 0;
                    previousOpponentGoals = 0;
                }

                if (state.YourTeam.Goals > previousOwnTeamGoals)//keep track of goals even if we dont play the animation
                {
                    previousOwnTeamGoals = state.YourTeam.Goals;
                    if (Properties.ShowFriendlyGoalExplosion && state.ColorsValid())
                    {
                        Color playerColor = state.YourTeam.TeamColor;
                        this.SetTracks(playerColor);
                        goal_explosion_mix.Clear();
                        showAnimation_Explosion = true;
                    }
                }

                if (state.OpponentTeam.Goals > previousOpponentGoals)
                {
                    previousOpponentGoals = state.OpponentTeam.Goals;
                    if (Properties.ShowEnemyGoalExplosion && state.ColorsValid())
                    {
                        Color opponentColor = state.OpponentTeam.TeamColor;
                        this.SetTracks(opponentColor);
                        goal_explosion_mix.Clear();
                        showAnimation_Explosion = true;
                    }
                }

                if (showAnimation_Explosion)
                {
                    if (Properties.Background)
                    {
                        layer.Fill(Properties.PrimaryColor);
                    }

                    goal_explosion_mix = new AnimationMix(tracks);

                    goal_explosion_mix.Draw(layer.GetGraphics(), goalEffect_keyframe);
                    goalEffect_keyframe += (currenttime - previoustime) / 1000.0f;

                    if (goalEffect_keyframe >= goalEffect_animationTime)
                    {
                        showAnimation_Explosion = false;
                        goalEffect_keyframe     = 0;
                    }
                }
            }
            return(layer);
        }
예제 #16
0
        public override EffectLayer Render(IGameState gamestate)
        {
            EffectLayer gradient_layer = new EffectLayer();

            //If Wave Size 0 Gradiant Stop Moving Animation
            if (Properties.GradientConfig.gradient_size == 0)
            {
                Properties.GradientConfig.shift_amount    += ((Utils.Time.GetMillisecondsSinceEpoch() - Properties.GradientConfig.last_effect_call) / 1000.0f) * 5.0f * Properties.GradientConfig.speed;
                Properties.GradientConfig.shift_amount     = Properties.GradientConfig.shift_amount % Effects.canvas_biggest;
                Properties.GradientConfig.last_effect_call = Utils.Time.GetMillisecondsSinceEpoch();

                Color selected_color = Properties.GradientConfig.brush.GetColorSpectrum().GetColorAt(Properties.GradientConfig.shift_amount, Effects.canvas_biggest);

                gradient_layer.Set(Properties.Sequence, selected_color);
            }
            else
            {
                if (Properties.Sequence.type == KeySequenceType.Sequence)
                {
                    temp_layer = new EffectLayer("Color Zone Effect", LayerEffects.GradientShift_Custom_Angle, Properties.GradientConfig);

                    foreach (var key in Properties.Sequence.keys)
                    {
                        gradient_layer.Set(key, Utils.ColorUtils.AddColors(gradient_layer.Get(key), temp_layer.Get(key)));
                    }
                }
                else
                {
                    float x_pos = (float)Math.Round((Properties.Sequence.freeform.X + Effects.grid_baseline_x) * Effects.editor_to_canvas_width);
                    float y_pos = (float)Math.Round((Properties.Sequence.freeform.Y + Effects.grid_baseline_y) * Effects.editor_to_canvas_height);

                    float width  = (float)Math.Round((double)(Properties.Sequence.freeform.Width * Effects.editor_to_canvas_width));
                    float height = (float)Math.Round((double)(Properties.Sequence.freeform.Height * Effects.editor_to_canvas_height));

                    if (width < 3)
                    {
                        width = 3;
                    }
                    if (height < 3)
                    {
                        height = 3;
                    }

                    Rectangle rect = new Rectangle((int)x_pos, (int)y_pos, (int)width, (int)height);

                    temp_layer = new EffectLayer("Color Zone Effect", LayerEffects.GradientShift_Custom_Angle, Properties.GradientConfig, rect);

                    using (Graphics g = gradient_layer.GetGraphics())
                    {
                        PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));

                        Matrix myMatrix = new Matrix();
                        myMatrix.RotateAt(Properties.Sequence.freeform.Angle, rotatePoint, MatrixOrder.Append);

                        g.Transform = myMatrix;
                        g.DrawImage(temp_layer.GetBitmap(), rect, rect, GraphicsUnit.Pixel);
                    }
                }
            }
            return(gradient_layer);
        }
        public override EffectLayer Render(IGameState state)
        {
            EffectLayer bg_layer = new EffectLayer("Resident Evil 2 - Health");

            if (state is GameState_ResidentEvil2)
            {
                if (Properties.DisplayType == ResidentEvil2HealthLayerHandlerProperties.HealthDisplayType.Static)
                {
                    GameState_ResidentEvil2 re2state = state as GameState_ResidentEvil2;

                    switch (re2state.Player.Status)
                    {
                    case Player_ResidentEvil2.PlayerStatus.Fine:
                        bg_layer.Fill(Color.Green);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.LiteFine:
                        bg_layer.Fill(Color.YellowGreen);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.Caution:
                        bg_layer.Fill(Color.Gold);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.Danger:
                        bg_layer.Fill(Color.Red);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.Dead:
                        bg_layer.Fill(Color.DarkGray);
                        break;

                    default:
                        bg_layer.Fill(Color.DarkSlateBlue);
                        break;
                    }

                    return(bg_layer);
                }
                else if (Properties.DisplayType == ResidentEvil2HealthLayerHandlerProperties.HealthDisplayType.Scanning)
                {
                    previoustime = currenttime;
                    currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

                    GameState_ResidentEvil2 re2state = state as GameState_ResidentEvil2;

                    switch (re2state.Player.Status)
                    {
                    case Player_ResidentEvil2.PlayerStatus.Fine:
                        bg_layer.Fill(Color.FromArgb(8, Color.Green.R, Color.Green.G, Color.Green.B));
                        heartbeat_animationTime = fullAnimTimes[0];
                        mixFine.Draw(bg_layer.GetGraphics(), heartbeat_keyframe);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.LiteFine:
                        bg_layer.Fill(Color.FromArgb(8, Color.YellowGreen.R, Color.YellowGreen.G, Color.YellowGreen.B));
                        heartbeat_animationTime = fullAnimTimes[0];
                        mixLiteFine.Draw(bg_layer.GetGraphics(), heartbeat_keyframe);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.Caution:
                        bg_layer.Fill(Color.FromArgb(8, Color.Gold.R, Color.Gold.G, Color.Gold.B));
                        heartbeat_animationTime = fullAnimTimes[1];
                        mixCaution.Draw(bg_layer.GetGraphics(), heartbeat_keyframe);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.Danger:
                        bg_layer.Fill(Color.FromArgb(8, Color.Red.R, Color.Red.G, Color.Red.B));
                        heartbeat_animationTime = fullAnimTimes[2];
                        mixDanger.Draw(bg_layer.GetGraphics(), heartbeat_keyframe);
                        break;

                    case Player_ResidentEvil2.PlayerStatus.Dead:
                        bg_layer.Fill(Color.DarkGray);
                        break;

                    default:
                        bg_layer.Fill(Color.DarkSlateBlue);
                        break;
                    }

                    heartbeat_keyframe += (currenttime - previoustime) / 1000.0f;

                    if (heartbeat_keyframe >= heartbeat_animationTime)
                    {
                        heartbeat_keyframe = 0;
                    }

                    return(bg_layer);
                }
                else
                {
                    return(bg_layer);
                }
            }
            else
            {
                return(bg_layer);
            }
        }
예제 #18
0
        public override void UpdateLights(EffectFrame frame)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            Queue <EffectLayer> layers = new Queue <EffectLayer>();
            EffectLayer         layer;

            effect_cfg.speed = Global.Configuration.idle_speed;

            switch (Global.Configuration.idle_type)
            {
            case IdleEffects.Dim:
                layer = new EffectLayer("Idle - Dim");

                layer.Fill(Color.FromArgb(125, 0, 0, 0));

                layers.Enqueue(layer);
                break;

            case IdleEffects.ColorBreathing:
                layer = new EffectLayer("Idle - Color Breathing");

                Color breathe_bg_color = Global.Configuration.idle_effect_secondary_color;
                layer.Fill(breathe_bg_color);

                float sine = (float)Math.Pow(Math.Sin((double)((currenttime % 10000L) / 10000.0f) * 2 * Math.PI * Global.Configuration.idle_speed), 2);

                layer.Fill(Color.FromArgb((byte)(sine * 255), Global.Configuration.idle_effect_primary_color));

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Horizontal:
                layer = new EffectLayer("Idle - Rainbow Shift (Horizontal)", LayerEffects.RainbowShift_Horizontal, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Vertical:
                layer = new EffectLayer("Idle - Rainbow Shift (Vertical)", LayerEffects.RainbowShift_Vertical, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.StarFall:
                layer = new EffectLayer("Idle - Starfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (stars.ContainsKey(star))
                        {
                            stars[star] = 1.0f;
                        }
                        else
                        {
                            stars.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] stars_keys = stars.Keys.ToArray();

                foreach (Devices.DeviceKeys star in stars_keys)
                {
                    layer.Set(star, Utils.ColorUtils.MultiplyColorByScalar(Global.Configuration.idle_effect_primary_color, stars[star]));
                    stars[star] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainFall:
                layer = new EffectLayer("Idle - Rainfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (raindrops.ContainsKey(star))
                        {
                            raindrops[star] = 1.0f;
                        }
                        else
                        {
                            raindrops.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] raindrops_keys = raindrops.Keys.ToArray();

                ColorSpectrum drop_spec = new ColorSpectrum(Global.Configuration.idle_effect_primary_color, Color.FromArgb(0, Global.Configuration.idle_effect_primary_color));

                foreach (Devices.DeviceKeys raindrop in raindrops_keys)
                {
                    PointF pt = Effects.GetBitmappingFromDeviceKey(raindrop).Center;

                    float transition_value = 1.0f - raindrops[raindrop];
                    float radius           = transition_value * Effects.canvas_biggest;

                    layer.GetGraphics().DrawEllipse(new Pen(drop_spec.GetColorAt(transition_value), 2),
                                                    pt.X - radius,
                                                    pt.Y - radius,
                                                    2 * radius,
                                                    2 * radius);

                    raindrops[raindrop] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            case IdleEffects.Blackout:
                layer = new EffectLayer("Idle - Blackout");

                layer.Fill(Color.Black);

                layers.Enqueue(layer);
                break;

            case IdleEffects.Matrix:
                layer = new EffectLayer("Idle - Matrix");

                if (nextstarset < currenttime)
                {
                    Color darker_primary = Utils.ColorUtils.MultiplyColorByScalar(Global.Configuration.idle_effect_primary_color, 0.50);

                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        int   width_start = randomizer.Next(Effects.canvas_width);
                        float delay       = randomizer.Next(550) / 100.0f;
                        int   random_id   = randomizer.Next(125536789);

                        //Create animation
                        AnimationTrack matrix_line =
                            new AnimationTrack("Matrix Line (Head) " + random_id, 0.0f).SetFrame(
                                0.0f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, -3, width_start, 0, Global.Configuration.idle_effect_primary_color, 3)).SetFrame(
                                0.5f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, Effects.canvas_height, width_start, Effects.canvas_height + 3, Global.Configuration.idle_effect_primary_color, 3)).SetShift(
                                (currenttime % 1000000L) / 1000.0f + delay
                                );

                        AnimationTrack matrix_line_trail =
                            new AnimationTrack("Matrix Line (Trail) " + random_id, 0.0f).SetFrame(
                                0.0f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, -12, width_start, -3, darker_primary, 3)).SetFrame(
                                0.5f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, Effects.canvas_height - 12, width_start, Effects.canvas_height, darker_primary, 3)).SetFrame(
                                0.75f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, Effects.canvas_height, width_start, Effects.canvas_height, darker_primary, 3)).SetShift(
                                (currenttime % 1000000L) / 1000.0f + delay
                                );

                        matrix_lines.AddTrack(matrix_line);
                        matrix_lines.AddTrack(matrix_line_trail);
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                using (Graphics g = layer.GetGraphics())
                {
                    matrix_lines.Draw(g, (currenttime % 1000000L) / 1000.0f);
                }

                layers.Enqueue(layer);
                break;

            default:
                break;
            }

            frame.AddOverlayLayers(layers.ToArray());
        }
예제 #19
0
        public override void UpdateLights(EffectFrame frame)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            Queue <EffectLayer> layers = new Queue <EffectLayer>();
            EffectLayer         layer;

            effect_cfg.speed = Global.Configuration.idle_speed;

            switch (Global.Configuration.idle_type)
            {
            case IdleEffects.Dim:
                layer = new EffectLayer("Idle - Dim");

                layer.Fill(Color.FromArgb(125, 0, 0, 0));

                layers.Enqueue(layer);
                break;

            case IdleEffects.ColorBreathing:
                layer = new EffectLayer("Idle - Color Breathing");

                Color breathe_bg_color = Global.Configuration.idle_effect_secondary_color;
                layer.Fill(breathe_bg_color);

                float sine = (float)Math.Pow(Math.Sin((double)((currenttime % 10000L) / 10000.0f) * 2 * Math.PI * Global.Configuration.idle_speed), 2);

                layer.Fill(Color.FromArgb((byte)(sine * 255), Global.Configuration.idle_effect_primary_color));

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Horizontal:
                layer = new EffectLayer("Idle - Rainbow Shift (Horizontal)", LayerEffects.RainbowShift_Horizontal, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Vertical:
                layer = new EffectLayer("Idle - Rainbow Shift (Vertical)", LayerEffects.RainbowShift_Vertical, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.StarFall:
                layer = new EffectLayer("Idle - Starfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (stars.ContainsKey(star))
                        {
                            stars[star] = 1.0f;
                        }
                        else
                        {
                            stars.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] stars_keys = stars.Keys.ToArray();

                foreach (Devices.DeviceKeys star in stars_keys)
                {
                    layer.Set(star, Utils.ColorUtils.MultiplyColorByScalar(Global.Configuration.idle_effect_primary_color, stars[star]));
                    stars[star] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainFall:
                layer = new EffectLayer("Idle - Rainfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (raindrops.ContainsKey(star))
                        {
                            raindrops[star] = 1.0f;
                        }
                        else
                        {
                            raindrops.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] raindrops_keys = raindrops.Keys.ToArray();

                ColorSpectrum drop_spec = new ColorSpectrum(Global.Configuration.idle_effect_primary_color, Color.FromArgb(0, Global.Configuration.idle_effect_primary_color));

                foreach (Devices.DeviceKeys raindrop in raindrops_keys)
                {
                    PointF pt = Effects.GetBitmappingFromDeviceKey(raindrop).Center;

                    float transition_value = 1.0f - raindrops[raindrop];
                    float radius           = transition_value * Effects.canvas_biggest;

                    layer.GetGraphics().DrawEllipse(new Pen(drop_spec.GetColorAt(transition_value), 2),
                                                    pt.X - radius,
                                                    pt.Y - radius,
                                                    2 * radius,
                                                    2 * radius);

                    raindrops[raindrop] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            case IdleEffects.Blackout:
                layer = new EffectLayer("Idle - Blackout");

                layer.Fill(Color.Black);

                layers.Enqueue(layer);
                break;

            case IdleEffects.Matrix:
                layer = new EffectLayer("Idle - Matrix");

                if (nextstarset < currenttime)
                {
                    Color darker_primary = Utils.ColorUtils.MultiplyColorByScalar(Global.Configuration.idle_effect_primary_color, 0.50);

                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        int   width_start = randomizer.Next(Effects.canvas_width);
                        float delay       = randomizer.Next(550) / 100.0f;
                        int   random_id   = randomizer.Next(125536789);

                        //Create animation
                        AnimationTrack matrix_line =
                            new AnimationTrack("Matrix Line (Head) " + random_id, 0.0f).SetFrame(
                                0.0f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, -3, width_start, 0, Global.Configuration.idle_effect_primary_color, 3)).SetFrame(
                                0.5f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, Effects.canvas_height, width_start, Effects.canvas_height + 3, Global.Configuration.idle_effect_primary_color, 3)).SetShift(
                                (currenttime % 1000000L) / 1000.0f + delay
                                );

                        AnimationTrack matrix_line_trail =
                            new AnimationTrack("Matrix Line (Trail) " + random_id, 0.0f).SetFrame(
                                0.0f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, -12, width_start, -3, darker_primary, 3)).SetFrame(
                                0.5f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, Effects.canvas_height - 12, width_start, Effects.canvas_height, darker_primary, 3)).SetFrame(
                                0.75f * 1.0f / (0.05f * Global.Configuration.idle_speed), new AnimationLine(width_start, Effects.canvas_height, width_start, Effects.canvas_height, darker_primary, 3)).SetShift(
                                (currenttime % 1000000L) / 1000.0f + delay
                                );

                        matrix_lines.AddTrack(matrix_line);
                        matrix_lines.AddTrack(matrix_line_trail);
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                using (Graphics g = layer.GetGraphics())
                {
                    matrix_lines.Draw(g, (currenttime % 1000000L) / 1000.0f);
                }

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainFallSmooth:
                layer = new EffectLayer("Idle - RainfallSmooth");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (raindrops.ContainsKey(star))
                        {
                            raindrops[star] = 1.0f;
                        }
                        else
                        {
                            raindrops.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }
                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                ColorSpectrum drop_spec2 = new ColorSpectrum(
                    Global.Configuration.idle_effect_primary_color,
                    Color.FromArgb(0, Global.Configuration.idle_effect_primary_color));

                var drops = raindrops.Keys.ToArray().Select(d =>
                {
                    PointF pt             = Effects.GetBitmappingFromDeviceKey(d).Center;
                    float transitionValue = 1.0f - raindrops[d];
                    float radius          = transitionValue * Effects.canvas_biggest;
                    raindrops[d]         -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                    return(new Tuple <Devices.DeviceKeys, PointF, float, float>(d, pt, transitionValue, radius));
                }).Where(d => d.Item3 <= 1.5).ToArray();

                float circleHalfThickness = 1f;

                foreach (var key in allKeys)
                {
                    var keyInfo = Effects.GetBitmappingFromDeviceKey(key);

                    // For easy calculation every button considered as circle with this radius
                    var btnRadius = ((keyInfo.Width + keyInfo.Height) / 4f);
                    if (btnRadius <= 0)
                    {
                        continue;
                    }

                    foreach (var raindrop in drops)
                    {
                        float circleInEdge  = (raindrop.Item4 - circleHalfThickness);
                        float circleOutEdge = (raindrop.Item4 + circleHalfThickness);
                        circleInEdge  *= circleInEdge;
                        circleOutEdge *= circleOutEdge;

                        float xKey        = Math.Abs(keyInfo.Center.X - raindrop.Item2.X);
                        float yKey        = Math.Abs(keyInfo.Center.Y - raindrop.Item2.Y);
                        float xKeyInEdge  = xKey - btnRadius;
                        float xKeyOutEdge = xKey + btnRadius;
                        float yKeyInEdge  = yKey - btnRadius;
                        float yKeyOutEdge = yKey + btnRadius;
                        float keyInEdge   = xKeyInEdge * xKeyInEdge + yKeyInEdge * yKeyInEdge;
                        float keyOutEdge  = xKeyOutEdge * xKeyOutEdge + yKeyOutEdge * yKeyOutEdge;

                        var btnDiameter    = keyOutEdge - keyInEdge;
                        var inEdgePercent  = (circleOutEdge - keyInEdge) / btnDiameter;
                        var outEdgePercent = (keyOutEdge - circleInEdge) / btnDiameter;
                        var percent        = Math.Min(1, Math.Max(0, inEdgePercent))
                                             + Math.Min(1, Math.Max(0, outEdgePercent)) - 1f;

                        if (percent > 0)
                        {
                            layer.Set(key, (Color)EffectColor.BlendColors(
                                          new EffectColor(layer.Get(key)),
                                          new EffectColor(drop_spec2.GetColorAt(raindrop.Item3)), percent));
                        }
                    }
                }
                layers.Enqueue(layer);
                break;

            default:
                break;
            }

            frame.AddOverlayLayers(layers.ToArray());
        }
예제 #20
0
        public override EffectLayer Render(IGameState gamestate)
        {
            EffectLayer image_layer = new EffectLayer();

            if (!String.IsNullOrWhiteSpace(Properties.ImagePath))
            {
                if (!_loaded_image_path.Equals(Properties.ImagePath))
                {
                    //Not loaded, load it!

                    _loaded_image      = new Bitmap(Properties.ImagePath);
                    _loaded_image_path = Properties.ImagePath;

                    if (Properties.ImagePath.EndsWith(".gif") && ImageAnimator.CanAnimate(_loaded_image))
                    {
                        ImageAnimator.Animate(_loaded_image, null);
                    }
                }

                if (Properties.ImagePath.EndsWith(".gif") && ImageAnimator.CanAnimate(_loaded_image))
                {
                    ImageAnimator.UpdateFrames(_loaded_image);
                }

                temp_layer = new EffectLayer("Temp Image Render");

                if (Properties.Sequence.type == KeySequenceType.Sequence)
                {
                    using (Graphics g = temp_layer.GetGraphics())
                    {
                        g.DrawImage(_loaded_image, new RectangleF(0, 0, Effects.canvas_width, Effects.canvas_height), new RectangleF(0, 0, _loaded_image.Width, _loaded_image.Height), GraphicsUnit.Pixel);
                    }

                    foreach (var key in Properties.Sequence.keys)
                    {
                        image_layer.Set(key, Utils.ColorUtils.AddColors(image_layer.Get(key), temp_layer.Get(key)));
                    }
                }
                else
                {
                    float x_pos  = (float)Math.Round((Properties.Sequence.freeform.X + Effects.grid_baseline_x) * Effects.editor_to_canvas_width);
                    float y_pos  = (float)Math.Round((Properties.Sequence.freeform.Y + Effects.grid_baseline_y) * Effects.editor_to_canvas_height);
                    float width  = (float)Math.Round((double)(Properties.Sequence.freeform.Width * Effects.editor_to_canvas_width));
                    float height = (float)Math.Round((double)(Properties.Sequence.freeform.Height * Effects.editor_to_canvas_height));

                    if (width < 3)
                    {
                        width = 3;
                    }
                    if (height < 3)
                    {
                        height = 3;
                    }

                    Rectangle rect = new Rectangle((int)x_pos, (int)y_pos, (int)width, (int)height);

                    using (Graphics g = temp_layer.GetGraphics())
                    {
                        g.DrawImage(_loaded_image, rect, new RectangleF(0, 0, _loaded_image.Width, _loaded_image.Height), GraphicsUnit.Pixel);
                    }

                    using (Graphics g = image_layer.GetGraphics())
                    {
                        PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));

                        Matrix myMatrix = new Matrix();
                        myMatrix.RotateAt(Properties.Sequence.freeform.Angle, rotatePoint, MatrixOrder.Append);

                        g.Transform = myMatrix;
                        g.DrawImage(temp_layer.GetBitmap(), rect, rect, GraphicsUnit.Pixel);
                    }
                }
            }

            return(image_layer);
        }
예제 #21
0
        public override EffectLayer Render(IGameState gamestate)
        {
            last_use_time = Utils.Time.GetMillisecondsSinceEpoch();

            if (!screenshotTimer.Enabled) // Static timer isn't running, start it!
            {
                screenshotTimer.Start();
            }

            //Handle different capture types
            Image screen_image  = screen;
            Color average_color = avg_color;

            IntPtr foregroundapp;

            User32.Rect app_rect = new User32.Rect();

            switch (Properties.AmbilightCaptureType)
            {
            case AmbilightCaptureType.MainMonitor:

                if (screen_image != null)
                {
                    var newImage = new Bitmap(Effects.canvas_width, Effects.canvas_height);

                    RectangleF prim_scr_region = new RectangleF(
                        Screen.PrimaryScreen.Bounds.X * image_scale_x,
                        Screen.PrimaryScreen.Bounds.Y * image_scale_y,
                        Screen.PrimaryScreen.Bounds.Width * image_scale_x,
                        Screen.PrimaryScreen.Bounds.Height * image_scale_y);

                    using (var graphics = Graphics.FromImage(newImage))
                        graphics.DrawImage(screen_image, new RectangleF(0, 0, Effects.canvas_width, Effects.canvas_height), prim_scr_region, GraphicsUnit.Pixel);

                    screen_image  = newImage;
                    average_color = GetAverageColor(newImage);
                }
                else
                {
                    screen_image  = null;
                    average_color = Color.Empty;
                }

                break;

            case AmbilightCaptureType.ForegroundApp:
                foregroundapp = User32.GetForegroundWindow();
                User32.GetWindowRect(foregroundapp, ref app_rect);

                if (screen_image != null)
                {
                    var newImage = new Bitmap(Effects.canvas_width, Effects.canvas_height);

                    RectangleF scr_region = new RectangleF(
                        app_rect.left * image_scale_x,
                        app_rect.top * image_scale_y,
                        (app_rect.right - app_rect.left) * image_scale_x,
                        (app_rect.bottom - app_rect.top) * image_scale_y);

                    using (var graphics = Graphics.FromImage(newImage))
                        graphics.DrawImage(screen_image, new RectangleF(0, 0, Effects.canvas_width, Effects.canvas_height), scr_region, GraphicsUnit.Pixel);

                    screen_image  = newImage;
                    average_color = GetAverageColor(newImage);
                }
                else
                {
                    screen_image  = null;
                    average_color = Color.Empty;
                }
                break;

            case AmbilightCaptureType.SpecificProcess:

                if (!String.IsNullOrWhiteSpace(Properties.SpecificProcess))
                {
                    var processes = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(Properties.SpecificProcess));

                    if (processes.Length > 0)
                    {
                        User32.GetWindowRect(processes[0].MainWindowHandle, ref app_rect);

                        if (screen_image != null)
                        {
                            var newImage = new Bitmap(Effects.canvas_width, Effects.canvas_height);

                            RectangleF scr_region = new RectangleF(
                                app_rect.left * image_scale_x,
                                app_rect.top * image_scale_y,
                                (app_rect.right - app_rect.left) * image_scale_x,
                                (app_rect.bottom - app_rect.top) * image_scale_y);

                            using (var graphics = Graphics.FromImage(newImage))
                                graphics.DrawImage(screen_image, new RectangleF(0, 0, Effects.canvas_width, Effects.canvas_height), scr_region, GraphicsUnit.Pixel);

                            screen_image  = newImage;
                            average_color = GetAverageColor(newImage);
                        }
                    }
                    else
                    {
                        screen_image  = null;
                        average_color = Color.Empty;
                    }
                }
                else
                {
                    screen_image  = null;
                    average_color = Color.Empty;
                }
                break;
            }

            EffectLayer ambilight_layer = new EffectLayer();

            if (Properties.AmbilightType == AmbilightType.Default)
            {
                using (Graphics g = ambilight_layer.GetGraphics())
                {
                    if (screen_image != null)
                    {
                        g.DrawImageUnscaled(screen_image, 0, 0);
                    }
                }
            }
            else if (Properties.AmbilightType == AmbilightType.AverageColor)
            {
                ambilight_layer.Fill(average_color);
            }

            return(ambilight_layer);
        }
예제 #22
0
        public override void UpdateLights(EffectFrame frame)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            Queue <EffectLayer> layers = new Queue <EffectLayer>();

            float time = (float)Math.Pow(Math.Sin(1.0D * (internalcounter++ / 10.0f)), 2.0d);

            EffectLayer cz_layer = new EffectLayer("Color Zones");

            cz_layer.DrawColorZones((Global.Configuration.desktop_profile.Settings as DesktopSettings).lighting_areas.ToArray());
            layers.Enqueue(cz_layer);

            if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).cpu_usage_enabled)
            {
                EffectLayer cpu = new EffectLayer("CPU");

                if (currentCPUValue - previousCPUValue > 0.0f && transitionalCPUValue < currentCPUValue)
                {
                    transitionalCPUValue += (currentCPUValue - previousCPUValue) / 100.0f;
                }
                else if (currentCPUValue - previousCPUValue < 0.0f && transitionalCPUValue > currentCPUValue)
                {
                    transitionalCPUValue -= (previousCPUValue - currentCPUValue) / 100.0f;
                }
                else if (currentCPUValue - previousCPUValue == 0.0f && transitionalCPUValue != currentCPUValue)
                {
                    transitionalCPUValue = currentCPUValue;
                }

                Color cpu_used = (Global.Configuration.desktop_profile.Settings as DesktopSettings).cpu_used_color;
                Color cpu_free = (Global.Configuration.desktop_profile.Settings as DesktopSettings).cpu_free_color;

                if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).cpu_free_color_transparent)
                {
                    cpu_free = Color.FromArgb(0, cpu_used);
                }

                cpu.PercentEffect(cpu_used, cpu_free, (Global.Configuration.desktop_profile.Settings as DesktopSettings).cpu_sequence, transitionalCPUValue, 100.0f, (Global.Configuration.desktop_profile.Settings as DesktopSettings).cpu_usage_effect_type);

                layers.Enqueue(cpu);
            }

            if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).ram_usage_enabled)
            {
                EffectLayer memory = new EffectLayer("Memory");

                double percentFree     = ((double)memory_Available / (double)memory_Total);
                double percentOccupied = 1.0D - percentFree;

                Color ram_used = (Global.Configuration.desktop_profile.Settings as DesktopSettings).ram_used_color;
                Color ram_free = (Global.Configuration.desktop_profile.Settings as DesktopSettings).ram_free_color;

                if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).ram_free_color_transparent)
                {
                    ram_free = Color.FromArgb(0, ram_used);
                }

                memory.PercentEffect(ram_used, ram_free, (Global.Configuration.desktop_profile.Settings as DesktopSettings).ram_sequence, percentOccupied, 1.0D, (Global.Configuration.desktop_profile.Settings as DesktopSettings).ram_usage_effect_type);

                layers.Enqueue(memory);
            }

            //Scripts before interactive and shortcut assistant layers
            Global.Configuration.desktop_profile.UpdateEffectScripts(layers);

            EffectLayer interactive_layer = new EffectLayer("Interactive Effects");

            foreach (var input in input_list.ToArray())
            {
                if (input == null)
                {
                    continue;
                }

                try
                {
                    if (input.type == input_item.input_type.Spectrum)
                    {
                        float transition_value = input.progress / Effects.canvas_width;

                        if (transition_value > 1.0f)
                        {
                            continue;
                        }

                        Color color = input.spectrum.GetColorAt(transition_value);

                        interactive_layer.Set(input.key, color);
                    }
                    else if (input.type == input_item.input_type.AnimationMix)
                    {
                        float time_value = input.progress / Effects.canvas_width;

                        if (time_value > 1.0f)
                        {
                            continue;
                        }

                        input.animation.Draw(interactive_layer.GetGraphics(), time_value);
                    }
                }
                catch (Exception exc)
                {
                    Global.logger.LogLine("Interative layer exception, " + exc, Logging_Level.Error);
                }
            }

            for (int x = input_list.Count - 1; x >= 0; x--)
            {
                try
                {
                    if (input_list[x].progress > Effects.canvas_width)
                    {
                        input_list.RemoveAt(x);
                    }
                    else
                    {
                        float trans_added = ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_speed * (getDeltaTime() * 5.0f));
                        input_list[x].progress += trans_added;
                    }
                }
                catch (Exception exc)
                {
                    Global.logger.LogLine("Interative layer exception, " + exc, Logging_Level.Error);
                }
            }

            layers.Enqueue(interactive_layer);

            if (Global.Configuration.time_based_dimming_enabled)
            {
                if (
                    Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_end_hour)
                    )
                {
                    layers.Clear();

                    EffectLayer time_based_dim_layer = new EffectLayer("Time Based Dim");
                    time_based_dim_layer.Fill(Color.Black);

                    layers.Enqueue(time_based_dim_layer);
                }
            }

            EffectLayer sc_assistant_layer = new EffectLayer("Shortcut Assistant");

            if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).shortcuts_assistant_enabled)
            {
                if (Global.held_modified == Keys.LControlKey || Global.held_modified == Keys.RControlKey)
                {
                    if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).shortcuts_assistant_bim_bg)
                    {
                        sc_assistant_layer.Fill(Color.FromArgb(169, 0, 0, 0));
                    }

                    if (Global.held_modified == Keys.LControlKey)
                    {
                        sc_assistant_layer.Set(Devices.DeviceKeys.LEFT_CONTROL, (Global.Configuration.desktop_profile.Settings as DesktopSettings).ctrl_key_color);
                    }
                    else
                    {
                        sc_assistant_layer.Set(Devices.DeviceKeys.RIGHT_CONTROL, (Global.Configuration.desktop_profile.Settings as DesktopSettings).ctrl_key_color);
                    }
                    sc_assistant_layer.Set((Global.Configuration.desktop_profile.Settings as DesktopSettings).ctrl_key_sequence, (Global.Configuration.desktop_profile.Settings as DesktopSettings).ctrl_key_color);
                }
                else if (Global.held_modified == Keys.LMenu || Global.held_modified == Keys.RMenu)
                {
                    if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).shortcuts_assistant_bim_bg)
                    {
                        sc_assistant_layer.Fill(Color.FromArgb(169, 0, 0, 0));
                    }

                    if (Global.held_modified == Keys.LMenu)
                    {
                        sc_assistant_layer.Set(Devices.DeviceKeys.LEFT_ALT, (Global.Configuration.desktop_profile.Settings as DesktopSettings).alt_key_color);
                    }
                    else
                    {
                        sc_assistant_layer.Set(Devices.DeviceKeys.RIGHT_ALT, (Global.Configuration.desktop_profile.Settings as DesktopSettings).alt_key_color);
                    }
                    sc_assistant_layer.Set((Global.Configuration.desktop_profile.Settings as DesktopSettings).alt_key_sequence, (Global.Configuration.desktop_profile.Settings as DesktopSettings).alt_key_color);
                }
                else if (Global.held_modified == Keys.LWin || Global.held_modified == Keys.RWin)
                {
                    if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).shortcuts_assistant_bim_bg)
                    {
                        sc_assistant_layer.Fill(Color.FromArgb(169, 0, 0, 0));
                    }

                    if (Global.held_modified == Keys.LWin)
                    {
                        sc_assistant_layer.Set(Devices.DeviceKeys.LEFT_WINDOWS, (Global.Configuration.desktop_profile.Settings as DesktopSettings).win_key_color);
                    }
                    else
                    {
                        sc_assistant_layer.Set(Devices.DeviceKeys.RIGHT_WINDOWS, (Global.Configuration.desktop_profile.Settings as DesktopSettings).win_key_color);
                    }
                    sc_assistant_layer.Set((Global.Configuration.desktop_profile.Settings as DesktopSettings).win_key_sequence, (Global.Configuration.desktop_profile.Settings as DesktopSettings).win_key_color);
                }
            }
            layers.Enqueue(sc_assistant_layer);

            frame.AddLayers(layers.ToArray());
        }
예제 #23
0
        public override EffectLayer Render(IGameState state)
        {
            GameState_EliteDangerous gameState = state as GameState_EliteDangerous;

            previousTime = currentTime;
            currentTime  = Time.GetMillisecondsSinceEpoch();

            EffectLayer animation_layer = new EffectLayer("Elite: Dangerous - Animations");

            if (gameState.Journal.ExitStarClass != StarClass.None)
            {
                RegenerateHyperspaceExitAnimation(gameState.Journal.ExitStarClass);
                gameState.Journal.ExitStarClass = StarClass.None;
                animateOnce        = EliteAnimation.HyperspaceExit;
                totalAnimationTime = 0;
                animationKeyframe  = 0;
            }

            if (animateOnce != EliteAnimation.None)
            {
                currentAnimation = animateOnce;
            }
            else if (gameState.Journal.fsdState == FSDState.Idle)
            {
                currentAnimation = EliteAnimation.None;
            }
            else if (gameState.Journal.fsdState == FSDState.CountdownSupercruise || gameState.Journal.fsdState == FSDState.CountdownHyperspace)
            {
                currentAnimation = EliteAnimation.FsdCountdowm;
            }
            else if (gameState.Journal.fsdState == FSDState.InHyperspace)
            {
                currentAnimation = EliteAnimation.Hyperspace;
            }

            if (currentAnimation == EliteAnimation.None)
            {
                animationKeyframe  = 0;
                totalAnimationTime = 0;
            }

            if ((currentAnimation != EliteAnimation.None && currentAnimation != EliteAnimation.HyperspaceExit) || gameState.Journal.fsdWaitingSupercruise)
            {
                BgFadeIn(animation_layer);
            }
            else if (layerFadeState > 0)
            {
                BgFadeOut(animation_layer);
            }

            float deltaTime = 0f, currentAnimationDuration = 0f;

            if (currentAnimation == EliteAnimation.FsdCountdowm)
            {
                currentAnimationDuration = fsd_countdown_mix.GetDuration();
                fsd_countdown_mix.Draw(animation_layer.GetGraphics(), animationKeyframe);
                deltaTime          = getDeltaTime();
                animationKeyframe += deltaTime;
            }
            else if (currentAnimation == EliteAnimation.Hyperspace)
            {
                currentAnimationDuration = hyperspace_mix.GetDuration();
                hyperspace_mix.Draw(animation_layer.GetGraphics(), animationKeyframe);
                hyperspace_mix.Draw(animation_layer.GetGraphics(), findMod(animationKeyframe + 1.2f, currentAnimationDuration));
                hyperspace_mix.Draw(animation_layer.GetGraphics(), findMod(animationKeyframe + 2.8f, currentAnimationDuration));
                deltaTime = getDeltaTime();
                //Loop the animation
                animationKeyframe = findMod(animationKeyframe + (deltaTime), currentAnimationDuration);
            }
            else if (currentAnimation == EliteAnimation.HyperspaceExit)
            {
                currentAnimationDuration = hypespace_exit_mix.GetDuration();
                hypespace_exit_mix.Draw(animation_layer.GetGraphics(), animationKeyframe);
                deltaTime = getDeltaTime();

                animationKeyframe += deltaTime;
            }

            totalAnimationTime += deltaTime;
            if (totalAnimationTime > currentAnimationDuration)
            {
                animateOnce = EliteAnimation.None;
            }

            return(animation_layer);
        }