Skip to content

Commit f6eac34

Browse files
committed
Fix for #893. HeliosVisualRenderer had old code to RenderToBitmap the image, however this is not needed and should have been replaced by a DrawRectangle using a VisualBrush instead.
1 parent aa39d5a commit f6eac34

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

Aircraft AH-64D Plugin/Gauges/IAS/IAS.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ namespace GadrocsWorkshop.Helios.Gauges.AH64D
2424
[HeliosControl("Helios.AH64D.IAS", "Standby IAS Gauge", "AH-64D", typeof(GaugeRenderer),HeliosControlFlags.NotShownInUI)]
2525
public class IAS : BaseGauge
2626
{
27-
private HeliosValue _indicatedAirSpeed;
28-
private GaugeNeedle _needle;
29-
private CalibrationPointCollectionDouble _needleCalibration;
27+
private readonly HeliosValue _indicatedAirSpeed;
28+
private readonly GaugeNeedle _needle;
29+
private readonly CalibrationPointCollectionDouble _needleCalibration;
3030

3131
public IAS()
3232
: base("Standby IAS Gauge", new Size(300, 300))

Helios/Controls/CustomGaugeRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CustomGaugeRenderer : HeliosVisualRenderer
2525
private Rect _imageRect, _backgroundRect;
2626
private Point _center, _nextToCenter;
2727
private double _rotation;
28-
private readonly Brush _scopeBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
28+
private readonly Brush _scopeBrush = new SolidColorBrush(Color.FromRgb(127, 0, 0));
2929
private readonly Pen _scopePen;
3030
private CustomGauge _gauge;
3131

Helios/Gauges/GaugeNeedle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public double VerticalOffset
133133

134134
#endregion
135135

136-
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
136+
protected override void OnRender(DrawingContext drawingContext)
137137
{
138138
TransformGroup transform = new TransformGroup();
139139
transform.Children.Add(new TranslateTransform((-_center.X + HorizontalOffset) * _xScale, (-_center.Y + VerticalOffset) * _yScale));

Helios/HeliosVisualRenderer.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ private void CheckRefresh()
120120

121121
protected virtual void OnRender(DrawingContext drawingContext, double scaleX, double scaleY)
122122
{
123-
drawingContext.PushTransform(new ScaleTransform(scaleX, scaleY));
123+
if (scaleX != 1d || scaleY != 1d)
124+
{
125+
drawingContext.PushTransform(new ScaleTransform(scaleX, scaleY));
126+
}
124127
OnRender(drawingContext);
125-
drawingContext.Pop();
128+
if (scaleX != 1d || scaleY != 1d)
129+
{
130+
drawingContext.Pop();
131+
}
126132
}
127133

128134

@@ -152,7 +158,7 @@ private void UpdateTransform()
152158
/// <param name="drawingContext"></param>
153159
/// <param name="image"></param>
154160
/// <param name="imageRectangle"></param>
155-
private void RenderEffect(DrawingContext drawingContext, ImageSource image, Rect imageRectangle)
161+
private void RenderEffect(DrawingContext drawingContext, DrawingVisual image, Rect imageRectangle)
156162
{
157163
// ShaderEffect can be deleted in Profile Editor so we always need to get it from ProfileManager
158164
if (!_designTimeChecked)
@@ -174,19 +180,12 @@ private void RenderEffect(DrawingContext drawingContext, ImageSource image, Rect
174180
_effect = ConfigManager.ProfileManager.CurrentEffect as Effects.ColorAdjustEffect;
175181
}
176182

177-
System.Windows.Controls.Image imageControl = new System.Windows.Controls.Image
178-
{
179-
Source = image,
180-
Width = image != null ? image.Width : 0,
181-
Height = image != null ? image.Width : 0,
182-
183-
};
184183
if (!Visual.EffectsExclusion)
185184
{
186-
imageControl.Effect = _effect;
185+
image.Effect = _effect;
187186
}
188-
VisualBrush visualBrush = new VisualBrush(imageControl);
189-
drawingContext.DrawRectangle(visualBrush, null, imageRectangle);
187+
188+
drawingContext.DrawRectangle(new VisualBrush(image), null, imageRectangle);
190189
}
191190

192191
/// <summary>
@@ -197,16 +196,12 @@ private void RenderEffect(DrawingContext drawingContext, ImageSource image, Rect
197196
/// <param name="rectangle"></param>
198197
protected void RenderVisual(DrawingContext drawingContext, DrawingVisual visual, Rect rectangle)
199198
{
200-
if(visual.ContentBounds.IsEmpty || rectangle.Width == 0 || rectangle.Height == 0) { return; }
201-
RenderTargetBitmap rtb = new RenderTargetBitmap(Convert.ToInt32(rectangle.Width), Convert.ToInt32(rectangle.Height), 96, 96, PixelFormats.Pbgra32);
202-
rtb.Render(visual);
203-
//drawingContext.DrawImage(rtb, rectangle);
204-
RenderEffect(drawingContext, rtb, rectangle);
205-
206-
// Address MILERR_WIN32ERROR (Exception from HRESULT: 0x88980003 in PresentationCore
207-
(rtb.GetType().GetField("_renderTargetBitmap", BindingFlags.Instance | BindingFlags.NonPublic)?
208-
.GetValue(rtb) as IDisposable)?.Dispose(); // from https://github.com/dotnet/wpf/issues/3067
199+
if(visual.ContentBounds.IsEmpty || rectangle.Width == 0 || rectangle.Height == 0)
200+
{
201+
return;
202+
}
209203

204+
RenderEffect(drawingContext, visual, rectangle);
210205
}
211206

212207
#region Draw Proxies

0 commit comments

Comments
 (0)