1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-26 06:49:19 +00:00

Render the animation overlay image instead of loading from a file

Mostly because I'm a lousy artist, and if I do it in code it's easy
to make it symmetric and tweak the colors.
This commit is contained in:
Andy McFadden 2019-12-22 13:15:13 -08:00
parent 12293d3cf8
commit 4e645d911c
6 changed files with 50 additions and 13 deletions

Binary file not shown.

View File

@ -103,6 +103,14 @@ namespace SourceGen {
/// <summary>
/// Visualization sets. Uses file offset as key.
/// </summary>
/// <remarks>
/// TODO(maybe): certain operations must be performed on the set of all visualizations
/// or the set of all animations, requiring a double "foreach" with an "is" clause.
/// It might be simpler and more efficient overall to split this into three lists: one
/// for visualizations (perhaps keyed by serial number), one for animations, and one
/// for VisualizationSet objects (the latter required to establish ordering). The
/// primary argument against is that this makes undo/redo more complicated.
/// </remarks>
public SortedList<int, VisualizationSet> VisualizationSets { get; private set; }
/// <summary>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 B

View File

@ -430,8 +430,5 @@
<ItemGroup>
<Resource Include="Res\RedX.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Res\BlueChevron.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -77,7 +77,7 @@ namespace SourceGen {
/// </summary>
public bool HasImage {
get {
return CachedImage != BROKEN_IMAGE && CachedImage != ANIM_IMAGE;
return CachedImage != BROKEN_IMAGE && CachedImage != ANIM_OVERLAY_IMAGE;
}
}
@ -87,8 +87,11 @@ namespace SourceGen {
public static readonly BitmapImage BROKEN_IMAGE =
new BitmapImage(new Uri("pack://application:,,,/Res/RedX.png"));
internal static readonly BitmapImage ANIM_IMAGE =
new BitmapImage(new Uri("pack://application:,,,/Res/BlueChevron.png"));
/// <summary>
/// Image to overlay on animation visualizations.
/// </summary>
internal static readonly BitmapSource ANIM_OVERLAY_IMAGE =
VisualizationAnimation.GenerateAnimOverlayImage();
/// <summary>
/// Serial number, for reference from other Visualization objects. Not serialized.

View File

@ -80,7 +80,7 @@ namespace SourceGen {
mSerialNumbers.Add(serial);
}
CachedImage = ANIM_IMAGE; // default to this
CachedImage = ANIM_OVERLAY_IMAGE; // default to this
}
/// <summary>
@ -93,7 +93,7 @@ namespace SourceGen {
public void GenerateImage(SortedList<int, VisualizationSet> visSets) {
const int IMAGE_SIZE = 64;
CachedImage = ANIM_IMAGE;
CachedImage = ANIM_OVERLAY_IMAGE;
if (mSerialNumbers.Count == 0) {
return;
@ -113,16 +113,16 @@ namespace SourceGen {
DrawingVisual visual = new DrawingVisual();
//RenderOptions.SetBitmapScalingMode(visual, BitmapScalingMode.NearestNeighbor);
DrawingContext dc = visual.RenderOpen();
dc.DrawImage(vis.CachedImage, imgBounds);
dc.DrawImage(ANIM_IMAGE, new Rect(0, 0, IMAGE_SIZE, IMAGE_SIZE));
dc.Close();
using (DrawingContext dc = visual.RenderOpen()) {
dc.DrawImage(vis.CachedImage, imgBounds);
dc.DrawImage(ANIM_OVERLAY_IMAGE, new Rect(0, 0, IMAGE_SIZE, IMAGE_SIZE));
}
RenderTargetBitmap bmp = new RenderTargetBitmap(IMAGE_SIZE, IMAGE_SIZE, 96.0, 96.0,
PixelFormats.Pbgra32);
bmp.Render(visual);
CachedImage = bmp;
Debug.WriteLine("RENDERED " + Tag);
//Debug.WriteLine("RENDERED " + Tag);
}
/// <summary>
@ -176,6 +176,35 @@ namespace SourceGen {
return somethingRemoved;
}
public static BitmapSource GenerateAnimOverlayImage() {
const int IMAGE_SIZE = 128;
// Glowy "high tech" blue.
SolidColorBrush outlineBrush = new SolidColorBrush(Color.FromArgb(255, 0, 216, 255));
SolidColorBrush fillBrush = new SolidColorBrush(Color.FromArgb(128, 0, 182, 215));
DrawingVisual visual = new DrawingVisual();
using (DrawingContext dc = visual.RenderOpen()) {
// Thanks: https://stackoverflow.com/a/29249100/294248
Point p1 = new Point(IMAGE_SIZE * 5 / 8, IMAGE_SIZE / 2);
Point p2 = new Point(IMAGE_SIZE * 3 / 8, IMAGE_SIZE / 4);
Point p3 = new Point(IMAGE_SIZE * 3 / 8, IMAGE_SIZE * 3 / 4);
StreamGeometry sg = new StreamGeometry();
using (StreamGeometryContext sgc = sg.Open()) {
sgc.BeginFigure(p1, true, true);
PointCollection points = new PointCollection() { p2, p3 };
sgc.PolyLineTo(points, true, true);
}
sg.Freeze();
dc.DrawGeometry(fillBrush, new Pen(outlineBrush, 3), sg);
}
RenderTargetBitmap bmp = new RenderTargetBitmap(IMAGE_SIZE, IMAGE_SIZE, 96.0, 96.0,
PixelFormats.Pbgra32);
bmp.Render(visual);
return bmp;
}
public static bool operator ==(VisualizationAnimation a, VisualizationAnimation b) {
if (ReferenceEquals(a, b)) {