| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using ChunkyImageLib;
- using CommunityToolkit.Mvvm.ComponentModel;
- using PixiEditor.ChangeableDocument.Actions.Generated;
- using Drawie.Backend.Core;
- using PixiEditor.Models.DocumentModels;
- using PixiEditor.Models.Handlers;
- using PixiEditor.Models.Rendering;
- namespace PixiEditor.ViewModels.Document;
- internal abstract class CelViewModel : ObservableObject, ICelHandler
- {
- private PreviewPainter? previewPainter;
- private int startFrameBindable;
- private int durationBindable;
- private bool isVisibleBindable = true;
- private bool isSelected;
- private bool isCollapsed;
- public bool IsCollapsed
- {
- get => isCollapsed;
- set => SetProperty(ref isCollapsed, value);
- }
- public DocumentViewModel Document { get; }
- protected DocumentInternalParts Internals { get; }
- IDocument ICelHandler.Document => Document;
- public PreviewPainter? PreviewPainter
- {
- get => previewPainter;
- set => SetProperty(ref previewPainter, value);
- }
- public virtual int StartFrameBindable
- {
- get => startFrameBindable;
- set
- {
- if (value < 0)
- {
- value = 0;
- }
- if (!Document.BlockingUpdateableChangeActive)
- {
- Internals.ActionAccumulator.AddFinishedActions(
- new KeyFrameLength_Action(Id, value, DurationBindable),
- new EndKeyFrameLength_Action());
- }
- }
- }
- public virtual int DurationBindable
- {
- get => durationBindable;
- set
- {
- if (value < 1)
- {
- value = 1;
- }
- if (!Document.BlockingUpdateableChangeActive)
- {
- Internals.ActionAccumulator.AddFinishedActions(
- new KeyFrameLength_Action(Id, StartFrameBindable, value),
- new EndKeyFrameLength_Action());
- }
- }
- }
- public virtual bool IsVisible
- {
- get => isVisibleBindable;
- set
- {
- if (!Document.BlockingUpdateableChangeActive)
- {
- Internals.ActionAccumulator.AddFinishedActions(new KeyFrameVisibility_Action(Id, value));
- }
- }
- }
- public Guid LayerGuid { get; }
- public Guid Id { get; }
- public bool IsSelected
- {
- get => isSelected;
- set
- {
- if (StartFrameBindable == 0) return;
- SetProperty(ref isSelected, value);
- }
- }
- protected CelViewModel(int startFrame, int duration, Guid layerGuid, Guid id,
- DocumentViewModel document, DocumentInternalParts internalParts)
- {
- startFrameBindable = startFrame;
- durationBindable = duration;
- LayerGuid = layerGuid;
- Id = id;
- Document = document;
- Internals = internalParts;
- }
- public void SetStartFrame(int newStartFrame)
- {
- startFrameBindable = newStartFrame;
- OnPropertyChanged(nameof(StartFrameBindable));
- }
- public void SetDuration(int newDuration)
- {
- durationBindable = newDuration;
- OnPropertyChanged(nameof(DurationBindable));
- }
- public void ChangeFrameLength(int newStartFrame, int newDuration)
- {
- newStartFrame = Math.Max(0, newStartFrame);
- newDuration = Math.Max(1, newDuration);
- Internals.ActionAccumulator.AddActions(
- new KeyFrameLength_Action(Id, newStartFrame, newDuration));
- }
- public void EndChangeFrameLength()
- {
- Internals.ActionAccumulator.AddFinishedActions(new EndKeyFrameLength_Action());
- }
- public virtual void SetVisibility(bool isVisible)
- {
- isVisibleBindable = isVisible;
- OnPropertyChanged(nameof(IsVisible));
- }
- public bool IsWithinRange(int frame)
- {
- return frame >= StartFrameBindable && frame < StartFrameBindable + DurationBindable;
- }
- public void Dispose()
- {
- PreviewPainter?.Dispose();
- PreviewPainter = null;
- }
- }
|