Skip to content

Commit

Permalink
Wave animation in the gradient Layer
Browse files Browse the repository at this point in the history
  • Loading branch information
xQwexx committed Dec 8, 2019
1 parent 9a447c9 commit fa78c50
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Project-Aurora/Project-Aurora/Settings/LayerEffectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class LayerEffectConfig
public Color secondary;
public float speed;
public float angle;
public float gradient_size = 100.0f;
public AnimationType animation_type;
public bool animation_reverse;
public EffectBrush brush;
Expand All @@ -35,6 +36,7 @@ public class LayerEffectConfig
[JsonIgnore] public Color Secondary { get => secondary; set => secondary = value; }
[JsonIgnore] public float Speed { get => speed; set => speed = value; }
[JsonIgnore] public float Angle { get => angle; set => angle = value; }
[JsonIgnore] public float GradientSize { get => gradient_size; set => gradient_size = value; }
[JsonIgnore] public AnimationType AnimationType { get => animation_type; set => animation_type = value; }
[JsonIgnore] public bool AnimationReverse { get => animation_reverse; set => animation_reverse = value; }
[JsonIgnore] public EffectBrush Brush { get => brush; set => brush = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@
<Grid>
<Controls:KeySequence x:Name="KeySequence_keys" Margin="265,0,0,24" HorizontalAlignment="Left" Width="230" RecordingTag="SolidColorLayer" Title="Affected Keys" SequenceUpdated="KeySequence_keys_SequenceUpdated"/>
<ncore:ColorBox x:Name="gradient_editor" HorizontalAlignment="Left" Height="80" Margin="0,21,0,0" VerticalAlignment="Top" Width="260" BrushChanged="Gradient_editor_BrushChanged"/>
<TextBlock HorizontalAlignment="Left" Margin="0,133,0,0" TextWrapping="Wrap" Text="Effect Speed: " VerticalAlignment="Top"/>
<Slider x:Name="effect_speed_slider" HorizontalAlignment="Left" Margin="80,133,0,0" VerticalAlignment="Top" Width="140" Minimum="1" SmallChange="0.5" SelectionStart="6" IsSnapToTickEnabled="True" TickFrequency="0.25" Maximum="10" ValueChanged="effect_speed_slider_ValueChanged"/>
<TextBlock x:Name="effect_speed_label" HorizontalAlignment="Left" Margin="225,133,0,0" TextWrapping="Wrap" Text="x 1.0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="0,132,0,0" TextWrapping="Wrap" Text="Wave Size: " VerticalAlignment="Top"/>
<Slider x:Name="wave_size_slider" HorizontalAlignment="Left" Margin="80,132,0,0" VerticalAlignment="Top" Width="140" Minimum="0" SmallChange="1" SelectionStart="100" IsSnapToTickEnabled="True" TickFrequency="0.25" Maximum="100" ValueChanged="wave_size_slider_ValueChanged"/>
<TextBlock x:Name="wave_size_label" HorizontalAlignment="Left" Margin="225,132,0,0" TextWrapping="Wrap" Text="100 %" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="0,156,0,0" TextWrapping="Wrap" Text="Effect Speed: " VerticalAlignment="Top"/>
<Slider x:Name="effect_speed_slider" HorizontalAlignment="Left" Margin="80,156,0,0" VerticalAlignment="Top" Width="140" Minimum="1" SmallChange="0.5" SelectionStart="6" IsSnapToTickEnabled="True" TickFrequency="0.25" Maximum="10" ValueChanged="effect_speed_slider_ValueChanged"/>
<TextBlock x:Name="effect_speed_label" HorizontalAlignment="Left" Margin="225,156,0,0" TextWrapping="Wrap" Text="x 1.0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Gradient: " VerticalAlignment="Top"/>
<Button x:Name="Button_SetGradientRainbow" Content="Set to Rainbow" HorizontalAlignment="Left" Margin="0,106,0,0" VerticalAlignment="Top" Click="Button_SetGradientRainbow_Click"/>
<Button x:Name="Button_SetGradientRainbowLoop" Content="Set to Rainbow (Seamless)" Margin="91,106,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="145" Click="Button_SetGradientRainbowLoop_Click"/>
<TextBlock HorizontalAlignment="Left" Margin="0,160,0,0" TextWrapping="Wrap" Text="Effect Angle: " VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="139,160,0,0" TextWrapping="Wrap" Text="degrees" VerticalAlignment="Top"/>
<xctk:IntegerUpDown x:Name="effect_angle" HorizontalAlignment="Left" Height="20" Margin="74,160,0,0" VerticalAlignment="Top" Width="60" Value="0" Minimum="-360" Maximum="360" Increment="1" ValueChanged="effect_angle_ValueChanged"/>
<TextBlock HorizontalAlignment="Left" Margin="0,188,0,0" TextWrapping="Wrap" Text="Animation Type: " VerticalAlignment="Top"/>
<ComboBox x:Name="effect_animation_type" HorizontalAlignment="Left" Margin="94,185,0,0" VerticalAlignment="Top" Width="155" IsSynchronizedWithCurrentItem="True" SelectedIndex="0" ItemsSource="{Binding Source={StaticResource AnimationType}}" ItemTemplate="{Binding Source={StaticResource AnimationTypeTemplate}}" SelectionChanged="effect_animation_type_SelectionChanged"/>
<CheckBox x:Name="effect_animation_reversed" Content="Reverse animation direction" HorizontalAlignment="Left" Margin="0,212,0,0" VerticalAlignment="Top" Checked="effect_animation_reversed_Checked" Unchecked="effect_animation_reversed_Checked"/>
<TextBlock HorizontalAlignment="Left" Margin="0,183,0,0" TextWrapping="Wrap" Text="Effect Angle: " VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="139,183,0,0" TextWrapping="Wrap" Text="degrees" VerticalAlignment="Top"/>
<xctk:IntegerUpDown x:Name="effect_angle" HorizontalAlignment="Left" Height="20" Margin="74,183,0,0" VerticalAlignment="Top" Width="60" Value="0" Minimum="-360" Maximum="360" Increment="1" ValueChanged="effect_angle_ValueChanged"/>
<TextBlock HorizontalAlignment="Left" Margin="0,211,0,0" TextWrapping="Wrap" Text="Animation Type: " VerticalAlignment="Top"/>
<ComboBox x:Name="effect_animation_type" HorizontalAlignment="Left" Margin="94,208,0,-3" VerticalAlignment="Top" Width="155" IsSynchronizedWithCurrentItem="True" SelectedIndex="0" ItemsSource="{Binding Source={StaticResource AnimationType}}" ItemTemplate="{Binding Source={StaticResource AnimationTypeTemplate}}" SelectionChanged="effect_animation_type_SelectionChanged"/>
<CheckBox x:Name="effect_animation_reversed" Content="Reverse animation direction" HorizontalAlignment="Left" Margin="0,235,0,-23" VerticalAlignment="Top" Checked="effect_animation_reversed_Checked" Unchecked="effect_animation_reversed_Checked"/>

</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void SetSettings()
{
if(this.DataContext is GradientLayerHandler && !settingsset)
{
this.wave_size_slider.Value = (this.DataContext as GradientLayerHandler).Properties.GradientConfig.gradient_size;
this.wave_size_label.Text = (this.DataContext as GradientLayerHandler).Properties.GradientConfig.gradient_size + " %";
this.effect_speed_slider.Value = (this.DataContext as GradientLayerHandler).Properties._GradientConfig.speed;
this.effect_speed_label.Text = "x " + (this.DataContext as GradientLayerHandler).Properties._GradientConfig.speed;
this.effect_angle.Text = (this.DataContext as GradientLayerHandler).Properties._GradientConfig.angle.ToString();
Expand Down Expand Up @@ -96,7 +98,6 @@ private void Button_SetGradientRainbowLoop_Click(object sender, RoutedEventArgs
Global.logger.Error("Could not set brush, exception: " + exc);
}
}

private void effect_speed_slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (IsLoaded && settingsset && this.DataContext is GradientLayerHandler && sender is Slider)
Expand All @@ -108,6 +109,24 @@ private void effect_speed_slider_ValueChanged(object sender, RoutedPropertyChang
}
}

private void wave_size_slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (IsLoaded && settingsset && this.DataContext is GradientLayerHandler && sender is Slider)
{
(this.DataContext as GradientLayerHandler).Properties.GradientConfig.gradient_size = (float)(sender as Slider).Value;

if (this.wave_size_label is TextBlock)

{
this.wave_size_label.Text = (sender as Slider).Value + " %";
if ((sender as Slider).Value == 0)
{
this.wave_size_label.Text = "Stop";
}
}
}
}

