mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Profile editor - Improved scrubbing past layer timeline bounds
This commit is contained in:
parent
2105cf5e1d
commit
9fd0f921b5
@ -12,7 +12,7 @@ namespace Artemis.Core
|
|||||||
public class Timeline : CorePropertyChanged, IStorageModel
|
public class Timeline : CorePropertyChanged, IStorageModel
|
||||||
{
|
{
|
||||||
private const int MaxExtraTimelines = 15;
|
private const int MaxExtraTimelines = 15;
|
||||||
private readonly object _lock = new();
|
private readonly object _lock = new ();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="Timeline" /> class
|
/// Creates a new instance of the <see cref="Timeline" /> class
|
||||||
@ -306,6 +306,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#region Updating
|
#region Updating
|
||||||
|
|
||||||
|
private TimeSpan _lastOverridePosition;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the timeline, applying the provided <paramref name="delta" /> to the <see cref="Position" />
|
/// Updates the timeline, applying the provided <paramref name="delta" /> to the <see cref="Position" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -317,9 +319,11 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
Delta += delta;
|
Delta += delta;
|
||||||
Position += delta;
|
Position += delta;
|
||||||
IsOverridden = false;
|
|
||||||
|
|
||||||
if (stickToMainSegment && Position >= MainSegmentEndPosition)
|
IsOverridden = false;
|
||||||
|
_lastOverridePosition = Position;
|
||||||
|
|
||||||
|
if (stickToMainSegment && Position > MainSegmentEndPosition)
|
||||||
{
|
{
|
||||||
// If the main segment has no length, simply stick to the start of the segment
|
// If the main segment has no length, simply stick to the start of the segment
|
||||||
if (MainSegmentLength == TimeSpan.Zero)
|
if (MainSegmentLength == TimeSpan.Zero)
|
||||||
@ -389,14 +393,23 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
Delta += position - Position;
|
Delta += position - _lastOverridePosition;
|
||||||
Position = position;
|
Position = position;
|
||||||
|
|
||||||
IsOverridden = true;
|
IsOverridden = true;
|
||||||
|
_lastOverridePosition = position;
|
||||||
|
|
||||||
if (stickToMainSegment && Position >= MainSegmentStartPosition)
|
if (stickToMainSegment && Position >= MainSegmentStartPosition)
|
||||||
{
|
{
|
||||||
|
bool atSegmentStart = Position == MainSegmentStartPosition;
|
||||||
if (MainSegmentLength > TimeSpan.Zero)
|
if (MainSegmentLength > TimeSpan.Zero)
|
||||||
|
{
|
||||||
Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds);
|
Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds);
|
||||||
|
// If the cursor is at the end of the timeline we don't want to wrap back around yet so only allow going to the start if the cursor
|
||||||
|
// is actually at the start of the segment
|
||||||
|
if (Position == MainSegmentStartPosition && !atSegmentStart)
|
||||||
|
Position = MainSegmentEndPosition;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Position = MainSegmentStartPosition;
|
Position = MainSegmentStartPosition;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -85,9 +85,6 @@ namespace Artemis.UI.Shared.Services
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_currentTime.Equals(value)) return;
|
if (_currentTime.Equals(value)) return;
|
||||||
if (SelectedProfileElement != null && value > SelectedProfileElement.Timeline.Length)
|
|
||||||
_currentTime = SelectedProfileElement.Timeline.Length;
|
|
||||||
else
|
|
||||||
_currentTime = value;
|
_currentTime = value;
|
||||||
UpdateProfilePreview();
|
UpdateProfilePreview();
|
||||||
OnCurrentTimeChanged();
|
OnCurrentTimeChanged();
|
||||||
@ -188,9 +185,9 @@ namespace Artemis.UI.Shared.Services
|
|||||||
|
|
||||||
// Stick to the main segment for any element that is not currently selected
|
// Stick to the main segment for any element that is not currently selected
|
||||||
foreach (Folder folder in SelectedProfile.GetAllFolders())
|
foreach (Folder folder in SelectedProfile.GetAllFolders())
|
||||||
folder.Timeline.Override(CurrentTime, folder != SelectedProfileElement && folder.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
folder.Timeline.Override(CurrentTime, folder.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
||||||
foreach (Layer layer in SelectedProfile.GetAllLayers())
|
foreach (Layer layer in SelectedProfile.GetAllLayers())
|
||||||
layer.Timeline.Override(CurrentTime, layer != SelectedProfileElement && layer.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
layer.Timeline.Override(CurrentTime, (layer != SelectedProfileElement || layer.Timeline.Length < CurrentTime) && layer.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
||||||
|
|
||||||
_coreService.FrameRendered += CoreServiceOnFrameRendered;
|
_coreService.FrameRendered += CoreServiceOnFrameRendered;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,8 +127,12 @@
|
|||||||
<TextBlock Text="Repeat segment"
|
<TextBlock Text="Repeat segment"
|
||||||
Visibility="{Binding RepeatSegment, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" />
|
Visibility="{Binding RepeatSegment, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<TextBlock Visibility="{Binding Repeating, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">Don't repeat the timeline</TextBlock>
|
<TextBlock Visibility="{Binding Repeating, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
||||||
<TextBlock>This setting only applies to the editor and <Run Text="does not" FontWeight="Bold" /> affect the repeat mode during profile use</TextBlock>
|
Don't repeat the timeline
|
||||||
|
</TextBlock>
|
||||||
|
<TextBlock TextWrapping="Wrap">
|
||||||
|
This setting only applies to the editor and <Run Text="does not" FontWeight="Bold" /> affect the repeat mode during normal profile playback
|
||||||
|
</TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</shared:LockableToggleButton.ToolTip>
|
</shared:LockableToggleButton.ToolTip>
|
||||||
<Grid>
|
<Grid>
|
||||||
@ -223,6 +227,18 @@
|
|||||||
<ContentControl Canvas.Left="{Binding MainTimelineSegmentViewModel.SegmentStartPosition}" s:View.Model="{Binding MainTimelineSegmentViewModel}" />
|
<ContentControl Canvas.Left="{Binding MainTimelineSegmentViewModel.SegmentStartPosition}" s:View.Model="{Binding MainTimelineSegmentViewModel}" />
|
||||||
<ContentControl Canvas.Left="{Binding StartTimelineSegmentViewModel.SegmentStartPosition}" s:View.Model="{Binding StartTimelineSegmentViewModel}" />
|
<ContentControl Canvas.Left="{Binding StartTimelineSegmentViewModel.SegmentStartPosition}" s:View.Model="{Binding StartTimelineSegmentViewModel}" />
|
||||||
|
|
||||||
|
<!-- Timeline header body -->
|
||||||
|
<controls:PropertyTimelineHeader Margin="0 18 0 0"
|
||||||
|
Foreground="{DynamicResource MaterialDesignBody}"
|
||||||
|
Background="{DynamicResource MaterialDesignCardBackground}"
|
||||||
|
PixelsPerSecond="{Binding ProfileEditorService.PixelsPerSecond}"
|
||||||
|
HorizontalOffset="{Binding ContentHorizontalOffset, ElementName=TimelineHeaderScrollViewer}"
|
||||||
|
VisibleWidth="{Binding ActualWidth, ElementName=TimelineHeaderScrollViewer}"
|
||||||
|
OffsetFirstValue="True"
|
||||||
|
MouseLeftButtonUp="{s:Action TimelineJump}"
|
||||||
|
Width="{Binding ActualWidth, ElementName=PropertyTimeLine}"
|
||||||
|
Cursor="Hand"/>
|
||||||
|
|
||||||
<!-- Timeline caret -->
|
<!-- Timeline caret -->
|
||||||
<Polygon Canvas.Left="{Binding TimeCaretPosition}"
|
<Polygon Canvas.Left="{Binding TimeCaretPosition}"
|
||||||
Cursor="SizeWE"
|
Cursor="SizeWE"
|
||||||
@ -242,16 +258,6 @@
|
|||||||
Y2="{Binding ActualHeight, ElementName=ContainerGrid}"
|
Y2="{Binding ActualHeight, ElementName=ContainerGrid}"
|
||||||
StrokeThickness="2"
|
StrokeThickness="2"
|
||||||
Stroke="{StaticResource SecondaryAccentBrush}" />
|
Stroke="{StaticResource SecondaryAccentBrush}" />
|
||||||
|
|
||||||
|
|
||||||
<!-- Timeline header body -->
|
|
||||||
<controls:PropertyTimelineHeader Margin="0 18 0 0"
|
|
||||||
Fill="{DynamicResource MaterialDesignBody}"
|
|
||||||
PixelsPerSecond="{Binding ProfileEditorService.PixelsPerSecond}"
|
|
||||||
HorizontalOffset="{Binding ContentHorizontalOffset, ElementName=TimelineHeaderScrollViewer}"
|
|
||||||
VisibleWidth="{Binding ActualWidth, ElementName=TimelineHeaderScrollViewer}"
|
|
||||||
OffsetFirstValue="True"
|
|
||||||
Width="{Binding ActualWidth, ElementName=PropertyTimeLine}" />
|
|
||||||
</Canvas>
|
</Canvas>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
|
||||||
|
|||||||
@ -486,7 +486,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
|||||||
|
|
||||||
public void GoToEnd()
|
public void GoToEnd()
|
||||||
{
|
{
|
||||||
ProfileEditorService.CurrentTime = CalculateEndTime();
|
ProfileEditorService.CurrentTime = SelectedProfileElement.Timeline.EndSegmentEndPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoToPreviousFrame()
|
public void GoToPreviousFrame()
|
||||||
@ -500,7 +500,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
|||||||
{
|
{
|
||||||
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
||||||
double newTime = Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds + frameTime) / frameTime) * frameTime;
|
double newTime = Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds + frameTime) / frameTime) * frameTime;
|
||||||
newTime = Math.Min(newTime, CalculateEndTime().TotalMilliseconds);
|
newTime = Math.Min(newTime, SelectedProfileElement.Timeline.EndSegmentEndPosition.TotalMilliseconds);
|
||||||
ProfileEditorService.CurrentTime = TimeSpan.FromMilliseconds(newTime);
|
ProfileEditorService.CurrentTime = TimeSpan.FromMilliseconds(newTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,17 +525,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeSpan CalculateEndTime()
|
|
||||||
{
|
|
||||||
List<ITimelineKeyframeViewModel> keyframeViewModels = Items.SelectMany(g => g.GetAllKeyframeViewModels(false)).ToList();
|
|
||||||
|
|
||||||
// If there are no keyframes, don't stop at all
|
|
||||||
if (!keyframeViewModels.Any())
|
|
||||||
return TimeSpan.MaxValue;
|
|
||||||
// If there are keyframes, stop after the last keyframe + 10 sec
|
|
||||||
return keyframeViewModels.Max(k => k.Position).Add(TimeSpan.FromSeconds(10));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TimeSpan GetCurrentSegmentStart()
|
private TimeSpan GetCurrentSegmentStart()
|
||||||
{
|
{
|
||||||
TimeSpan current = ProfileEditorService.CurrentTime;
|
TimeSpan current = ProfileEditorService.CurrentTime;
|
||||||
@ -642,6 +631,24 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TimelineJump(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
// Get the parent grid, need that for our position
|
||||||
|
IInputElement parent = (IInputElement)VisualTreeHelper.GetParent((DependencyObject)sender);
|
||||||
|
double x = Math.Max(0, e.GetPosition(parent).X);
|
||||||
|
TimeSpan newTime = TimeSpan.FromSeconds(x / ProfileEditorService.PixelsPerSecond);
|
||||||
|
|
||||||
|
// Round the time to something that fits the current zoom level
|
||||||
|
if (ProfileEditorService.PixelsPerSecond < 200)
|
||||||
|
newTime = TimeSpan.FromMilliseconds(Math.Round(newTime.TotalMilliseconds / 5.0) * 5.0);
|
||||||
|
else if (ProfileEditorService.PixelsPerSecond < 500)
|
||||||
|
newTime = TimeSpan.FromMilliseconds(Math.Round(newTime.TotalMilliseconds / 2.0) * 2.0);
|
||||||
|
else
|
||||||
|
newTime = TimeSpan.FromMilliseconds(Math.Round(newTime.TotalMilliseconds));
|
||||||
|
|
||||||
|
ProfileEditorService.CurrentTime = newTime;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,7 +8,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Controls
|
|||||||
{
|
{
|
||||||
public class PropertyTimelineHeader : FrameworkElement
|
public class PropertyTimelineHeader : FrameworkElement
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty FillProperty = DependencyProperty.Register(nameof(Fill), typeof(Brush), typeof(PropertyTimelineHeader),
|
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register(nameof(Foreground), typeof(Brush), typeof(PropertyTimelineHeader),
|
||||||
|
new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.AffectsRender));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register(nameof(Background), typeof(Brush), typeof(PropertyTimelineHeader),
|
||||||
new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.AffectsRender));
|
new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.AffectsRender));
|
||||||
|
|
||||||
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(nameof(FontFamily), typeof(FontFamily), typeof(PropertyTimelineHeader),
|
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(nameof(FontFamily), typeof(FontFamily), typeof(PropertyTimelineHeader),
|
||||||
@ -30,10 +33,16 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Controls
|
|||||||
private double _subd2;
|
private double _subd2;
|
||||||
private double _subd3;
|
private double _subd3;
|
||||||
|
|
||||||
public Brush Fill
|
public Brush Foreground
|
||||||
{
|
{
|
||||||
get => (Brush) GetValue(FillProperty);
|
get => (Brush) GetValue(ForegroundProperty);
|
||||||
set => SetValue(FillProperty, value);
|
set => SetValue(ForegroundProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Brush Background
|
||||||
|
{
|
||||||
|
get => (Brush) GetValue(BackgroundProperty);
|
||||||
|
set => SetValue(BackgroundProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FontFamily FontFamily
|
public FontFamily FontFamily
|
||||||
@ -71,7 +80,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Controls
|
|||||||
base.OnRender(drawingContext);
|
base.OnRender(drawingContext);
|
||||||
UpdateTimeScale();
|
UpdateTimeScale();
|
||||||
|
|
||||||
Pen linePen = new(Fill, 1);
|
if (Background != null)
|
||||||
|
drawingContext.DrawRectangle(Background, null, new Rect(0,0, ActualWidth, 30));
|
||||||
|
|
||||||
|
Pen linePen = new(Foreground, 1);
|
||||||
double width = HorizontalOffset + VisibleWidth;
|
double width = HorizontalOffset + VisibleWidth;
|
||||||
int frameStart = 0;
|
int frameStart = 0;
|
||||||
|
|
||||||
@ -127,7 +139,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Controls
|
|||||||
private void RenderLabel(DrawingContext drawingContext, string text, double x)
|
private void RenderLabel(DrawingContext drawingContext, string text, double x)
|
||||||
{
|
{
|
||||||
Typeface typeFace = new(FontFamily, new FontStyle(), new FontWeight(), new FontStretch());
|
Typeface typeFace = new(FontFamily, new FontStyle(), new FontWeight(), new FontStretch());
|
||||||
FormattedText formattedText = new(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeFace, 9, Fill, null, VisualTreeHelper.GetDpi(this).PixelsPerDip);
|
FormattedText formattedText = new(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeFace, 9, Foreground, null, VisualTreeHelper.GetDpi(this).PixelsPerDip);
|
||||||
if (x == 0 && OffsetFirstValue)
|
if (x == 0 && OffsetFirstValue)
|
||||||
drawingContext.DrawText(formattedText, new Point(2, 5));
|
drawingContext.DrawText(formattedText, new Point(2, 5));
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user