From 4e645d911cd4ced94bfda13c121262907e8f72b9 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sun, 22 Dec 2019 13:15:13 -0800 Subject: [PATCH] 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. --- ImageSrc/BlueChevron.xcf | Bin 2421 -> 0 bytes SourceGen/DisasmProject.cs | 8 ++++++ SourceGen/Res/BlueChevron.png | Bin 376 -> 0 bytes SourceGen/SourceGen.csproj | 3 -- SourceGen/Visualization.cs | 9 ++++-- SourceGen/VisualizationAnimation.cs | 43 +++++++++++++++++++++++----- 6 files changed, 50 insertions(+), 13 deletions(-) delete mode 100644 ImageSrc/BlueChevron.xcf delete mode 100644 SourceGen/Res/BlueChevron.png diff --git a/ImageSrc/BlueChevron.xcf b/ImageSrc/BlueChevron.xcf deleted file mode 100644 index c1732ab4f7bf7663c37ebcb33fdfcd70d56ea9e3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2421 zcmeHF%SyvQ6rIH2qg8x&?7JlR5GH-W`8(I{cwluQNnLg7^!t3>XHMRbciE5&^LWSbzzX zB&WW0^q(Uyc-Xq?guR{{B&ZoZTsezeJ8|3m(NAvp`NicGJy{a1e$V#Ysu%ff($HfJDwAE!-$tfsz%XaXrO@b8d}lj; z;PK-l`3i{r-$bcZ?*l*Ke&F1=G0lgaPV6Sb1Jd+QDN{yA=^nH&-n2r|1_*&}w|Hth zw_X(92jU9J8H#CuoJxUB;wR5o;U+*jjm}Aq#I`iPq49#oxyFkcpV#<;#uvfqeJW-^ z=-sscuH;B;hj@xW-qyJOw?S56zAJ{@kf41L=4Y10+Q3Rcm|t0DY+!savo+7m(gB-l z71>m2U*^2FS_NiJfIfQuiu{fW%g&$IS>L$n>fZOI9|PkxbEgS+DsZC-cPi)-Ij^lI z+?fD<^!#u`d /// Visualization sets. Uses file offset as key. /// + /// + /// 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. + /// public SortedList VisualizationSets { get; private set; } /// diff --git a/SourceGen/Res/BlueChevron.png b/SourceGen/Res/BlueChevron.png deleted file mode 100644 index 4c41364d83fa9e9f002f84488c3f0446e4c6cb96..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 376 zcmV-;0f+vHP)HK~#9!?V7O_gFp;JF+*gC?2#_xrpq1~B1@1eFFalv;A~4zQbhxW ztbg43JWZBmS(YWMIP>!Twk+T0$1`?+>vH|Q|9(Yu7%-3e(Atb6TAM*>fFuI{D!&(n zZRM*`7@hz&6iyp(Wbx~)_;3W+QAk?^Sx^{e04oZSU3qjA()R)AC=54%4TY$xJSqxh zTVYfb(hOihA*w5nhC=yi5DkTN1JF^3uF9jJ(AE$^L7~h5R1~7S^4%!3_XN99C^rBN zg+Qr%7Yg!iao-Cl$KPiG1O&SO3ZWYP@&w3rgjhC2p&I?N1jyYB_$)vY{qzLL-43%w zKNSI{8)DB0sYX8q0meBYPl~EWe<%XX)1tF#^wSWKnh|0jlx}T^ph$jF)UqtgQq~8w WQ~+h|c!Br;0000 - - - \ No newline at end of file diff --git a/SourceGen/Visualization.cs b/SourceGen/Visualization.cs index c6c85db..b2280c5 100644 --- a/SourceGen/Visualization.cs +++ b/SourceGen/Visualization.cs @@ -77,7 +77,7 @@ namespace SourceGen { /// 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")); + /// + /// Image to overlay on animation visualizations. + /// + internal static readonly BitmapSource ANIM_OVERLAY_IMAGE = + VisualizationAnimation.GenerateAnimOverlayImage(); /// /// Serial number, for reference from other Visualization objects. Not serialized. diff --git a/SourceGen/VisualizationAnimation.cs b/SourceGen/VisualizationAnimation.cs index 1d68383..c0740ea 100644 --- a/SourceGen/VisualizationAnimation.cs +++ b/SourceGen/VisualizationAnimation.cs @@ -80,7 +80,7 @@ namespace SourceGen { mSerialNumbers.Add(serial); } - CachedImage = ANIM_IMAGE; // default to this + CachedImage = ANIM_OVERLAY_IMAGE; // default to this } /// @@ -93,7 +93,7 @@ namespace SourceGen { public void GenerateImage(SortedList 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); } /// @@ -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)) {