private void effect_angle_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (IsLoaded && settingsset && this.DataContext is GradientLayerHandler && sender is IntegerUpDown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,27 @@ protected override UserControl CreateControl()

public override EffectLayer Render(IGameState gamestate)
{

EffectLayer gradient_layer = new EffectLayer();

if (Properties.Sequence.type == KeySequenceType.Sequence)
//If Wave Size 0 Gradiant Stop Moving Animation
if (Properties.GradientConfig.gradient_size == 0)
{
temp_layer = new EffectLayer("Color Zone Effect", LayerEffects.GradientShift_Custom_Angle, Properties.GradientConfig);
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);

foreach (var key in Properties.Sequence.keys)
gradient_layer.Set(key, Utils.ColorUtils.AddColors(gradient_layer.Get(key), temp_layer.Get(key)));
gradient_layer.Set(Properties.Sequence, selected_color);
}
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));

float width = (float)Math.Round((double)(10500.0f - ((Properties.GradientConfig.gradient_size) * 100f)) * Effects.editor_to_canvas_width);
float height = (float)Math.Round((double)(10500.0f - ((Properties.GradientConfig.gradient_size) * 100f)) * Effects.editor_to_canvas_height);

if (width < 3) width = 3;
if (height < 3) height = 3;
Expand All @@ -73,18 +79,26 @@ public override EffectLayer Render(IGameState gamestate)

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

using (Graphics g = gradient_layer.GetGraphics())
if (Properties.Sequence.type == KeySequenceType.Sequence)
{
PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));
foreach (var key in Properties.Sequence.keys)
gradient_layer.Set(key, Utils.ColorUtils.AddColors(gradient_layer.Get(key), temp_layer.Get(key)));
}
else
{

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);
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);
g.Transform = myMatrix;
g.DrawImage(temp_layer.GetBitmap(), rect, rect, GraphicsUnit.Pixel);
}
}
}

return gradient_layer;
}
}
Expand Down

0 comments on commit fa78c50

Please sign in to comment.