Browse Source

Duplicate frame

flabbet 1 year ago
parent
commit
85ca774d0b

+ 4 - 0
src/PixiEditor.AvaloniaUI/Styles/Templates/Timeline.axaml

@@ -29,6 +29,10 @@
                         <Button DockPanel.Dock="Left" Classes="pixi-icon"
                                 Content="{DynamicResource icon-plus-square}"
                                 Command="{TemplateBinding NewKeyFrameCommand}"/>
+                        
+                        <Button DockPanel.Dock="Left" Classes="pixi-icon"
+                                Content="{DynamicResource icon-duplicate}"
+                                Command="{TemplateBinding DuplicateKeyFrameCommand}"/>
                         <Panel>
                             <ToggleButton HorizontalAlignment="Center" Content="Play" Name="PART_PlayToggle"/>
                         </Panel>

+ 4 - 3
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/AnimationsViewModel.cs

@@ -11,8 +11,9 @@ internal class AnimationsViewModel : SubViewModel<ViewModelMain>
         
     }
     
-    [Command.Basic("PixiEditor.Animation.CreateRasterKeyFrame", "Create Raster Key Frame", "Create a raster key frame")]
-    public void CreateRasterClip()
+    [Command.Basic("PixiEditor.Animation.CreateRasterKeyFrame", "Create Raster Key Frame", "Create a raster key frame", Parameter = false)]
+    [Command.Basic("PixiEditor.Animation.DuplicateRasterKeyFrame", "Duplicate Raster Key Frame", "Duplicate a raster key frame", Parameter = true)]
+    public void CreateRasterClip(bool duplicate)
     {
         var activeDocument = Owner.DocumentManagerSubViewModel.ActiveDocument;
         if (activeDocument == null)
@@ -30,7 +31,7 @@ internal class AnimationsViewModel : SubViewModel<ViewModelMain>
         activeDocument.AnimationDataViewModel.CreateRasterKeyFrame(
             activeDocument.SelectedStructureMember.GuidValue, 
             newFrame,
-            false);
+            duplicate);
     }
     
     [Command.Internal("PixiEditor.Document.StartChangeActiveFrame", CanExecute = "PixiEditor.HasDocument")]

+ 11 - 2
src/PixiEditor.AvaloniaUI/Views/Animations/Timeline.cs

@@ -33,6 +33,15 @@ public class Timeline : TemplatedControl
         set => SetValue(NewKeyFrameCommandProperty, value);
     }
 
+    public static readonly StyledProperty<ICommand> DuplicateKeyFrameCommandProperty = AvaloniaProperty.Register<Timeline, ICommand>(
+        "DuplicateKeyFrameCommand");
+
+    public ICommand DuplicateKeyFrameCommand
+    {
+        get => GetValue(DuplicateKeyFrameCommandProperty);
+        set => SetValue(DuplicateKeyFrameCommandProperty, value);
+    }
+
     public bool IsPlaying
     {
         get => GetValue(IsPlayingProperty);
@@ -61,7 +70,7 @@ public class Timeline : TemplatedControl
 
     public Timeline()
     {
-        _playTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1000 / 60f) };
+        _playTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1000 / 8f) };
         _playTimer.Tick += PlayTimerOnTick;
     }
 
@@ -80,7 +89,7 @@ public class Timeline : TemplatedControl
     {
         ActiveFrame++;
         
-        if (ActiveFrame >= KeyFrames.Count)
+        if (ActiveFrame >= KeyFrames.FrameCount)
         {
             ActiveFrame = 0;
         }

+ 2 - 1
src/PixiEditor.AvaloniaUI/Views/Dock/TimelineDockView.axaml

@@ -15,5 +15,6 @@
     <animations:Timeline 
         KeyFrames="{Binding DocumentManagerSubViewModel.ActiveDocument.AnimationDataViewModel.KeyFrames}" 
         ActiveFrame="{Binding DocumentManagerSubViewModel.ActiveDocument.AnimationDataViewModel.ActiveFrameBindable, Mode=TwoWay}"
-        NewKeyFrameCommand="{xaml:Command PixiEditor.Animation.CreateRasterKeyFrame}"/>
+        NewKeyFrameCommand="{xaml:Command PixiEditor.Animation.CreateRasterKeyFrame}"
+        DuplicateKeyFrameCommand="{xaml:Command PixiEditor.Animation.DuplicateRasterKeyFrame}"/>
 </UserControl>