1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-12 08:29:29 +00:00
6502bench/SourceGen/VisualizationAnimation.cs
Andy McFadden fef7668b63 Progress on animated visualizations
Visualization editor dialog is fully functional.  Add/remove,
up/down, tag/interval timer editing, and animated preview are now
working.
2019-12-20 15:09:57 -08:00

88 lines
3.4 KiB
C#

/*
* 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.Collections.ObjectModel;
using System.Diagnostics;
using System.Text;
namespace SourceGen {
/// <summary>
/// A visualization with animated contents.
/// </summary>
/// <remarks>
/// References to Visualization objects (such as a 3D mesh or list of bitmaps) are held
/// here. The VisGenParams property holds animation properties, such as frame rate and
/// view angles.
/// </remarks>
public class VisualizationAnimation : Visualization {
/// <summary>
/// Frame delay parameter.
/// </summary>
public const string FRAME_DELAY_MSEC_PARAM = "frame-delay-msec";
/// <summary>
/// Fake visualization generation identifier.
/// </summary>
public const string ANIM_VIS_GEN = "(animation)";
/// <summary>
/// Serial numbers of visualizations, e.g. bitmap frames.
/// </summary>
/// <remarks>
/// We don't reference the Visualization objects directly because they might get
/// edited (e.g. the tag gets renamed), which replaces them with a new object with
/// the same serial number. We don't do things like renames in place because that
/// makes undo/redo harder.
///
/// (We could reference the Visualization objects and then do a serial number lookup
/// before using it. Some opportunities for optimization should the need arise. This
/// might also allow us to avoid exposing the serial number as a public property, though
/// there's not much advantage to that.)
/// </remarks>
private List<int> mSerialNumbers;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="tag">Unique identifier.</param>
/// <param name="visGenIdent">Visualization generator identifier.</param>
/// <param name="visGenParams">Parameters for visualization generator.</param>
/// <param name="visSerialNumbers">Serial numbers of referenced Visualizations.</param>
public VisualizationAnimation(string tag, string visGenIdent,
ReadOnlyDictionary<string, object> visGenParams, List<int> visSerialNumbers)
: base(tag, visGenIdent, visGenParams) {
Debug.Assert(visSerialNumbers != null);
mSerialNumbers = visSerialNumbers;
}
/// <summary>
/// Returns true if this visualization holds a reference to the specified serial number.
/// </summary>
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;
}
}
}