Skip to content

Commit 917f089

Browse files
authored
Added DynamicRefreshRateSample (microsoft#256)
1 parent 50ddb41 commit 917f089

39 files changed

+1964
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.vs/
2+
3+
Debug/
4+
Release/
5+
6+
x64/
7+
8+
packages/
9+
10+
Generated Files/
11+
12+
AppPackages/
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
#include "pch.h"
16+
#include "AnimationPage.h"
17+
#if __has_include("AnimationPage.g.cpp")
18+
#include "AnimationPage.g.cpp"
19+
#endif
20+
21+
using namespace winrt;
22+
using namespace Microsoft::UI::Xaml;
23+
using namespace Microsoft::UI::Xaml::Controls::Primitives;
24+
25+
namespace winrt::DynamicRefreshRateTool::implementation
26+
{
27+
const float DEFAULT_ROTATION_SPEED = 3600;
28+
29+
AnimationPage::AnimationPage()
30+
{
31+
InitializeComponent();
32+
myStoryBoard().Begin();
33+
}
34+
35+
void AnimationPage::Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
36+
{
37+
auto buttonClicked = sender.try_as<ToggleButton>();
38+
39+
for (auto button : { Button1(), Button2(), Button3() }) {
40+
if ((buttonClicked == button) != button.IsChecked().GetBoolean()) {
41+
button.OnToggle();
42+
}
43+
}
44+
45+
if (Button1().IsChecked().GetBoolean()) {
46+
RotationAnimation().To(DEFAULT_ROTATION_SPEED / 2);
47+
}
48+
49+
if (Button2().IsChecked().GetBoolean()) {
50+
RotationAnimation().To(DEFAULT_ROTATION_SPEED);
51+
}
52+
53+
if (Button3().IsChecked().GetBoolean()) {
54+
RotationAnimation().To(DEFAULT_ROTATION_SPEED * 2);
55+
}
56+
}
57+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
#pragma once
16+
17+
#include "AnimationPage.g.h"
18+
19+
namespace winrt::DynamicRefreshRateTool::implementation
20+
{
21+
struct AnimationPage : AnimationPageT<AnimationPage>
22+
{
23+
AnimationPage();
24+
25+
void Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
26+
};
27+
}
28+
29+
namespace winrt::DynamicRefreshRateTool::factory_implementation
30+
{
31+
struct AnimationPage : AnimationPageT<AnimationPage, implementation::AnimationPage>
32+
{
33+
};
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
namespace DynamicRefreshRateTool
16+
{
17+
[default_interface]
18+
runtimeclass AnimationPage : Microsoft.UI.Xaml.Controls.Page
19+
{
20+
AnimationPage();
21+
}
22+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<Page
2+
x:Class="DynamicRefreshRateTool.AnimationPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:DynamicRefreshRateTool"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
9+
mc:Ignorable="d">
10+
11+
<Grid Background="{ThemeResource ForegroundBrush}">
12+
<Grid.Clip>
13+
<RectangleGeometry Rect="0,0,9999,9999" />
14+
</Grid.Clip>
15+
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5">
16+
<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
17+
<Ellipse.RenderTransform>
18+
<CompositeTransform TranslateX="150"/>
19+
</Ellipse.RenderTransform>
20+
</Ellipse>
21+
22+
<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
23+
<Ellipse.RenderTransform>
24+
<CompositeTransform TranslateY="150"/>
25+
</Ellipse.RenderTransform>
26+
</Ellipse>
27+
28+
<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
29+
<Ellipse.RenderTransform>
30+
<CompositeTransform TranslateX="-150"/>
31+
</Ellipse.RenderTransform>
32+
</Ellipse>
33+
34+
<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
35+
<Ellipse.RenderTransform>
36+
<CompositeTransform TranslateY="-150"/>
37+
</Ellipse.RenderTransform>
38+
</Ellipse>
39+
40+
<Grid.RenderTransform>
41+
<CompositeTransform x:Name="globalTrnsform"/>
42+
</Grid.RenderTransform>
43+
</Grid>
44+
45+
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
46+
<ToggleButton Margin="10" Name="Button1" Click="Button_Click">x0.5 Speed</ToggleButton>
47+
<ToggleButton Margin="10" Name="Button2" Click="Button_Click" IsChecked="True">x1 Speed</ToggleButton>
48+
<ToggleButton Margin="10" Name="Button3" Click="Button_Click">x2 Speed</ToggleButton>
49+
</StackPanel>
50+
51+
52+
<Grid.Resources>
53+
<Storyboard x:Name="myStoryBoard">
54+
<DoubleAnimation Storyboard.TargetName="globalTrnsform"
55+
Storyboard.TargetProperty="Rotation"
56+
From="0.0"
57+
To="3600.0"
58+
Duration="0:0:6.66666"
59+
RepeatBehavior="Forever"
60+
x:Name="RotationAnimation"/>
61+
</Storyboard>
62+
</Grid.Resources>
63+
</Grid>
64+
</Page>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
namespace DynamicRefreshRateTool
16+
{
17+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Application
2+
x:Class="DynamicRefreshRateTool.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:DynamicRefreshRateTool">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
9+
<ResourceDictionary.MergedDictionaries>
10+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
11+
</ResourceDictionary.MergedDictionaries>
12+
13+
<ResourceDictionary.ThemeDictionaries>
14+
<ResourceDictionary x:Key="Light">
15+
<SolidColorBrush x:Key="BackgroundBrush" Color="#F0F0F0"/>
16+
<SolidColorBrush x:Key="BackgroundBrush2" Color="#F6F6F6"/>
17+
<SolidColorBrush x:Key="ForegroundBrush" Color="#FDFDFD"/>
18+
<SolidColorBrush x:Key="BorderBrush" Color="#E5E5E5"/>
19+
<SolidColorBrush x:Key="ChartMain" Color="{ThemeResource SystemAccentColor}"/>
20+
<SolidColorBrush x:Key="ChartDash" Color="{ThemeResource SystemAccentColorLight1}"/>
21+
<SolidColorBrush x:Key="ChartFill" Color="{ThemeResource SystemAccentColorLight3}"/>
22+
<StaticResource x:Key="ControlExampleDisplayBrush" ResourceKey="SolidBackgroundFillColorBaseBrush" />
23+
24+
<SolidColorBrush x:Key="WindowCaptionBackground">#20A0A0A0</SolidColorBrush>
25+
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled">#20A0A0A0</SolidColorBrush>
26+
</ResourceDictionary>
27+
28+
<ResourceDictionary x:Key="Dark">
29+
<SolidColorBrush x:Key="BackgroundBrush" Color="#202020"/>
30+
<SolidColorBrush x:Key="BackgroundBrush2" Color="#262626"/>
31+
<SolidColorBrush x:Key="ForegroundBrush" Color="#2B2B2B"/>
32+
<SolidColorBrush x:Key="BorderBrush" Color="#1A1A1A"/>
33+
<SolidColorBrush x:Key="ChartMain" Color="{ThemeResource SystemAccentColor}"/>
34+
<SolidColorBrush x:Key="ChartDash" Color="{ThemeResource SystemAccentColorDark1}"/>
35+
<SolidColorBrush x:Key="ChartFill" Color="{ThemeResource SystemAccentColorDark3}"/>
36+
<StaticResource x:Key="ControlExampleDisplayBrush" ResourceKey="SolidBackgroundFillColorBaseBrush" />
37+
</ResourceDictionary>
38+
</ResourceDictionary.ThemeDictionaries>
39+
</ResourceDictionary>
40+
41+
</Application.Resources>
42+
</Application>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
#include "pch.h"
16+
17+
#include "App.xaml.h"
18+
#include "MainWindow.xaml.h"
19+
20+
using namespace winrt;
21+
using namespace Windows::Foundation;
22+
using namespace Microsoft::UI::Xaml;
23+
using namespace Microsoft::UI::Xaml::Controls;
24+
using namespace Microsoft::UI::Xaml::Navigation;
25+
using namespace DynamicRefreshRateTool;
26+
using namespace DynamicRefreshRateTool::implementation;
27+
using namespace Windows::UI::ViewManagement;
28+
29+
/// <summary>
30+
/// Initializes the singleton application object. This is the first line of authored code
31+
/// executed, and as such is the logical equivalent of main() or WinMain().
32+
/// </summary>
33+
App::App()
34+
{
35+
InitializeComponent();
36+
37+
#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
38+
UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
39+
{
40+
if (IsDebuggerPresent())
41+
{
42+
auto errorMessage = e.Message();
43+
__debugbreak();
44+
}
45+
});
46+
#endif
47+
}
48+
49+
/// <summary>
50+
/// Invoked when the application is launched normally by the end user. Other entry points
51+
/// will be used such as when the application is launched to open a specific file.
52+
/// </summary>
53+
/// <param name="e">Details about the launch request and process.</param>
54+
void App::OnLaunched(LaunchActivatedEventArgs const&)
55+
{
56+
window = make<MainWindow>();
57+
58+
// Set default window size on startup
59+
HWND hwnd{ nullptr };
60+
window.try_as<IWindowNative>()->get_WindowHandle(&hwnd);
61+
auto winid = winrt::Microsoft::UI::GetWindowIdFromWindow(hwnd);
62+
auto appWindow = winrt::Microsoft::UI::Windowing::AppWindow::GetFromWindowId(winid);
63+
double scale = GetDpiForWindow(hwnd) / 96.0;
64+
appWindow.Resize({ static_cast<int>(800 * scale), static_cast<int>(600 * scale) });
65+
66+
window.Activate();
67+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
#pragma once
16+
17+
#include "App.xaml.g.h"
18+
19+
namespace winrt::DynamicRefreshRateTool::implementation
20+
{
21+
struct App : AppT<App>
22+
{
23+
App();
24+
25+
void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);
26+
27+
private:
28+
winrt::Microsoft::UI::Xaml::Window window{ nullptr };
29+
};
30+
}
3.46 KB
Loading

0 commit comments

Comments
 (0)