diff --git a/CommonWPF/CommonWPF.csproj b/CommonWPF/CommonWPF.csproj index 101b77e..a452ff1 100644 --- a/CommonWPF/CommonWPF.csproj +++ b/CommonWPF/CommonWPF.csproj @@ -48,6 +48,9 @@ + + FrameAnimationControl.xaml + @@ -79,6 +82,10 @@ + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/CommonWPF/FrameAnimationControl.xaml b/CommonWPF/FrameAnimationControl.xaml new file mode 100644 index 0000000..778441e --- /dev/null +++ b/CommonWPF/FrameAnimationControl.xaml @@ -0,0 +1,37 @@ + + + + + + + + diff --git a/CommonWPF/FrameAnimationControl.xaml.cs b/CommonWPF/FrameAnimationControl.xaml.cs new file mode 100644 index 0000000..c01be07 --- /dev/null +++ b/CommonWPF/FrameAnimationControl.xaml.cs @@ -0,0 +1,111 @@ +/* + * Copyright 2019 faddenSoft + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Windows.Controls; +using System.Windows.Media.Imaging; +using System.Windows.Threading; + +namespace CommonWPF { + /// + /// The Frame Animation control provides a simple way to display a series of images. + /// (Think of an animated GIF.) + /// + /// Set Bitmaps and IntervalMsec, then call Start. + /// + public partial class FrameAnimationControl : UserControl { + /// + /// List of bitmaps to be displayed. + /// + public List Bitmaps { + get { return mBitmaps; } + set { + if (value == null || value.Count == 0) { + throw new ArgumentException("Invalid bitmap list"); + } + mBitmaps = value; + if (mNext >= value.Count) { + mNext = 0; + } + } + } + private List mBitmaps; + + /// + /// How long to wait before showing next bitmap. + /// + public int IntervalMsec { + get { return mIntervalMsec; } + set { + if (value < 1) { + throw new ArgumentException("Invalid interval " + value); + } + mIntervalMsec = value; + mTimer.Interval = TimeSpan.FromMilliseconds(value); + } + } + private int mIntervalMsec = 100; + + /// + /// True if the animation is currently running. + /// + public bool IsRunning { + get { return mTimer.IsEnabled; } + } + + /// + /// Index of next image to display. + /// + private int mNext; + + /// + /// Dispatcher-linked timer object. + /// + private DispatcherTimer mTimer; + + + /// + /// Constructor, invoked from XAML. + /// + public FrameAnimationControl() { + InitializeComponent(); + + mTimer = new DispatcherTimer(DispatcherPriority.Render); + mTimer.Interval = TimeSpan.FromMilliseconds(IntervalMsec); + mTimer.Tick += Tick; + } + + public void Start() { + mTimer.Start(); + } + + public void Stop() { + mTimer.Stop(); + } + + private void Tick(object sender, EventArgs e) { + if (mBitmaps == null) { + throw new InvalidOperationException("Must set bitmaps before starting"); + } + if (mNext >= mBitmaps.Count) { + mNext = 0; + } + theImage.Source = mBitmaps[mNext]; + mNext++; + } + } +} diff --git a/SourceGen/VisualizationAnimation.cs b/SourceGen/VisualizationAnimation.cs index 8f47b95..237a0ca 100644 --- a/SourceGen/VisualizationAnimation.cs +++ b/SourceGen/VisualizationAnimation.cs @@ -29,6 +29,16 @@ namespace SourceGen { /// view angles. /// public class VisualizationAnimation : Visualization { + /// + /// Frame delay parameter. + /// + public const string FRAME_DELAY_MSEC_PARAM = "frame-delay-msec"; + + /// + /// Fake visualization generation identifier. + /// + public const string ANIM_VIS_GEN = "(animation)"; + /// /// Serial numbers of visualizations, e.g. bitmap frames. /// @@ -60,5 +70,18 @@ namespace SourceGen { mSerialNumbers = visSerialNumbers; } + + /// + /// Returns true if this visualization holds a reference to the specified serial number. + /// + public bool ContainsSerial(int serial) { + // Linear search. We don't do this a lot and our lists our short, so okay for now. + foreach (int ser in mSerialNumbers) { + if (ser == serial) { + return true; + } + } + return false; + } } } diff --git a/SourceGen/WpfGui/EditBitmapAnimation.xaml b/SourceGen/WpfGui/EditBitmapAnimation.xaml index 96a50a2..44b8793 100644 --- a/SourceGen/WpfGui/EditBitmapAnimation.xaml +++ b/SourceGen/WpfGui/EditBitmapAnimation.xaml @@ -20,10 +20,12 @@ limitations under the License. xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SourceGen.WpfGui" + xmlns:common="clr-namespace:CommonWPF;assembly=CommonWPF" mc:Ignorable="d" Title="Edit Bitmap Animation" SizeToContent="WidthAndHeight" ResizeMode="NoResize" - ShowInTaskbar="False" WindowStartupLocation="CenterOwner"> + ShowInTaskbar="False" WindowStartupLocation="CenterOwner" + Closing="Window_Closing"> @@ -31,10 +33,23 @@ limitations under the License. + - - + + + + + + + + + + + + @@ -45,10 +60,10 @@ limitations under the License. - + - @@ -83,7 +99,7 @@ limitations under the License. - - -