-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
382 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="WpfApp1.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:WpfApp1" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Windows; | ||
|
||
namespace WpfApp1; | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Window x:Class="WpfApp1.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:WpfApp1" | ||
mc:Ignorable="d" | ||
Title="MainWindow" Height="450" Width="800"> | ||
<Grid> | ||
<TextBlock Name="textBlock" HorizontalAlignment="Left" Margin="108,131,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="50" Width="292"/> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using R3; | ||
using R3.WPF; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
using System.Windows.Threading; | ||
|
||
namespace WpfApp1; | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
|
||
|
||
//Dispatcher.Yield(DispatcherPriority.Input); | ||
|
||
|
||
|
||
R3.WPF.WpfProviderInitializer.SetDefaultProviders(); | ||
|
||
|
||
|
||
|
||
//var sw = Stopwatch.StartNew(); | ||
//Observable.Timer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5)).Subscribe(_ => | ||
//{ | ||
// textBlock.Text = "Hello World:" + sw.Elapsed; | ||
//}); | ||
|
||
Observable.TimerFrame(50, 100).Subscribe(_ => | ||
{ | ||
textBlock.Text = "Hello World:" + ObservableSystem.DefaultFrameProvider.GetFrameCount(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\R3.WPF\R3.WPF.csproj" /> | ||
<ProjectReference Include="..\..\src\R3\R3.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System.Windows.Threading; | ||
|
||
namespace R3.WPF; | ||
|
||
public sealed class WpfDispatcherTimerProvider : TimeProvider | ||
{ | ||
readonly DispatcherPriority? priority; | ||
readonly Dispatcher? dispatcher; | ||
|
||
public WpfDispatcherTimerProvider() | ||
{ | ||
this.priority = null; | ||
this.dispatcher = null; | ||
} | ||
|
||
public WpfDispatcherTimerProvider(DispatcherPriority priority) | ||
{ | ||
this.priority = priority; | ||
this.dispatcher = null; | ||
} | ||
|
||
public WpfDispatcherTimerProvider(DispatcherPriority priority, Dispatcher dispatcher) | ||
{ | ||
this.priority = priority; | ||
this.dispatcher = dispatcher; | ||
} | ||
|
||
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period) | ||
{ | ||
return new WpfDispatcherTimerProviderTimer(priority, dispatcher, callback, state, dueTime, period); | ||
} | ||
} | ||
|
||
internal sealed class WpfDispatcherTimerProviderTimer : ITimer | ||
{ | ||
DispatcherTimer? timer; | ||
TimerCallback callback; | ||
object? state; | ||
EventHandler timerTick; | ||
TimeSpan? period; | ||
|
||
public WpfDispatcherTimerProviderTimer(DispatcherPriority? priority, Dispatcher? dispatcher, TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period) | ||
{ | ||
this.timerTick = Timer_Tick; | ||
this.callback = callback; | ||
this.state = state; | ||
if (priority == null && dispatcher == null) | ||
{ | ||
this.timer = new DispatcherTimer(); | ||
} | ||
if (dispatcher == null) // priority is not null | ||
{ | ||
this.timer = new DispatcherTimer(priority!.Value); | ||
} | ||
else | ||
{ | ||
this.timer = new DispatcherTimer(priority!.Value, dispatcher); | ||
} | ||
|
||
timer.Tick += timerTick; | ||
|
||
if (dueTime != Timeout.InfiniteTimeSpan) | ||
{ | ||
Change(dueTime, period); | ||
} | ||
} | ||
|
||
public bool Change(TimeSpan dueTime, TimeSpan period) | ||
{ | ||
if (timer != null) | ||
{ | ||
timer.Stop(); | ||
|
||
this.period = period; | ||
timer.Interval = dueTime; | ||
|
||
timer.Start(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void Timer_Tick(object? sender, EventArgs e) | ||
{ | ||
callback(state); | ||
|
||
if (timer != null && period != null) | ||
{ | ||
timer.Stop(); | ||
|
||
if (period.Value == Timeout.InfiniteTimeSpan) | ||
{ | ||
period = null; | ||
} | ||
else | ||
{ | ||
timer.Interval = period.Value; | ||
period = null; | ||
timer.Start(); | ||
} | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (timer != null) | ||
{ | ||
timer.Stop(); | ||
timer.Tick -= timerTick; | ||
timer = null; | ||
} | ||
} | ||
|
||
public ValueTask DisposeAsync() | ||
{ | ||
Dispose(); | ||
return default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Windows.Threading; | ||
|
||
namespace R3.WPF; | ||
|
||
public static class WpfProviderInitializer | ||
{ | ||
public static void SetDefaultProviders() | ||
{ | ||
ObservableSystem.DefaultTimeProvider = new WpfDispatcherTimerProvider(); | ||
ObservableSystem.DefaultFrameProvider = new WpfRenderingFrameProvider(); | ||
} | ||
|
||
public static void SetDefaultProviders(DispatcherPriority priority) | ||
{ | ||
ObservableSystem.DefaultTimeProvider = new WpfDispatcherTimerProvider(priority); | ||
ObservableSystem.DefaultFrameProvider = new WpfRenderingFrameProvider(); | ||
} | ||
|
||
public static void SetDefaultProviders(DispatcherPriority priority, Dispatcher dispatcher) | ||
{ | ||
ObservableSystem.DefaultTimeProvider = new WpfDispatcherTimerProvider(priority, dispatcher); | ||
ObservableSystem.DefaultFrameProvider = new WpfRenderingFrameProvider(); | ||
} | ||
} |
Oops, something went wrong.