committed by
GitHub
56 changed files with 65 additions and 169 deletions
@ -1,6 +0,0 @@ |
|||
namespace Avalonia.Platform.Storage; |
|||
|
|||
public class NameCollisionOption |
|||
{ |
|||
|
|||
} |
|||
@ -1,50 +0,0 @@ |
|||
using System; |
|||
using System.Diagnostics; |
|||
using System.Globalization; |
|||
using Avalonia.Media; |
|||
|
|||
namespace Avalonia.Rendering |
|||
{ |
|||
public class RendererBase |
|||
{ |
|||
private readonly bool _useManualFpsCounting; |
|||
private static int s_fontSize = 18; |
|||
private readonly Stopwatch _stopwatch = Stopwatch.StartNew(); |
|||
private int _framesThisSecond; |
|||
private int _fps; |
|||
private TimeSpan _lastFpsUpdate; |
|||
|
|||
public RendererBase(bool useManualFpsCounting = false) |
|||
{ |
|||
_useManualFpsCounting = useManualFpsCounting; |
|||
} |
|||
|
|||
protected void FpsTick() => _framesThisSecond++; |
|||
|
|||
protected void RenderFps(DrawingContext context, Rect clientRect, int? layerCount) |
|||
{ |
|||
var now = _stopwatch.Elapsed; |
|||
var elapsed = now - _lastFpsUpdate; |
|||
|
|||
if (!_useManualFpsCounting) |
|||
++_framesThisSecond; |
|||
|
|||
if (elapsed.TotalSeconds > 1) |
|||
{ |
|||
_fps = (int)(_framesThisSecond / elapsed.TotalSeconds); |
|||
_framesThisSecond = 0; |
|||
_lastFpsUpdate = now; |
|||
} |
|||
|
|||
var text = layerCount.HasValue ? FormattableString.Invariant($"Layers: {layerCount} FPS: {_fps:000}") : FormattableString.Invariant($"FPS: {_fps:000}"); |
|||
|
|||
var formattedText = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Typeface.Default, s_fontSize, Brushes.White); |
|||
|
|||
var rect = new Rect(clientRect.Right - formattedText.Width, 0, formattedText.Width, formattedText.Height); |
|||
|
|||
context.DrawRectangle(Brushes.Black, null, rect); |
|||
|
|||
context.DrawText(formattedText, rect.TopLeft); |
|||
} |
|||
} |
|||
} |
|||
@ -1,49 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Threading; |
|||
|
|||
namespace Avalonia.Utilities |
|||
{ |
|||
public class WeakTimer |
|||
{ |
|||
public interface IWeakTimerSubscriber |
|||
{ |
|||
bool Tick(); |
|||
} |
|||
|
|||
private readonly WeakReference<IWeakTimerSubscriber> _subscriber; |
|||
private DispatcherTimer _timer; |
|||
|
|||
public WeakTimer(IWeakTimerSubscriber subscriber) |
|||
{ |
|||
_subscriber = new WeakReference<IWeakTimerSubscriber>(subscriber); |
|||
_timer = new DispatcherTimer(); |
|||
|
|||
_timer.Tick += delegate { OnTick(); }; |
|||
} |
|||
|
|||
private void OnTick() |
|||
{ |
|||
if (!_subscriber.TryGetTarget(out var subscriber) || !subscriber.Tick()) |
|||
Stop(); |
|||
} |
|||
|
|||
public TimeSpan Interval |
|||
{ |
|||
get { return _timer.Interval; } |
|||
set { _timer.Interval = value; } |
|||
} |
|||
|
|||
public void Start() => _timer.Start(); |
|||
|
|||
public void Stop() => _timer.Stop(); |
|||
|
|||
|
|||
public static WeakTimer StartWeakTimer(IWeakTimerSubscriber subscriber, TimeSpan interval) |
|||
{ |
|||
var timer = new WeakTimer(subscriber) {Interval = interval}; |
|||
timer.Start(); |
|||
return timer; |
|||
} |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue